From d381d9a74cc2cb4e8cebf21aa9e4927a6e1867d6 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 18 May 2015 09:16:10 -0500 Subject: Return nil for certain fields on eth_getBlockByNumber pending --- rpc/api.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'rpc') diff --git a/rpc/api.go b/rpc/api.go index b59253ef7..47409b4af 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -231,6 +231,13 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := api.xeth().EthBlockByNumber(args.BlockNumber) br := NewBlockRes(block, args.IncludeTxs) + if args.BlockNumber == -2 { + br.BlockHash = nil + br.BlockNumber = nil + br.Miner = nil + br.Nonce = nil + br.LogsBloom = nil + } *reply = br case "eth_getTransactionByHash": args := new(HashArgs) -- cgit From a528bd04db4adc8de707f8b5a3a7b2cef52a2fbc Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 18 May 2015 10:09:00 -0500 Subject: Return nil for certain fields on eth_getTransactionByHash when not part of a block --- rpc/api.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'rpc') diff --git a/rpc/api.go b/rpc/api.go index 47409b4af..495f07835 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -1,6 +1,7 @@ package rpc import ( + "bytes" "encoding/json" "math/big" // "sync" @@ -247,9 +248,12 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err tx, bhash, bnum, txi := api.xeth().EthTransactionByHash(args.Hash) if tx != nil { v := NewTransactionRes(tx) - v.BlockHash = newHexData(bhash) - v.BlockNumber = newHexNum(bnum) - v.TxIndex = newHexNum(txi) + // if the blockhash is 0, assume this is a pending transaction + if bytes.Compare(bhash.Bytes(), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) != 0 { + v.BlockHash = newHexData(bhash) + v.BlockNumber = newHexNum(bnum) + v.TxIndex = newHexNum(txi) + } *reply = v } case "eth_getTransactionByBlockHashAndIndex": -- cgit From 62d76b8e1f0ebfe213c50006bec7dc1b5473029a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 18 May 2015 10:11:27 -0500 Subject: Cleanup --- rpc/api.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'rpc') diff --git a/rpc/api.go b/rpc/api.go index 495f07835..b2566cfc5 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "math/big" - // "sync" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -231,7 +230,6 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := api.xeth().EthBlockByNumber(args.BlockNumber) br := NewBlockRes(block, args.IncludeTxs) - if args.BlockNumber == -2 { br.BlockHash = nil br.BlockNumber = nil @@ -588,7 +586,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err return NewNotImplementedError(req.Method) } - glog.V(logger.Detail).Infof("Reply: %T %s\n", reply, reply) + // glog.V(logger.Detail).Infof("Reply: %v\n", reply) return nil } -- cgit From 748263d2f011382c832cbebb8d4e10fba8a09f71 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 19 May 2015 08:14:48 -0500 Subject: Use bytes.Repeat() instead of 32-byte literal --- rpc/api.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'rpc') diff --git a/rpc/api.go b/rpc/api.go index b2566cfc5..0c1409d71 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -230,6 +230,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := api.xeth().EthBlockByNumber(args.BlockNumber) br := NewBlockRes(block, args.IncludeTxs) + // If request was for "pending", nil nonsensical fields if args.BlockNumber == -2 { br.BlockHash = nil br.BlockNumber = nil @@ -247,7 +248,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err if tx != nil { v := NewTransactionRes(tx) // if the blockhash is 0, assume this is a pending transaction - if bytes.Compare(bhash.Bytes(), []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) != 0 { + if bytes.Compare(bhash.Bytes(), bytes.Repeat([]byte{0}, 32)) != 0 { v.BlockHash = newHexData(bhash) v.BlockNumber = newHexNum(bnum) v.TxIndex = newHexNum(txi) -- cgit