ethclient: omit nil address/topics from filter args (#33464)

Fixes #33369

This omits "topics" and "addresses" from the filter when they are unspecified.
It is required for interoperability with some server implementations that cannot
handle `null` for these fields.
This commit is contained in:
Madison carter 2026-01-08 05:09:29 -05:00 committed by GitHub
parent d5efd34010
commit 52f998d5ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View file

@ -497,9 +497,12 @@ func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuer
}
func toFilterArg(q ethereum.FilterQuery) (interface{}, error) {
arg := map[string]interface{}{
"address": q.Addresses,
"topics": q.Topics,
arg := map[string]interface{}{}
if q.Addresses != nil {
arg["address"] = q.Addresses
}
if q.Topics != nil {
arg["topics"] = q.Topics
}
if q.BlockHash != nil {
arg["blockHash"] = *q.BlockHash

View file

@ -41,6 +41,18 @@ func TestToFilterArg(t *testing.T) {
output interface{}
err error
}{
{
"without addresses",
ethereum.FilterQuery{
FromBlock: big.NewInt(1),
ToBlock: big.NewInt(2),
},
map[string]interface{}{
"fromBlock": "0x1",
"toBlock": "0x2",
},
nil,
},
{
"without BlockHash",
ethereum.FilterQuery{