mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add FromRecoveredTransaction conversion trait (#207)
This commit is contained in:
@ -11,7 +11,10 @@ use rand::{
|
||||
distributions::{Uniform, WeightedIndex},
|
||||
prelude::Distribution,
|
||||
};
|
||||
use reth_primitives::{Address, TxHash, H256, U256};
|
||||
use reth_primitives::{
|
||||
Address, FromRecoveredTransaction, Transaction, TransactionSignedEcRecovered, TxHash, H256,
|
||||
U256,
|
||||
};
|
||||
use std::{ops::Range, sync::Arc, time::Instant};
|
||||
|
||||
pub type MockTxPool = TxPool<MockOrdering>;
|
||||
@ -333,6 +336,48 @@ impl PoolTransaction for MockTransaction {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRecoveredTransaction for MockTransaction {
|
||||
fn from_recovered_transaction(tx: TransactionSignedEcRecovered) -> Self {
|
||||
let sender = tx.signer();
|
||||
let transaction = tx.into_signed();
|
||||
let hash = transaction.hash;
|
||||
match transaction.transaction {
|
||||
Transaction::Legacy { chain_id, nonce, gas_price, gas_limit, to, value, input } => {
|
||||
MockTransaction::Legacy {
|
||||
hash,
|
||||
sender,
|
||||
nonce,
|
||||
gas_price: gas_price.into(),
|
||||
gas_limit,
|
||||
value,
|
||||
}
|
||||
}
|
||||
Transaction::Eip1559 {
|
||||
chain_id,
|
||||
nonce,
|
||||
gas_limit,
|
||||
max_fee_per_gas,
|
||||
max_priority_fee_per_gas,
|
||||
to,
|
||||
value,
|
||||
input,
|
||||
access_list,
|
||||
} => MockTransaction::Eip1559 {
|
||||
hash,
|
||||
sender,
|
||||
nonce,
|
||||
max_fee_per_gas: max_fee_per_gas.into(),
|
||||
max_priority_fee_per_gas: max_priority_fee_per_gas.into(),
|
||||
gas_limit,
|
||||
value,
|
||||
},
|
||||
Transaction::Eip2930 { .. } => {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MockTransactionFactory {
|
||||
pub ids: SenderIdentifiers,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use crate::{error::PoolResult, pool::state::SubPool, validate::ValidPoolTransaction, BlockID};
|
||||
use futures::{channel::mpsc::Receiver, future::Shared};
|
||||
use reth_primitives::{Address, TxHash, H256, U256};
|
||||
use reth_primitives::{Address, FromRecoveredTransaction, TxHash, H256, U256};
|
||||
use std::{fmt, sync::Arc};
|
||||
|
||||
/// General purpose abstraction fo a transaction-pool.
|
||||
@ -174,7 +174,7 @@ impl<T> BestTransactions for std::iter::Empty<T> {
|
||||
}
|
||||
|
||||
/// Trait for transaction types used inside the pool
|
||||
pub trait PoolTransaction: fmt::Debug + Send + Sync + 'static {
|
||||
pub trait PoolTransaction: fmt::Debug + Send + Sync + FromRecoveredTransaction {
|
||||
/// Hash of the transaction.
|
||||
fn hash(&self) -> &TxHash;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user