refactor(anvil): simplify transaction conversion to RpcTransaction #12391
+60
−86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The transaction conversion logic from TypedTransaction to RpcTransaction was spread across multiple functions with significant code duplication. This change consolidates and simplifies the conversion flow.
TypedTransaction now has a try_into_eth() method that converts to TxEnvelope, returning an error for OP-stack Deposit transactions which aren't part of standard Ethereum transaction types.
The new MaybeImpersonatedTransaction::into_rpc_transaction() method encapsulates the entire conversion logic in one place, making the API more explicit and easier to use. The From trait implementation now simply delegates to this method.
The standalone to_alloy_transaction_with_hash_and_sender function has been removed since its logic is now part of the into_rpc_transaction method. This eliminates ~80 lines of duplicated RpcTransaction construction and makes the code easier to maintain.
this is still a bit verbose because we need to inject fake fake hashes for impersonated txs