Skip to content

Commit 7163a66

Browse files
ethclient: serialize negative block number as "pending" (#21177)
Fixes #21175 Co-authored-by: sammy007 <[email protected]> Co-authored-by: Adam Schmideg <[email protected]>
1 parent 4366c45 commit 7163a66

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

core/types/gen_log_json.go

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/types/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ type Log struct {
4444
// hash of the transaction
4545
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
4646
// index of the transaction in the block
47-
TxIndex uint `json:"transactionIndex" gencodec:"required"`
47+
TxIndex uint `json:"transactionIndex"`
4848
// hash of the block in which the transaction was included
4949
BlockHash common.Hash `json:"blockHash"`
5050
// index of the log in the block
51-
Index uint `json:"logIndex" gencodec:"required"`
51+
Index uint `json:"logIndex"`
5252

5353
// The Removed field is true if this log was reverted due to a chain reorganisation.
5454
// You must pay attention to this field if you receive logs through a filter query.

ethclient/ethclient.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ func toBlockNumArg(number *big.Int) string {
282282
if number == nil {
283283
return "latest"
284284
}
285+
pending := big.NewInt(-1)
286+
if number.Cmp(pending) == 0 {
287+
return "pending"
288+
}
285289
return hexutil.EncodeBig(number)
286290
}
287291

ethclient/ethclient_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ func TestToFilterArg(t *testing.T) {
9797
},
9898
nil,
9999
},
100+
{
101+
"with negative fromBlock and negative toBlock",
102+
ethereum.FilterQuery{
103+
Addresses: addresses,
104+
FromBlock: big.NewInt(-1),
105+
ToBlock: big.NewInt(-1),
106+
Topics: [][]common.Hash{},
107+
},
108+
map[string]interface{}{
109+
"address": addresses,
110+
"fromBlock": "pending",
111+
"toBlock": "pending",
112+
"topics": [][]common.Hash{},
113+
},
114+
nil,
115+
},
100116
{
101117
"with blockhash",
102118
ethereum.FilterQuery{

0 commit comments

Comments
 (0)