-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: separate contract events from diagnostic
- Loading branch information
1 parent
516bf59
commit d4e38f1
Showing
4 changed files
with
74 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,47 @@ | ||
use crate::xdr; | ||
pub mod auth; | ||
pub mod budget; | ||
pub mod contract_event; | ||
pub mod cost; | ||
pub mod diagnostic_event; | ||
pub mod footprint; | ||
pub mod host_event; | ||
|
||
pub use auth::*; | ||
pub use budget::*; | ||
pub use contract_event::*; | ||
pub use cost::*; | ||
pub use diagnostic_event::*; | ||
pub use footprint::*; | ||
pub use host_event::*; | ||
|
||
pub fn events(events: &[xdr::DiagnosticEvent]) { | ||
let (contract_events, other_events): (Vec<_>, Vec<_>) = | ||
events.iter().partition(|e| is_contract_event(e)); | ||
contract_event::contract_events(&contract_events, tracing::Level::INFO); | ||
diagnostic_event::diagnostic_events(&other_events, tracing::Level::DEBUG); | ||
} | ||
|
||
pub fn extract_events(tx_meta: &xdr::TransactionMeta) -> Vec<xdr::DiagnosticEvent> { | ||
match tx_meta { | ||
xdr::TransactionMeta::V3(xdr::TransactionMetaV3 { | ||
soroban_meta: Some(meta), | ||
.. | ||
}) => { | ||
let mut events = meta.diagnostic_events.to_vec(); | ||
// NOTE: we assume there can only be one operation, since we only send one | ||
if meta.events.len() >= 1 { | ||
events.extend(meta.events.iter().map(|e| xdr::DiagnosticEvent { | ||
in_successful_contract_call: true, | ||
event: e.clone(), | ||
})); | ||
}; | ||
events | ||
} | ||
_ => Vec::new(), | ||
} | ||
} | ||
|
||
fn is_contract_event(event: &xdr::DiagnosticEvent) -> bool { | ||
matches!(event.event.type_, xdr::ContractEventType::Contract) | ||
} |
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,19 @@ | ||
pub fn contract_events(events: &[impl std::fmt::Debug], level: tracing::Level) { | ||
for (i, event) in events.iter().enumerate() { | ||
match level { | ||
tracing::Level::TRACE => { | ||
tracing::trace!("{i}: {event:#?}"); | ||
} | ||
tracing::Level::INFO => { | ||
tracing::info!("{i}: {event:#?}"); | ||
} | ||
tracing::Level::ERROR => { | ||
tracing::error!("{i}: {event:#?}"); | ||
} | ||
tracing::Level::DEBUG => { | ||
tracing::debug!("{i}: {event:#?}"); | ||
} | ||
_ => {} | ||
} | ||
} | ||
} |
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,11 +1,19 @@ | ||
pub fn diagnostic_events(events: &[impl std::fmt::Debug], level: tracing::Level) { | ||
for (i, event) in events.iter().enumerate() { | ||
if level == tracing::Level::TRACE { | ||
tracing::trace!("{i}: {event:#?}"); | ||
} else if level == tracing::Level::INFO { | ||
tracing::info!("{i}: {event:#?}"); | ||
} else if level == tracing::Level::ERROR { | ||
tracing::error!("{i}: {event:#?}"); | ||
match level { | ||
tracing::Level::TRACE => { | ||
tracing::trace!("{i}: {event:#?}"); | ||
} | ||
tracing::Level::INFO => { | ||
tracing::info!("{i}: {event:#?}"); | ||
} | ||
tracing::Level::ERROR => { | ||
tracing::error!("{i}: {event:#?}"); | ||
} | ||
tracing::Level::DEBUG => { | ||
tracing::debug!("{i}: {event:#?}"); | ||
} | ||
_ => {} | ||
} | ||
} | ||
} |