Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/cli/src/cast/cmd/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ethers::{
providers::Middleware,
types::{BlockId, NameOrAddress},
};
use eyre::WrapErr;
use eyre::{Result, WrapErr};
use foundry_cli::{
opts::{EthereumOpts, TransactionOpts},
utils,
Expand Down Expand Up @@ -57,7 +57,7 @@ pub struct AccessListArgs {
}

impl AccessListArgs {
pub async fn run(self) -> eyre::Result<()> {
pub async fn run(self) -> Result<()> {
let AccessListArgs { to, sig, args, data, tx, eth, block, json: to_json } = self;

let config = Config::from(&eth);
Expand All @@ -82,7 +82,7 @@ async fn access_list<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddres
chain: Chain,
block: Option<BlockId>,
to_json: bool,
) -> eyre::Result<()>
) -> Result<()>
where
M::Error: 'static,
{
Expand Down
8 changes: 4 additions & 4 deletions crates/cli/src/cast/cmd/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ethers::{
solc::EvmVersion,
types::{BlockId, NameOrAddress, U256},
};
use eyre::WrapErr;
use eyre::{Result, WrapErr};
use forge::executor::opts::EvmOpts;
use foundry_cli::{
opts::{EthereumOpts, TransactionOpts},
Expand Down Expand Up @@ -108,7 +108,7 @@ pub enum CallSubcommands {
}

impl CallArgs {
pub async fn run(self) -> eyre::Result<()> {
pub async fn run(self) -> Result<()> {
let CallArgs {
to,
sig,
Expand Down Expand Up @@ -224,7 +224,7 @@ async fn fill_create(
code: String,
sig: Option<String>,
args: Vec<String>,
) -> eyre::Result<()> {
) -> Result<()> {
builder.value(value);

let mut data = hex::decode(code.strip_prefix("0x").unwrap_or(&code))?;
Expand All @@ -246,7 +246,7 @@ async fn fill_tx(
sig: Option<String>,
args: Vec<String>,
data: Option<String>,
) -> eyre::Result<()> {
) -> Result<()> {
builder.value(value);

if let Some(sig) = sig {
Expand Down
11 changes: 1 addition & 10 deletions crates/cli/src/cast/cmd/create2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use ethers::{
utils::{get_create2_address_from_hash, keccak256},
};
use eyre::{Result, WrapErr};
use foundry_cli::utils::Cmd;
use rayon::prelude::*;
use regex::RegexSetBuilder;
use std::{str::FromStr, time::Instant};
Expand Down Expand Up @@ -59,16 +58,8 @@ pub struct Create2Output {
pub salt: U256,
}

impl Cmd for Create2Args {
type Output = Create2Output;

fn run(self) -> eyre::Result<Self::Output> {
Create2Args::generate_address(self)
}
}

impl Create2Args {
fn generate_address(self) -> Result<Create2Output> {
pub fn run(self) -> Result<Create2Output> {
let Create2Args {
starts_with,
ends_with,
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/cast/cmd/interface.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cast::{AbiPath, SimpleCast};
use clap::Parser;
use eyre::Result;
use foundry_cli::opts::EtherscanOpts;
use foundry_common::fs;
use foundry_config::Config;
Expand Down Expand Up @@ -37,7 +38,7 @@ pub struct InterfaceArgs {
}

impl InterfaceArgs {
pub async fn run(self) -> eyre::Result<()> {
pub async fn run(self) -> Result<()> {
let InterfaceArgs { path_or_address, name, pragma, output: output_location, etherscan } =
self;
let config = Config::from(&etherscan);
Expand Down
6 changes: 2 additions & 4 deletions crates/cli/src/cast/cmd/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ use ethers::{
providers::Middleware,
types::{BlockId, BlockNumber, Filter, FilterBlockOption, NameOrAddress, ValueOrArray, H256},
};
use eyre::Result;
use foundry_cli::{opts::EthereumOpts, utils};

use foundry_common::abi::{get_event, parse_tokens};
use foundry_config::Config;

use itertools::Itertools;

use std::str::FromStr;

/// CLI arguments for `cast logs`.
Expand Down Expand Up @@ -55,7 +53,7 @@ pub struct LogsArgs {
}

impl LogsArgs {
pub async fn run(self) -> eyre::Result<()> {
pub async fn run(self) -> Result<()> {
let LogsArgs {
from_block, to_block, address, topics_or_args, sig_or_topic, json, eth, ..
} = self;
Expand Down
4 changes: 2 additions & 2 deletions crates/cli/src/cast/cmd/run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use ethers::{prelude::Middleware, solc::EvmVersion, types::H160};
use eyre::WrapErr;
use eyre::{Result, WrapErr};
use forge::{
executor::{inspector::cheatcodes::util::configure_tx_env, opts::EvmOpts},
revm::primitives::U256 as rU256,
Expand Down Expand Up @@ -82,7 +82,7 @@ impl RunArgs {
/// This replays the entire block the transaction was mined in unless `quick` is set to true
///
/// Note: This executes the transaction(s) as is: Cheatcodes are disabled
pub async fn run(self) -> eyre::Result<()> {
pub async fn run(self) -> Result<()> {
let figment =
Config::figment_with_root(find_project_root_path(None).unwrap()).merge(self.rpc);
let evm_opts = figment.extract::<EvmOpts>()?;
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/cast/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::Parser;
use ethers::{
prelude::MiddlewareBuilder, providers::Middleware, signers::Signer, types::NameOrAddress,
};
use eyre::Result;
use foundry_cli::{
opts::{EthereumOpts, TransactionOpts},
utils,
Expand Down Expand Up @@ -73,7 +74,7 @@ pub enum SendTxSubcommands {
}

impl SendTxArgs {
pub async fn run(self) -> eyre::Result<()> {
pub async fn run(self) -> Result<()> {
let SendTxArgs {
eth,
to,
Expand Down Expand Up @@ -208,7 +209,7 @@ async fn cast_send<M: Middleware, F: Into<NameOrAddress>, T: Into<NameOrAddress>
cast_async: bool,
confs: usize,
to_json: bool,
) -> eyre::Result<()>
) -> Result<()>
where
M::Error: 'static,
{
Expand Down
11 changes: 4 additions & 7 deletions crates/cli/src/cast/cmd/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use ethers::{
signers::{LocalWallet, Signer},
types::{transaction::eip712::TypedData, Address, Signature},
};
use eyre::Context;
use foundry_cli::{
opts::{RawWallet, Wallet},
utils::Cmd,
};
use eyre::{Context, Result};
use foundry_cli::opts::{RawWallet, Wallet};
use foundry_common::fs;
use foundry_config::Config;
use std::path::Path;
Expand Down Expand Up @@ -120,7 +117,7 @@ pub enum WalletSubcommands {
}

impl WalletSubcommands {
pub async fn run(self) -> eyre::Result<()> {
pub async fn run(self) -> Result<()> {
match self {
WalletSubcommands::New { path, unsafe_password, .. } => {
let mut rng = thread_rng();
Expand Down Expand Up @@ -281,7 +278,7 @@ flag to set your key via:
Ok(())
}

fn hex_str_to_bytes(s: &str) -> eyre::Result<Vec<u8>> {
fn hex_str_to_bytes(s: &str) -> Result<Vec<u8>> {
Ok(match s.strip_prefix("0x") {
Some(data) => hex::decode(data).wrap_err("Could not decode 0x-prefixed string.")?,
None => s.as_bytes().to_vec(),
Expand Down
9 changes: 4 additions & 5 deletions crates/cli/src/cast/cmd/wallet/vanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use ethers::{
types::{H160, U256},
utils::{get_contract_address, secret_key_to_address},
};
use foundry_cli::utils::Cmd;
use eyre::Result;

use rayon::iter::{self, ParallelIterator};
use regex::Regex;
use std::time::Instant;
Expand Down Expand Up @@ -37,10 +38,8 @@ pub struct VanityArgs {
pub nonce: Option<u64>,
}

impl Cmd for VanityArgs {
type Output = LocalWallet;

fn run(self) -> eyre::Result<Self::Output> {
impl VanityArgs {
pub fn run(self) -> Result<LocalWallet> {
let Self { starts_with, ends_with, nonce } = self;
let mut left_exact_hex = None;
let mut left_regex = None;
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/cast/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use ethers::{
types::Address,
utils::keccak256,
};
use foundry_cli::{handler, prompt, stdin, utils, utils::Cmd};
use eyre::Result;
use foundry_cli::{handler, prompt, stdin, utils};
use foundry_common::{
abi::{format_tokens, get_event},
fs,
Expand All @@ -25,7 +26,7 @@ pub mod opts;
use opts::{Opts, Subcommands, ToBaseArgs};

#[tokio::main]
async fn main() -> eyre::Result<()> {
async fn main() -> Result<()> {
utils::load_dotenv();
handler::install()?;
utils::subscriber();
Expand Down
3 changes: 2 additions & 1 deletion crates/cli/src/cast/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use ethers::{
abi::ethabi::ethereum_types::BigEndianHash,
types::{serde_helpers::Numeric, Address, BlockId, NameOrAddress, H256, U256},
};
use eyre::Result;
use foundry_cli::{
opts::{EtherscanOpts, RpcOpts},
utils::parse_u256,
Expand Down Expand Up @@ -862,7 +863,7 @@ pub struct ToBaseArgs {
pub base_in: Option<String>,
}

pub fn parse_slot(s: &str) -> eyre::Result<H256> {
pub fn parse_slot(s: &str) -> Result<H256> {
Numeric::from_str(s)
.map_err(|e| eyre::eyre!("Could not parse slot number: {e}"))
.map(|n| H256::from_uint(&n.into()))
Expand Down
18 changes: 6 additions & 12 deletions crates/cli/src/forge/cmd/bind.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use clap::{Parser, ValueHint};
use ethers::contract::{Abigen, ContractFilter, ExcludeContracts, MultiAbigen, SelectContracts};
use foundry_cli::{
opts::CoreBuildArgs,
utils::{Cmd, LoadConfig},
};
use eyre::Result;
use foundry_cli::{opts::CoreBuildArgs, utils::LoadConfig};
use foundry_common::{compile, fs::json_files};
use foundry_config::impl_figment_convert;
use std::{
Expand Down Expand Up @@ -121,7 +119,7 @@ impl BindArgs {
}

/// Instantiate the multi-abigen
fn get_multi(&self, artifacts: impl AsRef<Path>) -> eyre::Result<MultiAbigen> {
fn get_multi(&self, artifacts: impl AsRef<Path>) -> Result<MultiAbigen> {
let abigens = json_files(artifacts.as_ref())
.into_iter()
.filter_map(|path| {
Expand All @@ -147,7 +145,7 @@ No contract artifacts found. Hint: Have you built your contracts yet? `forge bin
}

/// Check that the existing bindings match the expected abigen output
fn check_existing_bindings(&self, artifacts: impl AsRef<Path>) -> eyre::Result<()> {
fn check_existing_bindings(&self, artifacts: impl AsRef<Path>) -> Result<()> {
let bindings = self.get_multi(&artifacts)?.build()?;
println!("Checking bindings for {} contracts.", bindings.len());
if !self.module {
Expand All @@ -166,7 +164,7 @@ No contract artifacts found. Hint: Have you built your contracts yet? `forge bin
}

/// Generate the bindings
fn generate_bindings(&self, artifacts: impl AsRef<Path>) -> eyre::Result<()> {
fn generate_bindings(&self, artifacts: impl AsRef<Path>) -> Result<()> {
let bindings = self.get_multi(&artifacts)?.build()?;
println!("Generating bindings for {} contracts", bindings.len());
if !self.module {
Expand All @@ -181,12 +179,8 @@ No contract artifacts found. Hint: Have you built your contracts yet? `forge bin
}
Ok(())
}
}

impl Cmd for BindArgs {
type Output = ();

fn run(self) -> eyre::Result<Self::Output> {
pub fn run(self) -> Result<()> {
if !self.skip_build {
// run `forge build`
let project = self.build_args.project()?;
Expand Down
18 changes: 6 additions & 12 deletions crates/cli/src/forge/cmd/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::{install, watch::WatchArgs};
use clap::Parser;
use ethers::solc::{Project, ProjectCompileOutput};
use foundry_cli::{
opts::CoreBuildArgs,
utils::{Cmd, LoadConfig},
};
use eyre::Result;
use foundry_cli::{opts::CoreBuildArgs, utils::LoadConfig};
use foundry_common::{
compile,
compile::{ProjectCompiler, SkipBuildFilter},
Expand Down Expand Up @@ -73,10 +71,8 @@ pub struct BuildArgs {
pub watch: WatchArgs,
}

impl Cmd for BuildArgs {
type Output = ProjectCompileOutput;

fn run(self) -> eyre::Result<Self::Output> {
impl BuildArgs {
pub fn run(self) -> Result<ProjectCompileOutput> {
let mut config = self.try_load_config_emit_warnings()?;
let mut project = config.project()?;

Expand All @@ -97,15 +93,13 @@ impl Cmd for BuildArgs {
compiler.compile(&project)
}
}
}

impl BuildArgs {
/// Returns the `Project` for the current workspace
///
/// This loads the `foundry_config::Config` for the current workspace (see
/// [`utils::find_project_root_path`] and merges the cli `BuildArgs` into it before returning
/// [`foundry_config::Config::project()`]
pub fn project(&self) -> eyre::Result<Project> {
pub fn project(&self) -> Result<Project> {
self.args.project()
}

Expand All @@ -116,7 +110,7 @@ impl BuildArgs {

/// Returns the [`watchexec::InitConfig`] and [`watchexec::RuntimeConfig`] necessary to
/// bootstrap a new [`watchexe::Watchexec`] loop.
pub(crate) fn watchexec_config(&self) -> eyre::Result<(InitConfig, RuntimeConfig)> {
pub(crate) fn watchexec_config(&self) -> Result<(InitConfig, RuntimeConfig)> {
// use the path arguments or if none where provided the `src` dir
self.watch.watchexec_config(|| {
let config = Config::from(self);
Expand Down
Loading