From d381d9a74cc2cb4e8cebf21aa9e4927a6e1867d6 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 18 May 2015 09:16:10 -0500 Subject: [PATCH 1/5] Return nil for certain fields on eth_getBlockByNumber pending --- rpc/api.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rpc/api.go b/rpc/api.go index b59253ef73..47409b4aff 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) From a528bd04db4adc8de707f8b5a3a7b2cef52a2fbc Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 18 May 2015 10:09:00 -0500 Subject: [PATCH 2/5] 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(-) diff --git a/rpc/api.go b/rpc/api.go index 47409b4aff..495f078355 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": From 62d76b8e1f0ebfe213c50006bec7dc1b5473029a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 18 May 2015 10:11:27 -0500 Subject: [PATCH 3/5] Cleanup --- rpc/api.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index 495f078355..b2566cfc5d 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 } From 54b5c8273db33ebc2bee762b92fa4a6c24e6ad94 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Mon, 18 May 2015 10:41:56 -0500 Subject: [PATCH 4/5] XEth comment clarification --- xeth/xeth.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/xeth/xeth.go b/xeth/xeth.go index 88cd30afce..2d01bc6812 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -304,6 +304,8 @@ func (self *XEth) EthBlockByHash(strHash string) *types.Block { } func (self *XEth) EthTransactionByHash(hash string) (tx *types.Transaction, blhash common.Hash, blnum *big.Int, txi uint64) { + // Due to increasing return params and need to determine if this is from transaction pool or + // some chain, this probably needs to be refactored for more expressiveness data, _ := self.backend.ExtraDb().Get(common.FromHex(hash)) if len(data) != 0 { tx = types.NewTransactionFromBytes(data) @@ -357,7 +359,7 @@ func (self *XEth) Block(v interface{}) *Block { return self.BlockByNumber(int64(n)) } else if str, ok := v.(string); ok { return self.BlockByHash(str) - } else if f, ok := v.(float64); ok { // Don't ask ... + } else if f, ok := v.(float64); ok { // JSON numbers are represented as float64 return self.BlockByNumber(int64(f)) } @@ -778,7 +780,7 @@ func (self *XEth) PushTx(encodedTx string) (string, error) { } func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, string, error) { - statedb := self.State().State().Copy() //self.eth.ChainManager().TransState() + statedb := self.State().State().Copy() var from *state.StateObject if len(fromStr) == 0 { accounts, err := self.backend.AccountManager().Accounts() @@ -869,6 +871,7 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS contractCreation bool ) + // 2015-05-18 Is this still needed? // TODO if no_private_key then //if _, exists := p.register[args.From]; exists { // p.register[args.From] = append(p.register[args.From], args) From 748263d2f011382c832cbebb8d4e10fba8a09f71 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 19 May 2015 08:14:48 -0500 Subject: [PATCH 5/5] Use bytes.Repeat() instead of 32-byte literal --- rpc/api.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rpc/api.go b/rpc/api.go index b2566cfc5d..0c1409d71b 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)