From fe1e0974cb24ab81e2249b612e7c23f31c63a5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 2 Feb 2023 14:26:56 +0100 Subject: [PATCH] feat: ethrpc: Support filtering by address in subscribe --- chain/types/ethtypes/eth_types.go | 6 ++++++ itests/eth_config_test.go | 2 +- itests/eth_filter_test.go | 5 ++++- node/impl/full/eth.go | 11 ++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/chain/types/ethtypes/eth_types.go b/chain/types/ethtypes/eth_types.go index 584a7d2be..c53178564 100644 --- a/chain/types/ethtypes/eth_types.go +++ b/chain/types/ethtypes/eth_types.go @@ -660,6 +660,12 @@ type EthSubscriptionParams struct { // List of topics to be matched. // Optional, default: empty list Topics EthTopicSpec `json:"topics,omitempty"` + + // Actor address or a list of addresses from which event logs should originate. + // Optional, default nil. + // The JSON decoding must treat a string as equivalent to an array with one value, for example + // "0x8888f1f195afa192cfee86069858" must be decoded as [ "0x8888f1f195afa192cfee86069858" ] + Address EthAddressList `json:"address"` } type EthSubscriptionResponse struct { diff --git a/itests/eth_config_test.go b/itests/eth_config_test.go index 5b04755ed..5ce9516d2 100644 --- a/itests/eth_config_test.go +++ b/itests/eth_config_test.go @@ -52,7 +52,7 @@ func TestEthFilterAPIDisabledViaConfig(t *testing.T) { require.NotNil(t, err) require.Equal(t, err.Error(), api.ErrNotSupported.Error()) - _, err = client.EthSubscribe(ctx, "newHeads", nil) + _, err = client.EthSubscribe(ctx, []byte{}) require.NotNil(t, err) require.Equal(t, err.Error(), api.ErrNotSupported.Error()) diff --git a/itests/eth_filter_test.go b/itests/eth_filter_test.go index c66a56154..d26222e69 100644 --- a/itests/eth_filter_test.go +++ b/itests/eth_filter_test.go @@ -575,7 +575,10 @@ func TestEthSubscribeLogs(t *testing.T) { // subscribe to topics in filter subParam, err := json.Marshal(ethtypes.EthSubscribeParams{ EventType: "logs", - Params: ðtypes.EthSubscriptionParams{Topics: tc.spec.Topics}, + Params: ðtypes.EthSubscriptionParams{ + Topics: tc.spec.Topics, + Address: tc.spec.Address, + }, }) require.NoError(err) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 40b2c7c10..ef68b02e6 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -1147,7 +1147,16 @@ func (e *EthEvent) EthSubscribe(ctx context.Context, p jsonrpc.RawParams) (ethty } } - f, err := e.EventFilterManager.Install(ctx, -1, -1, cid.Undef, []address.Address{}, keys) + var addresses []address.Address + for _, ea := range params.Params.Address { + a, err := ea.ToFilecoinAddress() + if err != nil { + return ethtypes.EthSubscriptionID{}, xerrors.Errorf("invalid address %x", ea) + } + addresses = append(addresses, a) + } + + f, err := e.EventFilterManager.Install(ctx, -1, -1, cid.Undef, addresses, keys) if err != nil { // clean up any previous filters added and stop the sub _, _ = e.EthUnsubscribe(ctx, sub.id)