feat: add a way to convert consensus to pooled variant (#12734)

This commit is contained in:
Matthias Seitz
2024-11-21 12:22:35 +01:00
committed by GitHub
parent d00920c421
commit ac1867b631
2 changed files with 17 additions and 0 deletions

View File

@ -608,6 +608,12 @@ impl PoolTransaction for MockTransaction {
pooled.into() pooled.into()
} }
fn try_consensus_into_pooled(
tx: Self::Consensus,
) -> Result<Self::Pooled, Self::TryFromConsensusError> {
Self::Pooled::try_from(tx).map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing)
}
fn hash(&self) -> &TxHash { fn hash(&self) -> &TxHash {
self.get_hash() self.get_hash()
} }

View File

@ -946,6 +946,11 @@ pub trait PoolTransaction: fmt::Debug + Send + Sync + Clone {
pooled.into() pooled.into()
} }
/// Tries to convert the `Consensus` type into the `Pooled` type.
fn try_consensus_into_pooled(
tx: Self::Consensus,
) -> Result<Self::Pooled, Self::TryFromConsensusError>;
/// Hash of the transaction. /// Hash of the transaction.
fn hash(&self) -> &TxHash; fn hash(&self) -> &TxHash;
@ -1207,6 +1212,12 @@ impl PoolTransaction for EthPooledTransaction {
type Pooled = PooledTransactionsElementEcRecovered; type Pooled = PooledTransactionsElementEcRecovered;
fn try_consensus_into_pooled(
tx: Self::Consensus,
) -> Result<Self::Pooled, Self::TryFromConsensusError> {
Self::Pooled::try_from(tx).map_err(|_| TryFromRecoveredTransactionError::BlobSidecarMissing)
}
/// Returns hash of the transaction. /// Returns hash of the transaction.
fn hash(&self) -> &TxHash { fn hash(&self) -> &TxHash {
self.transaction.hash_ref() self.transaction.hash_ref()