Skip to content

Commit

Permalink
feat: move to revert_decoder level
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiweixie committed Aug 15, 2024
1 parent 86f344a commit a5e61d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 11 additions & 7 deletions crates/evm/core/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ impl RevertDecoder {
return Some(std::str::from_utf8(err).unwrap().to_string());
}

// Generic custom error.
Some(format!(
"custom error {}:{}",
hex::encode(selector),
std::str::from_utf8(data).map_or_else(|_| trimmed_hex(data), String::from)
))
}

pub fn may_decode_using_open_chain(&self, err: &[u8]) -> Option<String> {
let (selector, data) = err.split_at(SELECTOR_LEN);
// try from https://openchain.xyz
if let Some(client) = self.open_chain_client.clone() {
if let Ok(handle) = Handle::try_current() {
Expand Down Expand Up @@ -214,13 +224,7 @@ impl RevertDecoder {
}
}
}

// Generic custom error.
Some(format!(
"custom error {}:{}",
hex::encode(selector),
std::str::from_utf8(data).map_or_else(|_| trimmed_hex(data), String::from)
))
None
}
}

Expand Down
10 changes: 9 additions & 1 deletion crates/evm/traces/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,15 @@ impl CallTraceDecoder {

/// The default decoded return data for a trace.
fn default_return_data(&self, trace: &CallTrace) -> Option<String> {
(!trace.success).then(|| self.revert_decoder.decode(&trace.output, Some(trace.status)))
(!trace.success).then(|| {
let err_str = self.revert_decoder.decode(&trace.output, Some(trace.status));
if err_str.contains("custom error") {
if let Some(err) = self.revert_decoder.may_decode_using_open_chain(&trace.output) {
return err;
}
}
err_str
})
}

/// Decodes an event.
Expand Down

0 comments on commit a5e61d9

Please sign in to comment.