Skip to content

Commit

Permalink
feat(forge): modify events in forge inspect to return event signa…
Browse files Browse the repository at this point in the history
…ture (#8561)

* feat(forge): add `eventIdentifiers` to `forge inspect`

* chore: remove quotes from output

* fix: test

* fix: output 32 bytes of the event identifier

* fix: add back `0x` prefix

* chore: modify forge inspect <contract> events instead of implementing a new cmd
  • Loading branch information
leovct authored Aug 3, 2024
1 parent 2cb388d commit 55bf415
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/forge/bin/cmd/inspect.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::Address;
use alloy_primitives::{hex, keccak256, Address};
use clap::Parser;
use comfy_table::{presets::ASCII_MARKDOWN, Table};
use eyre::{Context, Result};
Expand Down Expand Up @@ -133,7 +133,7 @@ impl InspectArgs {
let mut out = serde_json::Map::new();
if let Some(abi) = &artifact.abi {
let abi = &abi;
// Print the signature of all errors
// Print the signature of all errors.
for er in abi.errors.iter().flat_map(|(_, errors)| errors) {
let types = er.inputs.iter().map(|p| p.ty.clone()).collect::<Vec<_>>();
let sig = format!("{:x}", er.selector());
Expand All @@ -150,13 +150,13 @@ impl InspectArgs {
let mut out = serde_json::Map::new();
if let Some(abi) = &artifact.abi {
let abi = &abi;

// print the signature of all events including anonymous
// Print the topic of all events including anonymous.
for ev in abi.events.iter().flat_map(|(_, events)| events) {
let types = ev.inputs.iter().map(|p| p.ty.clone()).collect::<Vec<_>>();
let topic = hex::encode(keccak256(ev.signature()));
out.insert(
format!("{}({})", ev.name, types.join(",")),
format!("{:?}", ev.signature()).into(),
format!("0x{topic}").into(),
);
}
}
Expand Down

0 comments on commit 55bf415

Please sign in to comment.