Skip to content

Commit

Permalink
chore(sdk): limit FillTxEnv to super trait of FullSignedTx (parad…
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Nov 18, 2024
1 parent 7fb862c commit 641d128
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 42 deletions.
70 changes: 36 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/optimism/payload/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloy_eips::{
use alloy_primitives::{keccak256, Address, Bytes, B256, B64, U256};
use alloy_rlp::Encodable;
use alloy_rpc_types_engine::{ExecutionPayloadEnvelopeV2, ExecutionPayloadV1, PayloadId};
use op_alloy_consensus::eip1559::{decode_holocene_extra_data, EIP1559ParamError};
use op_alloy_consensus::{decode_holocene_extra_data, EIP1559ParamError};
/// Re-export for use in downstream arguments.
pub use op_alloy_rpc_types_engine::OpPayloadAttributes;
use op_alloy_rpc_types_engine::{OpExecutionPayloadEnvelopeV3, OpExecutionPayloadEnvelopeV4};
Expand Down
1 change: 1 addition & 0 deletions crates/primitives-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub use receipt::{FullReceipt, Receipt};

pub mod transaction;
pub use transaction::{
execute::FillTxEnv,
signed::{FullSignedTx, SignedTransaction},
FullTransaction, Transaction, TransactionExt,
};
Expand Down
10 changes: 10 additions & 0 deletions crates/primitives-traits/src/transaction/execute.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! Abstraction of an executable transaction.
use alloy_primitives::Address;
use revm_primitives::TxEnv;

/// Loads transaction into execution environment.
pub trait FillTxEnv {
/// Fills [`TxEnv`] with an [`Address`] and transaction.
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address);
}
1 change: 1 addition & 0 deletions crates/primitives-traits/src/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Transaction abstraction
pub mod execute;
pub mod signed;

use core::{fmt, hash::Hash};
Expand Down
16 changes: 9 additions & 7 deletions crates/primitives-traits/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ use core::hash::Hash;
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{keccak256, Address, PrimitiveSignature, TxHash, B256};
use reth_codecs::Compact;
use revm_primitives::TxEnv;

use crate::{FullTransaction, InMemorySize, MaybeArbitrary, MaybeSerde, Transaction};
use crate::{FillTxEnv, FullTransaction, InMemorySize, MaybeArbitrary, MaybeSerde, Transaction};

/// Helper trait that unifies all behaviour required by block to support full node operations.
pub trait FullSignedTx: SignedTransaction<Transaction: FullTransaction> + Compact {}
pub trait FullSignedTx:
SignedTransaction<Transaction: FullTransaction> + FillTxEnv + Compact
{
}

impl<T> FullSignedTx for T where T: SignedTransaction<Transaction: FullTransaction> + Compact {}
impl<T> FullSignedTx for T where
T: SignedTransaction<Transaction: FullTransaction> + FillTxEnv + Compact
{
}

/// A signed transaction.
#[auto_impl::auto_impl(&, Arc)]
Expand Down Expand Up @@ -71,9 +76,6 @@ pub trait SignedTransaction:
fn recalculate_hash(&self) -> B256 {
keccak256(self.encoded_2718())
}

/// Fills [`TxEnv`] with an [`Address`] and transaction.
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address);
}

/// Helper trait used in testing.
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,9 @@ impl SignedTransaction for TransactionSigned {
let signature_hash = self.signature_hash();
recover_signer_unchecked(&self.signature, signature_hash)
}
}

impl reth_primitives_traits::FillTxEnv for TransactionSigned {
fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address) {
tx_env.caller = sender;
match self.as_ref() {
Expand Down

0 comments on commit 641d128

Please sign in to comment.