diff --git a/common/src/ether/signatures.rs b/common/src/ether/signatures.rs index 7c5cbed7..82e1c5f5 100644 --- a/common/src/ether/signatures.rs +++ b/common/src/ether/signatures.rs @@ -40,6 +40,12 @@ pub trait ResolveSelector { #[async_trait] impl ResolveSelector for ResolvedError { async fn resolve(selector: &str) -> Option> { + // normalize selector + let selector = match selector.strip_prefix("0x") { + Some(selector) => selector, + None => selector, + }; + debug_max!("resolving error selector {}", &selector); // get cached results @@ -119,6 +125,12 @@ impl ResolveSelector for ResolvedError { #[async_trait] impl ResolveSelector for ResolvedLog { async fn resolve(selector: &str) -> Option> { + // normalize selector + let selector = match selector.strip_prefix("0x") { + Some(selector) => selector, + None => selector, + }; + debug_max!("resolving event selector {}", &selector); // get cached results @@ -198,6 +210,12 @@ impl ResolveSelector for ResolvedLog { #[async_trait] impl ResolveSelector for ResolvedFunction { async fn resolve(selector: &str) -> Option> { + // normalize selector + let selector = match selector.strip_prefix("0x") { + Some(selector) => selector, + None => selector, + }; + debug_max!("resolving event selector {}", &selector); // get cached results diff --git a/core/src/inspect/core/contracts.rs b/core/src/inspect/core/contracts.rs index c487bd71..58cd8b84 100644 --- a/core/src/inspect/core/contracts.rs +++ b/core/src/inspect/core/contracts.rs @@ -12,6 +12,7 @@ pub struct Contracts { transpose_api_key: Option, } +#[allow(dead_code)] impl Contracts { pub fn new(args: &InspectArgs) -> Self { Self { contracts: HashMap::new(), transpose_api_key: args.transpose_api_key.clone() } diff --git a/core/src/inspect/core/logs.rs b/core/src/inspect/core/logs.rs index dcf6eafb..8124f33c 100644 --- a/core/src/inspect/core/logs.rs +++ b/core/src/inspect/core/logs.rs @@ -2,10 +2,15 @@ use async_convert::{async_trait, TryFrom}; use ethers::types::{Address, Bytes, Log, H256, U256, U64}; +use heimdall_common::{ + debug_max, + ether::signatures::{ResolveSelector, ResolvedLog}, + utils::hex::ToLowerHex, +}; use serde::{Deserialize, Serialize}; /// Represents a decoded log -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, PartialOrd)] +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct DecodedLog { /// H160. the contract that emitted the log pub address: Address, @@ -19,6 +24,11 @@ pub struct DecodedLog { /// Data pub data: Bytes, + /// Resolved Event + #[serde(rename = "resolvedEvent")] + #[serde(skip_serializing_if = "Option::is_none")] + pub resolved_event: Option, + /// Block Hash #[serde(rename = "blockHash")] #[serde(skip_serializing_if = "Option::is_none")] @@ -66,6 +76,22 @@ impl TryFrom for DecodedLog { type Error = crate::error::Error; async fn try_from(value: Log) -> Result { + let signature = match value.topics.first() { + Some(topic) => { + let topic = topic.to_lower_hex(); + Some(topic) + } + None => None, + }; + + let resolved_logs = match signature { + Some(signature) => { + debug_max!("resolving signature: {}", signature.to_string().to_lowercase()); + ResolvedLog::resolve(&signature).await.unwrap_or(Vec::new()) + } + None => Vec::new(), + }; + Ok(Self { address: value.address, topics: value.topics, @@ -78,6 +104,7 @@ impl TryFrom for DecodedLog { transaction_log_index: value.transaction_log_index, log_type: value.log_type, removed: value.removed, + resolved_event: resolved_logs.first().cloned(), }) } }