feat: Add tx_type() and encoded_length() on PoolTransaction trait (#1500)

This commit is contained in:
Aurélien
2023-02-22 13:56:35 +01:00
committed by GitHub
parent 44e1d13f11
commit 2e73463a58
4 changed files with 32 additions and 2 deletions

1
Cargo.lock generated
View File

@@ -5108,6 +5108,7 @@ dependencies = [
"rand 0.8.5",
"reth-metrics-derive",
"reth-primitives",
"reth-rlp",
"ruint",
"serde",
"thiserror",

View File

@@ -17,8 +17,9 @@ normal = [
[dependencies]
# eth
# reth
reth-primitives = { path = "../primitives" }
reth-rlp = { path = "../rlp" }
# async/futures
async-trait = "0.1"

View File

@@ -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 {

View File

@@ -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 {