Merge pull request #1036 from tgerring/issue884

JSON RPC null field updates
This commit is contained in:
Jeffrey Wilcke 2015-05-19 06:44:31 -07:00
commit 9b825e2728
2 changed files with 21 additions and 8 deletions

View File

@ -1,9 +1,9 @@
package rpc package rpc
import ( import (
"bytes"
"encoding/json" "encoding/json"
"math/big" "math/big"
// "sync"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
@ -230,7 +230,14 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
block := api.xeth().EthBlockByNumber(args.BlockNumber) block := api.xeth().EthBlockByNumber(args.BlockNumber)
br := NewBlockRes(block, args.IncludeTxs) br := NewBlockRes(block, args.IncludeTxs)
// If request was for "pending", nil nonsensical fields
if args.BlockNumber == -2 {
br.BlockHash = nil
br.BlockNumber = nil
br.Miner = nil
br.Nonce = nil
br.LogsBloom = nil
}
*reply = br *reply = br
case "eth_getTransactionByHash": case "eth_getTransactionByHash":
args := new(HashArgs) args := new(HashArgs)
@ -240,9 +247,12 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
tx, bhash, bnum, txi := api.xeth().EthTransactionByHash(args.Hash) tx, bhash, bnum, txi := api.xeth().EthTransactionByHash(args.Hash)
if tx != nil { if tx != nil {
v := NewTransactionRes(tx) v := NewTransactionRes(tx)
v.BlockHash = newHexData(bhash) // if the blockhash is 0, assume this is a pending transaction
v.BlockNumber = newHexNum(bnum) if bytes.Compare(bhash.Bytes(), bytes.Repeat([]byte{0}, 32)) != 0 {
v.TxIndex = newHexNum(txi) v.BlockHash = newHexData(bhash)
v.BlockNumber = newHexNum(bnum)
v.TxIndex = newHexNum(txi)
}
*reply = v *reply = v
} }
case "eth_getTransactionByBlockHashAndIndex": case "eth_getTransactionByBlockHashAndIndex":
@ -577,7 +587,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return NewNotImplementedError(req.Method) 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 return nil
} }

View File

@ -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) { 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)) data, _ := self.backend.ExtraDb().Get(common.FromHex(hash))
if len(data) != 0 { if len(data) != 0 {
tx = types.NewTransactionFromBytes(data) tx = types.NewTransactionFromBytes(data)
@ -357,7 +359,7 @@ func (self *XEth) Block(v interface{}) *Block {
return self.BlockByNumber(int64(n)) return self.BlockByNumber(int64(n))
} else if str, ok := v.(string); ok { } else if str, ok := v.(string); ok {
return self.BlockByHash(str) 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)) 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) { 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 var from *state.StateObject
if len(fromStr) == 0 { if len(fromStr) == 0 {
accounts, err := self.backend.AccountManager().Accounts() accounts, err := self.backend.AccountManager().Accounts()
@ -869,6 +871,7 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
contractCreation bool contractCreation bool
) )
// 2015-05-18 Is this still needed?
// TODO if no_private_key then // TODO if no_private_key then
//if _, exists := p.register[args.From]; exists { //if _, exists := p.register[args.From]; exists {
// p.register[args.From] = append(p.register[args.From], args) // p.register[args.From] = append(p.register[args.From], args)