From 55bf41564f605cae3ca4c95ac5d468b1f14447f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Vincent?= <28714795+leovct@users.noreply.github.com> Date: Sat, 3 Aug 2024 07:40:01 +0200 Subject: [PATCH] feat(forge): modify `events` in `forge inspect` to return event signature (#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 events instead of implementing a new cmd --- crates/forge/bin/cmd/inspect.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/forge/bin/cmd/inspect.rs b/crates/forge/bin/cmd/inspect.rs index ac0ed41b3f34..c1c9f7db83e1 100644 --- a/crates/forge/bin/cmd/inspect.rs +++ b/crates/forge/bin/cmd/inspect.rs @@ -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}; @@ -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::>(); let sig = format!("{:x}", er.selector()); @@ -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::>(); + let topic = hex::encode(keccak256(ev.signature())); out.insert( format!("{}({})", ev.name, types.join(",")), - format!("{:?}", ev.signature()).into(), + format!("0x{topic}").into(), ); } }