mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 23:57:23 +00:00
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:
parent
d5efd34010
commit
52f998d5ec
2 changed files with 18 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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{
|
||||
|
|
|
|||
Loading…
Reference in a new issue