mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-28 16:48:13 -05:00
feat: Add tx_type() and encoded_length() on PoolTransaction trait (#1500)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -5108,6 +5108,7 @@ dependencies = [
|
||||
"rand 0.8.5",
|
||||
"reth-metrics-derive",
|
||||
"reth-primitives",
|
||||
"reth-rlp",
|
||||
"ruint",
|
||||
"serde",
|
||||
"thiserror",
|
||||
|
||||
@@ -17,8 +17,9 @@ normal = [
|
||||
|
||||
[dependencies]
|
||||
|
||||
# eth
|
||||
# reth
|
||||
reth-primitives = { path = "../primitives" }
|
||||
reth-rlp = { path = "../rlp" }
|
||||
|
||||
# async/futures
|
||||
async-trait = "0.1"
|
||||
|
||||
@@ -13,7 +13,7 @@ use rand::{
|
||||
};
|
||||
use reth_primitives::{
|
||||
Address, FromRecoveredTransaction, IntoRecoveredTransaction, Transaction, TransactionKind,
|
||||
TransactionSignedEcRecovered, TxEip1559, TxHash, TxLegacy, H256, U128, U256,
|
||||
TransactionSignedEcRecovered, TxEip1559, TxHash, TxLegacy, TxType, H256, U128, U256,
|
||||
};
|
||||
use std::{ops::Range, sync::Arc, time::Instant};
|
||||
|
||||
@@ -345,6 +345,17 @@ impl PoolTransaction for MockTransaction {
|
||||
fn size(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn tx_type(&self) -> u8 {
|
||||
match self {
|
||||
MockTransaction::Legacy { .. } => TxType::Legacy.into(),
|
||||
MockTransaction::Eip1559 { .. } => TxType::EIP1559.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn encoded_length(&self) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRecoveredTransaction for MockTransaction {
|
||||
|
||||
@@ -3,6 +3,7 @@ use reth_primitives::{
|
||||
Address, FromRecoveredTransaction, IntoRecoveredTransaction, PeerId, Transaction,
|
||||
TransactionKind, TransactionSignedEcRecovered, TxHash, H256, U256,
|
||||
};
|
||||
use reth_rlp::Encodable;
|
||||
use std::{collections::HashMap, fmt, sync::Arc};
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
|
||||
@@ -287,6 +288,12 @@ pub trait PoolTransaction: fmt::Debug + Send + Sync + FromRecoveredTransaction {
|
||||
|
||||
/// Returns a measurement of the heap usage of this type and all its internals.
|
||||
fn size(&self) -> usize;
|
||||
|
||||
/// Returns the transaction type
|
||||
fn tx_type(&self) -> u8;
|
||||
|
||||
/// Returns the length of the rlp encoded object
|
||||
fn encoded_length(&self) -> usize;
|
||||
}
|
||||
|
||||
/// The default [PoolTransaction] for the [Pool](crate::Pool).
|
||||
@@ -372,6 +379,16 @@ impl PoolTransaction for PooledTransaction {
|
||||
fn size(&self) -> usize {
|
||||
self.transaction.transaction.input().len()
|
||||
}
|
||||
|
||||
/// Returns the transaction type
|
||||
fn tx_type(&self) -> u8 {
|
||||
self.transaction.tx_type().into()
|
||||
}
|
||||
|
||||
/// Returns the length of the rlp encoded object
|
||||
fn encoded_length(&self) -> usize {
|
||||
self.transaction.length()
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRecoveredTransaction for PooledTransaction {
|
||||
|
||||
Reference in New Issue
Block a user