Skip to content

Commit

Permalink
Perform dry run by default, need explicit flag to execute
Browse files Browse the repository at this point in the history
Also sneak in the license name mapping for our current backend.
  • Loading branch information
jkopanski committed Jan 3, 2025
1 parent 9d84e28 commit 67dabe9
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 29 deletions.
12 changes: 11 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ pub struct Args {

#[derive(clap::Subcommand)]
pub enum Commands {
/// Submit smart contract for verification
/// Submit smart contract for verification.
///
/// By default it will only report back to user what it is about
/// to do. In order to actually execute pass --exectue flag.
Submit(SubmitArgs),

/// Check verification job status
Expand All @@ -133,6 +136,13 @@ fn license_value_parser(license: &str) -> Result<LicenseId, String> {

#[derive(clap::Args)]
pub struct SubmitArgs {
/// Submit contract for verification.
#[arg(
short = 'x',
long,
default_value_t = false)]
pub execute: bool,

/// Path to Scarb project
#[arg(
long,
Expand Down
99 changes: 71 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum CliError {
#[error("Class hash {0} is not declared")]
NotDeclared(ClassHash),

#[error("Submit dry run")]
DryRun,

#[error(
"No contracts selected for verification. Add [tool.voyager] section to Scarb.toml file"
)]
Expand Down Expand Up @@ -184,36 +187,76 @@ fn submit(public: ApiClient, private: ApiClient, args: &SubmitArgs) -> Result<St
project_dir_path: project_dir_path.to_string(),
};

private
.get_class(&args.hash)
.map_err(CliError::from)
.and_then(|does_exist| {
if !does_exist {
Err(CliError::NotDeclared(args.hash.clone()))
} else {
Ok(does_exist)
// TODO: switch backend to use SPDX identifiers
let license: String = match args.license {
None => "No License (None)".to_string(),
Some(id) => match id.name {
"Unlicense" => "The Unlicense (Unlicense)".to_string(),
"MIT" => "MIT License (MIT)".to_string(),
"GPL-2.0" => "GNU General Public License v2.0 (GNU GPLv2)".to_string(),
"GPL-3.0" => "GNU General Public License v3.0 (GNU GPLv3)".to_string(),
"LGPL-2.1" => {
"GNU Lesser General Public License v2.1 (GNU LGPLv2.1)".to_string()
}
})?;
"LGPL-3.0" => "GNU Lesser General Public License v3.0 (GNU LGPLv3)".to_string(),
"BSD-2-Clause" => {
r#"BSD 2-clause "Simplified" license (BSD-2-Clause)"#.to_string()
}
"BSD-3-Clause" => {
r#"BSD 3-clause "New" Or "Revisited license (BSD-3-Clause)"#.to_string()
}
"MPL-2.0" => "Mozilla Public License 2.0 (MPL-2.0)".to_string(),
"OSL-3.0" => "Open Software License 3.0 (OSL-3.0)".to_string(),
"Apache-2.0" => "Apache 2.0 (Apache-2.0)".to_string(),
"AGPL-3.0" => "GNU Affero General Public License (GNU AGPLv3)".to_string(),
"BUSL-1.1" => "Business Source License (BSL 1.1)".to_string(),
_ => format!("{} ({})", id.full_name, id.name),
},
};

return public
.verify_class(
args.hash.clone(),
args.license
.map_or("No License (None)".to_string(), |l| {
format!("{} ({})", l.full_name, l.name)
})
.as_ref(),
args.name.as_ref(),
project_meta,
files
.into_iter()
.map(|(name, path)| FileInfo {
name,
path: path.into_std_path_buf(),
})
.collect_vec(),
)
.map_err(CliError::from);
println!(
"Submiting contract: {} from {},",
contract_name, contract_file
);
println!("under the name of: {},", args.name);
println!("licensed with: {}.", license);
println!("using cairo: {} and scarb {}", cairo_version, scarb_version);
println!("These are the files that I'm about to transfer:");
for (_name, path) in &files {
println!("{path}");
}

if args.execute {
private
.get_class(&args.hash)
.map_err(CliError::from)
.and_then(|does_exist| {
if !does_exist {
Err(CliError::NotDeclared(args.hash.clone()))
} else {
Ok(does_exist)
}
})?;

return public
.verify_class(
args.hash.clone(),
license.as_str(),
args.name.as_ref(),
project_meta,
files
.into_iter()
.map(|(name, path)| FileInfo {
name,
path: path.into_std_path_buf(),
})
.collect_vec(),
)
.map_err(CliError::from);
} else {
println!("Nothing to do, add `--execute` flag to actually submit contract");
return Err(CliError::DryRun);
}
}
}

Expand Down

0 comments on commit 67dabe9

Please sign in to comment.