diff options
Diffstat (limited to 'accounts/abi/abi.go')
-rw-r--r-- | accounts/abi/abi.go | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 324d3c76f..673088f60 100644 --- a/accounts/abi/abi.go +++ b/accounts/abi/abi.go @@ -56,17 +56,36 @@ func JSON(reader io.Reader) (ABI, error) { func (abi ABI) pack(name string, args ...interface{}) ([]byte, error) { method := abi.Methods[name] + // variable input is the output appended at the end of packed + // output. This is used for strings and bytes types input. + var variableInput []byte + var ret []byte for i, a := range args { input := method.Inputs[i] - + // pack the input packed, err := input.Type.pack(a) if err != nil { return nil, fmt.Errorf("`%s` %v", name, err) } - ret = append(ret, packed...) + // check for a string or bytes input type + switch input.Type.T { + case StringTy, BytesTy: + // calculate the offset + offset := len(method.Inputs)*32 + len(variableInput) + // set the offset + ret = append(ret, packNum(reflect.ValueOf(offset), UintTy)...) + // Append the packed output to the variable input. The variable input + // will be appended at the end of the input. + variableInput = append(variableInput, packed...) + default: + // append the packed value to the input + ret = append(ret, packed...) + } } + // append the variable input at the end of the packed input + ret = append(ret, variableInput...) return ret, nil } @@ -268,12 +287,12 @@ func set(dst, src reflect.Value, output Argument) error { func (abi *ABI) UnmarshalJSON(data []byte) error { var fields []struct { - Type string - Name string - Const bool - Indexed bool - Inputs []Argument - Outputs []Argument + Type string + Name string + Constant bool + Indexed bool + Inputs []Argument + Outputs []Argument } if err := json.Unmarshal(data, &fields); err != nil { @@ -288,7 +307,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error { case "function", "": abi.Methods[field.Name] = Method{ Name: field.Name, - Const: field.Const, + Const: field.Constant, Inputs: field.Inputs, Outputs: field.Outputs, } |