Time

Time is a structure used to mark the precise moment an event occurs on a universe chain.

In the blockchain context, events are logged within transactions, which are grouped into blocks. Each transaction can contain multiple log entries, allowing for detailed tracking of when and where events occur.

The Time structure is conceptually similar to a tuple of (block_num, txn_index, log_index).

Representation

#![allow(unused)]
fn main() {
pub struct Time {
    block: u64,
    second: u32,
    third: u32,
}
}

Fields of Time

  • block: The block number on the universe chain where the event occurred.
  • second: The index of the transaction within that block where the event is logged.
  • third: The index of the log entry within the transaction that records the event.

Encoding

The Time structure can be encoded into a u128 value for compact representation:

#![allow(unused)]
fn main() {
let encoded = (u128(time.block) << 64)
            | (u128(time.second) << 32)
            | u128(time.third);
}

Written Format

Time is commonly written in the format block:second:third. For example:

  • 0:0:0 - The singularity, representing the start of the universe.
  • 123456:0:0 - An event that occurred at block 123456, transaction 0, log entry 0.
  • 122456:7:8 - An event that occurred at block 122456, transaction 7, log entry 8.