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

Events returned by WebSocketProvider inconsistent with getLogs #795

Closed
bbarton opened this issue Apr 21, 2020 · 7 comments
Closed

Events returned by WebSocketProvider inconsistent with getLogs #795

bbarton opened this issue Apr 21, 2020 · 7 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@bbarton
Copy link

bbarton commented Apr 21, 2020

Hi @ricmoo ,

When I receive an event via Websockets, the event.blockNumber appears in hex (but otherwise seems to work fine).

However, when I do provider.getLogs() (using normal Infura provider), the log.blockNumber is in decimal format.

My assumption has been that a log (using normal provider) and a Websocket event are the same type of object. Is that correct? Should both be returning decimal blockNumber?

Thanks!

@ricmoo
Copy link
Member

ricmoo commented Apr 21, 2020

Both should be returning a decimal. You are right, the subscribed events in the WebSocketProvider is skipping the regular wrapping for block, but logs are still wrapped properly. I’ll fix it shortly. And double check everything else is being normalized correctly. :)

@ricmoo ricmoo added investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels Apr 21, 2020
@ricmoo
Copy link
Member

ricmoo commented Apr 22, 2020

Actually... I can't reproduce this and the place I thought might be left unguarded seems to wrap the call correctly. Can you include a snippet of code? Also, what backend are you using?

These seem to all work:

provider.getBlockNumber().then((b) => {
    console.log("getBlockNumber", b);
});

provider.on("block", (b) => {
    console.log("event", b);
    console.log("per event", provider.blockNumber);
});

@ricmoo
Copy link
Member

ricmoo commented Apr 22, 2020

Oh! Misread... One sec. :)

No wait... I didn't misread, please pass along a code snippet. :)

@bbarton
Copy link
Author

bbarton commented Apr 22, 2020

I can confirm that the block numbers are returned correctly for your code snippets above.

The issue I'm encountering is when listening for events:

    // Listen for all contract events.
    wsContract.on("*", (event) => {
      console.log("New event from block: ", event.blockNumber); // Returns a hex value
    });

@ricmoo ricmoo added bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels Apr 24, 2020
@ricmoo
Copy link
Member

ricmoo commented Apr 24, 2020

Found the problem. I'll publish after the CI completes. :)

@ricmoo
Copy link
Member

ricmoo commented Apr 24, 2020

This should be fixed in 5.0.0-beta.183. Try it out and let me know. :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Apr 24, 2020
@bbarton
Copy link
Author

bbarton commented Apr 25, 2020

It's working! Thank you.

@bbarton bbarton closed this as completed Apr 25, 2020
michaeltout pushed a commit to michaeltout/ethers.js that referenced this issue Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants