Skip to content

refactor(anvil-core): make ImpersonatedTransaction and BlockInfo generic#13629

Merged
DaniPopes merged 2 commits intofoundry-rs:masterfrom
stevencartavia:generic-anvil-core
Mar 6, 2026
Merged

refactor(anvil-core): make ImpersonatedTransaction and BlockInfo generic#13629
DaniPopes merged 2 commits intofoundry-rs:masterfrom
stevencartavia:generic-anvil-core

Conversation

@stevencartavia
Copy link
Contributor

@stevencartavia stevencartavia commented Mar 5, 2026

Motivation

Preparation for phasing out FoundryNetwork by making anvil-core RPC types generic over Network. Currently MaybeImpersonatedTransaction and BlockInfo are hardcoded to FoundryTxEnvelope and FoundryReceiptEnvelope, preventing reuse with different network implementations.

Solution

1. Remove into_rpc_transaction from anvil-core

  • Deleted into_rpc_transaction() and From<MaybeImpersonatedTransaction> for RpcTransaction from anvil-core
  • Inlined the conversion logic into transaction_build() in anvil/src/eth/backend/mem/mod.rs where it belongs (anvil-level concern, not a core type concern)

2. Extract ImpersonatedTxEnvelope trait

  • Defines tx_hash(), recover_signer(), impersonated_hash() — the interface MaybeImpersonatedTransaction needs from its inner envelope
  • Implemented for FoundryTxEnvelope, decoupling anvil-core from the concrete type

3. Make ImpersonatedTransaction<T> generic

  • Renamed struct to ImpersonatedTransaction<T> with all trait impls (Typed2718, Encodable2718, Encodable, Decodable, AsRef, Deref) generic over T
  • Type alias MaybeImpersonatedTransaction = ImpersonatedTransaction<FoundryTxEnvelope> preserves backward compat — zero changes needed in downstream code

4. Make TypedBlockInfo<T, R> generic

  • Renamed struct to TypedBlockInfo<T, R>, generic over transaction and receipt types
  • Type alias BlockInfo = TypedBlockInfo<MaybeImpersonatedTransaction, FoundryReceiptEnvelope> preserves backward compat
  • Added create_typed_block<T> generic helper alongside existing create_block

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@DaniPopes DaniPopes merged commit 10c0ab1 into foundry-rs:master Mar 6, 2026
16 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants