Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 32 additions & 38 deletions src/fill/alloy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::{Block, Tx};
use alloy::{
consensus::{
transaction::{Recovered, SignerRecoverable},
BlobTransactionSidecar, EthereumTxEnvelope, Signed, TxEip4844, TxEip4844WithSidecar,
TxEnvelope, TxType,
BlobTransactionSidecar, BlobTransactionSidecarVariant, EthereumTxEnvelope, Signed,
TxEip4844, TxEip4844WithSidecar, TxEnvelope, TxType,
},
eips::eip7594::BlobTransactionSidecarEip7594,
primitives::U256,
Expand Down Expand Up @@ -47,6 +47,7 @@ delegate_alloy_txs!(alloy::consensus::TxEip1559);
delegate_alloy_txs!(alloy::consensus::TxEip4844);
delegate_alloy_txs!(alloy::consensus::TxEip4844WithSidecar<BlobTransactionSidecar>);
delegate_alloy_txs!(alloy::consensus::TxEip4844WithSidecar<BlobTransactionSidecarEip7594>);
delegate_alloy_txs!(alloy::consensus::TxEip4844WithSidecar<BlobTransactionSidecarVariant>);
delegate_alloy_txs!(alloy::consensus::TxEip4844Variant);
delegate_alloy_txs!(alloy::consensus::TxEip7702);

Expand All @@ -56,6 +57,9 @@ delegate_alloy_txs!(@envelope EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransa
delegate_alloy_txs!(
@envelope EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarEip7594>>
);
delegate_alloy_txs!(
@envelope EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarVariant>>
);

impl Tx for Recovered<&alloy::consensus::TxLegacy> {
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
Expand Down Expand Up @@ -197,42 +201,10 @@ impl Tx for Recovered<&alloy::consensus::TxEip4844> {
}
}

impl Tx for Recovered<&alloy::consensus::TxEip4844WithSidecar<BlobTransactionSidecar>> {
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
let TxEnv {
tx_type,
caller,
gas_limit,
gas_price,
kind,
value,
data,
nonce,
chain_id,
access_list,
gas_priority_fee,
blob_hashes,
max_fee_per_blob_gas,
authorization_list,
} = tx_env;
*tx_type = TxType::Eip4844 as u8;
*caller = self.signer();
*gas_limit = self.inner().tx.gas_limit;
*gas_price = self.inner().tx.max_fee_per_gas;
*kind = self.inner().tx.to.into();
*value = self.inner().tx.value;
*data = self.inner().tx.input.clone();
*nonce = self.inner().tx.nonce;
*chain_id = Some(self.inner().tx.chain_id);
access_list.clone_from(&self.inner().tx.access_list);
*gas_priority_fee = Some(self.inner().tx.max_priority_fee_per_gas);
blob_hashes.clone_from(&self.inner().tx.blob_versioned_hashes);
*max_fee_per_blob_gas = self.inner().tx.max_fee_per_blob_gas;
authorization_list.clear();
}
}

impl Tx for Recovered<&alloy::consensus::TxEip4844WithSidecar<BlobTransactionSidecarEip7594>> {
impl<T> Tx for Recovered<&alloy::consensus::TxEip4844WithSidecar<T>>
where
T: Send + Sync,
{
Comment thread
prestwich marked this conversation as resolved.
Outdated
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
let TxEnv {
tx_type,
Expand Down Expand Up @@ -407,6 +379,28 @@ impl Tx for Recovered<&EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSi
}
}

impl Tx for Recovered<&EthereumTxEnvelope<TxEip4844WithSidecar<BlobTransactionSidecarVariant>>> {
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
match self.inner() {
EthereumTxEnvelope::Legacy(t) => {
Recovered::new_unchecked(t, self.signer()).fill_tx_env(tx_env)
}
EthereumTxEnvelope::Eip2930(t) => {
Recovered::new_unchecked(t, self.signer()).fill_tx_env(tx_env)
}
EthereumTxEnvelope::Eip1559(t) => {
Recovered::new_unchecked(t, self.signer()).fill_tx_env(tx_env)
}
EthereumTxEnvelope::Eip4844(t) => {
Recovered::new_unchecked(t, self.signer()).fill_tx_env(tx_env)
}
EthereumTxEnvelope::Eip7702(t) => {
Recovered::new_unchecked(t, self.signer()).fill_tx_env(tx_env)
}
}
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is also something that can be made generic, should i?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i'm on the fence about making these generic, as there's currently no trait bound to limit the typevar to something that's valid in context afaik

I suppose it won't cause any issues to go more generic, and it does DRY the code. let's make this generic as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

there was a problem with generics because of missing trait bound as you point out. but i added a macro instead.


impl Block for alloy::consensus::Header {
fn fill_block_env(&self, block_env: &mut BlockEnv) {
let BlockEnv {
Expand Down