forked from cerc-io/plugeth
accounts/abi: added unpacking "anything" in to interface{}
This commit is contained in:
parent
e0dc45fce2
commit
c3d5250473
@ -316,6 +316,8 @@ func set(dst, src reflect.Value, output Argument) error {
|
|||||||
return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.SliceSize, dst.Len())
|
return fmt.Errorf("abi: cannot unmarshal src (len=%d) in to dst (len=%d)", output.Type.SliceSize, dst.Len())
|
||||||
}
|
}
|
||||||
reflect.Copy(dst, src)
|
reflect.Copy(dst, src)
|
||||||
|
case dstType.Kind() == reflect.Interface:
|
||||||
|
dst.Set(src)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("abi: cannot unmarshal %v in to %v", src.Type(), dst.Type())
|
return fmt.Errorf("abi: cannot unmarshal %v in to %v", src.Type(), dst.Type())
|
||||||
}
|
}
|
||||||
|
@ -161,6 +161,13 @@ func TestSimpleMethodUnpack(t *testing.T) {
|
|||||||
"hash",
|
"hash",
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`[ { "type": "bytes32" } ]`,
|
||||||
|
pad([]byte{1}, 32, false),
|
||||||
|
pad([]byte{1}, 32, false),
|
||||||
|
"interface",
|
||||||
|
nil,
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
abiDefinition := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
|
abiDefinition := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
|
||||||
abi, err := JSON(strings.NewReader(abiDefinition))
|
abi, err := JSON(strings.NewReader(abiDefinition))
|
||||||
@ -203,6 +210,8 @@ func TestSimpleMethodUnpack(t *testing.T) {
|
|||||||
var v common.Hash
|
var v common.Hash
|
||||||
err = abi.Unpack(&v, "method", test.marshalledOutput)
|
err = abi.Unpack(&v, "method", test.marshalledOutput)
|
||||||
outvar = v
|
outvar = v
|
||||||
|
case "interface":
|
||||||
|
err = abi.Unpack(&outvar, "method", test.marshalledOutput)
|
||||||
default:
|
default:
|
||||||
t.Errorf("unsupported type '%v' please add it to the switch statement in this test", test.outVar)
|
t.Errorf("unsupported type '%v' please add it to the switch statement in this test", test.outVar)
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user