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                let content = provider.txpool_content().await?;
44                sh_println!("{}", serde_json::to_string_pretty(&content)?)?;
45            }
46            Self::ContentFrom { from, args } => {
47                let config = args.load_config()?;
48                let provider = utils::get_provider(&config)?;
49                let content = provider.txpool_content_from(from).await?;
50                sh_println!("{}", serde_json::to_string_pretty(&content)?)?;
51            }
52            Self::Inspect { args } => {
53                let config = args.load_config()?;
54                let provider = utils::get_provider(&config)?;
55                let inspect = provider.txpool_inspect().await?;
56                sh_println!("{}", serde_json::to_string_pretty(&inspect)?)?;
57            }
58            Self::Status { args } => {
59                let config = args.load_config()?;
60                let provider = utils::get_provider(&config)?;
61                let status = provider.txpool_status().await?;
62                sh_println!("{}", serde_json::to_string_pretty(&status)?)?;
63            }
64        };
65
66        Ok(())
67    }
68}