ethclient: omit empty address/topics fields in RPC filter requests (#33884)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

Changes JSON serialization of FilterCriteria to exclude "address" when it is empty.
This commit is contained in:
locoholy 2026-04-07 21:01:26 +05:00 committed by GitHub
parent 0bafb29490
commit 9878ef926d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View file

@ -498,7 +498,11 @@ func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuer
func toFilterArg(q ethereum.FilterQuery) (interface{}, error) {
arg := map[string]interface{}{}
if q.Addresses != nil {
// Only include "address" when there are actual address filters.
// An empty slice is treated the same as nil (no filter), and omitting
// the field avoids sending "address":[] to nodes that reject empty arrays
// (e.g. Hedera, some non-Geth implementations).
if len(q.Addresses) > 0 {
arg["address"] = q.Addresses
}
if q.Topics != nil {

View file

@ -53,6 +53,22 @@ func TestToFilterArg(t *testing.T) {
},
nil,
},
{
// empty Addresses slice must be treated same as nil:
// the "address" field must be omitted so that non-Geth nodes
// (e.g. Hedera) do not reject the request with an error.
"with empty addresses slice",
ethereum.FilterQuery{
Addresses: []common.Address{},
FromBlock: big.NewInt(1),
ToBlock: big.NewInt(2),
},
map[string]interface{}{
"fromBlock": "0x1",
"toBlock": "0x2",
},
nil,
},
{
"without BlockHash",
ethereum.FilterQuery{