rialo_rex_processor_interface/event.rs
1// Copyright (c) Subzero Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Events emitted by the REX Processor program.
5//!
6//! This module defines the events that are emitted when REX reports are stored.
7//! Subscribers can use these events to react to REX data updates without relying
8//! on aggregator programs.
9
10use rialo_events_core::derive::RialoEvent;
11use rialo_types::RexId;
12use serde::Serialize;
13
14/// Event emitted when an REX report is stored.
15///
16/// This event is emitted after a report is successfully written to the report PDA.
17/// Subscribers can listen to this event to react to REX data updates.
18///
19/// # Topic Format
20///
21/// The event uses a parameterized topic with the rex_id as the dynamic parameter.
22/// Topic format: `rialo_rex_processor_interface::event::RexReportEvent::{rex_id}`
23/// where `rex_id` is in the string format `{nonce}:{creator}`.
24///
25/// # Example Usage
26///
27/// Subscribers can:
28/// 1. Create an event instance: `let event = RexReportEvent::new(rex_id);`
29/// 2. Get the instance topic: `let topic = event.instance_topic();`
30/// 3. Subscribe to the topic for a specific REX request
31/// 4. Use `derive_report_address()` to get the report PDA from the rex_id
32/// 5. Read the full `RexReport` data from the PDA
33#[derive(Debug, Default, Clone, Serialize, RialoEvent)]
34pub struct RexReportEvent {
35 /// The REX ID - marked with #\[topic] to create instance-specific topics
36 #[topic]
37 pub rex_id: RexId,
38}
39
40impl RexReportEvent {
41 /// Creates a new `RexReportEvent`.
42 ///
43 /// # Arguments
44 ///
45 /// * `rex_id` - The REX ID
46 pub fn new(rex_id: RexId) -> Self {
47 Self { rex_id }
48 }
49}