forked from Vero-protocol/vero-core-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_utils.rs
More file actions
26 lines (22 loc) · 1.02 KB
/
Copy pathevent_utils.rs
File metadata and controls
26 lines (22 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//! Event publishing helpers.
use crate::event_struct::CompactEvent;
use soroban_sdk::{symbol_short, BytesN, Env, Map, Symbol, Val};
/// Publish a compact, structured event.
///
/// `flags` is built by OR-ing a `MOD_*` constant with an `ACT_*` constant from
/// [`crate::event_struct`]. The event topic is intentionally stable so the
/// off-chain bridge can consume every engine-core event with one subscription.
pub fn publish_event(env: &Env, flags: u32, value: u64, hash: BytesN<32>) {
let event = CompactEvent { flags, value, hash };
env.events()
.publish((symbol_short!("EVENT"), symbol_short!("LOG")), event);
}
/// Return the canonical all-zero hash used when an event has no hash payload.
pub fn zero_hash(env: &Env) -> BytesN<32> {
BytesN::from_array(env, &[0u8; 32])
}
/// Compatibility function for legacy events.
pub fn publish_event_legacy(env: &Env, event_type: BytesN<32>, action: BytesN<32>, payload: Map<Symbol, Val>) {
// legacy publish
env.events().publish((event_type, action), payload);
}