Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mcmire
Copy link
Collaborator

@mcmire mcmire commented Dec 16, 2022

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 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.

Screencaps

Screen.Recording.2022-12-15.at.5.24.28.PM.mov

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).
Comment on lines +34 to +37
if (!['log', 'block', 'pendingTransaction'].includes(filterType)) {
throw new Error(
"filterType must be either 'log', 'block', or 'pendingTransaction'",
);
Copy link
Contributor

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 ;)

Suggested change
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],
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants