ethclient: serialize negative block number as "pending" (#21177)
Fixes #21175 Co-authored-by: sammy007 <sammy007@users.noreply.github.com> Co-authored-by: Adam Schmideg <adamschmideg@users.noreply.github.com>
This commit is contained in:
@ -282,6 +282,10 @@ func toBlockNumArg(number *big.Int) string {
|
||||
if number == nil {
|
||||
return "latest"
|
||||
}
|
||||
pending := big.NewInt(-1)
|
||||
if number.Cmp(pending) == 0 {
|
||||
return "pending"
|
||||
}
|
||||
return hexutil.EncodeBig(number)
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,22 @@ func TestToFilterArg(t *testing.T) {
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"with negative fromBlock and negative toBlock",
|
||||
ethereum.FilterQuery{
|
||||
Addresses: addresses,
|
||||
FromBlock: big.NewInt(-1),
|
||||
ToBlock: big.NewInt(-1),
|
||||
Topics: [][]common.Hash{},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"address": addresses,
|
||||
"fromBlock": "pending",
|
||||
"toBlock": "pending",
|
||||
"topics": [][]common.Hash{},
|
||||
},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"with blockhash",
|
||||
ethereum.FilterQuery{
|
||||
|
Reference in New Issue
Block a user