feat: ethrpc: Support filtering by address in subscribe
This commit is contained in:
parent
3d207de6aa
commit
fe1e0974cb
@ -660,6 +660,12 @@ type EthSubscriptionParams struct {
|
|||||||
// List of topics to be matched.
|
// List of topics to be matched.
|
||||||
// Optional, default: empty list
|
// Optional, default: empty list
|
||||||
Topics EthTopicSpec `json:"topics,omitempty"`
|
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 {
|
type EthSubscriptionResponse struct {
|
||||||
|
@ -52,7 +52,7 @@ func TestEthFilterAPIDisabledViaConfig(t *testing.T) {
|
|||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
require.Equal(t, err.Error(), api.ErrNotSupported.Error())
|
require.Equal(t, err.Error(), api.ErrNotSupported.Error())
|
||||||
|
|
||||||
_, err = client.EthSubscribe(ctx, "newHeads", nil)
|
_, err = client.EthSubscribe(ctx, []byte{})
|
||||||
require.NotNil(t, err)
|
require.NotNil(t, err)
|
||||||
require.Equal(t, err.Error(), api.ErrNotSupported.Error())
|
require.Equal(t, err.Error(), api.ErrNotSupported.Error())
|
||||||
|
|
||||||
|
@ -575,7 +575,10 @@ func TestEthSubscribeLogs(t *testing.T) {
|
|||||||
// subscribe to topics in filter
|
// subscribe to topics in filter
|
||||||
subParam, err := json.Marshal(ethtypes.EthSubscribeParams{
|
subParam, err := json.Marshal(ethtypes.EthSubscribeParams{
|
||||||
EventType: "logs",
|
EventType: "logs",
|
||||||
Params: ðtypes.EthSubscriptionParams{Topics: tc.spec.Topics},
|
Params: ðtypes.EthSubscriptionParams{
|
||||||
|
Topics: tc.spec.Topics,
|
||||||
|
Address: tc.spec.Address,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
|
@ -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 {
|
if err != nil {
|
||||||
// clean up any previous filters added and stop the sub
|
// clean up any previous filters added and stop the sub
|
||||||
_, _ = e.EthUnsubscribe(ctx, sub.id)
|
_, _ = e.EthUnsubscribe(ctx, sub.id)
|
||||||
|
Loading…
Reference in New Issue
Block a user