accounts/abi: fix comments

This commit is contained in:
adriamb 2018-05-11 09:51:29 +02:00
parent cc34d6e2b8
commit 4566fa8660

View file

@ -116,7 +116,7 @@ func requireUnpackKind(v reflect.Value, t reflect.Type, k reflect.Kind,
// first round: for each Exportable field that contains a `abi:""` tag // first round: for each Exportable field that contains a `abi:""` tag
// and this field name exists in the arguments, pair them together. // and this field name exists in the arguments, pair them together.
// second round: for each argument field that has not been already linked, // second round: for each argument field that has not been already linked,
// find what variable is expected to be mapped into, if exists and has not been // find what variable is expected to be mapped into, if it exists and has not been
// used, pair them. // used, pair them.
func mapAbiToStructFields(args Arguments, value reflect.Value) (map[string]string, error) { func mapAbiToStructFields(args Arguments, value reflect.Value) (map[string]string, error) {
@ -134,14 +134,14 @@ func mapAbiToStructFields(args Arguments, value reflect.Value) (map[string]strin
continue continue
} }
// skip fields that has not `abi:""` tag. // skip fields that have no abi:"" tag.
var ok bool var ok bool
var tagName string var tagName string
if tagName, ok = typ.Field(i).Tag.Lookup("abi"); !ok { if tagName, ok = typ.Field(i).Tag.Lookup("abi"); !ok {
continue continue
} }
// check if tag is emmpty. // check if tag is empty.
if tagName == "" { if tagName == "" {
return nil, fmt.Errorf("struct: abi tag in '%s' is empty", structFieldName) return nil, fmt.Errorf("struct: abi tag in '%s' is empty", structFieldName)
} }
@ -177,9 +177,11 @@ func mapAbiToStructFields(args Arguments, value reflect.Value) (map[string]strin
return nil, fmt.Errorf("abi: purely underscored output cannot unpack to struct") return nil, fmt.Errorf("abi: purely underscored output cannot unpack to struct")
} }
// this abi been already paired, skip // this abi has already been paired, skip... unless exists another not still assigned
// struct field with the same field name, in the case raise an error:
// abi: [ { "name": "value" } ]
// struct { Value *big.Int , Value1 *big.Int `abi:"value"`}
if abi2struct[abiFieldName] != "" { if abi2struct[abiFieldName] != "" {
// unless if exists another not still assigned struct field with the same name
if abi2struct[abiFieldName] != structFieldName && if abi2struct[abiFieldName] != structFieldName &&
struct2abi[structFieldName] == "" && struct2abi[structFieldName] == "" &&
value.FieldByName(structFieldName).IsValid() { value.FieldByName(structFieldName).IsValid() {
@ -188,7 +190,7 @@ func mapAbiToStructFields(args Arguments, value reflect.Value) (map[string]strin
continue continue
} }
// error if this struct field been already paired. // return an error if this struct field has already been paired.
if struct2abi[structFieldName] != "" { if struct2abi[structFieldName] != "" {
return nil, fmt.Errorf("abi: multiple outputs mapping to the same struct field '%s'", structFieldName) return nil, fmt.Errorf("abi: multiple outputs mapping to the same struct field '%s'", structFieldName)
} }