diff --git a/common/src/ether/signatures.rs b/common/src/ether/signatures.rs index b8afee19..7b0b4954 100644 --- a/common/src/ether/signatures.rs +++ b/common/src/ether/signatures.rs @@ -50,14 +50,17 @@ impl ResolveSelector for ResolvedError { 0 => return None, _ => { logger.debug_max(&format!("found cached results for selector: {}", &selector)); - return Some(cached_results) + return Some(cached_results); } } } - // get function possibilities from etherface + // get function possibilities from openchain let signatures = match get_json_from_url( - &format!("https://api.etherface.io/v1/signatures/hash/error/{}/1", &selector), + &format!( + "https://api.openchain.xyz/signature-database/v1/lookup?filter=true&function=0x{}", + &selector + ), 10, ) .await @@ -68,13 +71,12 @@ impl ResolveSelector for ResolvedError { }; // convert the serde value into a vec of possible functions - let results = match signatures.get("items") { - Some(items) => match items.as_array() { - Some(items) => items.to_vec(), - None => return None, - }, - None => return None, - }; + let results = signatures + .get("result")? + .get("function")? + .get(&format!("0x{selector}"))? + .as_array()? + .to_vec(); logger.debug_max(&format!( "found {} possible functions for selector: {}", @@ -86,7 +88,7 @@ impl ResolveSelector for ResolvedError { for signature in results { // get the function text signature and unwrap it into a string - let text_signature = match signature.get("text") { + let text_signature = match signature.get("name") { Some(text_signature) => text_signature.to_string().replace('"', ""), None => continue, }; @@ -133,14 +135,17 @@ impl ResolveSelector for ResolvedLog { 0 => return None, _ => { logger.debug_max(&format!("found cached results for selector: {}", &selector)); - return Some(cached_results) + return Some(cached_results); } } } - // get function possibilities from etherface + // get function possibilities from openchain let signatures = match get_json_from_url( - &format!("https://api.etherface.io/v1/signatures/hash/event/{}/1", &selector), + &format!( + "https://api.openchain.xyz/signature-database/v1/lookup?filter=true&event=0x{}", + &selector + ), 10, ) .await @@ -151,13 +156,12 @@ impl ResolveSelector for ResolvedLog { }; // convert the serde value into a vec of possible functions - let results = match signatures.get("items") { - Some(items) => match items.as_array() { - Some(items) => items.to_vec(), - None => return None, - }, - None => return None, - }; + let results = signatures + .get("result")? + .get("event")? + .get(&format!("0x{selector}"))? + .as_array()? + .to_vec(); logger.debug_max(&format!( "found {} possible functions for selector: {}", @@ -169,7 +173,7 @@ impl ResolveSelector for ResolvedLog { for signature in results { // get the function text signature and unwrap it into a string - let text_signature = match signature.get("text") { + let text_signature = match signature.get("name") { Some(text_signature) => text_signature.to_string().replace('"', ""), None => continue, }; @@ -216,14 +220,17 @@ impl ResolveSelector for ResolvedFunction { 0 => return None, _ => { logger.debug_max(&format!("found cached results for selector: {}", &selector)); - return Some(cached_results) + return Some(cached_results); } } } - // get function possibilities from etherface + // get function possibilities from openchain let signatures = match get_json_from_url( - &format!("https://api.etherface.io/v1/signatures/hash/function/{}/1", &selector), + &format!( + "https://api.openchain.xyz/signature-database/v1/lookup?filter=true&function=0x{}", + &selector + ), 10, ) .await @@ -234,13 +241,12 @@ impl ResolveSelector for ResolvedFunction { }; // convert the serde value into a vec of possible functions - let results = match signatures.get("items") { - Some(items) => match items.as_array() { - Some(items) => items.to_vec(), - None => return None, - }, - None => return None, - }; + let results = signatures + .get("result")? + .get("function")? + .get(&format!("0x{selector}"))? + .as_array()? + .to_vec(); logger.debug_max(&format!( "found {} possible functions for selector: {}", @@ -252,7 +258,7 @@ impl ResolveSelector for ResolvedFunction { for signature in results { // get the function text signature and unwrap it into a string - let text_signature = match signature.get("text") { + let text_signature = match signature.get("name") { Some(text_signature) => text_signature.to_string().replace('"', ""), None => continue, }; @@ -306,6 +312,34 @@ mod tests { score_signature, ResolveSelector, ResolvedError, ResolvedFunction, ResolvedLog, }; + #[tokio::test] + async fn resolve_function_signature_nominal() { + let signature = String::from("095ea7b3"); + delete_cache(&format!("selector.{}", &signature)); + let result = ResolvedFunction::resolve(&signature).await; + assert!(result.is_some()); + assert!(!result.unwrap().is_empty()); + } + + #[tokio::test] + async fn resolve_error_signature_nominal() { + let signature = String::from("30cd7471"); + delete_cache(&format!("selector.{}", &signature)); + let result = ResolvedError::resolve(&signature).await; + assert!(result.is_some()); + assert!(!result.unwrap().is_empty()); + } + + #[tokio::test] + async fn resolve_event_signature_nominal() { + let signature = + String::from("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"); + delete_cache(&format!("selector.{}", &signature)); + let result = ResolvedLog::resolve(&signature).await; + assert!(result.is_some()); + assert!(!result.unwrap().is_empty()); + } + #[tokio::test] async fn resolve_function_signature_should_return_none_when_cached_results_not_found() { let signature = String::from("test_signature_nocache"); diff --git a/common/src/utils/io/logging.rs b/common/src/utils/io/logging.rs index 8d587ecf..f813aadd 100644 --- a/common/src/utils/io/logging.rs +++ b/common/src/utils/io/logging.rs @@ -108,7 +108,7 @@ impl TraceFactory { "{} {} {}", replace_last(prefix, "│ ", " ├─").bold().bright_white(), format!("[{}]", trace.instruction).bold().bright_white(), - trace.message.get(0).expect("Failed to build trace.") + trace.message.first().expect("Failed to build trace.") ); // print the children @@ -136,7 +136,7 @@ impl TraceFactory { println!( "{} emit {}", replace_last(prefix, "│ ", " ├─").bold().bright_white(), - trace.message.get(0).expect("Failed to build trace.") + trace.message.first().expect("Failed to build trace.") ); } TraceCategory::LogUnknown => { @@ -211,7 +211,7 @@ impl TraceFactory { "{} {} create → {}", replace_last(prefix, "│ ", " ├─").bold().bright_white(), format!("[{}]", trace.instruction).bold().bright_white(), - trace.message.get(0).expect("Failed to build trace.") + trace.message.first().expect("Failed to build trace.") ); // print the children diff --git a/core/src/decompile/resolve.rs b/core/src/decompile/resolve.rs index bb06c495..a00fa138 100644 --- a/core/src/decompile/resolve.rs +++ b/core/src/decompile/resolve.rs @@ -21,7 +21,7 @@ pub fn match_parameters( &function .arguments .values() - .map(|(_, types)| types.get(0).unwrap().clone()) + .map(|(_, types)| types.first().unwrap().clone()) .collect::>() .join(",") )); diff --git a/core/src/snapshot/resolve.rs b/core/src/snapshot/resolve.rs index a4c6508d..62863da9 100644 --- a/core/src/snapshot/resolve.rs +++ b/core/src/snapshot/resolve.rs @@ -22,7 +22,7 @@ pub fn match_parameters( &function .arguments .values() - .map(|(_, types)| types.get(0).unwrap().clone()) + .map(|(_, types)| types.first().unwrap().clone()) .collect::>() .join(",") ));