mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-31 17:13:57 +00:00
accounts/abi: current workings on packing and unpacking, trying to decide how to design this
Signed-off-by: RJ Catalano <rj@monax.io>
This commit is contained in:
parent
3a72388020
commit
a0083e913a
2 changed files with 16 additions and 0 deletions
|
|
@ -97,6 +97,11 @@ func toGoSlice(i int, t Argument, output []byte) (interface{}, error) {
|
|||
inter = common.BytesToHash(returnOutput)
|
||||
case FixedBytesTy:
|
||||
inter = returnOutput
|
||||
case SliceTy, ArrayTy:
|
||||
inter, err = toGoSlice(i+index/32, t, output)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("abi: unsupported slice type passed in")
|
||||
}
|
||||
|
|
@ -158,6 +163,9 @@ func readBool(word []byte) (bool, error) {
|
|||
// toGoType parses the input and casts it to the proper type defined by the ABI
|
||||
// argument in T.
|
||||
func toGoType(i int, t Argument, output []byte) (interface{}, error) {
|
||||
if len(output)%32 != 0 {
|
||||
return nil, fmt.Errorf("abi: improperly formatted output")
|
||||
}
|
||||
// we need to treat slices differently
|
||||
if (t.Type.IsSlice || t.Type.IsArray) && t.Type.T != BytesTy && t.Type.T != StringTy && t.Type.T != FixedBytesTy && t.Type.T != FunctionTy {
|
||||
return toGoSlice(i, t, output)
|
||||
|
|
|
|||
|
|
@ -244,6 +244,13 @@ func TestArraysAndSlicesUnpack(t *testing.T) {
|
|||
[]uint8{},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint8[][]" } ]`,
|
||||
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000E0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||
[][]uint8{{1, 2}, {1, 2}},
|
||||
[][]uint8{{}},
|
||||
"",
|
||||
},
|
||||
{
|
||||
`[ { "type": "uint8[2]" } ]`,
|
||||
common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"),
|
||||
|
|
@ -378,6 +385,7 @@ func TestArraysAndSlicesUnpack(t *testing.T) {
|
|||
"",
|
||||
},
|
||||
} {
|
||||
//t.Log(test.marshalledOutput)
|
||||
|
||||
abiDefinition := fmt.Sprintf(`[{ "name" : "method", "outputs": %s}]`, test.def)
|
||||
abi, err := JSON(strings.NewReader(abiDefinition))
|
||||
|
|
|
|||
Loading…
Reference in a new issue