Skip to main content

cast/cmd/
txpool.rs

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