Skip to content

Latest commit

 

History

History
194 lines (89 loc) · 5.67 KB

timestamp.md

File metadata and controls

194 lines (89 loc) · 5.67 KB

Module 0x3::timestamp

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

A object holding the current Unix time in milliseconds

struct Timestamp has key

Constants

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;

Function genesis_init

public(friend) fun genesis_init(ctx: &mut context::Context, _genesis_account: &signer, initial_time_milliseconds: u64)

Function update_global_time

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)

Function try_update_global_time

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

Function timestamp

Function milliseconds

public fun milliseconds(self: &timestamp::Timestamp): u64

Function seconds

public fun seconds(self: &timestamp::Timestamp): u64

Function now_milliseconds

Gets the current time in milliseconds.

public fun now_milliseconds(ctx: &context::Context): u64

Function now_seconds

Gets the current time in seconds.

public fun now_seconds(ctx: &context::Context): u64

Function seconds_to_milliseconds

public fun seconds_to_milliseconds(seconds: u64): u64

Function fast_forward_seconds_for_local

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)