diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-03 23:09:21 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-03 23:09:21 +0800 |
commit | 11d90d9b2229917b00459ffbad4b1ff6e3c180a2 (patch) | |
tree | 187751e89b8654f575da00b4ff80fc5fc1813244 /rpc/api.go | |
parent | 4558e04c0d35d2d057a7182593e8baaa2d3adec0 (diff) | |
parent | 47feff361113fd4b28f81f7b7094c4662b4e8786 (diff) | |
download | dexon-11d90d9b2229917b00459ffbad4b1ff6e3c180a2.tar dexon-11d90d9b2229917b00459ffbad4b1ff6e3c180a2.tar.gz dexon-11d90d9b2229917b00459ffbad4b1ff6e3c180a2.tar.bz2 dexon-11d90d9b2229917b00459ffbad4b1ff6e3c180a2.tar.lz dexon-11d90d9b2229917b00459ffbad4b1ff6e3c180a2.tar.xz dexon-11d90d9b2229917b00459ffbad4b1ff6e3c180a2.tar.zst dexon-11d90d9b2229917b00459ffbad4b1ff6e3c180a2.zip |
Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop
Diffstat (limited to 'rpc/api.go')
-rw-r--r-- | rpc/api.go | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/rpc/api.go b/rpc/api.go index afd242aa3..30ba1ddc1 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -2,6 +2,7 @@ package rpc import ( "encoding/json" + // "fmt" "math/big" "sync" @@ -112,7 +113,11 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } block := NewBlockRes(api.xeth().EthBlockByHash(args.Hash), false) - *reply = common.ToHex(big.NewInt(int64(len(block.Transactions))).Bytes()) + if block == nil { + *reply = nil + } else { + *reply = common.ToHex(big.NewInt(int64(len(block.Transactions))).Bytes()) + } case "eth_getBlockTransactionCountByNumber": args := new(BlockNumArg) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -192,9 +197,9 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err *reply = br case "eth_getTransactionByHash": - // HashIndexArgs used, but only the "Hash" part we need. - args := new(HashIndexArgs) + args := new(HashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { + return err } tx, bhash, bnum, txi := api.xeth().EthTransactionByHash(args.Hash) if tx != nil { @@ -212,11 +217,16 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := api.xeth().EthBlockByHash(args.Hash) br := NewBlockRes(block, true) + if br == nil { + *reply = nil + } if args.Index >= int64(len(br.Transactions)) || args.Index < 0 { - return NewValidationError("Index", "does not exist") + // return NewValidationError("Index", "does not exist") + *reply = nil + } else { + *reply = br.Transactions[args.Index] } - *reply = br.Transactions[args.Index] case "eth_getTransactionByBlockNumberAndIndex": args := new(BlockNumIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -225,11 +235,16 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := api.xeth().EthBlockByNumber(args.BlockNumber) v := NewBlockRes(block, true) + if v == nil { + *reply = nil + } if args.Index >= int64(len(v.Transactions)) || args.Index < 0 { - return NewValidationError("Index", "does not exist") + // return NewValidationError("Index", "does not exist") + *reply = nil + } else { + *reply = v.Transactions[args.Index] } - *reply = v.Transactions[args.Index] case "eth_getUncleByBlockHashAndIndex": args := new(HashIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -243,13 +258,11 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } if args.Index >= int64(len(br.Uncles)) || args.Index < 0 { - return NewValidationError("Index", "does not exist") + // return NewValidationError("Index", "does not exist") + *reply = nil + } else { + *reply = br.Uncles[args.Index] } - - uhash := br.Uncles[args.Index] - uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()), false) - - *reply = uncle case "eth_getUncleByBlockNumberAndIndex": args := new(BlockNumIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -265,13 +278,11 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err } if args.Index >= int64(len(v.Uncles)) || args.Index < 0 { - return NewValidationError("Index", "does not exist") + // return NewValidationError("Index", "does not exist") + *reply = nil + } else { + *reply = v.Uncles[args.Index] } - - uhash := v.Uncles[args.Index] - uncle := NewBlockRes(api.xeth().EthBlockByHash(uhash.String()), false) - - *reply = uncle case "eth_getCompilers": c := []string{""} *reply = c |