diff options
author | Vedhavyas Singareddi <vedhavyas.singareddi@gmail.com> | 2018-12-04 22:27:55 +0800 |
---|---|---|
committer | Guillaume Ballet <gballet@gmail.com> | 2018-12-04 22:27:55 +0800 |
commit | 92639b676aaa7f262d19081256c43cdb78aa0efd (patch) | |
tree | 8eaa518265c07c5beeb8a8e98092ef415b5e5096 /accounts/abi/argument.go | |
parent | f74077b4c24a6d1490dc12564d001df57d2a41fe (diff) | |
download | dexon-92639b676aaa7f262d19081256c43cdb78aa0efd.tar dexon-92639b676aaa7f262d19081256c43cdb78aa0efd.tar.gz dexon-92639b676aaa7f262d19081256c43cdb78aa0efd.tar.bz2 dexon-92639b676aaa7f262d19081256c43cdb78aa0efd.tar.lz dexon-92639b676aaa7f262d19081256c43cdb78aa0efd.tar.xz dexon-92639b676aaa7f262d19081256c43cdb78aa0efd.tar.zst dexon-92639b676aaa7f262d19081256c43cdb78aa0efd.zip |
Add packing for dynamic array and slice types (#18051)
* added tests for new abi encoding features (#4)
* added tests from bytes32[][] and string[]
* added offset to other types
* formatting
* Abi/dynamic types (#5)
* Revert "Abi/dynamic types (#5)" (#6)
This reverts commit dabca31d797623d43bd780721fc0ad461d24be53.
* Abi/dynamic types (#7)
* some cleanup
* Apply suggestions from code review
apply suggestions
Co-Authored-By: vedhavyas <vedhavyas.singareddi@gmail.com>
* added better formatting (#8)
* review chnages
* better comments
Diffstat (limited to 'accounts/abi/argument.go')
-rw-r--r-- | accounts/abi/argument.go | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/accounts/abi/argument.go b/accounts/abi/argument.go index 93b513c34..f544c80db 100644 --- a/accounts/abi/argument.go +++ b/accounts/abi/argument.go @@ -243,11 +243,7 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) { // input offset is the bytes offset for packed output inputOffset := 0 for _, abiArg := range abiArgs { - if abiArg.Type.T == ArrayTy { - inputOffset += 32 * abiArg.Type.Size - } else { - inputOffset += 32 - } + inputOffset += getDynamicTypeOffset(abiArg.Type) } var ret []byte for i, a := range args { @@ -257,14 +253,13 @@ func (arguments Arguments) Pack(args ...interface{}) ([]byte, error) { if err != nil { return nil, err } - // check for a slice type (string, bytes, slice) - if input.Type.requiresLengthPrefix() { - // calculate the offset - offset := inputOffset + len(variableInput) + // check for dynamic types + if isDynamicType(input.Type) { // set the offset - ret = append(ret, packNum(reflect.ValueOf(offset))...) - // Append the packed output to the variable input. The variable input - // will be appended at the end of the input. + ret = append(ret, packNum(reflect.ValueOf(inputOffset))...) + // calculate next offset + inputOffset += len(packed) + // append to variable input variableInput = append(variableInput, packed...) } else { // append the packed value to the input |