Skip to content

Commit

Permalink
fix(forge): verify-contract only needs subset of BuildArgs options (#844
Browse files Browse the repository at this point in the history
)
  • Loading branch information
welps authored Mar 6, 2022
1 parent 36483e8 commit cc13c40
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 37 deletions.
66 changes: 32 additions & 34 deletions cli/src/cmd/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,20 @@ use clap::{Parser, ValueHint};
use foundry_config::Config;

#[derive(Debug, Clone, Parser)]
pub struct FlattenArgs {
#[clap(help = "the path to the contract to flatten", value_hint = ValueHint::FilePath)]
pub target_path: PathBuf,

#[clap(long, short, help = "output path for the flattened contract", value_hint = ValueHint::FilePath)]
pub output: Option<PathBuf>,

pub struct CoreFlattenArgs {
#[clap(
help = "the project's root path. By default, this is the root directory of the current Git repository or the current working directory if it is not part of a Git repository",
long,
value_hint = ValueHint::DirPath
help = "the project's root path. By default, this is the root directory of the current Git repository or the current working directory if it is not part of a Git repository",
long,
value_hint = ValueHint::DirPath
)]
pub root: Option<PathBuf>,

#[clap(
env = "DAPP_SRC",
help = "the directory relative to the root under which the smart contracts are",
long,
short,
value_hint = ValueHint::DirPath
env = "DAPP_SRC",
help = "the directory relative to the root under which the smart contracts are",
long,
short,
value_hint = ValueHint::DirPath
)]
pub contracts: Option<PathBuf>,

Expand All @@ -36,9 +30,9 @@ pub struct FlattenArgs {
pub remappings_env: Option<String>,

#[clap(
help = "the paths where your libraries are installed",
long,
value_hint = ValueHint::DirPath
help = "the paths where your libraries are installed",
long,
value_hint = ValueHint::DirPath
)]
pub lib_paths: Vec<PathBuf>,

Expand All @@ -51,26 +45,30 @@ pub struct FlattenArgs {
pub hardhat: bool,
}

#[derive(Debug, Clone, Parser)]
pub struct FlattenArgs {
#[clap(help = "the path to the contract to flatten", value_hint = ValueHint::FilePath)]
pub target_path: PathBuf,

#[clap(long, short, help = "output path for the flattened contract", value_hint = ValueHint::FilePath)]
pub output: Option<PathBuf>,

#[clap(flatten)]
core_flatten_args: CoreFlattenArgs,
}

impl Cmd for FlattenArgs {
type Output = ();
fn run(self) -> eyre::Result<Self::Output> {
let FlattenArgs {
target_path,
output,
root,
contracts,
remappings,
remappings_env,
lib_paths,
hardhat,
} = self;
let FlattenArgs { target_path, output, core_flatten_args } = self;

// flatten is a subset of `BuildArgs` so we can reuse that to get the config
let build_args = BuildArgs {
root,
contracts,
remappings,
remappings_env,
lib_paths,
root: core_flatten_args.root,
contracts: core_flatten_args.contracts,
remappings: core_flatten_args.remappings,
remappings_env: core_flatten_args.remappings_env,
lib_paths: core_flatten_args.lib_paths,
out_path: None,
compiler: Default::default(),
names: false,
Expand All @@ -79,7 +77,7 @@ impl Cmd for FlattenArgs {
no_auto_detect: false,
offline: false,
force: false,
hardhat,
hardhat: core_flatten_args.hardhat,
libraries: vec![],
watch: Default::default(),
};
Expand Down
30 changes: 27 additions & 3 deletions cli/src/cmd/verify.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Verify contract source on etherscan
use crate::{cmd::build::BuildArgs, opts::forge::ContractInfo};
use crate::{
cmd::{build::BuildArgs, flatten::CoreFlattenArgs},
opts::forge::ContractInfo,
};
use clap::Parser;
use ethers::{
abi::Address,
Expand Down Expand Up @@ -33,7 +36,7 @@ pub struct VerifyArgs {
etherscan_key: String,

#[clap(flatten)]
opts: BuildArgs,
opts: CoreFlattenArgs,
}

/// Check verification status arguments
Expand All @@ -56,7 +59,28 @@ pub async fn run_verify(args: &VerifyArgs) -> eyre::Result<()> {
eyre::bail!("Contract info must be provided in the format <path>:<name>")
}

let project = args.opts.project()?;
let CoreFlattenArgs { root, contracts, remappings, remappings_env, lib_paths, hardhat } =
args.opts.clone();

let build_args = BuildArgs {
root,
contracts,
remappings,
remappings_env,
lib_paths,
out_path: None,
compiler: Default::default(),
names: false,
sizes: false,
ignored_error_codes: vec![],
no_auto_detect: false,
offline: false,
force: false,
hardhat,
libraries: vec![],
};

let project = build_args.project()?;
let contract = project
.flatten(&project.root().join(args.contract.path.as_ref().unwrap()))
.map_err(|err| eyre::eyre!("Failed to flatten contract: {}", err))?;
Expand Down

0 comments on commit cc13c40

Please sign in to comment.