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

feat(rpc-types): add topic0 (alias event_signature) getter to Log #799

Merged
merged 4 commits into from
May 29, 2024

Conversation

zerosnacks
Copy link
Member

@zerosnacks zerosnacks commented May 29, 2024

Motivation

Currently there is not an elegant way of accessing the event signature in the Log as returned by the SubscriptionStream, which is useful for matching against when one subscribes to all (or multiple) contract events.

For context: https://github.com/alloy-rs/examples/blob/dbe65d8ca96348ffa64720ea566079e7c1e87fbf/examples/subscriptions/examples/subscribe_all_logs.rs#L45-L62

Solution

Adds simple getter for 0-indexing into topics, mirrors the event_signature syntax used for setting topic0 on the Filter instance. I don't see a good reason to add getters for the other topics.

Adds simple getter for topic0, checking for existence.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@prestwich
Copy link
Member

2 things

  • this will panic. Should check that topics is non-empty
  • not all events have a signature. anonymous events have none. should name this topic0

@zerosnacks
Copy link
Member Author

2 things

  • this will panic. Should check that topics is non-empty
  • not all events have a signature. anonymous events have none. should name this topic0

Thanks! Good catch

@zerosnacks zerosnacks marked this pull request as ready for review May 29, 2024 15:32
@prestwich
Copy link
Member

one more nit and then lfg

we could add a doc alias for event_signature so it shows up in searches

@zerosnacks zerosnacks changed the title feat(rpc-types): add event_signature (topic0) getter to Log feat(rpc-types): add topic0 (alias event_signature) getter to Log May 29, 2024
@zerosnacks zerosnacks changed the title feat(rpc-types): add topic0 (alias event_signature) getter to Log feat(rpc-types): add topic0 (alias event_signature) getter to Log May 29, 2024
@prestwich prestwich merged commit 3edca45 into main May 29, 2024
24 checks passed
@prestwich prestwich deleted the zerosnacks/add-event-signature-getter branch May 29, 2024 15:48
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
…alloy-rs#799)

* add simple getter for the topic0 field, useful when matching event signatures against it

* make sure index is safely accessed

* fix clippy

* add docs alias of event_signature for topic0
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.

2 participants