diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-03-17 16:21:34 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-03-17 16:21:34 +0800 |
commit | b3b110bc951f70df7bd3816033f7a93ed8752c25 (patch) | |
tree | 28babd93e1a98595bf88885e5d7a13d0c593fcea /accounts/abi/abi.go | |
parent | 138e7af96c2316f38f0ba8c7692253a7ad97ffba (diff) | |
parent | fe45210c552f5de2ec6293817dc0363a34d0ebfb (diff) | |
download | dexon-b3b110bc951f70df7bd3816033f7a93ed8752c25.tar dexon-b3b110bc951f70df7bd3816033f7a93ed8752c25.tar.gz dexon-b3b110bc951f70df7bd3816033f7a93ed8752c25.tar.bz2 dexon-b3b110bc951f70df7bd3816033f7a93ed8752c25.tar.lz dexon-b3b110bc951f70df7bd3816033f7a93ed8752c25.tar.xz dexon-b3b110bc951f70df7bd3816033f7a93ed8752c25.tar.zst dexon-b3b110bc951f70df7bd3816033f7a93ed8752c25.zip |
Merge pull request #2348 from obscuren/abi-variable-input
accounts/abi: Fixed bytes input accept []byte and variable input support
Diffstat (limited to 'accounts/abi/abi.go')
-rw-r--r-- | accounts/abi/abi.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go index 3704e6262..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 } |