Skip to content

Latest commit

 

History

History
180 lines (82 loc) · 4.94 KB

timestamp.md

File metadata and controls

180 lines (82 loc) · 4.94 KB

Module 0x2::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
  • L2 transactions: update the timestamp via L2 transaction's timestamp

Resource Timestamp

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

Constants

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;

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(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(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(): u64

Function now_seconds

Gets the current time in seconds.

public fun now_seconds(): u64

Function seconds_to_milliseconds

public fun seconds_to_milliseconds(seconds: u64): u64

Function fast_forward_seconds_by_system

public fun fast_forward_seconds_by_system(genesis_account: &signer, timestamp_seconds: u64)