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: add generics to filter, transaction, and pub_sub. #573

Merged
merged 5 commits into from
Apr 20, 2024

Conversation

EmperorOrokuSaki
Copy link
Contributor

@EmperorOrokuSaki EmperorOrokuSaki commented Apr 18, 2024

Motivation

In order to be able to use several structs and types from this repository for the Optimism port, they should take generics that can be replaced/used with the optimism types.

Solution

Add generics to the necessary structs and types.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@EmperorOrokuSaki EmperorOrokuSaki changed the title feat: add generics to filter, block, transaction, and pub_sub. feat: add generics to filter, transaction, and pub_sub. Apr 18, 2024
@EmperorOrokuSaki EmperorOrokuSaki marked this pull request as ready for review April 18, 2024 20:46
@prestwich
Copy link
Member

In favor of making the code reusable by other networks. At what point is this PR done? do we have a list of types we need to update?

@mattsse
Copy link
Member

mattsse commented Apr 19, 2024

At what point is this PR done?

this process will take a few iterations because when adding new network specific types we'll discover more things that could be reused.

I think we will run into a few issues with types that have multiple network specific fields, like Transactions,Logs,Block,Header, for which we either need to add a bunch of generics or also do some kind of network trait with associated types...

perhaps, at some point it's just easier to simply duplicate the types but not sure if we want to

@EmperorOrokuSaki
Copy link
Contributor Author

The block struct also needs to take a generic for example but that means many other dependent structs will need the same thing later. Making Transaction a trait here would solve such issue for example.
So far for optimism rpc types everything needed to take a generic, takes it with this pr (except block as that depends on the trait discussion)

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are reasonable,

I think we could also restrict this to : Transaction

Comment on lines 13 to 21
pub enum SubscriptionResult<T = Transaction> {
/// New block header.
Header(Box<RichHeader>),
/// Log
Log(Box<Log>),
/// Transaction hash
TransactionHash(B256),
/// Full Transaction
FullTransaction(Box<Transaction>),
FullTransaction(Box<T>),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume eventually there'll be the case where this also needs a log type.

@EmperorOrokuSaki
Copy link
Contributor Author

these are reasonable,

I think we could also restrict this to : Transaction

Just updated that. We can add the log generic later when needed probably

@EmperorOrokuSaki
Copy link
Contributor Author

Can we merge this? @mattsse @prestwich

@prestwich prestwich merged commit 2d47879 into alloy-rs:main Apr 20, 2024
18 checks passed
@EmperorOrokuSaki EmperorOrokuSaki deleted the feat/generic-rpc-types branch April 20, 2024 10:06
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
* feat: add generics to filter, block, transaction, and pub_sub.

* refactor: change blockhash structs to not take a generic.

* refactor: remove the block generic transaction

* refactor: make BlockTransactions generic

* refactor: make subscription result use the fixed transaction type
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