Skip to content

Commit b4d888b

Browse files
tskoyoDaniPopes
andauthored
feat(cast): strip WalletOpts and EtherscanOpts from cast subcommands that dont expect a signer or need etherscan api (#12705)
* Use only RpcOpts struct in cast subcommands * Fix failing tests * run fmt * PR fix * Pipeline fix * Update crates/cast/src/cmd/call.rs --------- Co-authored-by: DaniPopes <[email protected]>
1 parent 5375ff4 commit b4d888b

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

crates/cast/src/cmd/access_list.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use alloy_rpc_types::BlockId;
77
use clap::Parser;
88
use eyre::Result;
99
use foundry_cli::{
10-
opts::{EthereumOpts, TransactionOpts},
10+
opts::{RpcOpts, TransactionOpts},
1111
utils::{self, LoadConfig},
1212
};
13+
use foundry_wallets::WalletOpts;
1314
use std::str::FromStr;
1415

1516
/// CLI arguments for `cast access-list`.
@@ -40,16 +41,19 @@ pub struct AccessListArgs {
4041
tx: TransactionOpts,
4142

4243
#[command(flatten)]
43-
eth: EthereumOpts,
44+
rpc: RpcOpts,
45+
46+
#[command(flatten)]
47+
wallet: WalletOpts,
4448
}
4549

4650
impl AccessListArgs {
4751
pub async fn run(self) -> Result<()> {
48-
let Self { to, sig, args, tx, eth, block } = self;
52+
let Self { to, sig, args, tx, rpc, wallet, block } = self;
4953

50-
let config = eth.load_config()?;
54+
let config = rpc.load_config()?;
5155
let provider = utils::get_provider(&config)?;
52-
let sender = SenderKind::from_wallet_opts(eth.wallet).await?;
56+
let sender = SenderKind::from_wallet_opts(wallet).await?;
5357

5458
let (tx, _) = CastTxBuilder::new(&provider, tx, &config)
5559
.await?

crates/cast/src/cmd/call.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use alloy_rpc_types::{
1515
use clap::Parser;
1616
use eyre::Result;
1717
use foundry_cli::{
18-
opts::{EthereumOpts, TransactionOpts},
18+
opts::{ChainValueParser, RpcOpts, TransactionOpts},
1919
utils::{self, TraceResult, parse_ether_value},
2020
};
2121
use foundry_common::shell;
2222
use foundry_compilers::artifacts::EvmVersion;
2323
use foundry_config::{
24-
Config,
24+
Chain, Config,
2525
figment::{
2626
self, Metadata, Profile,
2727
value::{Dict, Map},
@@ -32,6 +32,7 @@ use foundry_evm::{
3232
opts::EvmOpts,
3333
traces::{InternalTraceMode, TraceMode},
3434
};
35+
use foundry_wallets::WalletOpts;
3536
use itertools::Either;
3637
use regex::Regex;
3738
use revm::context::TransactionType;
@@ -129,7 +130,19 @@ pub struct CallArgs {
129130
tx: TransactionOpts,
130131

131132
#[command(flatten)]
132-
eth: EthereumOpts,
133+
rpc: RpcOpts,
134+
135+
#[command(flatten)]
136+
wallet: WalletOpts,
137+
138+
#[arg(
139+
short,
140+
long,
141+
alias = "chain-id",
142+
env = "CHAIN",
143+
value_parser = ChainValueParser::default(),
144+
)]
145+
pub chain: Option<Chain>,
133146

134147
/// Use current project artifacts for trace decoding.
135148
#[arg(long, visible_alias = "la")]
@@ -196,7 +209,7 @@ pub enum CallSubcommands {
196209

197210
impl CallArgs {
198211
pub async fn run(self) -> Result<()> {
199-
let figment = self.eth.rpc.clone().into_figment(self.with_local_artifacts).merge(&self);
212+
let figment = self.rpc.clone().into_figment(self.with_local_artifacts).merge(&self);
200213
let evm_opts = figment.extract::<EvmOpts>()?;
201214
let mut config = Config::from_provider(figment)?.sanitized();
202215
let state_overrides = self.get_state_overrides()?;
@@ -207,7 +220,6 @@ impl CallArgs {
207220
mut sig,
208221
mut args,
209222
mut tx,
210-
eth,
211223
command,
212224
block,
213225
trace,
@@ -218,6 +230,7 @@ impl CallArgs {
218230
data,
219231
with_local_artifacts,
220232
disable_labels,
233+
wallet,
221234
..
222235
} = self;
223236

@@ -226,7 +239,7 @@ impl CallArgs {
226239
}
227240

228241
let provider = utils::get_provider(&config)?;
229-
let sender = SenderKind::from_wallet_opts(eth.wallet).await?;
242+
let sender = SenderKind::from_wallet_opts(wallet).await?;
230243
let from = sender.address();
231244

232245
let code = if let Some(CallSubcommands::Create {

crates/cast/src/cmd/estimate.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use alloy_rpc_types::BlockId;
66
use clap::Parser;
77
use eyre::Result;
88
use foundry_cli::{
9-
opts::{EthereumOpts, TransactionOpts},
9+
opts::{RpcOpts, TransactionOpts},
1010
utils::{self, LoadConfig, parse_ether_value},
1111
};
12+
use foundry_wallets::WalletOpts;
1213
use std::str::FromStr;
1314

1415
/// CLI arguments for `cast estimate`.
@@ -37,14 +38,17 @@ pub struct EstimateArgs {
3738
#[arg(long)]
3839
cost: bool,
3940

41+
#[command(flatten)]
42+
wallet: WalletOpts,
43+
4044
#[command(subcommand)]
4145
command: Option<EstimateSubcommands>,
4246

4347
#[command(flatten)]
4448
tx: TransactionOpts,
4549

4650
#[command(flatten)]
47-
eth: EthereumOpts,
51+
rpc: RpcOpts,
4852
}
4953

5054
#[derive(Debug, Parser)]
@@ -74,11 +78,11 @@ pub enum EstimateSubcommands {
7478

7579
impl EstimateArgs {
7680
pub async fn run(self) -> Result<()> {
77-
let Self { to, mut sig, mut args, mut tx, block, cost, eth, command } = self;
81+
let Self { to, mut sig, mut args, mut tx, block, cost, wallet, rpc, command } = self;
7882

79-
let config = eth.load_config()?;
83+
let config = rpc.load_config()?;
8084
let provider = utils::get_provider(&config)?;
81-
let sender = SenderKind::from_wallet_opts(eth.wallet).await?;
85+
let sender = SenderKind::from_wallet_opts(wallet).await?;
8286

8387
let code = if let Some(EstimateSubcommands::Create {
8488
code,

crates/cast/src/cmd/logs.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use alloy_primitives::{Address, B256, hex::FromHex};
77
use alloy_rpc_types::{BlockId, BlockNumberOrTag, Filter, FilterBlockOption, FilterSet, Topic};
88
use clap::Parser;
99
use eyre::Result;
10-
use foundry_cli::{opts::EthereumOpts, utils, utils::LoadConfig};
10+
use foundry_cli::{
11+
opts::RpcOpts,
12+
utils::{self, LoadConfig},
13+
};
1114
use itertools::Itertools;
1215
use std::{io, str::FromStr};
1316

@@ -51,7 +54,7 @@ pub struct LogsArgs {
5154
query_size: u64,
5255

5356
#[command(flatten)]
54-
eth: EthereumOpts,
57+
rpc: RpcOpts,
5558
}
5659

5760
impl LogsArgs {
@@ -64,10 +67,10 @@ impl LogsArgs {
6467
topics_or_args,
6568
subscribe,
6669
query_size,
67-
eth,
70+
rpc,
6871
} = self;
6972

70-
let config = eth.load_config()?;
73+
let config = rpc.load_config()?;
7174
let provider = utils::get_provider(&config)?;
7275

7376
let cast = Cast::new(&provider);

crates/cli/src/opts/rpc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::borrow::Cow;
1717
const FLASHBOTS_URL: &str = "https://rpc.flashbots.net/fast";
1818

1919
#[derive(Clone, Debug, Default, Parser)]
20+
#[command(next_help_heading = "Rpc options")]
2021
pub struct RpcOpts {
2122
/// The RPC endpoint, default value is http://localhost:8545.
2223
#[arg(short = 'r', long = "rpc-url", env = "ETH_RPC_URL")]

0 commit comments

Comments
 (0)