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
- TickTransaction: update the timestamp via the time offset in the TickTransaction(TODO)
- Resource
Timestamp
- Constants
- Function
genesis_init
- 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_for_local
use 0x2::context;
use 0x2::object;
use 0x2::signer;
use 0x3::chain_id;
use 0x3::core_addresses;
A object holding the current Unix time in milliseconds
struct Timestamp has key
const ErrorNotGenesisAddress: u64 = 2;
An invalid timestamp was provided
const ErrorInvalidTimestamp: u64 = 1;
Conversion factor between seconds and milliseconds
const MILLI_CONVERSION_FACTOR: u64 = 1000;
public(friend) fun genesis_init(ctx: &mut context::Context, _genesis_account: &signer, initial_time_milliseconds: u64)
Updates the global clock time, if the new time is smaller than the current time, aborts.
public(friend) fun update_global_time(ctx: &mut context::Context, 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(ctx: &mut context::Context, genesis_account: &signer, timestamp_milliseconds: u64): bool
public fun timestamp(ctx: &context::Context): ×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(ctx: &context::Context): u64
Gets the current time in seconds.
public fun now_seconds(ctx: &context::Context): u64
public fun seconds_to_milliseconds(seconds: u64): u64
Fast forwards the clock by the given number of seconds, but only if the chain is in local mode.
public entry fun fast_forward_seconds_for_local(ctx: &mut context::Context, timestamp_seconds: u64)