accounts/abi/bind: address comment

This commit is contained in:
rjl493456442 2019-11-14 13:52:06 +08:00
parent e4ddff2aad
commit 522e478f9e

View file

@ -79,25 +79,23 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
// and event. For all calls, transacts and events, abigen will generate // and event. For all calls, transacts and events, abigen will generate
// corresponding bindings. However we have to ensure there is no // corresponding bindings. However we have to ensure there is no
// identifier coliision in the bindings of these categories. // identifier coliision in the bindings of these categories.
// callIdentifiers = make(map[string]bool)
// The key of identifiers map is the concat of function name and function type. transactIdentifiers = make(map[string]bool)
identifiers = make(map[string]bool) eventIdentifiers = 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
normalizedName := methodNormalizer[lang](alias(aliases, original.Name)) normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
id := normalizedName // Ensure there is no duplicated identifier
if original.Const { var identifiers = callIdentifiers
id += "call" if !original.Const {
} else { identifiers = transactIdentifiers
id += "transact"
} }
if identifiers[id] { if identifiers[normalizedName] {
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName) return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
} }
identifiers[id] = true identifiers[normalizedName] = true
normalized.Name = normalizedName 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)
@ -136,11 +134,10 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
// Ensure there is no duplicated identifier // Ensure there is no duplicated identifier
normalizedName := methodNormalizer[lang](alias(aliases, original.Name)) normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
id := normalizedName + "event" if eventIdentifiers[normalizedName] {
if identifiers[id] {
return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName) return "", fmt.Errorf("duplicated identifier \"%s\"(normalized \"%s\"), use --alias for renaming", original.Name, normalizedName)
} }
identifiers[id] = true eventIdentifiers[normalizedName] = true
normalized.Name = normalizedName normalized.Name = normalizedName
normalized.Inputs = make([]abi.Argument, len(original.Inputs)) normalized.Inputs = make([]abi.Argument, len(original.Inputs))