feat: add additional conversion trait for pooled tx element (#4279)

This commit is contained in:
Matthias Seitz
2023-08-21 14:35:59 +02:00
committed by GitHub
parent e45a0d3e43
commit 2523154260
5 changed files with 47 additions and 12 deletions

View File

@ -91,11 +91,12 @@ pub use storage::StorageEntry;
pub use transaction::{
util::secp256k1::{public_key_to_address, recover_signer, sign_message},
AccessList, AccessListItem, AccessListWithGasUsed, BlobTransaction, BlobTransactionSidecar,
FromRecoveredTransaction, IntoRecoveredTransaction, InvalidTransactionError,
PooledTransactionsElement, PooledTransactionsElementEcRecovered, Signature, Transaction,
TransactionKind, TransactionMeta, TransactionSigned, TransactionSignedEcRecovered,
TransactionSignedNoHash, TxEip1559, TxEip2930, TxEip4844, TxLegacy, TxType, EIP1559_TX_TYPE_ID,
EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID,
FromRecoveredPooledTransaction, FromRecoveredTransaction, IntoRecoveredTransaction,
InvalidTransactionError, PooledTransactionsElement, PooledTransactionsElementEcRecovered,
Signature, Transaction, TransactionKind, TransactionMeta, TransactionSigned,
TransactionSignedEcRecovered, TransactionSignedNoHash, TxEip1559, TxEip2930, TxEip4844,
TxLegacy, TxType, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID,
LEGACY_TX_TYPE_ID,
};
pub use withdrawal::Withdrawal;

View File

@ -1089,6 +1089,16 @@ impl FromRecoveredTransaction for TransactionSignedEcRecovered {
}
}
/// A transaction type that can be created from a [`PooledTransactionsElementEcRecovered`]
/// transaction.
///
/// This is a conversion trait that'll ensure transactions received via P2P can be converted to the
/// transaction type that the transaction pool uses.
pub trait FromRecoveredPooledTransaction {
/// Converts to this type from the given [`PooledTransactionsElementEcRecovered`].
fn from_recovered_transaction(tx: PooledTransactionsElementEcRecovered) -> Self;
}
/// The inverse of [`FromRecoveredTransaction`] that ensure the transaction can be sent over the
/// network
pub trait IntoRecoveredTransaction {

View File

@ -373,6 +373,12 @@ impl PooledTransactionsElementEcRecovered {
self.transaction
}
/// Transform back to [`PooledTransactionsElement`]
pub fn into_ecrecovered_transaction(self) -> TransactionSignedEcRecovered {
let (tx, signer) = self.into_components();
tx.into_ecrecovered_transaction(signer)
}
/// Desolve Self to its component
pub fn into_components(self) -> (PooledTransactionsElement, Address) {
(self.transaction, self.signer)