-
-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add interactions involving filters & subscriptions #202
base: main
Are you sure you want to change the base?
Conversation
We have a PR in the extension repo which touches code around RPC middleware for filter- and subscription-based RPC methods, and we want to be able to test these methods manually to ensure they are still working as designed. In order to accomplish this, I've added new cards which allow the user to: * Create and remove a filter. * Currently there is support for creating a generic log filter via `eth_newFilter` as well as a block filter via `eth_newBlockFilter`. Once a filter is created, `eth_getFilterChanges` is then polled every 2 seconds. Filters are removed via `eth_uninstallFilter`. * I tried to add a button which created a pending transaction filter via `eth_newPendingTransactionFilter`, but it appears that `eth-json-rpc-filters` has a [bug](MetaMask/eth-json-rpc-filters#81) which prohibits this RPC method from working fully. * Start and stop a subscription. * As with filters, currently there is support for subscribing to new blocks via the `newHeads` parameter to `eth_subscribe` as well as new logs via the `logs` parameter. Subscriptions are stopped via `eth_unsubscribe`. * I also tried to add a button for subscribing to pending transactions, but [this doesn't seem to be supported outright by `eth-json-rpc-filters`](https://github.com/MetaMask/eth-json-rpc-filters/blob/5cbea3037b0655aa2c188d85b8ffe559a263dc0d/subscriptionManager.js#L50).
if (!['log', 'block', 'pendingTransaction'].includes(filterType)) { | ||
throw new Error( | ||
"filterType must be either 'log', 'block', or 'pendingTransaction'", | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly to get rid of double-quotes ;)
if (!['log', 'block', 'pendingTransaction'].includes(filterType)) { | |
throw new Error( | |
"filterType must be either 'log', 'block', or 'pendingTransaction'", | |
); | |
const validFilterTypes = ['log', 'block', 'pendingTransaction']; | |
if (!validFilterTypes.includes(filterType)) { | |
throw new Error( | |
`filterType must be one of: ${validFilterTypes.join(',')}.`, | |
); |
|
||
newSubscriptionId = await ethereum.request({ | ||
method: 'eth_subscribe', | ||
params: [subscriptionType], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the logs
subscription type, this ends up being very noisy. Perhaps we could add a "topic" filter to reduce the volume?
We have a PR in the extension repo which touches code around RPC middleware for filter- and subscription-based RPC methods, and we want to be able to test these methods manually to ensure they are still working as designed. In order to accomplish this, I've added new cards which allow the user to:
eth_newFilter
as well as a block filter viaeth_newBlockFilter
. Once a filter is created,eth_getFilterChanges
is then polled every 2 seconds. Filters are removed viaeth_uninstallFilter
.eth_newPendingTransactionFilter
, but it appears thateth-json-rpc-filters
has a bug which prohibits this RPC method from working fully.newHeads
parameter toeth_subscribe
as well as new logs via thelogs
parameter. Subscriptions are stopped viaeth_unsubscribe
.eth-json-rpc-filters
.Screencaps
Screen.Recording.2022-12-15.at.5.24.28.PM.mov