mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/abi: More Gary feedback
This commit is contained in:
parent
b7fb49c624
commit
4ee8f14ee0
2 changed files with 17 additions and 2 deletions
|
|
@ -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{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}});
|
||||
|
|
|
|||
Loading…
Reference in a new issue