Skip to content

Commit ab9a9e5

Browse files
0xOsirismattsse
andauthored
feat(cast): add cast txpool (#10104)
* feat(cast): txpool inspection utils * fix: typo * chore: cleanup * clippy --------- Co-authored-by: Matthias Seitz <[email protected]>
1 parent 759b7d6 commit ab9a9e5

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

crates/cast/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ alloy-provider = { workspace = true, features = [
4242
"ws",
4343
"ipc",
4444
"trace-api",
45+
"txpool-api"
4546
] }
4647
alloy-rlp.workspace = true
4748
alloy-rpc-types = { workspace = true, features = ["eth", "trace"] }

crates/cast/src/args.rs

+1
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ pub async fn run_command(args: CastArgs) -> Result<()> {
704704
let eof = stdin::unwrap_line(eof)?;
705705
sh_println!("{}", SimpleCast::decode_eof(&eof)?)?
706706
}
707+
CastSubcommand::TxPool { command } => command.run().await?,
707708
};
708709

709710
/// Prints slice of tokens using [`format_tokens`] or [`format_tokens_raw`] depending whether

crates/cast/src/cmd/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ pub mod rpc;
2121
pub mod run;
2222
pub mod send;
2323
pub mod storage;
24+
pub mod txpool;
2425
pub mod wallet;

crates/cast/src/cmd/txpool.rs

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use alloy_primitives::Address;
2+
use alloy_provider::ext::TxPoolApi;
3+
use clap::Parser;
4+
use foundry_cli::{
5+
opts::RpcOpts,
6+
utils::{self, LoadConfig},
7+
};
8+
9+
/// CLI arguments for `cast tx-pool`.
10+
#[derive(Debug, Parser, Clone)]
11+
pub enum TxPoolSubcommands {
12+
/// Fetches the content of the transaction pool.
13+
Content {
14+
#[command(flatten)]
15+
args: RpcOpts,
16+
},
17+
/// Fetches the content of the transaction pool filtered by a specific address.
18+
ContentFrom {
19+
/// The Signer to filter the transactions by.
20+
#[arg(short, long)]
21+
from: Address,
22+
#[command(flatten)]
23+
args: RpcOpts,
24+
},
25+
/// Fetches a textual summary of each transaction in the pool.
26+
Inspect {
27+
#[command(flatten)]
28+
args: RpcOpts,
29+
},
30+
/// Fetches the current status of the transaction pool.
31+
Status {
32+
#[command(flatten)]
33+
args: RpcOpts,
34+
},
35+
}
36+
37+
impl TxPoolSubcommands {
38+
pub async fn run(self) -> eyre::Result<()> {
39+
match self {
40+
Self::Content { args } => {
41+
let config = args.load_config()?;
42+
let provider = utils::get_provider(&config)?;
43+
sh_println!("{:#?}", provider.txpool_content().await?)?;
44+
}
45+
Self::ContentFrom { from, args } => {
46+
let config = args.load_config()?;
47+
let provider = utils::get_provider(&config)?;
48+
sh_println!("{:#?}", provider.txpool_content_from(from).await?)?;
49+
}
50+
Self::Inspect { args } => {
51+
let config = args.load_config()?;
52+
let provider = utils::get_provider(&config)?;
53+
sh_println!("{:#?}", provider.txpool_inspect().await?)?;
54+
}
55+
Self::Status { args } => {
56+
let config = args.load_config()?;
57+
let provider = utils::get_provider(&config)?;
58+
sh_println!("{:#?}", provider.txpool_status().await?)?;
59+
}
60+
};
61+
62+
Ok(())
63+
}
64+
}

crates/cast/src/opts.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::cmd::{
33
constructor_args::ConstructorArgsArgs, create2::Create2Args, creation_code::CreationCodeArgs,
44
estimate::EstimateArgs, find_block::FindBlockArgs, interface::InterfaceArgs, logs::LogsArgs,
55
mktx::MakeTxArgs, rpc::RpcArgs, run::RunArgs, send::SendTxArgs, storage::StorageArgs,
6-
wallet::WalletSubcommands,
6+
txpool::TxPoolSubcommands, wallet::WalletSubcommands,
77
};
88
use alloy_primitives::{Address, B256, U256};
99
use alloy_rpc_types::BlockId;
@@ -1052,6 +1052,13 @@ pub enum CastSubcommand {
10521052
/// Decodes EOF container bytes
10531053
#[command()]
10541054
DecodeEof { eof: Option<String> },
1055+
1056+
/// Inspect the TxPool of a node.
1057+
#[command(visible_alias = "tp")]
1058+
TxPool {
1059+
#[command(subcommand)]
1060+
command: TxPoolSubcommands,
1061+
},
10551062
}
10561063

10571064
/// CLI arguments for `cast --to-base`.

0 commit comments

Comments
 (0)