forked from Vero-protocol/vero-core-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent_struct.rs
More file actions
65 lines (59 loc) · 2.65 KB
/
Copy pathevent_struct.rs
File metadata and controls
65 lines (59 loc) · 2.65 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Compact event encoding for audit-ready Soroban logs.
//!
//! `CompactEvent` keeps on-chain events small and deterministic while still
//! giving the relayer/dashboard enough data to reconstruct the control-plane
//! audit trail. `flags` packs a module id and an action id; `value` carries the
//! primary numeric datum; `hash` carries a state/action hash when present.
//!
//! Replaces the previous fat `Event { event_type: BytesN<32>, action: BytesN<32>, payload: Map }`
//! which wasted 64 bytes of zeroed data and allocated an expensive `Map<Symbol,Val>` on every call.
//!
//! ## Encoding
//!
//! `flags` packs module id (bits 0–7) and action id (bits 8–15) into a single `u32`:
//!
//! ```text
//! bits 0– 7 : module id (MOD_*)
//! bits 8–15 : action id (ACT_*)
//! bits 16–31 : reserved for future use / version
//! ```
//!
//! `value` carries a u64 primary value (sequence, proposal id, amount, …).
//! `hash` carries an optional 32-byte hash (state_hash, action_hash). Zero if unused.
use soroban_sdk::{contracttype, BytesN};
// ── module ids (bits 0..=7) ─────────────────────────────────────────────────
pub const MOD_AUDIT: u32 = 0x01;
pub const MOD_GOV: u32 = 0x02;
pub const MOD_TREASURY: u32 = 0x03;
pub const MOD_CB: u32 = 0x04;
pub const MOD_BURN: u32 = 0x05;
pub const MOD_RECOVERY: u32 = 0x06;
pub const MOD_FEE: u32 = 0x07;
pub const MOD_CORE: u32 = 0x08;
pub const MOD_UPGRADE: u32 = 0x09;
// ── action ids (bits 8..=15) ────────────────────────────────────────────────
pub const ACT_COMMIT: u32 = 0x01 << 8;
pub const ACT_SNAPSHOT: u32 = 0x02 << 8;
pub const ACT_PROPOSE: u32 = 0x03 << 8;
pub const ACT_APPROVE: u32 = 0x04 << 8;
pub const ACT_EXECUTE: u32 = 0x05 << 8;
pub const ACT_TRIP: u32 = 0x06 << 8;
pub const ACT_RESET: u32 = 0x07 << 8;
pub const ACT_BURN_SAFE: u32 = 0x08 << 8;
pub const ACT_REQUEST: u32 = 0x09 << 8;
pub const ACT_TRIGGERED: u32 = 0x0A << 8;
pub const ACT_FEE: u32 = 0x0B << 8;
pub const ACT_INIT: u32 = 0x0C << 8;
pub const ACT_TRANSITION: u32 = 0x0D << 8;
pub const ACT_UPGRADE: u32 = 0x0E << 8;
/// Compact event struct emitted by all engine-core modules.
#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct CompactEvent {
/// Packed module + action bitmask. Use `MOD_* | ACT_*` constants.
pub flags: u32,
/// Primary numeric value — sequence number, proposal id, amount, etc.
pub value: u64,
/// Optional 32-byte hash (state_hash, action_hash). All-zero when unused.
pub hash: BytesN<32>,
}