From 62e13dbe6eacb68e805ef7da620068dc5712e2ac Mon Sep 17 00:00:00 2001 From: Steven <112043913+stevencartavia@users.noreply.github.com> Date: Thu, 13 Mar 2025 17:55:07 -0600 Subject: [PATCH] feat: Impl TryFrom> for MockTransaction { } } +impl TryFrom> for MockTransaction { + type Error = TryFromRecoveredTransactionError; + + fn try_from(tx: Recovered) -> Result { + let sender = tx.signer(); + let transaction = tx.into_inner(); + let hash = *transaction.tx_hash(); + let size = transaction.size(); + + match transaction { + EthereumTxEnvelope::Legacy(signed_tx) => { + let tx = signed_tx.strip_signature(); + Ok(Self::Legacy { + chain_id: tx.chain_id, + hash, + sender, + nonce: tx.nonce, + gas_price: tx.gas_price, + gas_limit: tx.gas_limit, + to: tx.to, + value: tx.value, + input: tx.input, + size, + cost: U256::from(tx.gas_limit) * U256::from(tx.gas_price) + tx.value, + }) + } + EthereumTxEnvelope::Eip2930(signed_tx) => { + let tx = signed_tx.strip_signature(); + Ok(Self::Eip2930 { + chain_id: tx.chain_id, + hash, + sender, + nonce: tx.nonce, + gas_price: tx.gas_price, + gas_limit: tx.gas_limit, + to: tx.to, + value: tx.value, + input: tx.input, + access_list: tx.access_list, + size, + cost: U256::from(tx.gas_limit) * U256::from(tx.gas_price) + tx.value, + }) + } + EthereumTxEnvelope::Eip1559(signed_tx) => { + let tx = signed_tx.strip_signature(); + Ok(Self::Eip1559 { + chain_id: tx.chain_id, + hash, + sender, + nonce: tx.nonce, + max_fee_per_gas: tx.max_fee_per_gas, + max_priority_fee_per_gas: tx.max_priority_fee_per_gas, + gas_limit: tx.gas_limit, + to: tx.to, + value: tx.value, + input: tx.input, + access_list: tx.access_list, + size, + cost: U256::from(tx.gas_limit) * U256::from(tx.max_fee_per_gas) + tx.value, + }) + } + EthereumTxEnvelope::Eip4844(signed_tx) => match signed_tx.tx() { + TxEip4844Variant::TxEip4844(tx) => Ok(Self::Eip4844 { + chain_id: tx.chain_id, + hash, + sender, + nonce: tx.nonce, + max_fee_per_gas: tx.max_fee_per_gas, + max_priority_fee_per_gas: tx.max_priority_fee_per_gas, + max_fee_per_blob_gas: tx.max_fee_per_blob_gas, + gas_limit: tx.gas_limit, + to: tx.to, + value: tx.value, + input: tx.input.clone(), + access_list: tx.access_list.clone(), + sidecar: BlobTransactionSidecar::default(), + blob_versioned_hashes: tx.blob_versioned_hashes.clone(), + size, + cost: U256::from(tx.gas_limit) * U256::from(tx.max_fee_per_gas) + tx.value, + }), + tx => Err(TryFromRecoveredTransactionError::UnsupportedTransactionType(tx.ty())), + }, + EthereumTxEnvelope::Eip7702(signed_tx) => { + let tx = signed_tx.strip_signature(); + Ok(Self::Eip7702 { + chain_id: tx.chain_id, + hash, + sender, + nonce: tx.nonce, + max_fee_per_gas: tx.max_fee_per_gas, + max_priority_fee_per_gas: tx.max_priority_fee_per_gas, + gas_limit: tx.gas_limit, + to: tx.to, + value: tx.value, + access_list: tx.access_list, + authorization_list: tx.authorization_list, + input: tx.input, + size, + cost: U256::from(tx.gas_limit) * U256::from(tx.max_fee_per_gas) + tx.value, + }) + } + } + } +} + impl From> for MockTransaction { fn from(tx: Recovered) -> Self { let (tx, signer) = tx.into_parts();