diff --git a/soroban-env-host/src/events/mod.rs b/soroban-env-host/src/events/mod.rs index fb70e1ac9..b1c880b98 100644 --- a/soroban-env-host/src/events/mod.rs +++ b/soroban-env-host/src/events/mod.rs @@ -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 { + 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)