aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/type.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/type.go
parente189fb839c688b418b43ad6533111c246c109a93 (diff)
downloadgo-tangerine-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar
go-tangerine-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.gz
go-tangerine-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.bz2
go-tangerine-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.lz
go-tangerine-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.xz
go-tangerine-fe45210c552f5de2ec6293817dc0363a34d0ebfb.tar.zst
go-tangerine-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/type.go')
-rw-r--r--accounts/abi/type.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/accounts/abi/type.go b/accounts/abi/type.go
index 6fb2950ba..c08b744f7 100644
--- a/accounts/abi/type.go
+++ b/accounts/abi/type.go
@@ -163,6 +163,13 @@ func (t Type) String() (out string) {
return t.stringKind
}
+// packBytesSlice packs the given bytes as [L, V] as the canonical representation
+// bytes slice
+func packBytesSlice(bytes []byte, l int) []byte {
+ len := packNum(reflect.ValueOf(l), UintTy)
+ return append(len, common.RightPadBytes(bytes, (l+31)/32*32)...)
+}
+
// Test the given input parameter `v` and checks if it matches certain
// criteria
// * Big integers are checks for ptr types and if the given value is
@@ -193,8 +200,14 @@ func (t Type) pack(v interface{}) ([]byte, error) {
if t.Size > -1 && value.Len() > t.Size {
return nil, fmt.Errorf("%v out of bound. %d for %d", value.Kind(), value.Len(), t.Size)
}
- return []byte(common.LeftPadString(t.String(), 32)), nil
+
+ return packBytesSlice([]byte(value.String()), value.Len()), nil
case reflect.Slice:
+ // if the param is a bytes type, pack the slice up as a string
+ if t.T == BytesTy {
+ return packBytesSlice(value.Bytes(), value.Len()), nil
+ }
+
if t.Size > -1 && value.Len() > t.Size {
return nil, fmt.Errorf("%v out of bound. %d for %d", value.Kind(), value.Len(), t.Size)
}