diff options
author | Martin Holst Swende <martin@swende.se> | 2017-12-23 03:59:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-23 03:59:41 +0800 |
commit | 9d187f02389ba12493112c7feb15a83f44e3a3ff (patch) | |
tree | c98e69e41f2412d8ccf6ebec886ed2110be866bb /accounts/abi/reflect.go | |
parent | 5f8888e11606296c9582496974c0f6b96a882146 (diff) | |
parent | c095c87e117785ba5467487336215f86a958409b (diff) | |
download | dexon-9d187f02389ba12493112c7feb15a83f44e3a3ff.tar.gz dexon-9d187f02389ba12493112c7feb15a83f44e3a3ff.tar.zst dexon-9d187f02389ba12493112c7feb15a83f44e3a3ff.zip |
Merge pull request #15731 from holiman/revamp_abi
accounts/abi refactor
Diffstat (limited to 'accounts/abi/reflect.go')
-rw-r--r-- | accounts/abi/reflect.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/accounts/abi/reflect.go b/accounts/abi/reflect.go index e953b77c1..7a9cdacd5 100644 --- a/accounts/abi/reflect.go +++ b/accounts/abi/reflect.go @@ -85,3 +85,28 @@ func set(dst, src reflect.Value, output Argument) error { } 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 { + return fmt.Errorf("abi: cannot unmarshal %v into %v", src.Type(), dst.Type()) + } + return nil +} + +// requireUnpackKind verifies preconditions for unpacking `args` into `kind` +func requireUnpackKind(v reflect.Value, t reflect.Type, k reflect.Kind, + args Arguments) error { + + switch k { + case reflect.Struct: + case reflect.Slice, reflect.Array: + if minLen := args.LengthNonIndexed(); v.Len() < minLen { + return fmt.Errorf("abi: insufficient number of elements in the list/array for unpack, want %d, got %d", + minLen, v.Len()) + } + default: + return fmt.Errorf("abi: cannot unmarshal tuple into %v", t) + } + return nil +} |