cast/cmd/
txpool.rs

1use alloy_primitives::Address;
2use alloy_provider::ext::TxPoolApi;
3use clap::Parser;
4use foundry_cli::{
5    opts::RpcOpts,
6    utils::{self, LoadConfig},
7};
8
9/// CLI arguments for `cast tx-pool`.
10#[derive(Debug, Parser, Clone)]
11pub 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
37impl 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}