Skip to content

Commit

Permalink
chore(sdk): impl SignedTransaction for TransactionSigned (#12187)
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane authored Nov 10, 2024
1 parent 7110397 commit 3774100
Showing 1 changed file with 73 additions and 72 deletions.
145 changes: 73 additions & 72 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,96 +1297,35 @@ impl TransactionSigned {
}
}

impl alloy_consensus::Transaction for TransactionSigned {
fn chain_id(&self) -> Option<ChainId> {
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<u128> {
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<u128> {
self.deref().max_priority_fee_per_gas()
}

fn max_fee_per_blob_gas(&self) -> Option<u128> {
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<Address> {
Self::recover_signer(self)
let signature_hash = self.signature_hash();
recover_signer(&self.signature, signature_hash)
}

fn recover_signer_unchecked(&self) -> Option<Address> {
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) {
Expand Down Expand Up @@ -1469,6 +1408,68 @@ impl SignedTransaction for TransactionSigned {
}
}

impl alloy_consensus::Transaction for TransactionSigned {
fn chain_id(&self) -> Option<ChainId> {
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<u128> {
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<u128> {
self.deref().max_priority_fee_per_gas()
}

fn max_fee_per_blob_gas(&self) -> Option<u128> {
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<TransactionSignedEcRecovered> for TransactionSigned {
fn from(recovered: TransactionSignedEcRecovered) -> Self {
recovered.signed_transaction
Expand Down

0 comments on commit 3774100

Please sign in to comment.