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 all commits
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
26 changes: 26 additions & 0 deletions soroban-env-host/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,37 @@ 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, ", ")?;
}

// 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 try_convert_to_hash =
TryInto::<[u8; 32]>::try_into(bytes.0.clone());
if let Ok(contract_id) = try_convert_to_hash {
let strkey = stellar_strkey::Contract(contract_id);
write!(f, "{}", strkey)?;
continue;
}
}
}

display_scval(topic, f)?;

if i == 0 {
if let ScVal::Symbol(first_topic_str) = topic {
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