Module sui::clock
APIs for accessing time from move calls, via the
Clockuse std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
use sui::address;
use sui::hex;
use sui::object;
use sui::party;
use sui::transfer;
use sui::tx_context;
use sui::vec_map;
Struct Clock
Singleton shared object that exposes time to Move calls. This object is found at address 0x6, and can only be read (accessed via an immutable reference) by entry functions.
Entry Functions that attempt to accept
ClockClockpublic struct Clock has key
Click to open
Fields
- 
id: sui::object::UID
- 
timestamp_ms: u64
- 
 The clock's timestamp, which is set automatically by a
 system transaction every time consensus commits a
 schedule, or by sui::clock::increment_for_testingduring testing.
Constants
Sender is not @0x0 the system address.
const ENotSystemAddress: u64 = 0;
Function timestamp_ms
The
clockpublic fun timestamp_ms(clock: &sui::clock::Clock): u64
Click to open
Implementation
public fun timestamp_ms(clock: &Clock): u64 {
    clock.timestamp_ms
}
Function create
Create and share the singleton Clock -- this function is called exactly once, during genesis.
fun create(ctx: &sui::tx_context::TxContext)
Click to open
Implementation
fun create(ctx: &TxContext) {
    assert!(ctx.sender() == @0x0, ENotSystemAddress);
    transfer::share_object(Clock {
        id: object::clock(),
        // Initialised to zero, but set to a real timestamp by a
        // system transaction before it can be witnessed by a move
        // call.
        timestamp_ms: 0,
    })
}
Function consensus_commit_prologue
fun consensus_commit_prologue(clock: &mut sui::clock::Clock, timestamp_ms: u64, ctx: &sui::tx_context::TxContext)
Click to open
Implementation
fun consensus_commit_prologue(clock: &mut Clock, timestamp_ms: u64, ctx: &TxContext) {
    // Validator will make a special system call with sender set as 0x0.
    assert!(ctx.sender() == @0x0, ENotSystemAddress);
    clock.timestamp_ms = timestamp_ms
}