aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-04-03 17:58:18 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-04-03 17:58:18 +0800
commita6ca3d0261e915ac495a15e676eba54c2b57c980 (patch)
treec0da6efb242c9b5dbafa43a8621de156147bf4ca /rpc/api.go
parent29a9c6bedd39f3432f8031475646ec151ca5caa5 (diff)
parent3e042317adc99438d6ffde0cbde4f0b40ad579c1 (diff)
downloaddexon-a6ca3d0261e915ac495a15e676eba54c2b57c980.tar
dexon-a6ca3d0261e915ac495a15e676eba54c2b57c980.tar.gz
dexon-a6ca3d0261e915ac495a15e676eba54c2b57c980.tar.bz2
dexon-a6ca3d0261e915ac495a15e676eba54c2b57c980.tar.lz
dexon-a6ca3d0261e915ac495a15e676eba54c2b57c980.tar.xz
dexon-a6ca3d0261e915ac495a15e676eba54c2b57c980.tar.zst
dexon-a6ca3d0261e915ac495a15e676eba54c2b57c980.zip
Merge pull request #626 from tgerring/rpcfabian
RPC Tests updates
Diffstat (limited to 'rpc/api.go')
-rw-r--r--rpc/api.go49
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