Skip to content
14 changes: 9 additions & 5 deletions crates/cast/src/cmd/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use alloy_rpc_types::BlockId;
use clap::Parser;
use eyre::Result;
use foundry_cli::{
opts::{EthereumOpts, TransactionOpts},
opts::{RpcOpts, TransactionOpts},
utils::{self, LoadConfig},
};
use foundry_wallets::WalletOpts;
use std::str::FromStr;

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

#[command(flatten)]
eth: EthereumOpts,
rpc: RpcOpts,

#[command(flatten)]
wallet: WalletOpts,
}

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

let config = eth.load_config()?;
let config = rpc.load_config()?;
let provider = utils::get_provider(&config)?;
let sender = SenderKind::from_wallet_opts(eth.wallet).await?;
let sender = SenderKind::from_wallet_opts(wallet).await?;

let (tx, _) = CastTxBuilder::new(&provider, tx, &config)
.await?
Expand Down
26 changes: 20 additions & 6 deletions crates/cast/src/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use alloy_rpc_types::{
use clap::Parser;
use eyre::Result;
use foundry_cli::{
opts::{EthereumOpts, TransactionOpts},
opts::{ChainValueParser, RpcOpts, TransactionOpts},
utils::{self, TraceResult, parse_ether_value},
};
use foundry_common::shell;
use foundry_compilers::artifacts::EvmVersion;
use foundry_config::{
Config,
Chain, Config,
figment::{
self, Metadata, Profile,
value::{Dict, Map},
Expand All @@ -32,6 +32,7 @@ use foundry_evm::{
opts::EvmOpts,
traces::{InternalTraceMode, TraceMode},
};
use foundry_wallets::WalletOpts;
use itertools::Either;
use regex::Regex;
use revm::context::TransactionType;
Expand Down Expand Up @@ -129,7 +130,19 @@ pub struct CallArgs {
tx: TransactionOpts,

#[command(flatten)]
eth: EthereumOpts,
rpc: RpcOpts,

#[command(flatten)]
wallet: WalletOpts,

#[arg(
short,
long,
alias = "chain-id",
env = "CHAIN",
value_parser = ChainValueParser::default(),
)]
pub chain: Option<Chain>,

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

impl CallArgs {
pub async fn run(self) -> Result<()> {
let figment = self.eth.rpc.clone().into_figment(self.with_local_artifacts).merge(&self);
let figment = self.rpc.clone().into_figment(self.with_local_artifacts).merge(&self);
let evm_opts = figment.extract::<EvmOpts>()?;
let mut config = Config::from_provider(figment)?.sanitized();
let state_overrides = self.get_state_overrides()?;
Expand All @@ -207,7 +220,6 @@ impl CallArgs {
mut sig,
mut args,
mut tx,
eth,
command,
block,
trace,
Expand All @@ -218,6 +230,7 @@ impl CallArgs {
data,
with_local_artifacts,
disable_labels,
wallet,
..
} = self;

Expand All @@ -226,7 +239,8 @@ impl CallArgs {
}

let provider = utils::get_provider(&config)?;
let sender = SenderKind::from_wallet_opts(eth.wallet).await?;
let sender = SenderKind::from_wallet_opts(wallet).await?;

let from = sender.address();

let code = if let Some(CallSubcommands::Create {
Expand Down
14 changes: 9 additions & 5 deletions crates/cast/src/cmd/estimate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use alloy_rpc_types::BlockId;
use clap::Parser;
use eyre::Result;
use foundry_cli::{
opts::{EthereumOpts, TransactionOpts},
opts::{RpcOpts, TransactionOpts},
utils::{self, LoadConfig, parse_ether_value},
};
use foundry_wallets::WalletOpts;
use std::str::FromStr;

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

#[command(flatten)]
wallet: WalletOpts,

#[command(subcommand)]
command: Option<EstimateSubcommands>,

#[command(flatten)]
tx: TransactionOpts,

#[command(flatten)]
eth: EthereumOpts,
rpc: RpcOpts,
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -74,11 +78,11 @@ pub enum EstimateSubcommands {

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

let config = eth.load_config()?;
let config = rpc.load_config()?;
let provider = utils::get_provider(&config)?;
let sender = SenderKind::from_wallet_opts(eth.wallet).await?;
let sender = SenderKind::from_wallet_opts(wallet).await?;

let code = if let Some(EstimateSubcommands::Create {
code,
Expand Down
11 changes: 7 additions & 4 deletions crates/cast/src/cmd/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use alloy_primitives::{Address, B256, hex::FromHex};
use alloy_rpc_types::{BlockId, BlockNumberOrTag, Filter, FilterBlockOption, FilterSet, Topic};
use clap::Parser;
use eyre::Result;
use foundry_cli::{opts::EthereumOpts, utils, utils::LoadConfig};
use foundry_cli::{
opts::RpcOpts,
utils::{self, LoadConfig},
};
use itertools::Itertools;
use std::{io, str::FromStr};

Expand Down Expand Up @@ -46,15 +49,15 @@ pub struct LogsArgs {
subscribe: bool,

#[command(flatten)]
eth: EthereumOpts,
rpc: RpcOpts,
}

impl LogsArgs {
pub async fn run(self) -> Result<()> {
let Self { from_block, to_block, address, sig_or_topic, topics_or_args, subscribe, eth } =
let Self { from_block, to_block, address, sig_or_topic, topics_or_args, subscribe, rpc } =
self;

let config = eth.load_config()?;
let config = rpc.load_config()?;
let provider = utils::get_provider(&config)?;

let cast = Cast::new(&provider);
Expand Down
1 change: 1 addition & 0 deletions crates/cli/src/opts/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::borrow::Cow;
const FLASHBOTS_URL: &str = "https://rpc.flashbots.net/fast";

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