iota_sdk_types/
events.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2025 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use super::{Address, Identifier, ObjectId, StructTag, TypeTag};
6
7/// Events emitted during the successful execution of a transaction
8///
9/// # BCS
10///
11/// The BCS serialized form for this type is defined by the following ABNF:
12///
13/// ```text
14/// transaction-events = vector event
15/// ```
16#[derive(Eq, PartialEq, Clone, Debug)]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
19#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
20pub struct TransactionEvents(pub Vec<Event>);
21
22/// An event
23///
24/// # BCS
25///
26/// The BCS serialized form for this type is defined by the following ABNF:
27///
28/// ```text
29/// event = object-id identifier address struct-tag bytes
30/// ```
31#[derive(PartialEq, Eq, Debug, Clone)]
32#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
33#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
34#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
35pub struct Event {
36    /// Package id of the top-level function invoked by a MoveCall command which
37    /// triggered this event to be emitted.
38    pub package_id: ObjectId,
39    /// Module name of the top-level function invoked by a MoveCall command
40    /// which triggered this event to be emitted.
41    pub module: Identifier,
42    /// Address of the account that sent the transaction where this event was
43    /// emitted.
44    pub sender: Address,
45    /// The type of the event emitted
46    #[cfg_attr(feature = "serde", serde(rename = "type"))]
47    pub type_: StructTag,
48    /// BCS serialized bytes of the event
49    #[cfg_attr(
50        feature = "serde",
51        serde(with = "crate::_serde::ReadableBase64Encoded")
52    )]
53    #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::Base64"))]
54    pub contents: Vec<u8>,
55}
56
57#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
58#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
59#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
60#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
61pub struct BalanceChange {
62    /// Owner of the balance change
63    pub address: Address,
64    /// Type of the Coin
65    pub coin_type: TypeTag,
66    /// The amount indicate the balance value changes.
67    ///
68    /// A negative amount means spending coin value and positive means receiving
69    /// coin value.
70    #[cfg_attr(feature = "serde", serde(with = "crate::_serde::ReadableDisplay"))]
71    #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::I128"))]
72    pub amount: i128,
73}