Skip to content

Commit

Permalink
feat: Add tx_type() and encoded_length() on PoolTransaction trait (#1500
Browse files Browse the repository at this point in the history
)
  • Loading branch information
leruaa authored Feb 22, 2023
1 parent 44e1d13 commit 2e73463
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/transaction-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ normal = [

[dependencies]

# eth
# reth
reth-primitives = { path = "../primitives" }
reth-rlp = { path = "../rlp" }

# async/futures
async-trait = "0.1"
Expand Down
13 changes: 12 additions & 1 deletion crates/transaction-pool/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2e73463

Please sign in to comment.