From c4ea1ca98057edc33804bad258c4c7fe3c529f6f Mon Sep 17 00:00:00 2001 From: guha-rahul <69rahul16@gmail.com> Date: Fri, 10 May 2024 11:36:30 +0530 Subject: [PATCH 1/4] alloy-compact from block and header --- crates/primitives/src/block.rs | 45 -------------- crates/primitives/src/compat/mod.rs | 93 +++++++++++++++++++++++++++++ crates/primitives/src/header.rs | 47 --------------- crates/primitives/src/lib.rs | 5 +- 4 files changed, 97 insertions(+), 93 deletions(-) create mode 100644 crates/primitives/src/compat/mod.rs diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 8a029dc0523..467bca8166e 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -147,51 +147,6 @@ impl Deref for Block { } } -#[cfg(feature = "alloy-compat")] -impl TryFrom for Block { - type Error = alloy_rpc_types::ConversionError; - - fn try_from(block: alloy_rpc_types::Block) -> Result { - use alloy_rpc_types::ConversionError; - - let body = { - let transactions: Result, ConversionError> = match block - .transactions - { - alloy_rpc_types::BlockTransactions::Full(transactions) => transactions - .into_iter() - .map(|tx| { - let signature = tx.signature.ok_or(ConversionError::MissingSignature)?; - Ok(TransactionSigned::from_transaction_and_signature( - tx.try_into()?, - crate::Signature { - r: signature.r, - s: signature.s, - odd_y_parity: signature - .y_parity - .unwrap_or(alloy_rpc_types::Parity(false)) - .0, - }, - )) - }) - .collect(), - alloy_rpc_types::BlockTransactions::Hashes(_) | - alloy_rpc_types::BlockTransactions::Uncle => { - return Err(ConversionError::MissingFullTransactions) - } - }; - transactions? - }; - - Ok(Self { - header: block.header.try_into()?, - body, - ommers: Default::default(), - withdrawals: block.withdrawals.map(Into::into), - }) - } -} - /// Sealed block with senders recovered from transactions. #[derive(Debug, Clone, PartialEq, Eq, Default)] pub struct BlockWithSenders { diff --git a/crates/primitives/src/compat/mod.rs b/crates/primitives/src/compat/mod.rs new file mode 100644 index 00000000000..993fe569b27 --- /dev/null +++ b/crates/primitives/src/compat/mod.rs @@ -0,0 +1,93 @@ +#[cfg(feature = "alloy-compat")] +use crate::{Block, Header, TransactionSigned}; +#[cfg(feature = "alloy-compat")] +impl TryFrom for Block { + type Error = alloy_rpc_types::ConversionError; + + fn try_from(block: alloy_rpc_types::Block) -> Result { + use alloy_rpc_types::ConversionError; + + let body = { + let transactions: Result, ConversionError> = match block + .transactions + { + alloy_rpc_types::BlockTransactions::Full(transactions) => transactions + .into_iter() + .map(|tx| { + let signature = tx.signature.ok_or(ConversionError::MissingSignature)?; + Ok(TransactionSigned::from_transaction_and_signature( + tx.try_into()?, + crate::Signature { + r: signature.r, + s: signature.s, + odd_y_parity: signature + .y_parity + .unwrap_or(alloy_rpc_types::Parity(false)) + .0, + }, + )) + }) + .collect(), + alloy_rpc_types::BlockTransactions::Hashes(_) | + alloy_rpc_types::BlockTransactions::Uncle => { + return Err(ConversionError::MissingFullTransactions) + } + }; + transactions? + }; + + Ok(Self { + header: block.header.try_into()?, + body, + ommers: Default::default(), + withdrawals: block.withdrawals.map(Into::into), + }) + } +} + +#[cfg(feature = "alloy-compat")] +impl TryFrom for Header { + type Error = alloy_rpc_types::ConversionError; + + fn try_from(header: alloy_rpc_types::Header) -> Result { + use alloy_rpc_types::ConversionError; + + Ok(Self { + base_fee_per_gas: header + .base_fee_per_gas + .map(|base_fee_per_gas| { + base_fee_per_gas.try_into().map_err(ConversionError::BaseFeePerGasConversion) + }) + .transpose()?, + beneficiary: header.miner, + blob_gas_used: header + .blob_gas_used + .map(|blob_gas_used| { + blob_gas_used.try_into().map_err(ConversionError::BlobGasUsedConversion) + }) + .transpose()?, + difficulty: header.difficulty, + excess_blob_gas: header + .excess_blob_gas + .map(|excess_blob_gas| { + excess_blob_gas.try_into().map_err(ConversionError::ExcessBlobGasConversion) + }) + .transpose()?, + extra_data: header.extra_data, + gas_limit: header.gas_limit.try_into().map_err(ConversionError::GasLimitConversion)?, + gas_used: header.gas_used.try_into().map_err(ConversionError::GasUsedConversion)?, + logs_bloom: header.logs_bloom, + mix_hash: header.mix_hash.unwrap_or_default(), + nonce: u64::from_be_bytes(header.nonce.unwrap_or_default().0), + number: header.number.ok_or(ConversionError::MissingBlockNumber)?, + ommers_hash: header.uncles_hash, + parent_beacon_block_root: header.parent_beacon_block_root, + parent_hash: header.parent_hash, + receipts_root: header.receipts_root, + state_root: header.state_root, + timestamp: header.timestamp, + transactions_root: header.transactions_root, + withdrawals_root: header.withdrawals_root, + }) + } +} diff --git a/crates/primitives/src/header.rs b/crates/primitives/src/header.rs index d0bd5baf865..db75e1b6d4c 100644 --- a/crates/primitives/src/header.rs +++ b/crates/primitives/src/header.rs @@ -485,53 +485,6 @@ impl Decodable for Header { } } -#[cfg(feature = "alloy-compat")] -impl TryFrom for Header { - type Error = alloy_rpc_types::ConversionError; - - fn try_from(header: alloy_rpc_types::Header) -> Result { - use alloy_rpc_types::ConversionError; - - Ok(Self { - base_fee_per_gas: header - .base_fee_per_gas - .map(|base_fee_per_gas| { - base_fee_per_gas.try_into().map_err(ConversionError::BaseFeePerGasConversion) - }) - .transpose()?, - beneficiary: header.miner, - blob_gas_used: header - .blob_gas_used - .map(|blob_gas_used| { - blob_gas_used.try_into().map_err(ConversionError::BlobGasUsedConversion) - }) - .transpose()?, - difficulty: header.difficulty, - excess_blob_gas: header - .excess_blob_gas - .map(|excess_blob_gas| { - excess_blob_gas.try_into().map_err(ConversionError::ExcessBlobGasConversion) - }) - .transpose()?, - extra_data: header.extra_data, - gas_limit: header.gas_limit.try_into().map_err(ConversionError::GasLimitConversion)?, - gas_used: header.gas_used.try_into().map_err(ConversionError::GasUsedConversion)?, - logs_bloom: header.logs_bloom, - mix_hash: header.mix_hash.unwrap_or_default(), - nonce: u64::from_be_bytes(header.nonce.unwrap_or_default().0), - number: header.number.ok_or(ConversionError::MissingBlockNumber)?, - ommers_hash: header.uncles_hash, - parent_beacon_block_root: header.parent_beacon_block_root, - parent_hash: header.parent_hash, - receipts_root: header.receipts_root, - state_root: header.state_root, - timestamp: header.timestamp, - transactions_root: header.transactions_root, - withdrawals_root: header.withdrawals_root, - }) - } -} - /// Errors that can occur during header sanity checks. #[derive(thiserror::Error, Debug, PartialEq, Eq, Clone)] pub enum HeaderValidationError { diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 27c66e69e78..fd2f5b62379 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -22,6 +22,7 @@ mod account; pub mod basefee; mod block; mod chain; +mod compat; #[cfg(feature = "zstd-codec")] mod compression; pub mod constants; @@ -46,7 +47,6 @@ mod storage; pub mod transaction; pub mod trie; mod withdrawal; - pub use account::{Account, Bytecode}; #[cfg(any(test, feature = "arbitrary"))] pub use block::{generate_valid_header, valid_header_strategy}; @@ -59,6 +59,9 @@ pub use chain::{ ChainSpecBuilder, DisplayHardforks, ForkBaseFeeParams, ForkCondition, NamedChain, DEV, GOERLI, HOLESKY, MAINNET, SEPOLIA, }; +#[allow(unused_imports)] +#[cfg(feature = "alloy-compat")] +use compat::*; #[cfg(feature = "zstd-codec")] pub use compression::*; pub use constants::{ From 158a6dba3dc69fdc38865298d9525dbc64a59b93 Mon Sep 17 00:00:00 2001 From: guha-rahul <69rahul16@gmail.com> Date: Fri, 10 May 2024 19:18:24 +0530 Subject: [PATCH 2/4] fixes --- crates/primitives/src/compat/{mod.rs => alloy_compact.rs} | 0 crates/primitives/src/lib.rs | 4 +--- 2 files changed, 1 insertion(+), 3 deletions(-) rename crates/primitives/src/compat/{mod.rs => alloy_compact.rs} (100%) diff --git a/crates/primitives/src/compat/mod.rs b/crates/primitives/src/compat/alloy_compact.rs similarity index 100% rename from crates/primitives/src/compat/mod.rs rename to crates/primitives/src/compat/alloy_compact.rs diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index fd2f5b62379..8d2b6723eb9 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -22,6 +22,7 @@ mod account; pub mod basefee; mod block; mod chain; +#[cfg(feature = "alloy-compat")] mod compat; #[cfg(feature = "zstd-codec")] mod compression; @@ -59,9 +60,6 @@ pub use chain::{ ChainSpecBuilder, DisplayHardforks, ForkBaseFeeParams, ForkCondition, NamedChain, DEV, GOERLI, HOLESKY, MAINNET, SEPOLIA, }; -#[allow(unused_imports)] -#[cfg(feature = "alloy-compat")] -use compat::*; #[cfg(feature = "zstd-codec")] pub use compression::*; pub use constants::{ From d1dcb2101b44f35336d801dff9eaaca3eab5bc1c Mon Sep 17 00:00:00 2001 From: guha-rahul <69rahul16@gmail.com> Date: Fri, 10 May 2024 20:22:11 +0530 Subject: [PATCH 3/4] fix --- .../primitives/src/compat/{alloy_compact.rs => alloy_compat.rs} | 0 crates/primitives/src/lib.rs | 2 -- 2 files changed, 2 deletions(-) rename crates/primitives/src/compat/{alloy_compact.rs => alloy_compat.rs} (100%) diff --git a/crates/primitives/src/compat/alloy_compact.rs b/crates/primitives/src/compat/alloy_compat.rs similarity index 100% rename from crates/primitives/src/compat/alloy_compact.rs rename to crates/primitives/src/compat/alloy_compat.rs diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 8d2b6723eb9..fb1e03b0d6b 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -22,8 +22,6 @@ mod account; pub mod basefee; mod block; mod chain; -#[cfg(feature = "alloy-compat")] -mod compat; #[cfg(feature = "zstd-codec")] mod compression; pub mod constants; From 57d624eb7268966497f2ff3ca263d4a4fb65d642 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sun, 12 May 2024 13:13:33 +0200 Subject: [PATCH 4/4] smol touchups --- crates/primitives/src/alloy_compat.rs | 201 +++++++++++++++++++ crates/primitives/src/compat/alloy_compat.rs | 93 --------- crates/primitives/src/lib.rs | 2 + crates/primitives/src/transaction/mod.rs | 104 ---------- 4 files changed, 203 insertions(+), 197 deletions(-) create mode 100644 crates/primitives/src/alloy_compat.rs delete mode 100644 crates/primitives/src/compat/alloy_compat.rs diff --git a/crates/primitives/src/alloy_compat.rs b/crates/primitives/src/alloy_compat.rs new file mode 100644 index 00000000000..8b4368a1211 --- /dev/null +++ b/crates/primitives/src/alloy_compat.rs @@ -0,0 +1,201 @@ +//! Common conversions from alloy types. + +use crate::{ + Block, Header, Transaction, TransactionSigned, TxEip1559, TxEip2930, TxEip4844, TxLegacy, + TxType, +}; +use alloy_primitives::TxKind; +use alloy_rlp::Error as RlpError; + +impl TryFrom for Block { + type Error = alloy_rpc_types::ConversionError; + + fn try_from(block: alloy_rpc_types::Block) -> Result { + use alloy_rpc_types::ConversionError; + + let body = { + let transactions: Result, ConversionError> = match block + .transactions + { + alloy_rpc_types::BlockTransactions::Full(transactions) => transactions + .into_iter() + .map(|tx| { + let signature = tx.signature.ok_or(ConversionError::MissingSignature)?; + Ok(TransactionSigned::from_transaction_and_signature( + tx.try_into()?, + crate::Signature { + r: signature.r, + s: signature.s, + odd_y_parity: signature + .y_parity + .unwrap_or(alloy_rpc_types::Parity(false)) + .0, + }, + )) + }) + .collect(), + alloy_rpc_types::BlockTransactions::Hashes(_) | + alloy_rpc_types::BlockTransactions::Uncle => { + return Err(ConversionError::MissingFullTransactions) + } + }; + transactions? + }; + + Ok(Self { + header: block.header.try_into()?, + body, + ommers: Default::default(), + withdrawals: block.withdrawals.map(Into::into), + }) + } +} + +impl TryFrom for Header { + type Error = alloy_rpc_types::ConversionError; + + fn try_from(header: alloy_rpc_types::Header) -> Result { + use alloy_rpc_types::ConversionError; + + Ok(Self { + base_fee_per_gas: header + .base_fee_per_gas + .map(|base_fee_per_gas| { + base_fee_per_gas.try_into().map_err(ConversionError::BaseFeePerGasConversion) + }) + .transpose()?, + beneficiary: header.miner, + blob_gas_used: header + .blob_gas_used + .map(|blob_gas_used| { + blob_gas_used.try_into().map_err(ConversionError::BlobGasUsedConversion) + }) + .transpose()?, + difficulty: header.difficulty, + excess_blob_gas: header + .excess_blob_gas + .map(|excess_blob_gas| { + excess_blob_gas.try_into().map_err(ConversionError::ExcessBlobGasConversion) + }) + .transpose()?, + extra_data: header.extra_data, + gas_limit: header.gas_limit.try_into().map_err(ConversionError::GasLimitConversion)?, + gas_used: header.gas_used.try_into().map_err(ConversionError::GasUsedConversion)?, + logs_bloom: header.logs_bloom, + mix_hash: header.mix_hash.unwrap_or_default(), + nonce: u64::from_be_bytes(header.nonce.unwrap_or_default().0), + number: header.number.ok_or(ConversionError::MissingBlockNumber)?, + ommers_hash: header.uncles_hash, + parent_beacon_block_root: header.parent_beacon_block_root, + parent_hash: header.parent_hash, + receipts_root: header.receipts_root, + state_root: header.state_root, + timestamp: header.timestamp, + transactions_root: header.transactions_root, + withdrawals_root: header.withdrawals_root, + }) + } +} + +impl TryFrom for Transaction { + type Error = alloy_rpc_types::ConversionError; + + fn try_from(tx: alloy_rpc_types::Transaction) -> Result { + use alloy_eips::eip2718::Eip2718Error; + use alloy_rpc_types::ConversionError; + + match tx.transaction_type.map(TryInto::try_into).transpose().map_err(|_| { + ConversionError::Eip2718Error(Eip2718Error::UnexpectedType( + tx.transaction_type.unwrap(), + )) + })? { + None | Some(TxType::Legacy) => { + // legacy + if tx.max_fee_per_gas.is_some() || tx.max_priority_fee_per_gas.is_some() { + return Err(ConversionError::Eip2718Error( + RlpError::Custom("EIP-1559 fields are present in a legacy transaction") + .into(), + )) + } + Ok(Transaction::Legacy(TxLegacy { + chain_id: tx.chain_id, + nonce: tx.nonce, + gas_price: tx.gas_price.ok_or(ConversionError::MissingGasPrice)?, + gas_limit: tx + .gas + .try_into() + .map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?, + to: tx.to.map_or(TxKind::Create, TxKind::Call), + value: tx.value, + input: tx.input, + })) + } + Some(TxType::Eip2930) => { + // eip2930 + Ok(Transaction::Eip2930(TxEip2930 { + chain_id: tx.chain_id.ok_or(ConversionError::MissingChainId)?, + nonce: tx.nonce, + gas_limit: tx + .gas + .try_into() + .map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?, + to: tx.to.map_or(TxKind::Create, TxKind::Call), + value: tx.value, + input: tx.input, + access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?, + gas_price: tx.gas_price.ok_or(ConversionError::MissingGasPrice)?, + })) + } + Some(TxType::Eip1559) => { + // EIP-1559 + Ok(Transaction::Eip1559(TxEip1559 { + chain_id: tx.chain_id.ok_or(ConversionError::MissingChainId)?, + nonce: tx.nonce, + max_priority_fee_per_gas: tx + .max_priority_fee_per_gas + .ok_or(ConversionError::MissingMaxPriorityFeePerGas)?, + max_fee_per_gas: tx + .max_fee_per_gas + .ok_or(ConversionError::MissingMaxFeePerGas)?, + gas_limit: tx + .gas + .try_into() + .map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?, + to: tx.to.map_or(TxKind::Create, TxKind::Call), + value: tx.value, + access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?, + input: tx.input, + })) + } + Some(TxType::Eip4844) => { + // EIP-4844 + Ok(Transaction::Eip4844(TxEip4844 { + chain_id: tx.chain_id.ok_or(ConversionError::MissingChainId)?, + nonce: tx.nonce, + max_priority_fee_per_gas: tx + .max_priority_fee_per_gas + .ok_or(ConversionError::MissingMaxPriorityFeePerGas)?, + max_fee_per_gas: tx + .max_fee_per_gas + .ok_or(ConversionError::MissingMaxFeePerGas)?, + gas_limit: tx + .gas + .try_into() + .map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?, + to: tx.to.map_or(TxKind::Create, TxKind::Call), + value: tx.value, + access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?, + input: tx.input, + blob_versioned_hashes: tx + .blob_versioned_hashes + .ok_or(ConversionError::MissingBlobVersionedHashes)?, + max_fee_per_blob_gas: tx + .max_fee_per_blob_gas + .ok_or(ConversionError::MissingMaxFeePerBlobGas)?, + })) + } + #[cfg(feature = "optimism")] + Some(TxType::Deposit) => todo!(), + } + } +} diff --git a/crates/primitives/src/compat/alloy_compat.rs b/crates/primitives/src/compat/alloy_compat.rs deleted file mode 100644 index 993fe569b27..00000000000 --- a/crates/primitives/src/compat/alloy_compat.rs +++ /dev/null @@ -1,93 +0,0 @@ -#[cfg(feature = "alloy-compat")] -use crate::{Block, Header, TransactionSigned}; -#[cfg(feature = "alloy-compat")] -impl TryFrom for Block { - type Error = alloy_rpc_types::ConversionError; - - fn try_from(block: alloy_rpc_types::Block) -> Result { - use alloy_rpc_types::ConversionError; - - let body = { - let transactions: Result, ConversionError> = match block - .transactions - { - alloy_rpc_types::BlockTransactions::Full(transactions) => transactions - .into_iter() - .map(|tx| { - let signature = tx.signature.ok_or(ConversionError::MissingSignature)?; - Ok(TransactionSigned::from_transaction_and_signature( - tx.try_into()?, - crate::Signature { - r: signature.r, - s: signature.s, - odd_y_parity: signature - .y_parity - .unwrap_or(alloy_rpc_types::Parity(false)) - .0, - }, - )) - }) - .collect(), - alloy_rpc_types::BlockTransactions::Hashes(_) | - alloy_rpc_types::BlockTransactions::Uncle => { - return Err(ConversionError::MissingFullTransactions) - } - }; - transactions? - }; - - Ok(Self { - header: block.header.try_into()?, - body, - ommers: Default::default(), - withdrawals: block.withdrawals.map(Into::into), - }) - } -} - -#[cfg(feature = "alloy-compat")] -impl TryFrom for Header { - type Error = alloy_rpc_types::ConversionError; - - fn try_from(header: alloy_rpc_types::Header) -> Result { - use alloy_rpc_types::ConversionError; - - Ok(Self { - base_fee_per_gas: header - .base_fee_per_gas - .map(|base_fee_per_gas| { - base_fee_per_gas.try_into().map_err(ConversionError::BaseFeePerGasConversion) - }) - .transpose()?, - beneficiary: header.miner, - blob_gas_used: header - .blob_gas_used - .map(|blob_gas_used| { - blob_gas_used.try_into().map_err(ConversionError::BlobGasUsedConversion) - }) - .transpose()?, - difficulty: header.difficulty, - excess_blob_gas: header - .excess_blob_gas - .map(|excess_blob_gas| { - excess_blob_gas.try_into().map_err(ConversionError::ExcessBlobGasConversion) - }) - .transpose()?, - extra_data: header.extra_data, - gas_limit: header.gas_limit.try_into().map_err(ConversionError::GasLimitConversion)?, - gas_used: header.gas_used.try_into().map_err(ConversionError::GasUsedConversion)?, - logs_bloom: header.logs_bloom, - mix_hash: header.mix_hash.unwrap_or_default(), - nonce: u64::from_be_bytes(header.nonce.unwrap_or_default().0), - number: header.number.ok_or(ConversionError::MissingBlockNumber)?, - ommers_hash: header.uncles_hash, - parent_beacon_block_root: header.parent_beacon_block_root, - parent_hash: header.parent_hash, - receipts_root: header.receipts_root, - state_root: header.state_root, - timestamp: header.timestamp, - transactions_root: header.transactions_root, - withdrawals_root: header.withdrawals_root, - }) - } -} diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index fb1e03b0d6b..71d264712b7 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -19,6 +19,8 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] mod account; +#[cfg(feature = "alloy-compat")] +mod alloy_compat; pub mod basefee; mod block; mod chain; diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index eda139ffdf9..3117615e842 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -612,110 +612,6 @@ impl From for Transaction { } } -#[cfg(feature = "alloy-compat")] -impl TryFrom for Transaction { - type Error = alloy_rpc_types::ConversionError; - - fn try_from(tx: alloy_rpc_types::Transaction) -> Result { - use alloy_eips::eip2718::Eip2718Error; - use alloy_rpc_types::ConversionError; - - match tx.transaction_type.map(TryInto::try_into).transpose().map_err(|_| { - ConversionError::Eip2718Error(Eip2718Error::UnexpectedType( - tx.transaction_type.unwrap(), - )) - })? { - None | Some(TxType::Legacy) => { - // legacy - if tx.max_fee_per_gas.is_some() || tx.max_priority_fee_per_gas.is_some() { - return Err(ConversionError::Eip2718Error( - RlpError::Custom("EIP-1559 fields are present in a legacy transaction") - .into(), - )) - } - Ok(Transaction::Legacy(TxLegacy { - chain_id: tx.chain_id, - nonce: tx.nonce, - gas_price: tx.gas_price.ok_or(ConversionError::MissingGasPrice)?, - gas_limit: tx - .gas - .try_into() - .map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?, - to: tx.to.map_or(TxKind::Create, TxKind::Call), - value: tx.value, - input: tx.input, - })) - } - Some(TxType::Eip2930) => { - // eip2930 - Ok(Transaction::Eip2930(TxEip2930 { - chain_id: tx.chain_id.ok_or(ConversionError::MissingChainId)?, - nonce: tx.nonce, - gas_limit: tx - .gas - .try_into() - .map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?, - to: tx.to.map_or(TxKind::Create, TxKind::Call), - value: tx.value, - input: tx.input, - access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?, - gas_price: tx.gas_price.ok_or(ConversionError::MissingGasPrice)?, - })) - } - Some(TxType::Eip1559) => { - // EIP-1559 - Ok(Transaction::Eip1559(TxEip1559 { - chain_id: tx.chain_id.ok_or(ConversionError::MissingChainId)?, - nonce: tx.nonce, - max_priority_fee_per_gas: tx - .max_priority_fee_per_gas - .ok_or(ConversionError::MissingMaxPriorityFeePerGas)?, - max_fee_per_gas: tx - .max_fee_per_gas - .ok_or(ConversionError::MissingMaxFeePerGas)?, - gas_limit: tx - .gas - .try_into() - .map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?, - to: tx.to.map_or(TxKind::Create, TxKind::Call), - value: tx.value, - access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?, - input: tx.input, - })) - } - Some(TxType::Eip4844) => { - // EIP-4844 - Ok(Transaction::Eip4844(TxEip4844 { - chain_id: tx.chain_id.ok_or(ConversionError::MissingChainId)?, - nonce: tx.nonce, - max_priority_fee_per_gas: tx - .max_priority_fee_per_gas - .ok_or(ConversionError::MissingMaxPriorityFeePerGas)?, - max_fee_per_gas: tx - .max_fee_per_gas - .ok_or(ConversionError::MissingMaxFeePerGas)?, - gas_limit: tx - .gas - .try_into() - .map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?, - to: tx.to.map_or(TxKind::Create, TxKind::Call), - value: tx.value, - access_list: tx.access_list.ok_or(ConversionError::MissingAccessList)?, - input: tx.input, - blob_versioned_hashes: tx - .blob_versioned_hashes - .ok_or(ConversionError::MissingBlobVersionedHashes)?, - max_fee_per_blob_gas: tx - .max_fee_per_blob_gas - .ok_or(ConversionError::MissingMaxFeePerBlobGas)?, - })) - } - #[cfg(feature = "optimism")] - Some(TxType::Deposit) => todo!(), - } - } -} - impl Compact for Transaction { // Serializes the TxType to the buffer if necessary, returning 2 bits of the type as an // identifier instead of the length.