mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/abi/bind: address comments
This commit is contained in:
parent
8c77a09a59
commit
e4ddff2aad
1 changed files with 28 additions and 14 deletions
|
|
@ -74,18 +74,31 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
|
||||||
transacts = make(map[string]*tmplMethod)
|
transacts = make(map[string]*tmplMethod)
|
||||||
events = make(map[string]*tmplEvent)
|
events = make(map[string]*tmplEvent)
|
||||||
structs = make(map[string]*tmplStruct)
|
structs = make(map[string]*tmplStruct)
|
||||||
|
|
||||||
|
// identifiers are used to detect duplicated identifier of function
|
||||||
|
// and event. For all calls, transacts and events, abigen will generate
|
||||||
|
// corresponding bindings. However we have to ensure there is no
|
||||||
|
// identifier coliision in the bindings of these categories.
|
||||||
|
//
|
||||||
|
// The key of identifiers map is the concat of function name and function type.
|
||||||
identifiers = make(map[string]bool)
|
identifiers = make(map[string]bool)
|
||||||
)
|
)
|
||||||
for _, original := range evmABI.Methods {
|
for _, original := range evmABI.Methods {
|
||||||
// Normalize the method for capital cases and non-anonymous inputs/outputs
|
// Normalize the method for capital cases and non-anonymous inputs/outputs
|
||||||
normalized := original
|
normalized := original
|
||||||
// Ensure there is no duplicated identifier
|
// Ensure there is no duplicated identifier
|
||||||
identifier := methodNormalizer[lang](alias(aliases, original.Name))
|
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
|
||||||
if identifiers[identifier] {
|
id := normalizedName
|
||||||
return "", fmt.Errorf("dupliated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, identifier)
|
if original.Const {
|
||||||
|
id += "call"
|
||||||
|
} else {
|
||||||
|
id += "transact"
|
||||||
}
|
}
|
||||||
identifiers[identifier] = true
|
if identifiers[id] {
|
||||||
normalized.Name = identifier
|
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
|
||||||
|
}
|
||||||
|
identifiers[id] = true
|
||||||
|
normalized.Name = normalizedName
|
||||||
normalized.Inputs = make([]abi.Argument, len(original.Inputs))
|
normalized.Inputs = make([]abi.Argument, len(original.Inputs))
|
||||||
copy(normalized.Inputs, original.Inputs)
|
copy(normalized.Inputs, original.Inputs)
|
||||||
for j, input := range normalized.Inputs {
|
for j, input := range normalized.Inputs {
|
||||||
|
|
@ -122,12 +135,13 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
|
||||||
normalized := original
|
normalized := original
|
||||||
|
|
||||||
// Ensure there is no duplicated identifier
|
// Ensure there is no duplicated identifier
|
||||||
identifier := methodNormalizer[lang](alias(aliases, original.Name))
|
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
|
||||||
if identifiers[identifier] {
|
id := normalizedName + "event"
|
||||||
return "", fmt.Errorf("dupliated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, identifier)
|
if identifiers[id] {
|
||||||
|
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
|
||||||
}
|
}
|
||||||
identifiers[identifier] = true
|
identifiers[id] = true
|
||||||
normalized.Name = identifier
|
normalized.Name = normalizedName
|
||||||
|
|
||||||
normalized.Inputs = make([]abi.Argument, len(original.Inputs))
|
normalized.Inputs = make([]abi.Argument, len(original.Inputs))
|
||||||
copy(normalized.Inputs, original.Inputs)
|
copy(normalized.Inputs, original.Inputs)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue