mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
tx-pool: add try_from_consensus for PoolTransaction (#10504)
This commit is contained in:
@ -471,10 +471,7 @@ pub trait EthTransactions: LoadTransaction {
|
||||
let recovered =
|
||||
signed_tx.into_ecrecovered().ok_or(EthApiError::InvalidTransactionSignature)?;
|
||||
|
||||
let pool_transaction = match recovered.try_into() {
|
||||
Ok(converted) => converted,
|
||||
Err(_) => return Err(EthApiError::TransactionConversionError.into()),
|
||||
};
|
||||
let pool_transaction = <<Self as LoadTransaction>::Pool as TransactionPool>::Transaction::try_from_consensus(recovered).map_err(|_| EthApiError::TransactionConversionError)?;
|
||||
|
||||
// submit the transaction to the pool with a `Local` origin
|
||||
let hash = LoadTransaction::pool(self)
|
||||
|
||||
@ -344,7 +344,8 @@ pub async fn maintain_transaction_pool<Client, P, St, Tasks>(
|
||||
<<P as TransactionPool>::Transaction as PoolTransaction>::from_pooled(tx)
|
||||
})
|
||||
} else {
|
||||
tx.try_into().ok()
|
||||
|
||||
<P::Transaction as PoolTransaction>::try_from_consensus(tx).ok()
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
@ -588,7 +589,7 @@ where
|
||||
.filter_map(|tx| tx.try_ecrecovered())
|
||||
.filter_map(|tx| {
|
||||
// Filter out errors
|
||||
tx.try_into().ok()
|
||||
<P::Transaction as PoolTransaction>::try_from_consensus(tx).ok()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
@ -558,10 +558,16 @@ impl MockTransaction {
|
||||
}
|
||||
|
||||
impl PoolTransaction for MockTransaction {
|
||||
type TryFromConsensusError = TryFromRecoveredTransactionError;
|
||||
|
||||
type Consensus = TransactionSignedEcRecovered;
|
||||
|
||||
type Pooled = PooledTransactionsElementEcRecovered;
|
||||
|
||||
fn try_from_consensus(tx: Self::Consensus) -> Result<Self, Self::TryFromConsensusError> {
|
||||
tx.try_into()
|
||||
}
|
||||
|
||||
fn into_consensus(self) -> Self::Consensus {
|
||||
self.into()
|
||||
}
|
||||
|
||||
@ -773,15 +773,19 @@ impl BestTransactionsAttributes {
|
||||
}
|
||||
|
||||
/// Trait for transaction types used inside the pool
|
||||
pub trait PoolTransaction:
|
||||
fmt::Debug + Send + Sync + Clone + TryFrom<TransactionSignedEcRecovered>
|
||||
{
|
||||
pub trait PoolTransaction: fmt::Debug + Send + Sync + Clone {
|
||||
/// Associated error type for the `try_from_consensus` method.
|
||||
type TryFromConsensusError;
|
||||
|
||||
/// Associated type representing the raw consensus variant of the transaction.
|
||||
type Consensus: From<Self> + TryInto<Self>;
|
||||
|
||||
/// Associated type representing the recovered pooled variant of the transaction.
|
||||
type Pooled: Into<Self>;
|
||||
|
||||
/// Define a method to convert from the `Consensus` type to `Self`
|
||||
fn try_from_consensus(tx: Self::Consensus) -> Result<Self, Self::TryFromConsensusError>;
|
||||
|
||||
/// Define a method to convert from the `Self` type to `Consensus`
|
||||
fn into_consensus(self) -> Self::Consensus;
|
||||
|
||||
@ -1024,10 +1028,16 @@ impl From<PooledTransactionsElementEcRecovered> for EthPooledTransaction {
|
||||
}
|
||||
|
||||
impl PoolTransaction for EthPooledTransaction {
|
||||
type TryFromConsensusError = TryFromRecoveredTransactionError;
|
||||
|
||||
type Consensus = TransactionSignedEcRecovered;
|
||||
|
||||
type Pooled = PooledTransactionsElementEcRecovered;
|
||||
|
||||
fn try_from_consensus(tx: Self::Consensus) -> Result<Self, Self::TryFromConsensusError> {
|
||||
tx.try_into()
|
||||
}
|
||||
|
||||
fn into_consensus(self) -> Self::Consensus {
|
||||
self.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user