-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate out different events to only log user defined ones by …
…default (#1394) * feat: separate contract events from diagnostic * feat: separate out log events * fix: fmt * fix: clippy
- Loading branch information
1 parent
aba5bdd
commit 00826cf
Showing
5 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
use crate::xdr; | ||
pub mod auth; | ||
pub mod budget; | ||
pub mod cost; | ||
pub mod diagnostic_event; | ||
pub mod event; | ||
pub mod footprint; | ||
pub mod host_event; | ||
|
||
pub use auth::*; | ||
pub use budget::*; | ||
pub use cost::*; | ||
pub use diagnostic_event::*; | ||
pub use event::*; | ||
pub use footprint::*; | ||
pub use host_event::*; | ||
|
||
pub fn extract_events(tx_meta: &xdr::TransactionMeta) -> Vec<xdr::DiagnosticEvent> { | ||
match tx_meta { | ||
xdr::TransactionMeta::V3(xdr::TransactionMetaV3 { | ||
soroban_meta: Some(meta), | ||
.. | ||
}) => meta.diagnostic_events.to_vec(), | ||
_ => Vec::new(), | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use tracing::{debug, info, span, Level}; | ||
|
||
use crate::xdr; | ||
|
||
pub fn events(events: &[xdr::DiagnosticEvent]) { | ||
for (i, event) in events.iter().enumerate() { | ||
let span = if is_contract_event(event) { | ||
span!(Level::INFO, "contract_event") | ||
} else if is_log_event(event) { | ||
span!(Level::INFO, "log_event") | ||
} else { | ||
span!(Level::DEBUG, "diagnostic_event") | ||
}; | ||
|
||
let _enter = span.enter(); | ||
|
||
if span.metadata().unwrap().level() == &Level::INFO { | ||
info!("{i}: {event:#?}"); | ||
} else { | ||
debug!("{i}: {event:#?}"); | ||
} | ||
} | ||
} | ||
|
||
fn is_contract_event(event: &xdr::DiagnosticEvent) -> bool { | ||
matches!(event.event.type_, xdr::ContractEventType::Contract) | ||
} | ||
|
||
fn is_log_event(event: &xdr::DiagnosticEvent) -> bool { | ||
match &event.event.body { | ||
xdr::ContractEventBody::V0(xdr::ContractEventV0 { topics, .. }) | ||
if topics.len() == 1 | ||
&& matches!(event.event.type_, xdr::ContractEventType::Diagnostic) => | ||
{ | ||
topics[0] == xdr::ScVal::Symbol(str_to_sc_symbol("log")) | ||
} | ||
xdr::ContractEventBody::V0(_) => false, | ||
} | ||
} | ||
|
||
fn str_to_sc_symbol(s: &str) -> xdr::ScSymbol { | ||
let inner: xdr::StringM<32> = s.try_into().unwrap(); | ||
xdr::ScSymbol(inner) | ||
} |