Overview
The Event struct represents an event that has reached consensus in the Tashi Vertex network. Events contain one or more transactions that have been agreed upon by a super-majority of peers.
Methods
created_at
Gets the Unix timestamp (in seconds) at which this event was created.
pub fn created_at(&self) -> u64
Returns: Unix timestamp representing when the event was created.
let timestamp = event.created_at();
println!("Event created at: {}", timestamp);
consensus_at
Gets the Unix timestamp (in seconds) at which this event reached consensus.
pub fn consensus_at(&self) -> u64
Returns: Unix timestamp representing when consensus was reached.
let consensus_time = event.consensus_at();
println!("Consensus reached at: {}", consensus_time);
hash
Gets a cryptographically secure hash of this event.
pub fn hash(&self) -> &[u8; 32]
Returns: A 32-byte array containing the event’s hash.
let hash = event.hash();
println!("Event hash: {:x?}", hash);
creator
Gets the public key of the peer that created the event.
pub fn creator(&self) -> &KeyPublic
Returns: Reference to the creator’s public key.
let creator_key = event.creator();
println!("Event created by: {:?}", creator_key);
transaction_count
Gets the number of transactions contained in this event.
pub fn transaction_count(&self) -> usize
Returns: The number of transactions in the event.
let count = event.transaction_count();
println!("Event contains {} transactions", count);
transaction
Gets the transaction at the given index contained in this event.
pub fn transaction(&self, index: usize) -> Option<&[u8]>
The zero-based index of the transaction to retrieve
Returns: Some(&[u8]) containing the transaction data, or None if the index is out of bounds.
if let Some(tx) = event.transaction(0) {
println!("First transaction: {} bytes", tx.len());
}
transactions
Gets an iterator over all transactions contained in this event.
pub fn transactions(&self) -> impl Iterator<Item = &'_ [u8]>
Returns: An iterator that yields byte slices for each transaction. The iterator implements ExactSizeIterator.
for transaction in event.transactions() {
// Process each transaction
println!("Transaction size: {} bytes", transaction.len());
}
whitened_signature
Gets the whitened signature of this event, created by bytewise XORing the signature with the signatures of all unique famous witnesses.
pub fn whitened_signature(&self) -> &[u8]
Returns: A byte slice containing the whitened signature.
The whitened signature is infeasible to predict ahead of time and has relatively high entropy. Since all peers that see the event come to consensus calculate the same result, it makes a good seed for a consensus-driven PRNG (pseudorandom number generator).
let signature = event.whitened_signature();
let seed = u64::from_le_bytes(signature[..8].try_into().unwrap());
println!("PRNG seed from whitened signature: {}", seed);
Complete example
use tashi_vertex::{Engine, Message};
// Receive and process events
while let Some(message) = engine.recv_message().await? {
if let Message::Event(event) = message {
println!("Event {} reached consensus", hex::encode(event.hash()));
println!(" Created at: {}", event.created_at());
println!(" Consensus at: {}", event.consensus_at());
println!(" Creator: {:?}", event.creator());
println!(" Transactions: {}", event.transaction_count());
// Process all transactions
for (i, tx) in event.transactions().enumerate() {
println!(" Transaction {}: {} bytes", i, tx.len());
// Deserialize and handle transaction data
}
// Use whitened signature as consensus-driven randomness
let random_seed = event.whitened_signature();
// Initialize PRNG with the seed
}
}
Transactions are returned as raw byte slices. Your application is responsible for deserializing and validating the transaction data according to your protocol.