Skip to content

Commit 5707912

Browse files
committed
"pending" convention should be -2 instead of 0
1 parent 2f8601e commit 5707912

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎rpc/args.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func blockHeight(raw interface{}, number *int64) (err error) {
2626
case "latest":
2727
*number = -1
2828
case "pending":
29-
*number = 0
29+
*number = -2
3030
default:
3131
*number = common.String2Big(str).Int64()
3232
}

‎xeth/xeth.go‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,12 @@ func (self *XEth) AtStateNum(num int64) *XEth {
176176
chain := self.Backend().ChainManager()
177177
var block *types.Block
178178

179+
// -1 generally means "latest"
180+
// -2 means "pending", which has no blocknum
179181
if num < 0 {
180-
num = chain.CurrentBlock().Number().Int64() + num + 1
182+
num = chain.CurrentBlock().Number().Int64()
181183
}
184+
182185
block = chain.GetBlockByNumber(uint64(num))
183186

184187
var st *state.StateDB
@@ -229,6 +232,11 @@ func (self *XEth) EthTransactionByHash(hash string) *types.Transaction {
229232
}
230233

231234
func (self *XEth) BlockByNumber(num int64) *Block {
235+
if num == -2 {
236+
// "pending" is non-existant
237+
return &Block{}
238+
}
239+
232240
if num == -1 {
233241
return NewBlock(self.chainManager.CurrentBlock())
234242
}
@@ -237,6 +245,11 @@ func (self *XEth) BlockByNumber(num int64) *Block {
237245
}
238246

239247
func (self *XEth) EthBlockByNumber(num int64) *types.Block {
248+
if num == -2 {
249+
// "pending" is non-existant
250+
return &types.Block{}
251+
}
252+
240253
if num == -1 {
241254
return self.chainManager.CurrentBlock()
242255
}

0 commit comments

Comments
 (0)