aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/reflect.go
diff options
context:
space:
mode:
authorbas-vk <bas-vk@users.noreply.github.com>2018-12-22 18:26:49 +0800
committerGuillaume Ballet <gballet@gmail.com>2018-12-22 18:26:49 +0800
commit7df52e324c1393f9dad3daa8c724782f4ade5b42 (patch)
treed9676d352f19aab7e2e8f3f97fd939c0d97265b9 /accounts/abi/reflect.go
parent5e4fd8e7dbfe701b3b544c52c433c5d7c2e302c3 (diff)
downloaddexon-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar
dexon-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.gz
dexon-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.bz2
dexon-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.lz
dexon-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.xz
dexon-7df52e324c1393f9dad3daa8c724782f4ade5b42.tar.zst
dexon-7df52e324c1393f9dad3daa8c724782f4ade5b42.zip
accounts/abi: add support for unpacking returned bytesN arrays (#15242)
Diffstat (limited to 'accounts/abi/reflect.go')
-rw-r--r--accounts/abi/reflect.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/accounts/abi/reflect.go b/accounts/abi/reflect.go
index 0193517a4..6ec79a12f 100644
--- a/accounts/abi/reflect.go
+++ b/accounts/abi/reflect.go
@@ -77,6 +77,8 @@ func set(dst, src reflect.Value, output Argument) error {
switch {
case dstType.AssignableTo(srcType):
dst.Set(src)
+ case dstType.Kind() == reflect.Slice && srcType.Kind() == reflect.Slice:
+ return setSlice(dst, src, output)
case dstType.Kind() == reflect.Interface:
dst.Set(src)
case dstType.Kind() == reflect.Ptr:
@@ -87,6 +89,19 @@ func set(dst, src reflect.Value, output Argument) error {
return nil
}
+// setSlice attempts to assign src to dst when slices are not assignable by default
+// e.g. src: [][]byte -> dst: [][15]byte
+func setSlice(dst, src reflect.Value, output Argument) error {
+ slice := reflect.MakeSlice(dst.Type(), src.Len(), src.Len())
+ for i := 0; i < src.Len(); i++ {
+ v := src.Index(i)
+ reflect.Copy(slice.Index(i), v)
+ }
+
+ dst.Set(slice)
+ return nil
+}
+
// requireAssignable assures that `dest` is a pointer and it's not an interface.
func requireAssignable(dst, src reflect.Value) error {
if dst.Kind() != reflect.Ptr && dst.Kind() != reflect.Interface {