diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index 909b1ac602..e1be79c9f4 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -141,7 +141,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string] contracts[types[i]] = &tmplContract{ Type: capitalise(types[i]), InputABI: strings.Replace(strippedABI, "\"", "\\\"", -1), - InputBin: strings.TrimSpace(bytecodes[i]), + InputBin: strings.TrimPrefix(strings.TrimSpace(bytecodes[i]), "0x"), Constructor: evmABI.Constructor, Calls: calls, Transacts: transacts, @@ -149,17 +149,12 @@ 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 + // Function 4-byte signatures are stored in the same sequence // as types, if available. if len(fsigs) > i { contracts[types[i]].FuncSigs = fsigs[i] } - + // Parse library references. for pattern, name := range libs { matched, err := regexp.Match("__\\$"+pattern+"\\$__", []byte(contracts[types[i]].InputBin)) if err != nil { @@ -174,6 +169,11 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string] } } } + // Check if that type has already been identified as a library + for i := 0; i < len(types); i++ { + _, ok := isLib[types[i]] + contracts[types[i]].Library = ok + } // Generate the contract template data content and render it data := &tmplData{ Package: pkg, diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index 229e56cab8..3683a1eb4f 100644 --- a/accounts/abi/bind/template.go +++ b/accounts/abi/bind/template.go @@ -116,15 +116,14 @@ var ( {{if $contract.FuncSigs}} // {{.Type}}FuncSigs maps the 4-byte function signature to its string representation. var {{.Type}}FuncSigs = map[string]string{ - {{range $strsig, $binsig := .FuncSigs}} - "{{$binsig}}": "{{$strsig}}", + {{range $strsig, $binsig := .FuncSigs}}"{{$binsig}}": "{{$strsig}}", {{end}} } {{end}} {{if .InputBin}} // {{.Type}}Bin is the compiled bytecode used for deploying new contracts. - var {{.Type}}Bin = ` + "`" + `{{.InputBin}}` + "`" + ` + var {{.Type}}Bin = "0x{{.InputBin}}" // Deploy{{.Type}} deploys a new Ethereum contract, binding an instance of {{.Type}} to it. func Deploy{{.Type}}(auth *bind.TransactOpts, backend bind.ContractBackend {{range .Constructor.Inputs}}, {{.Name}} {{bindtype .Type $structs}}{{end}}) (common.Address, *types.Transaction, *{{.Type}}, error) { @@ -518,8 +517,7 @@ import java.util.*; public final static Map {{.Type}}FuncSigs; static { Hashtable temp = new Hashtable(); - {{range $strsig, $binsig := .FuncSigs}} - temp.put("{{$binsig}}", "{{$strsig}}"); + {{range $strsig, $binsig := .FuncSigs}}temp.put("{{$binsig}}", "{{$strsig}}"); {{end}} {{.Type}}FuncSigs = Collections.unmodifiableMap(temp); } @@ -537,7 +535,7 @@ import java.util.*; // "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.getHex().substring(2)); + bytecode = 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}});