Module sui::event
Events module. Defines the sui::event::emit
function which
creates and sends a custom MoveEvent as a part of the effects
certificate of the transaction.
Every MoveEvent has the following properties:
- sender
- type signature (
T
) - event data (the value of
T
) - timestamp (local to a node)
- transaction digest
Example:
module my::marketplace {
use sui::event;
/* ... */
struct ItemPurchased has copy, drop {
item_id: ID, buyer: address
}
entry fun buy(/* .... */) {
/* ... */
event::emit(ItemPurchased { item_id: ..., buyer: .... })
}
}
use std::address;
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::type_name;
use std::vector;
use sui::accumulator;
use sui::address;
use sui::dynamic_field;
use sui::hex;
use sui::object;
use sui::party;
use sui::transfer;
use sui::tx_context;
use sui::vec_map;
Struct EventStreamHead
public struct EventStreamHead has store
Fields
-
mmr: vector<vector<u8>>
- Merkle Mountain Range of all events in the stream.
-
checkpoint_seq: u64
- Checkpoint sequence number at which the event stream was written.
-
num_events: u64
- Number of events in the stream.
Function emit
Emit a custom Move event, sending the data offchain.
Used for creating custom indexes and tracking onchain activity in a way that suits a specific application the most.
The type T
is the main way to index the event, and can contain
phantom parameters, eg emit(MyEvent<phantom T>)
.
public fun emit<T: copy, drop>(event: T)
Function emit_authenticated
Emits a custom Move event which can be authenticated by a light client.
This method emits the authenticated event to the event stream for the Move package that
defines the event type T
.
Only the package that defines the type T
can emit authenticated events to this stream.
public fun emit_authenticated<T: copy, drop>(event: T)
Implementation
public fun emit_authenticated<T: copy + drop>(event: T) {
let stream_id = type_name::original_id<T>();
let accumulator_addr = accumulator::accumulator_address<EventStreamHead>(stream_id);
emit_authenticated_impl<EventStreamHead, T>(accumulator_addr, stream_id, event);
}
Function emit_authenticated_impl
fun emit_authenticated_impl<StreamHeadT, T: copy, drop>(accumulator_id: address, stream: address, event: T)
Implementation
native fun emit_authenticated_impl<StreamHeadT, T: copy + drop>(
accumulator_id: address,
stream: address,
event: T,
);