Skip to main content

cast/cmd/
txpool.rs

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