Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add helper for txpool inspect summary #1866

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion crates/rpc-types-txpool/src/txpool.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Types for the `txpool` namespace: <https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-txpool>

use alloy_primitives::{Address, U256};
use alloy_rpc_types_eth::Transaction;
use alloy_rpc_types_eth::{Transaction, TransactionTrait};
use serde::{
de::{self, Deserializer, Visitor},
Deserialize, Serialize,
Expand All @@ -21,6 +21,24 @@ pub struct TxpoolInspectSummary {
pub gas_price: u128,
}

impl TxpoolInspectSummary {
/// Extracts the [`TxpoolInspectSummary`] from a transaction.
pub fn from_tx<T: TransactionTrait>(tx: T) -> Self {
Self {
to: tx.to(),
value: tx.value(),
gas: tx.gas_limit(),
gas_price: tx.max_fee_per_gas(),
}
}
}

impl<T: TransactionTrait> From<T> for TxpoolInspectSummary {
fn from(value: T) -> Self {
Self::from_tx(value)
}
}

/// Visitor struct for TxpoolInspectSummary.
struct TxpoolInspectSummaryVisitor;

Expand Down
Loading