cast/cmd/
access_list.rs

1use crate::{
2    tx::{CastTxBuilder, SenderKind},
3    Cast,
4};
5use alloy_rpc_types::BlockId;
6use clap::Parser;
7use eyre::Result;
8use foundry_cli::{
9    opts::{EthereumOpts, TransactionOpts},
10    utils::{self, LoadConfig},
11};
12use foundry_common::ens::NameOrAddress;
13use std::str::FromStr;
14
15/// CLI arguments for `cast access-list`.
16#[derive(Debug, Parser)]
17pub struct AccessListArgs {
18    /// The destination of the transaction.
19    #[arg(
20        value_name = "TO",
21        value_parser = NameOrAddress::from_str
22    )]
23    to: Option<NameOrAddress>,
24
25    /// The signature of the function to call.
26    #[arg(value_name = "SIG")]
27    sig: Option<String>,
28
29    /// The arguments of the function to call.
30    #[arg(value_name = "ARGS")]
31    args: Vec<String>,
32
33    /// The block height to query at.
34    ///
35    /// Can also be the tags earliest, finalized, safe, latest, or pending.
36    #[arg(long, short = 'B')]
37    block: Option<BlockId>,
38
39    #[command(flatten)]
40    tx: TransactionOpts,
41
42    #[command(flatten)]
43    eth: EthereumOpts,
44}
45
46impl AccessListArgs {
47    pub async fn run(self) -> Result<()> {
48        let Self { to, sig, args, tx, eth, block } = self;
49
50        let config = eth.load_config()?;
51        let provider = utils::get_provider(&config)?;
52        let sender = SenderKind::from_wallet_opts(eth.wallet).await?;
53
54        let (tx, _) = CastTxBuilder::new(&provider, tx, &config)
55            .await?
56            .with_to(to)
57            .await?
58            .with_code_sig_and_args(None, sig, args)
59            .await?
60            .build_raw(sender)
61            .await?;
62
63        let cast = Cast::new(&provider);
64
65        let access_list: String = cast.access_list(&tx, block).await?;
66
67        sh_println!("{access_list}")?;
68
69        Ok(())
70    }
71}