Skip to main content

thruput_xdr/
event.rs

1// -*-Rust-*-
2// Generated Code: DO NOT CHECK IN
3
4// Generated from xdrc commit: 6ab835b07c234abb4b0b50b61d687904727a4f32
5
6#![allow(non_camel_case_types)]
7#![allow(non_snake_case)]
8#![allow(non_upper_case_globals)]
9#![allow(unused_imports)]
10#![allow(dead_code)]
11#![allow(unused_variables)]
12#![allow(clippy::unnecessary_cast)]
13
14use crate::*;
15use core::option::Option;
16use core::ops::{Deref, DerefMut};
17
18#[cfg(feature = "std")]
19use std::io::{Read, Write};
20#[cfg(feature = "xdrs")]
21use xdrs::*;
22
23
24#[cfg(feature = "serde")]
25use ::serde::{{Serialize, Deserialize}};
26
27
28
29// clang-format on
30
31// The event format puts the first N * 32 bytes of the data
32// as the topics.
33
34/// Maximum length in bytes for a serialized event.
35/// Events exceeding this length will be rejected by the LogEvent syscall.
36// 
37pub const kMaxEventLength : u32 = 1024;
38
39/// Maximum number of events a single transaction may emit.
40/// This keeps a single TxEventLog well below the RPC transport message limit.
41// 
42pub const kMaxEventsPerTransaction : u32 = 1000;
43
44/// Maximum number of topics that can be attached to an event.
45/// Topics enable efficient indexing and filtering of events.
46pub const kMaxTopics : u32 = 3;
47
48/// A 32-byte topic used for event indexing.
49/// Topics are prepended to the serialized event data. The num_topics field
50/// indicates how many of the leading 32-byte chunks are topics (up to kMaxTopics).
51/// Downstream indexers use topics to efficiently filter events without deserializing.
52// 
53#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
54#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
55#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
56#[derive(Default, Copy)]
57#[repr(transparent)]
58#[cfg_attr(feature = "serde", serde(transparent))]
59pub struct Topic {
60    #[cfg_attr(feature = "serde", serde(with = "xdr_common::serde_hex"))]
61    inner: [u8; 32 as usize],
62}
63impl From<[u8; 32 as usize]> for Topic {
64    fn from(_inner: [u8; 32 as usize]) -> Self {
65        Self { inner: _inner }
66    }
67}
68impl Topic {
69    pub fn into_inner(self) -> [u8; 32 as usize] {
70        self.inner
71    }
72    pub const fn new(_inner: [u8; 32 as usize]) -> Self {
73        Self { inner: _inner }
74    }
75}
76
77impl Deref for Topic {
78    type Target = [u8; 32 as usize];
79
80    fn deref(&self) -> &Self::Target {
81        &self.inner
82    }
83}
84impl DerefMut for Topic {
85    fn deref_mut(&mut self) -> &mut Self::Target {
86        &mut self.inner
87    }
88}
89impl AsRef<[u8]> for Topic {
90    fn as_ref(&self) -> &[u8] {
91        self.deref().as_slice()
92    }
93}
94impl<'a> From<&'a [u8; 32]> for &'a Topic {
95    fn from(arr: &[u8; 32]) -> Self {
96        let ptr = arr as *const [u8; 32] as *const Topic;
97        unsafe { &*ptr }
98    }
99}
100#[cfg(feature = "xdrs")]
101impl<'r: 'a, 'a> ReadXDR<'r> for &'a Topic {
102  fn read_xdr<R: xdrs::Reader<'r>>(r: &mut R) -> xdrs::ReadResult<Self> {
103      let arr: &[u8; 32] = xdrs::read_xdr(r)?;
104      let val = Self::from(arr);
105      Ok(val)
106  }
107}
108
109#[cfg(feature = "schema")]
110impl schemars::JsonSchema for Topic {
111    fn schema_name() -> ::std::borrow::Cow<'static, str> {
112        "Topic".into()
113    }
114    fn json_schema(_gen: &mut schemars::SchemaGenerator) -> schemars::Schema {
115        schemars::json_schema!({
116            "type": "string",
117            "contentEncoding": "hex",
118            "contentMediaType": "application/binary",
119            "minLength": 64,
120            "maxLength": 64
121        })
122    }
123}
124
125
126
127/// An event emitted by a contract during transaction execution.
128/// Events are logged via the LogEvent syscall and stored in the transaction's event log.
129///
130/// The serialized_event field contains topic0 || topic1 || topic2 || data, where
131/// the number of topic fields depends on num_topics.
132/// This structure is the minimum unit forwarded to downstream indexing systems.
133#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
134#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
135#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
136#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
137#[repr(C)]
138pub struct TxEmittedEvent {
139    pub contract_address: ContractAddress,
140    // <= kMaxTopics
141    pub num_topics: u32,
142    pub serialized_event: BytesM<kMaxEventLength>,
143}
144
145/// Event log for a single transaction, stored in the merkle-patricia trie.
146/// The trie leaf is encoded canonically as follows:
147///
148/// - key: the leading TransactionHash from XDR(TxEventLog);
149/// - value: the remainder of XDR(TxEventLog), followed by
150///   XDR(NondeterministicProposalData).
151///
152/// The appended proposal data binds the nondeterministic inputs used during
153/// execution to the events root. Signature-wrapper bytes are deliberately not
154/// included: TransactionHash identifies the inner Transaction independently
155/// of its signatures, so validators with different valid wrappers compute the
156/// same root.
157///
158/// That key is the identity of the transaction the submitter signed, not of
159/// the [`ProposedTransaction`] the proposer assembled from it, so a
160/// submitter can compute it before submission and use it to find its own
161/// events. See [`TransactionHash`].
162///
163/// `root_output` carries the InvocationFrameOutput of the transaction's
164/// root frame: the Return buffer on success, the Abort buffer on a
165/// deterministic revert, or the Fault variant when no root output was
166/// produced (e.g., non-deterministic failure).  Downstream indexers and
167/// the receipt-read paths surface this as `return_data`/`abort_data`.
168///
169/// `gas_consumed` is the gas the whole transaction consumed: the root frame,
170/// every frame it invoked, and the pre-execution validation of attached
171/// contracts. On an out-of-gas fault it is the transaction's gas limit. It
172/// is part of the leaf, so the events root commits to it and every
173/// validator's re-execution must reproduce it.
174#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
175#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
176#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
177#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
178#[repr(C)]
179pub struct TxEventLog {
180    // sha256(Transaction)
181    pub tx_hash: TransactionHash,
182    pub exec_result: ExecResult,
183    pub root_output: InvocationFrameOutput,
184    pub gas_consumed: GasAmount,
185    pub events: VecM<TxEmittedEvent, kMaxEventsPerTransaction>,
186}
187
188/// Complete identification of a unique event within the blockchain.
189/// This structure is not constructed during the main transaction workflow; instead,
190/// it may be produced by downstream systems (indexers, APIs) that cross-reference
191/// events across transactions and blocks.
192/// The combination of tx_hash and sequence_number uniquely identifies
193/// any event. The sequence_number distinguishes multiple events emitted by
194/// the same transaction.
195#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
196#[cfg_attr(feature = "xdrs", derive(ReadXDR, WriteXDR, ConstXDRSize))]
197#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
198#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
199#[repr(C)]
200pub struct IdentifiedEvent {
201    // sha256(Transaction)
202    pub tx_hash: TransactionHash,
203    pub block_height: BlockHeight,
204    // uniquifies the event
205    pub sequence_number: u32,
206    pub emitted_event: TxEmittedEvent,
207}
208
209
210//
211// XDR internals below this point
212//
213
214