Skip to content

Commit c3d5250

Browse files
committed
accounts/abi: added unpacking "anything" in to interface{}
1 parent e0dc45f commit c3d5250

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

accounts/abi/abi.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ func set(dst, src reflect.Value, output Argument) error {
316316
return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.SliceSize, dst.Len())
317317
}
318318
reflect.Copy(dst, src)
319+
case dstType.Kind() == reflect.Interface:
320+
dst.Set(src)
319321
default:
320322
return fmt.Errorf("abi: cannot unmarshal %v in to %v", src.Type(), dst.Type())
321323
}

accounts/abi/abi_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ func TestSimpleMethodUnpack(t *testing.T) {
161161
"hash",
162162
nil,
163163
},
164+
{
165+
`[ { "type": "bytes32" } ]`,
166+
pad([]byte{1}, 32, false),
167+
pad([]byte{1}, 32, false),
168+
"interface",
169+
nil,
170+
},
164171
} {
165172
abiDefinition := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
166173
abi, err := JSON(strings.NewReader(abiDefinition))
@@ -203,6 +210,8 @@ func TestSimpleMethodUnpack(t *testing.T) {
203210
var v common.Hash
204211
err = abi.Unpack(&v, "method", test.marshalledOutput)
205212
outvar = v
213+
case "interface":
214+
err = abi.Unpack(&outvar, "method", test.marshalledOutput)
206215
default:
207216
t.Errorf("unsupported type '%v' please add it to the switch statement in this test", test.outVar)
208217
continue

0 commit comments

Comments
 (0)