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

Feature Request: A query that returns the most recent event for a given filter. #20593

Open
4c656554 opened this issue Jan 25, 2020 · 4 comments

Comments

@4c656554
Copy link

Thanks to the developers for this great software!

This is a "would be nice to have" feature request to add a flag to the JSON-RPC/GraphQL query input have Geth search for the events in reverse chronological order and only return the most recent log (or the batch from that block).

Unless I'm mistaken, at the moment it is only possible to construct queries that return all of the events for a given filter.

If you have a case where you only want the most recent event, but you don't know when it occurred, you still need to get back all of the events and filter (potentially not ideal on a client machine).

See also:

https://ethereum.stackexchange.com/questions/41976/how-to-get-only-latest-log-from-my-event
https://ethereum.stackexchange.com/questions/8699/how-to-get-only-latest-logged-event-via-web3-api

Thanks,

Lee

@adamschmideg
Copy link
Contributor

A legit feature request. We'd first need a solid test suite for filtering.

@karalabe
Copy link
Member

This is not a bad idea, but our log filtering is a bit messy and not properly tested. We'd need to start by writing a very comprehensive test suite to avoid introducing regressions.

@4c656554
Copy link
Author

4c656554 commented Jan 30, 2020

Something along the lines of this? :- https://github.com/ethereum/rpc-tests

My approach would be to:

  1. duplicate the unindexedLogs function (as unindexedLogsReverse ) and adjust to iterate from end to head and return when it finds a log.

  2. duplicate getFilterLogs (as e.g. getLastFilterLog) to call above function.

  3. Add a references to a new API call (e.g. getLastFilterLog ) and link to above, if this is needed.

N.b. If it's not apparent, I haven't yet got a good understanding of the architecture, and am not familiar with Go.

@lhendre
Copy link
Contributor

lhendre commented May 2, 2022

@karalabe is there an issue or has the test suite been created?

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

No branches or pull requests

5 participants