diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index 8445003439..909b1ac602 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -51,6 +51,9 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string] // Process each individual contract requested binding contracts := make(map[string]*tmplContract) + // Map used to flag each encountered library as such + isLib := make(map[string]struct{}) + for i := 0; i < len(types); i++ { // Parse the actual ABI to generate the binding for evmABI, err := abi.JSON(strings.NewReader(abis[i])) @@ -146,6 +149,13 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string] Libraries: make(map[string]string), Structs: structs, } + + // check if that type has already been identified as a library + _, ok := isLib[types[i]] + contracts[types[i]].Library = ok + + // function 4-byte signatures are stored in the same sequence + // as types, if available. if len(fsigs) > i { contracts[types[i]].FuncSigs = fsigs[i] } @@ -157,6 +167,10 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string] } if matched { contracts[types[i]].Libraries[pattern] = name + // keep track that this type is a library + if _, ok := isLib[name]; !ok { + isLib[name] = struct{}{} + } } } } diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index 70f3f9c9f5..229e56cab8 100644 --- a/accounts/abi/bind/template.go +++ b/accounts/abi/bind/template.go @@ -37,6 +37,7 @@ type tmplContract struct { Events map[string]*tmplEvent // Contract events accessors Libraries map[string]string // Same as tmplData, but filtered to only keep what the contract needs Structs map[string]*tmplStruct // Contract struct type definitions + Library bool } // tmplMethod is a wrapper around an abi.Method that contains a few preprocessed @@ -509,7 +510,7 @@ import java.util.*; {{range $contract := .Contracts}} {{$structs := $contract.Structs}} -public class {{.Type}} { +{{if not .Library}}public {{end}}class {{.Type}} { // ABI is the input ABI used to generate the binding from. public final static String ABI = "{{.InputABI}}"; {{if $contract.FuncSigs}} @@ -536,7 +537,7 @@ public class {{.Type}} { // "link" contract to dependent libraries by deploying them first. {{range $pattern, $name := .Libraries}} {{capitalise $name}} {{decapitalise $name}}Inst = {{capitalise $name}}.deploy(auth, client); - bytecode.replace("__${{$pattern}}$__", {{decapitalise $name}}Inst.Address); + bytecode.replace("__${{$pattern}}$__", {{decapitalise $name}}Inst.Address.getHex().substring(2)); {{end}} {{end}} {{range $index, $element := .Constructor.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type $structs) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});