Skip to content
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

Format contract id in fn_call event topic #1465

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion soroban-env-host/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,33 @@ impl core::fmt::Display for HostEvent {
match &self.event.body {
ContractEventBody::V0(ceb) => {
write!(f, "topics:[")?;

let mut is_fn_call = false;
for (i, topic) in ceb.topics.iter().enumerate() {
if i != 0 {
write!(f, ", ")?;
}
display_scval(topic, f)?;

// The second topic of the fn_call event is the contract id as ScBytes,
// but we want to display it as a C key instead, so this block
// tries to deduce if the event is the fn_call event.
if i == 1 && is_fn_call {
dmkozh marked this conversation as resolved.
Show resolved Hide resolved
if let ScVal::Bytes(bytes) = topic {
let hash: [u8; 32] = bytes.clone().0.try_into().unwrap();
dmkozh marked this conversation as resolved.
Show resolved Hide resolved
let strkey = stellar_strkey::Contract(hash);
write!(f, "{}", strkey)?
} else {
display_scval(topic, f)?;
}
} else {
display_scval(topic, f)?;
}

if let ScVal::Symbol(first_topic_str) = topic {
dmkozh marked this conversation as resolved.
Show resolved Hide resolved
if first_topic_str.0.as_slice() == "fn_call".as_bytes() {
is_fn_call = true;
}
}
}
write!(f, "], data:")?;
display_scval(&ceb.data, f)
Expand Down
Loading