This module keeps a global wall clock that stores the current Unix time in milliseconds. It interacts with the other modules in the following ways:
- genesis: to initialize the timestamp
- L1 block: update the timestamp via L1s block header timestamp
- L2 transactions: update the timestamp via L2 transaction's timestamp
- Resource
Timestamp
- Constants
- Function
update_global_time
- Function
try_update_global_time
- Function
timestamp
- Function
milliseconds
- Function
seconds
- Function
now_milliseconds
- Function
now_seconds
- Function
seconds_to_milliseconds
- Function
fast_forward_seconds_by_system
use 0x2::core_addresses;
use 0x2::object;
use 0x2::signer;
A object holding the current Unix time in milliseconds Timestamp is initialized before genesis, so we do not need to initialize it in the genesis module.
struct Timestamp has key
An invalid timestamp was provided
const ErrorInvalidTimestamp: u64 = 1;
const ErrorNotGenesisAddress: u64 = 2;
Conversion factor between seconds and milliseconds
const MILLI_CONVERSION_FACTOR: u64 = 1000;
Updates the global clock time, if the new time is smaller than the current time, aborts.
public(friend) fun update_global_time(timestamp_milliseconds: u64)
Tries to update the global clock time, if the new time is smaller than the current time, ignores the update, and returns false. Only the framework genesis account can update the global clock time.
public fun try_update_global_time(genesis_account: &signer, timestamp_milliseconds: u64): bool
public fun timestamp(): ×tamp::Timestamp
public fun milliseconds(self: ×tamp::Timestamp): u64
public fun seconds(self: ×tamp::Timestamp): u64
Gets the current time in milliseconds.
public fun now_milliseconds(): u64
Gets the current time in seconds.
public fun now_seconds(): u64
public fun seconds_to_milliseconds(seconds: u64): u64
public fun fast_forward_seconds_by_system(genesis_account: &signer, timestamp_seconds: u64)