diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index e2bc68c67d..045182c1fa 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -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" diff --git a/ethclient/ethclient_test.go b/ethclient/types_test.go similarity index 90% rename from ethclient/ethclient_test.go rename to ethclient/types_test.go index 2eeb232a41..9de4707a14 100644 --- a/ethclient/ethclient_test.go +++ b/ethclient/types_test.go @@ -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{