accounts/abi: minor fixes

This commit is contained in:
rjl493456442 2019-07-08 11:13:54 +08:00
parent 4ee8f14ee0
commit 8b896b6179
2 changed files with 12 additions and 14 deletions

View file

@ -141,7 +141,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
contracts[types[i]] = &tmplContract{ contracts[types[i]] = &tmplContract{
Type: capitalise(types[i]), Type: capitalise(types[i]),
InputABI: strings.Replace(strippedABI, "\"", "\\\"", -1), InputABI: strings.Replace(strippedABI, "\"", "\\\"", -1),
InputBin: strings.TrimSpace(bytecodes[i]), InputBin: strings.TrimPrefix(strings.TrimSpace(bytecodes[i]), "0x"),
Constructor: evmABI.Constructor, Constructor: evmABI.Constructor,
Calls: calls, Calls: calls,
Transacts: transacts, Transacts: transacts,
@ -149,17 +149,12 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
Libraries: make(map[string]string), Libraries: make(map[string]string),
Structs: structs, Structs: structs,
} }
// Function 4-byte signatures are stored in the same sequence
// 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. // as types, if available.
if len(fsigs) > i { if len(fsigs) > i {
contracts[types[i]].FuncSigs = fsigs[i] contracts[types[i]].FuncSigs = fsigs[i]
} }
// Parse library references.
for pattern, name := range libs { for pattern, name := range libs {
matched, err := regexp.Match("__\\$"+pattern+"\\$__", []byte(contracts[types[i]].InputBin)) matched, err := regexp.Match("__\\$"+pattern+"\\$__", []byte(contracts[types[i]].InputBin))
if err != nil { 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 // Generate the contract template data content and render it
data := &tmplData{ data := &tmplData{
Package: pkg, Package: pkg,

View file

@ -116,15 +116,14 @@ var (
{{if $contract.FuncSigs}} {{if $contract.FuncSigs}}
// {{.Type}}FuncSigs maps the 4-byte function signature to its string representation. // {{.Type}}FuncSigs maps the 4-byte function signature to its string representation.
var {{.Type}}FuncSigs = map[string]string{ var {{.Type}}FuncSigs = map[string]string{
{{range $strsig, $binsig := .FuncSigs}} {{range $strsig, $binsig := .FuncSigs}}"{{$binsig}}": "{{$strsig}}",
"{{$binsig}}": "{{$strsig}}",
{{end}} {{end}}
} }
{{end}} {{end}}
{{if .InputBin}} {{if .InputBin}}
// {{.Type}}Bin is the compiled bytecode used for deploying new contracts. // {{.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. // 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) { 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<String, String> {{.Type}}FuncSigs; public final static Map<String, String> {{.Type}}FuncSigs;
static { static {
Hashtable<String, String> temp = new Hashtable<String, String>(); Hashtable<String, String> temp = new Hashtable<String, String>();
{{range $strsig, $binsig := .FuncSigs}} {{range $strsig, $binsig := .FuncSigs}}temp.put("{{$binsig}}", "{{$strsig}}");
temp.put("{{$binsig}}", "{{$strsig}}");
{{end}} {{end}}
{{.Type}}FuncSigs = Collections.unmodifiableMap(temp); {{.Type}}FuncSigs = Collections.unmodifiableMap(temp);
} }
@ -537,7 +535,7 @@ import java.util.*;
// "link" contract to dependent libraries by deploying them first. // "link" contract to dependent libraries by deploying them first.
{{range $pattern, $name := .Libraries}} {{range $pattern, $name := .Libraries}}
{{capitalise $name}} {{decapitalise $name}}Inst = {{capitalise $name}}.deploy(auth, client); {{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}}
{{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}}); {{range $index, $element := .Constructor.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type $structs) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});