From c2181fdbf2c17d404c2fd28e9568aadc3fba6379 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Wed, 11 Mar 2015 15:26:28 -0500 Subject: block&index args unmarshal plus test --- rpc/args.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'rpc/args.go') diff --git a/rpc/args.go b/rpc/args.go index d4d807060..2e4e2c7a9 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -227,11 +227,67 @@ type BlockNumIndexArgs struct { Index int64 } +func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + r := bytes.NewReader(b) + if err := json.NewDecoder(r).Decode(&obj); err != nil { + return errDecodeArgs + } + + if len(obj) < 1 { + return errArguments + } + + arg0, ok := obj[0].(string) + if !ok { + return errDecodeArgs + } + args.BlockNumber = ethutil.Big(arg0).Int64() + + if len(obj) > 1 { + arg1, ok := obj[1].(string) + if !ok { + return errDecodeArgs + } + args.Index = ethutil.Big(arg1).Int64() + } + + return nil +} + type HashIndexArgs struct { BlockHash string Index int64 } +func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) { + var obj []interface{} + r := bytes.NewReader(b) + if err := json.NewDecoder(r).Decode(&obj); err != nil { + return errDecodeArgs + } + + if len(obj) < 1 { + return errArguments + } + + arg0, ok := obj[0].(string) + if !ok { + return errDecodeArgs + } + args.BlockHash = arg0 + + if len(obj) > 1 { + arg1, ok := obj[1].(string) + if !ok { + return errDecodeArgs + } + args.Index = ethutil.Big(arg1).Int64() + } + + return nil +} + type Sha3Args struct { Data string } -- cgit