aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/abi.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-03-15 21:06:12 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-03-15 21:10:39 +0800
commitfe45210c552f5de2ec6293817dc0363a34d0ebfb (patch)
tree261ca0a2ec9582f7d9b7d2d3758cf13bf506a5e8 /accounts/abi/abi.go
parente189fb839c688b418b43ad6533111c246c109a93 (diff)
downloaddexon-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar
dexon-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.gz
dexon-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.bz2
dexon-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.lz
dexon-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.xz
dexon-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.zst
dexon-fe45210c552f5de2ec6293817dc0363a34d0ebfb.zip
accounts/abi: Fixed bytes input accept []byte and variable input support
Fixed up `[]byte` slice support such that `function print(bytes input)` accepts `[]byte` as input and treats it as 1 element rather than a slice of multiple elements. Added support for variable length input parameters like `bytes` and `strings`.
Diffstat (limited to 'accounts/abi/abi.go')
-rw-r--r--accounts/abi/abi.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/accounts/abi/abi.go b/accounts/abi/abi.go
index 324d3c76f..e299d43c8 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
}