Skip to content

Commit

Permalink
fix: review comments
Browse files Browse the repository at this point in the history
- added default for CoreBuildArgs
- cleaned up code ordering
- moved url to constant
  • Loading branch information
marktoda committed May 23, 2022
1 parent 44700c6 commit 6964a7c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 58 deletions.
20 changes: 19 additions & 1 deletion cli/src/cmd/forge/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,24 @@ impl Provider for CoreBuildArgs {
}
}

impl Default for CoreBuildArgs {
fn default() -> CoreBuildArgs {
CoreBuildArgs {
project_paths: Default::default(),
out_path: Default::default(),
compiler: Default::default(),
ignored_error_codes: vec![],
no_auto_detect: false,
use_solc: None,
offline: false,
force: false,
libraries: vec![],
via_ir: false,
revert_strings: None,
}
}
}

// All `forge build` related arguments
//
// CLI arguments take the highest precedence in the Config/Figment hierarchy.
Expand Down Expand Up @@ -310,7 +328,7 @@ impl Provider for BuildArgs {

impl_figment_convert!(BuildArgs, args);

#[derive(Debug, Clone, Parser, Serialize)]
#[derive(Debug, Clone, Parser, Serialize, Default)]
pub struct ProjectPathsArgs {
#[clap(
help = "The project's root path.",
Expand Down
105 changes: 49 additions & 56 deletions cli/src/cmd/forge/fourbyte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,7 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use tracing::trace;

#[derive(Serialize, Debug)]
struct ImportRequest {
#[serde(rename = "type")]
import_type: String,
data: Vec<LosslessAbi>,
}

#[derive(Deserialize, Debug)]
struct ImportTypeData {
imported: HashMap<String, String>,
duplicated: HashMap<String, String>,
}

#[derive(Deserialize, Debug)]
struct ImportData {
function: ImportTypeData,
event: ImportTypeData,
}

#[derive(Deserialize, Debug)]
struct ImportResponse {
result: ImportData,
}
static SELECTOR_DATABASE_URL: &str = "https://sig.eth.samczsun.com/api/v1/import";

#[derive(Debug, Clone, Parser)]
pub struct UploadSelectorsArgs {
Expand All @@ -49,19 +27,11 @@ impl UploadSelectorsArgs {

let build_args = CoreBuildArgs {
project_paths: project_paths.clone(),
out_path: Default::default(),
ignored_error_codes: vec![],
no_auto_detect: false,
use_solc: None,
offline: false,
force: false,
libraries: vec![],
via_ir: false,
revert_strings: None,
compiler: CompilerArgs {
extra_output: vec![ContractOutputSelection::Abi],
..Default::default()
},
..Default::default()
};

trace!("Building project");
Expand All @@ -80,40 +50,63 @@ impl UploadSelectorsArgs {
// upload abi to selector database
trace!("Uploading selector args {:?}", body);
let res: ImportResponse = reqwest::Client::new()
.post("https://sig.eth.samczsun.com/api/v1/import")
.post(SELECTOR_DATABASE_URL)
.json(&body)
.send()
.await?
.json()
.await?;
trace!("Got response: {:?}", res);
describe_upload(res);
res.describe_upload();

Ok(())
}
}

/// Print info about the functions which were uploaded or already known
fn describe_upload(response: ImportResponse) {
response
.result
.function
.imported
.iter()
.for_each(|(k, v)| println!("Imported: Function {k}: {v}"));
response.result.event.imported.iter().for_each(|(k, v)| println!("Imported: Event {k}: {v}"));
response
.result
.function
.duplicated
.iter()
.for_each(|(k, v)| println!("Duplicated: Function {k}: {v}"));
response
.result
.event
.duplicated
.iter()
.for_each(|(k, v)| println!("Duplicated: Event {k}: {v}"));
#[derive(Serialize, Debug)]
struct ImportRequest {
#[serde(rename = "type")]
import_type: String,
data: Vec<LosslessAbi>,
}

#[derive(Deserialize, Debug)]
struct ImportTypeData {
imported: HashMap<String, String>,
duplicated: HashMap<String, String>,
}

#[derive(Deserialize, Debug)]
struct ImportData {
function: ImportTypeData,
event: ImportTypeData,
}

#[derive(Deserialize, Debug)]
struct ImportResponse {
result: ImportData,
}

impl ImportResponse {
/// Print info about the functions which were uploaded or already known
pub fn describe_upload(&self) {
self.result
.function
.imported
.iter()
.for_each(|(k, v)| println!("Imported: Function {k}: {v}"));
self.result.event.imported.iter().for_each(|(k, v)| println!("Imported: Event {k}: {v}"));
self.result
.function
.duplicated
.iter()
.for_each(|(k, v)| println!("Duplicated: Function {k}: {v}"));
self.result
.event
.duplicated
.iter()
.for_each(|(k, v)| println!("Duplicated: Event {k}: {v}"));

println!("Selectors successfully uploaded to https://sig.eth.samczsun.com");
println!("Selectors successfully uploaded to https://sig.eth.samczsun.com");
}
}
5 changes: 4 additions & 1 deletion cli/src/opts/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ pub enum Subcommands {
#[clap(alias = "in", about = "Get specialized information about a smart contract")]
Inspect(inspect::InspectArgs),

#[clap(alias = "up", about = "Uploads abi to sig.eth.samczsun.com function selector database")]
#[clap(
alias = "up",
about = "Uploads abi of given contract to https://sig.eth.samczsun.com function selector database"
)]
UploadSelectors(UploadSelectorsArgs),

#[clap(
Expand Down

0 comments on commit 6964a7c

Please sign in to comment.