mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 17:18:08 -05:00
chore(txpool): pooled tx constructor (#3980)
This commit is contained in:
@@ -532,6 +532,18 @@ pub struct PooledTransaction {
|
||||
}
|
||||
|
||||
impl PooledTransaction {
|
||||
/// Create new instance of [Self].
|
||||
pub fn new(transaction: TransactionSignedEcRecovered) -> Self {
|
||||
let gas_cost = match &transaction.transaction {
|
||||
Transaction::Legacy(t) => U256::from(t.gas_price) * U256::from(t.gas_limit),
|
||||
Transaction::Eip2930(t) => U256::from(t.gas_price) * U256::from(t.gas_limit),
|
||||
Transaction::Eip1559(t) => U256::from(t.max_fee_per_gas) * U256::from(t.gas_limit),
|
||||
};
|
||||
let cost = gas_cost + U256::from(transaction.value());
|
||||
|
||||
Self { transaction, cost }
|
||||
}
|
||||
|
||||
/// Return the reference to the underlying transaction.
|
||||
pub fn transaction(&self) -> &TransactionSignedEcRecovered {
|
||||
&self.transaction
|
||||
@@ -634,14 +646,7 @@ impl PoolTransaction for PooledTransaction {
|
||||
|
||||
impl FromRecoveredTransaction for PooledTransaction {
|
||||
fn from_recovered_transaction(tx: TransactionSignedEcRecovered) -> Self {
|
||||
let gas_cost = match &tx.transaction {
|
||||
Transaction::Legacy(t) => U256::from(t.gas_price) * U256::from(t.gas_limit),
|
||||
Transaction::Eip2930(t) => U256::from(t.gas_price) * U256::from(t.gas_limit),
|
||||
Transaction::Eip1559(t) => U256::from(t.max_fee_per_gas) * U256::from(t.gas_limit),
|
||||
};
|
||||
let cost = gas_cost + U256::from(tx.value());
|
||||
|
||||
PooledTransaction { transaction: tx, cost }
|
||||
PooledTransaction::new(tx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user