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 blockHash in getLogs (EIP-234) #412

Closed
wants to merge 1 commit into from

Conversation

epheph
Copy link

@epheph epheph commented Feb 2, 2019

Simple change to allow blockHash through checkFilter(). The type union isn't strictly necessary, but it is more descriptive.

@ricmoo
Copy link
Member

ricmoo commented Feb 2, 2019

Is this widely supported? I don’t see it in the JSON-RPC specification: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_newfilter

@epheph
Copy link
Author

epheph commented Feb 2, 2019

It's for getLogs:
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
It wouldn't work as a filter, since it wouldn't change over time

@ricmoo
Copy link
Member

ricmoo commented Feb 2, 2019

Oh! That makes way more sense! :)

Thanks, I had not seen EIP-234. I’ll look into it and get back to this PR this week.

@epheph
Copy link
Author

epheph commented Feb 3, 2019

Awesome, thanks! For context, I am working on a project which injects ether.js into https://github.com/ethereumjs/ethereumjs-blockstream , which detects when new blocks come in and manually fetches their logs by blockHash (to avoid a race conditions during re-org where a different block's logs are returned)

@pgebheim
Copy link

pgebheim commented Feb 8, 2019

p.s. the CI is failing just 'cause the dist hash changed and wasn't updated in the test (until we're sure you like this change).

@ricmoo
Copy link
Member

ricmoo commented Feb 8, 2019

Oh yes, no worries. I expect those test cases to fail for normal humans. :)

They are there for me after I make changes so I don’t accidentally publish a package that fails verified deterministic building (could mean the code was maliciously modified by me or a script on my computer, or more likely, that I forgot to run npm run dist). :)

Today I have time to get back to some ethers issues. I’ll check this out this afternoon. :)

@ricmoo
Copy link
Member

ricmoo commented Feb 9, 2019

I have added the changes necessary to get this working for getLogs. I've modified your suggestions a little bit, to prevent the blockHash enabled filter from being used as an EventType, which will require additional work to fully support (which likely won't get in until v5; I'll start adding it to the local v5 branch now).

I've also updated Etherscan to throw if it is attempted, since their blockchain API does not support blockHash.

@ricmoo
Copy link
Member

ricmoo commented Feb 9, 2019

Try out 4.0.24 and let me know if this works for you. There is still some work to be done, and I need to think through what events should look like. I'll be refactoring this a bit in v5.

Thanks! :)

@ricmoo ricmoo closed this Feb 9, 2019
@epheph
Copy link
Author

epheph commented Feb 9, 2019

Yep, totally works, thanks!!!

@pgebheim
Copy link

pgebheim commented Feb 9, 2019 via email

@ricmoo
Copy link
Member

ricmoo commented Feb 14, 2019

Relevant snippet from v5, looking for some feedback:

export interface EventFilter {
    address?: string;
    topics?: Array<string | Array<string>>;
}

export interface Filter extends EventFilter {
    fromBlock?: BlockTag;
    toBlock?: BlockTag;
}

export interface FilterByBlockHash extends EventFilter {
    blockhash?: string;
}

export type EventType = string | Array<string> | EventFilter;

Thanks! :)

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