diff options
-rw-r--r-- | rpc/args.go | 16 | ||||
-rw-r--r-- | xeth/xeth.go | 15 |
2 files changed, 22 insertions, 9 deletions
diff --git a/rpc/args.go b/rpc/args.go index 06dab99bc..6e02b65ef 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" ) -func blockAge(raw interface{}, number *int64) (err error) { +func blockHeight(raw interface{}, number *int64) (err error) { // Parse as integer num, ok := raw.(float64) if ok { @@ -26,7 +26,7 @@ func blockAge(raw interface{}, number *int64) (err error) { case "latest": *number = -1 case "pending": - *number = 0 + *number = -2 default: *number = common.String2Big(str).Int64() } @@ -137,7 +137,7 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) { return NewDecodeParamError(err.Error()) } - if err := blockAge(raw, &args.BlockNumber); err != nil { + if err := blockHeight(raw, &args.BlockNumber); err != nil { return err } } @@ -174,7 +174,7 @@ func (args *GetStorageArgs) UnmarshalJSON(b []byte) (err error) { args.Address = addstr if len(obj) > 1 { - if err := blockAge(obj[1], &args.BlockNumber); err != nil { + if err := blockHeight(obj[1], &args.BlockNumber); err != nil { return err } } @@ -218,7 +218,7 @@ func (args *GetStorageAtArgs) UnmarshalJSON(b []byte) (err error) { args.Key = keystr if len(obj) > 2 { - if err := blockAge(obj[2], &args.BlockNumber); err != nil { + if err := blockHeight(obj[2], &args.BlockNumber); err != nil { return err } } @@ -259,7 +259,7 @@ func (args *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) { args.Address = addstr if len(obj) > 1 { - if err := blockAge(obj[1], &args.BlockNumber); err != nil { + if err := blockHeight(obj[1], &args.BlockNumber); err != nil { return err } } @@ -296,7 +296,7 @@ func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) { args.Address = addstr if len(obj) > 1 { - if err := blockAge(obj[1], &args.BlockNumber); err != nil { + if err := blockHeight(obj[1], &args.BlockNumber); err != nil { return err } } @@ -333,7 +333,7 @@ func (args *GetDataArgs) UnmarshalJSON(b []byte) (err error) { args.Address = addstr if len(obj) > 1 { - if err := blockAge(obj[1], &args.BlockNumber); err != nil { + if err := blockHeight(obj[1], &args.BlockNumber); err != nil { return err } } diff --git a/xeth/xeth.go b/xeth/xeth.go index 23e523980..f7f4ce0cf 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -176,9 +176,12 @@ func (self *XEth) AtStateNum(num int64) *XEth { chain := self.Backend().ChainManager() var block *types.Block + // -1 generally means "latest" + // -2 means "pending", which has no blocknum if num < 0 { - num = chain.CurrentBlock().Number().Int64() + num + 1 + num = chain.CurrentBlock().Number().Int64() } + block = chain.GetBlockByNumber(uint64(num)) var st *state.StateDB @@ -229,6 +232,11 @@ func (self *XEth) EthTransactionByHash(hash string) *types.Transaction { } func (self *XEth) BlockByNumber(num int64) *Block { + if num == -2 { + // "pending" is non-existant + return &Block{} + } + if num == -1 { return NewBlock(self.chainManager.CurrentBlock()) } @@ -237,6 +245,11 @@ func (self *XEth) BlockByNumber(num int64) *Block { } func (self *XEth) EthBlockByNumber(num int64) *types.Block { + if num == -2 { + // "pending" is non-existant + return &types.Block{} + } + if num == -1 { return self.chainManager.CurrentBlock() } |