Skip to content

Commit

Permalink
✨ feat: add lib examples (#155)
Browse files Browse the repository at this point in the history
* ✨ feat: init examples

* ✨ feat: more examples, fix some async things

* 🔧 fix: remove unused `err` var
  • Loading branch information
Jon-Becker authored Sep 30, 2023
1 parent b7a7533 commit b78691f
Show file tree
Hide file tree
Showing 28 changed files with 478 additions and 302 deletions.
92 changes: 73 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
[workspace]
members = ["common", "config", "core", "cli"]
members = [
"common",
"config",
"core",
"cli",
"examples/cfg",
"examples/dump",
"examples/decode",
"examples/snapshot",
"examples/decompile"
]
version = "0.6.0"
70 changes: 2 additions & 68 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
cmd.rpc_url = configuration.rpc_url;
}

// set logger environment variable if not already set
if std::env::var("RUST_LOG").is_err() {
std::env::set_var(
"RUST_LOG",
match cmd.verbose.log_level() {
Some(level) => level.as_str(),
None => "SILENT",
},
);
}

let assembly = disassemble(cmd.clone()).await?;

// write to file
Expand All @@ -137,17 +126,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
cmd.rpc_url = configuration.rpc_url;
}

// set logger environment variable if not already set
if std::env::var("RUST_LOG").is_err() {
std::env::set_var(
"RUST_LOG",
match cmd.verbose.log_level() {
Some(level) => level.as_str(),
None => "SILENT",
},
);
}

let result = decompile(cmd.clone()).await?;

// write to file
Expand Down Expand Up @@ -209,18 +187,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
cmd.openai_api_key = configuration.openai_api_key;
}

// set logger environment variable if not already set
if std::env::var("RUST_LOG").is_err() {
std::env::set_var(
"RUST_LOG",
match cmd.verbose.log_level() {
Some(level) => level.as_str(),
None => "SILENT",
},
);
}

decode(cmd).await;
let _ = decode(cmd).await;
}

Subcommands::CFG(mut cmd) => {
Expand All @@ -229,17 +196,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
cmd.rpc_url = configuration.rpc_url;
}

// set logger environment variable if not already set
if std::env::var("RUST_LOG").is_err() {
std::env::set_var(
"RUST_LOG",
match cmd.verbose.log_level() {
Some(level) => level.as_str(),
None => "SILENT",
},
);
}

let cfg = cfg(cmd.clone()).await?;

// write to file
Expand All @@ -263,17 +219,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
cmd.transpose_api_key = configuration.transpose_api_key;
}

// set logger environment variable if not already set
if std::env::var("RUST_LOG").is_err() {
std::env::set_var(
"RUST_LOG",
match cmd.verbose.log_level() {
Some(level) => level.as_str(),
None => "SILENT",
},
);
}

let result = dump(cmd.clone()).await?;
let mut lines = Vec::new();

Expand Down Expand Up @@ -305,17 +250,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
cmd.rpc_url = configuration.rpc_url;
}

// set logger environment variable if not already set
if std::env::var("RUST_LOG").is_err() {
std::env::set_var(
"RUST_LOG",
match cmd.verbose.log_level() {
Some(level) => level.as_str(),
None => "SILENT",
},
);
}

// write to file
if ADDRESS_REGEX.is_match(&cmd.target).unwrap() {
output_path.push_str(&format!("/{}/snapshot.csv", &cmd.target));
Expand All @@ -341,7 +275,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}

// check if the version is up to date
let remote_version = remote_version();
let remote_version = remote_version().await;
let current_version = current_version();

if remote_version.gt(&current_version) {
Expand Down
2 changes: 2 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
tokio = {version = "1", features = ["full"]}
strsim = "0.10.0"
async-recursion = "1.0.5"
async-trait = "0.1.51"
4 changes: 2 additions & 2 deletions common/src/ether/selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ where
let resolve_progress = resolve_progress.clone();

// create a new thread for each selector
threads.push(thread::spawn(move || {
if let Some(function) = T::resolve(&selector) {
threads.push(thread::spawn(move || async move {
if let Some(function) = T::resolve(&selector).await {
let mut _resolved_functions =
function_clone.lock().expect("Could not obtain lock on function_clone.");
let mut _resolve_progress =
Expand Down
Loading

0 comments on commit b78691f

Please sign in to comment.