From 3774100a0513e3d33246b3936aac74ef7251f4be Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Sun, 10 Nov 2024 14:11:58 +0100 Subject: [PATCH] chore(sdk): impl `SignedTransaction` for `TransactionSigned` (#12187) --- crates/primitives/src/transaction/mod.rs | 145 ++++++++++++----------- 1 file changed, 73 insertions(+), 72 deletions(-) diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index ed1a7daf1e84..685fd29a3c04 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1297,96 +1297,35 @@ impl TransactionSigned { } } -impl alloy_consensus::Transaction for TransactionSigned { - fn chain_id(&self) -> Option { - self.deref().chain_id() - } - - fn nonce(&self) -> u64 { - self.deref().nonce() - } - - fn gas_limit(&self) -> u64 { - self.deref().gas_limit() - } - - fn gas_price(&self) -> Option { - self.deref().gas_price() - } - - fn max_fee_per_gas(&self) -> u128 { - self.deref().max_fee_per_gas() - } - - fn max_priority_fee_per_gas(&self) -> Option { - self.deref().max_priority_fee_per_gas() - } - - fn max_fee_per_blob_gas(&self) -> Option { - self.deref().max_fee_per_blob_gas() - } - - fn priority_fee_or_price(&self) -> u128 { - self.deref().priority_fee_or_price() - } - - fn value(&self) -> U256 { - self.deref().value() - } - - fn input(&self) -> &Bytes { - self.deref().input() - } - - fn ty(&self) -> u8 { - self.deref().ty() - } - - fn access_list(&self) -> Option<&AccessList> { - self.deref().access_list() - } - - fn blob_versioned_hashes(&self) -> Option<&[B256]> { - alloy_consensus::Transaction::blob_versioned_hashes(self.deref()) - } - - fn authorization_list(&self) -> Option<&[SignedAuthorization]> { - self.deref().authorization_list() - } - - fn kind(&self) -> TxKind { - self.deref().kind() - } -} - impl SignedTransaction for TransactionSigned { type Transaction = Transaction; fn tx_hash(&self) -> &TxHash { - Self::hash_ref(self) + &self.hash } fn transaction(&self) -> &Self::Transaction { - Self::transaction(self) + &self.transaction } fn signature(&self) -> &Signature { - Self::signature(self) + &self.signature } fn recover_signer(&self) -> Option
{ - Self::recover_signer(self) + let signature_hash = self.signature_hash(); + recover_signer(&self.signature, signature_hash) } fn recover_signer_unchecked(&self) -> Option
{ - Self::recover_signer_unchecked(self) + let signature_hash = self.signature_hash(); + recover_signer_unchecked(&self.signature, signature_hash) } - fn from_transaction_and_signature( - transaction: Self::Transaction, - signature: Signature, - ) -> Self { - Self::from_transaction_and_signature(transaction, signature) + fn from_transaction_and_signature(transaction: Transaction, signature: Signature) -> Self { + let mut initial_tx = Self { transaction, hash: Default::default(), signature }; + initial_tx.hash = initial_tx.recalculate_hash(); + initial_tx } fn fill_tx_env(&self, tx_env: &mut TxEnv, sender: Address) { @@ -1469,6 +1408,68 @@ impl SignedTransaction for TransactionSigned { } } +impl alloy_consensus::Transaction for TransactionSigned { + fn chain_id(&self) -> Option { + self.deref().chain_id() + } + + fn nonce(&self) -> u64 { + self.deref().nonce() + } + + fn gas_limit(&self) -> u64 { + self.deref().gas_limit() + } + + fn gas_price(&self) -> Option { + self.deref().gas_price() + } + + fn max_fee_per_gas(&self) -> u128 { + self.deref().max_fee_per_gas() + } + + fn max_priority_fee_per_gas(&self) -> Option { + self.deref().max_priority_fee_per_gas() + } + + fn max_fee_per_blob_gas(&self) -> Option { + self.deref().max_fee_per_blob_gas() + } + + fn priority_fee_or_price(&self) -> u128 { + self.deref().priority_fee_or_price() + } + + fn value(&self) -> U256 { + self.deref().value() + } + + fn input(&self) -> &Bytes { + self.deref().input() + } + + fn ty(&self) -> u8 { + self.deref().ty() + } + + fn access_list(&self) -> Option<&AccessList> { + self.deref().access_list() + } + + fn blob_versioned_hashes(&self) -> Option<&[B256]> { + alloy_consensus::Transaction::blob_versioned_hashes(self.deref()) + } + + fn authorization_list(&self) -> Option<&[SignedAuthorization]> { + self.deref().authorization_list() + } + + fn kind(&self) -> TxKind { + self.deref().kind() + } +} + impl From for TransactionSigned { fn from(recovered: TransactionSignedEcRecovered) -> Self { recovered.signed_transaction