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

This commit is contained in:
Daniel Liu 2026-01-19 16:50:01 +08:00 committed by GitHub
parent 217b069ec0
commit 060a0e4810
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 18 deletions

View file

@ -493,9 +493,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.FromBlock == nil {
arg["fromBlock"] = "0x0"

View file

@ -29,21 +29,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/rpc"
)
// Verify that Client implements the ethereum interfaces.
var (
_ = ethereum.ChainReader(&Client{})
_ = ethereum.TransactionReader(&Client{})
_ = ethereum.ChainStateReader(&Client{})
_ = ethereum.ChainSyncReader(&Client{})
_ = ethereum.ContractCaller(&Client{})
_ = ethereum.GasEstimator(&Client{})
_ = ethereum.GasPricer(&Client{})
_ = ethereum.LogFilterer(&Client{})
_ = ethereum.PendingStateReader(&Client{})
// _ = ethereum.PendingStateEventer(&Client{})
_ = ethereum.PendingContractCaller(&Client{})
)
func TestToFilterArg(t *testing.T) {
blockHashErr := errors.New("cannot specify both BlockHash and FromBlock/ToBlock")
addresses := []common.Address{
@ -59,6 +44,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{