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

Support filtering options for eth_subscribe with logs #27842

Closed
vadimstruts opened this issue Jan 16, 2023 · 1 comment · Fixed by brave/brave-core#16826
Closed

Support filtering options for eth_subscribe with logs #27842

vadimstruts opened this issue Jan 16, 2023 · 1 comment · Fixed by brave/brave-core#16826
Assignees
Labels
feature/web3/wallet/core feature/web3/wallet Integrating Ethereum+ wallet support OS/Android Fixes related to Android browser functionality OS/Desktop OS/iOS Fixes related to iOS browser functionality priority/P4 Planned work. We expect to get to it "soon". QA Pass - Android ARM QA Pass-Win64 QA/Yes release-notes/include

Comments

@vadimstruts
Copy link
Collaborator

Description

The issue is a follow up of: #27283 - Support eth_subscribe with "logs" param

For now we support only this:
window.ethereum.on('message', (x, y, z) => console.log('message event: ', x, y, z)) window.ethereum.send({ id:5, method: 'eth_subscribe', params:["logs"]}, console.log)

But we need to extend the eth_subscribe subscription for method: "logs" with filtering options support.
Ex.:

window.ethereum.on('message', (x, y, z) => console.log('message event: ', x, y, z))
window.ethereum.send({ id:1, method: 'eth_subscribe', params:['logs', {"address":  "0xD9C2ec046dBbDe5e670D27250cf3385300062C5d",  "topics":  ["0x2edcb8328dc82dc24d7a2b50a94f19db11146048d396320228feb7c79c3301e1"]}]}, console.log)

Here is options that can be supported according with: eth_getLogs

  • fromBlock - (optional, default: "latest") Integer block number encoded as a hexadecimal or the string, "latest", "pending", and "earliest".
  • toBlock - (optional, default: "latest") Integer block number encoded as a hexadecimal or the string, "latest", "pending", and "earliest".
  • address - (optional) Contract address or a list of addresses from which logs should originate.
  • topics - (optional) Array of DATA topics. Topics are order-dependent. Visit this Wiki page to learn more about topics.
  • blockHash - (optional) With the addition of EIP-234, blockHash is a new filter option that restricts the logs returned to the block number referenced in the blockHash. Using the blockHash field is equivalent to setting the fromBlock and toBlock to the block number the blockHash references. If blockHash is present in the filter criteria, neither fromBlock nor toBlock is allowed.

Steps to Reproduce

  1. Setup Brave Wallet
  2. Open new tab with any website
  3. Open Developer console (F12)
  4. paste next code into console:
window.ethereum.on('message', (x, y, z) => console.log('message event: ', x, y, z))
window.ethereum.send({ id:1, method: 'eth_subscribe', params:['logs', {"address":  "0xD9C2ec046dBbDe5e670D27250cf3385300062C5d",  "topics":  ["0x2edcb8328dc82dc24d7a2b50a94f19db11146048d396320228feb7c79c3301e1"]}]}, console.log)

Actual result:

when you try ti subscribe for logging with filtering options, you get an error:
image

Expected result:

Successful subscription result:

{
    "id": 5,
    "jsonrpc": "2.0",
    "result": "0xf96fe6f4b327b323408ef991f99cd65b"
}

and filtering options are applied.

Reproduces how often:

Easily reproduced

Desktop Brave version:

1.49.27 Chromium: 109.0.5414.87 (Developer Build) (64-bit)

@srirambv
Copy link
Contributor

Verification passed on

Brave 1.50.94 Chromium: 111.0.5563.64 (Official Build) beta (64-bit)
Revision c710e93d5b63b7095afe8c2c17df34408078439d-refs/branch-heads/5563@{#995}
OS Windows 11 Version 22H2 (Build 22621.1344)
  • Verified steps from brave/brave-core#16826
  • Verified able to subscribe for logs with additional filter options
  • Verified able to successfully unsubscribe to logs with additional filter options
window.ethereum.on('message', (x, y, z) => console.log('message event: ', x, y, z))
window.ethereum.send({ id:1, method: 'eth_subscribe', params:['logs', {"address":  ["0xdac17f958d2ee523a2206206994597c13d831ec7", "0x51fe8e8fa3f9f10288fa8c2aff1400f887d21c42"]}]}, console.log)
undefined
null {id: 1, jsonrpc: '2.0', result: '0x56473b38e2489a3ad5168ac5ec5ea1ef'}id: 1jsonrpc: "2.0"result: "0x56473b38e2489a3ad5168ac5ec5ea1ef"[[Prototype]]: Object
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x56473b38e2489a3ad5168ac5ec5ea1ef'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x56473b38e2489a3ad5168ac5ec5ea1ef'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x56473b38e2489a3ad5168ac5ec5ea1ef'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x56473b38e2489a3ad5168ac5ec5ea1ef'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x56473b38e2489a3ad5168ac5ec5ea1ef'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x56473b38e2489a3ad5168ac5ec5ea1ef'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM1439:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
window.ethereum.on('message', (x, y, z) => console.log('message event: ', x, y, z))
window.ethereum.send({ id:5, method: 'eth_unsubscribe', params:['0x56473b38e2489a3ad5168ac5ec5ea1ef']}, console.log)
undefined
null {id: 5, jsonrpc: '2.0', result: true}id: 5jsonrpc: "2.0"result: true[[Prototype]]: Object
27842.mp4

Verification passed on Oppo Reno 5 with Android 13 running 1.50.93 x64 Beta build

  • Verified steps from brave/brave-core#16826
  • Verified able to subscribe for logs with additional filter options
  • Verified able to successfully unsubscribe to logs with additional filter options
window.ethereum.on('message', (x, y, z) => console.log('message event: ', x, y, z))
window.ethereum.send({ id:1, method: 'eth_subscribe', params:['logs', {"address":  ["0xdac17f958d2ee523a2206206994597c13d831ec7", "0x51fe8e8fa3f9f10288fa8c2aff1400f887d21c42"]}]}, console.log)
undefined
null {id: 1, jsonrpc: '2.0', result: '0x381372df84566b774dbc2d2caea021b5'}id: 1jsonrpc: "2.0"result: "0x381372df84566b774dbc2d2caea021b5"[[Prototype]]: Object
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x381372df84566b774dbc2d2caea021b5'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x381372df84566b774dbc2d2caea021b5'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x381372df84566b774dbc2d2caea021b5'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x381372df84566b774dbc2d2caea021b5'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x381372df84566b774dbc2d2caea021b5'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'}data: {result: {…}, subscription: '0x381372df84566b774dbc2d2caea021b5'}type: "eth_subscription"[[Prototype]]: Object undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
VM63:1 message event:  {data: {…}, type: 'eth_subscription'} undefined undefined
window.ethereum.on('message', (x, y, z) => console.log('message event: ', x, y, z))
window.ethereum.send({ id:5, method: 'eth_unsubscribe', params:['0x381372df84566b774dbc2d2caea021b5']}, console.log)
undefined
null {id: 5, jsonrpc: '2.0', result: true}id: 5jsonrpc: "2.0"result: true[[Prototype]]: Object
27842-Android.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/web3/wallet/core feature/web3/wallet Integrating Ethereum+ wallet support OS/Android Fixes related to Android browser functionality OS/Desktop OS/iOS Fixes related to iOS browser functionality priority/P4 Planned work. We expect to get to it "soon". QA Pass - Android ARM QA Pass-Win64 QA/Yes release-notes/include
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants