Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
43 changes: 40 additions & 3 deletions crates/common/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2454,8 +2454,8 @@ mod serde_impl {
InvalidTxType(TxType),
#[error("Blob bundle error: {0}")]
BlobBundleError(#[from] BlobsBundleError),
#[error("Missing fee token address")]
MissingFeeToken,
#[error("Missing field: {0}")]
MissingField(String),
}

/// Unsigned Transaction struct generic to all types which may not contain all required transaction fields
Expand Down Expand Up @@ -2710,6 +2710,41 @@ mod serde_impl {
}
}

impl TryFrom<GenericTransaction> for EIP7702Transaction {
type Error = GenericTransactionError;

fn try_from(value: GenericTransaction) -> Result<Self, Self::Error> {
if value.r#type != TxType::EIP7702 {
return Err(GenericTransactionError::InvalidTxType(value.r#type));
}
let TxKind::Call(to) = value.to else {
return Err(GenericTransactionError::MissingField("to".to_owned()));
};
Ok(Self {
chain_id: value.chain_id.unwrap_or_default(),
nonce: value.nonce.unwrap_or_default(),
max_priority_fee_per_gas: value.max_priority_fee_per_gas.unwrap_or_default(),
max_fee_per_gas: value.max_fee_per_gas.unwrap_or(value.gas_price),
gas_limit: value.gas.unwrap_or_default(),
to,
value: value.value,
data: value.input,
access_list: value
.access_list
.into_iter()
.map(|v| (v.address, v.storage_keys))
.collect::<Vec<_>>(),
authorization_list: value
.authorization_list
.unwrap_or_default()
.into_iter()
.map(AuthorizationTuple::from)
.collect(),
..Default::default()
})
}
}

impl From<PrivilegedL2Transaction> for GenericTransaction {
fn from(value: PrivilegedL2Transaction) -> Self {
Self {
Expand Down Expand Up @@ -2818,7 +2853,9 @@ mod serde_impl {
.collect::<Vec<_>>(),
fee_token: value
.fee_token
.ok_or(GenericTransactionError::MissingFeeToken)?,
.ok_or(GenericTransactionError::MissingField(
"fee token".to_owned(),
))?,
chain_id: value.chain_id.unwrap_or_default(),
..Default::default()
})
Expand Down
25 changes: 20 additions & 5 deletions crates/l2/sdk/src/sdk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bytes::Bytes;
use calldata::encode_calldata;
use ethereum_types::{H160, H256, U256};
use ethrex_common::types::EIP7702Transaction;
use ethrex_common::types::FeeTokenTransaction;
use ethrex_common::types::Fork;
use ethrex_common::utils::keccak;
Expand Down Expand Up @@ -810,6 +811,14 @@ pub async fn send_generic_transaction(

tx.encode(&mut encoded_tx);
}
TxType::EIP7702 => {
let tx: EIP7702Transaction = generic_tx.try_into()?;
let signed_tx = tx
.sign(signer)
.await
.map_err(|err| EthClientError::Custom(err.to_string()))?;
signed_tx.encode(&mut encoded_tx);
}
TxType::FeeToken => {
let tx: FeeTokenTransaction = generic_tx.try_into()?;
let signed_tx = tx
Expand All @@ -820,9 +829,10 @@ pub async fn send_generic_transaction(
signed_tx.encode(&mut encoded_tx);
}
_ => {
return Err(EthClientError::Custom(
"Unsupported transaction type".to_string(),
));
return Err(EthClientError::Custom(format!(
"Unsupported transaction type: {:?}",
generic_tx.r#type
)));
}
};

Expand Down Expand Up @@ -956,8 +966,12 @@ pub async fn build_generic_tx(
overrides: Overrides,
) -> Result<GenericTransaction, EthClientError> {
match r#type {
TxType::EIP1559 | TxType::EIP4844 | TxType::Privileged | TxType::FeeToken => {}
TxType::EIP2930 | TxType::EIP7702 | TxType::Legacy => {
TxType::EIP1559
| TxType::EIP4844
| TxType::EIP7702
| TxType::Privileged
| TxType::FeeToken => {}
TxType::EIP2930 | TxType::Legacy => {
return Err(EthClientError::Custom(
"Unsupported tx type in build_generic_tx".to_owned(),
));
Expand Down Expand Up @@ -996,6 +1010,7 @@ pub async fn build_generic_tx(
fee_token: overrides.fee_token,
from,
wrapper_version: overrides.wrapper_version,
authorization_list: overrides.authorization_list,
..Default::default()
};
tx.gas_price = tx.max_fee_per_gas.unwrap_or_default();
Expand Down
3 changes: 2 additions & 1 deletion crates/networking/rpc/clients/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use errors::{
};
use ethrex_common::{
Address, H256, U256,
types::{BlobsBundle, Block, GenericTransaction, TxKind},
types::{AuthorizationTupleEntry, BlobsBundle, Block, GenericTransaction, TxKind},
utils::decode_hex,
};
use ethrex_rlp::decode::RLPDecode;
Expand Down Expand Up @@ -70,6 +70,7 @@ pub struct Overrides {
pub gas_price_per_blob: Option<U256>,
pub block: Option<BlockIdentifier>,
pub blobs_bundle: Option<BlobsBundle>,
pub authorization_list: Option<Vec<AuthorizationTupleEntry>>,
pub wrapper_version: Option<u8>,
}

Expand Down