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: impl From<Transaction> for TransactionRequest + small type updates #338

Merged
merged 7 commits into from
Mar 20, 2024

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Mar 18, 2024

Motivation

This was in ethers and is being used in foundry: https://github.com/foundry-rs/foundry/blob/master/crates/common/src/transactions.rs#L43

Transaction does not include sidecar so this conversion is not lossless

I've also updated several field types on Transaction so they match TransactionRequest types.

  • Gas price related fields were updated to U256
  • Transaction::chain_id changed to u64 to match TransactionRequest
  • Transaction::access_list changed to use AccessList struct
  • Transaction::transaction_type changed to U8 (Ethereum spec defines it as a number <=127, Optimism deposit transaction has type 126).

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@klkvr klkvr changed the title feat: impl From<Transaction> for TransactionRequest + small type updates feat: impl From<Transaction> for TransactionRequest + small type updates Mar 18, 2024
crates/rpc-types/src/eth/transaction/mod.rs Show resolved Hide resolved
crates/rpc-types/src/eth/transaction/mod.rs Show resolved Hide resolved
Comment on lines +240 to +244
impl From<Transaction> for TransactionRequest {
fn from(tx: Transaction) -> TransactionRequest {
Copy link
Member

Choose a reason for hiding this comment

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

this is definitely useful, for example,

eth_getTransaction
-> eth_call

so I think we want/need this.
The missing blob is also not problematic because this will be used mostly for calls.
and there's nothing we can do without the blob anyway

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.

lgtm,

pending @onbjerg

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.

lgtm

pending @prestwich @onbjerg

@klkvr klkvr force-pushed the klkvr/impl-from-tx-request branch from bed2e9d to 47e349f Compare March 18, 2024 21:41
@mattsse mattsse mentioned this pull request Mar 19, 2024
3 tasks
///
/// During this conversion data for [TransactionRequest::sidecar] is not populated as it is not
/// part of [Transaction].
pub fn into_request(self) -> TransactionRequest {
Copy link
Member

Choose a reason for hiding this comment

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

any reason we have this instead of just the auto-impl'd Into we get from From?

Copy link
Member Author

Choose a reason for hiding this comment

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

We wanted to have it documented on Transaction

Ref #338 (comment)

@klkvr klkvr force-pushed the klkvr/impl-from-tx-request branch from fc028c1 to 65b6391 Compare March 19, 2024 18:33
@prestwich prestwich merged commit 5fb1cef into alloy-rs:main Mar 20, 2024
16 checks passed
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.

4 participants