aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/args.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-12 04:26:28 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-12 04:26:28 +0800
commitc2181fdbf2c17d404c2fd28e9568aadc3fba6379 (patch)
treee0b6d4ddcb861bba237f005a4c420f4acb2dbea9 /rpc/args.go
parent5a9f712144058c576d14b0d27ff2d2d270cd6d27 (diff)
downloaddexon-c2181fdbf2c17d404c2fd28e9568aadc3fba6379.tar.gz
dexon-c2181fdbf2c17d404c2fd28e9568aadc3fba6379.tar.zst
dexon-c2181fdbf2c17d404c2fd28e9568aadc3fba6379.zip
block&index args unmarshal plus test
Diffstat (limited to 'rpc/args.go')
-rw-r--r--rpc/args.go56
1 files changed, 56 insertions, 0 deletions
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
}