-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cast
): decode-error
with sig, local cache and openchain api
#9428
Merged
+124
−12
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7ec0aa1
feat(cast): Add custom error decoding support
grandizzy 0c1d2fd
Merge branch 'master' into cast-cust-err
grandizzy d349c9a
Review changes
grandizzy 35f5dc1
Changes after review: decode with Openchain too, add test
grandizzy 5610c48
Merge remote-tracking branch 'origin' into cast-cust-err
grandizzy 1834215
Review changes: nit, handle incomplete selectors
grandizzy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#[macro_use] | ||
extern crate tracing; | ||
|
||
use alloy_dyn_abi::{DynSolValue, EventExt}; | ||
use alloy_dyn_abi::{DynSolValue, ErrorExt, EventExt}; | ||
use alloy_primitives::{eip191_hash_message, hex, keccak256, Address, B256}; | ||
use alloy_provider::Provider; | ||
use alloy_rpc_types::{BlockId, BlockNumberOrTag::Latest}; | ||
|
@@ -11,7 +11,7 @@ use clap_complete::generate; | |
use eyre::Result; | ||
use foundry_cli::{handler, utils}; | ||
use foundry_common::{ | ||
abi::get_event, | ||
abi::{get_error, get_event}, | ||
ens::{namehash, ProviderEnsExt}, | ||
fmt::{format_tokens, format_tokens_raw, format_uint_exp}, | ||
fs, | ||
|
@@ -30,6 +30,7 @@ pub mod cmd; | |
pub mod tx; | ||
|
||
use args::{Cast as CastArgs, CastSubcommand, ToBaseArgs}; | ||
use cast::traces::identifier::SignaturesIdentifier; | ||
|
||
#[macro_use] | ||
extern crate foundry_common; | ||
|
@@ -216,6 +217,28 @@ async fn main_args(args: CastArgs) -> Result<()> { | |
let decoded_event = event.decode_log_parts(None, &hex::decode(data)?, false)?; | ||
print_tokens(&decoded_event.body); | ||
} | ||
CastSubcommand::DecodeError { sig, data } => { | ||
let error = if let Some(err_sig) = sig { | ||
get_error(err_sig.as_str())? | ||
} else { | ||
let data = data.strip_prefix("0x").unwrap_or(data.as_str()); | ||
let selector = &data[..8]; | ||
let err = SignaturesIdentifier::new(Config::foundry_cache_dir(), false)? | ||
.write() | ||
.await | ||
.identify_error(&hex::decode(selector)?) | ||
.await; | ||
if err.is_none() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let Some ... else There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed in 1834215 |
||
eyre::bail!("No matching error signature found for selector `{selector}`") | ||
} | ||
|
||
let error = err.unwrap(); | ||
let _ = sh_println!("{}", error.signature()); | ||
error | ||
}; | ||
let decoded_error = error.decode_error(&hex::decode(data)?)?; | ||
print_tokens(&decoded_error.body); | ||
} | ||
CastSubcommand::Interface(cmd) => cmd.run().await?, | ||
CastSubcommand::CreationCode(cmd) => cmd.run().await?, | ||
CastSubcommand::ConstructorArgs(cmd) => cmd.run().await?, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this optional for decode event too? followup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, will follow up with a PR, have to figure out how to parse with topics