Crates.io | pallet-timestamp |
lib.rs | pallet-timestamp |
version | 37.0.0 |
source | src |
created_at | 2020-02-27 09:30:49.173056 |
updated_at | 2024-09-26 08:38:04.465247 |
description | FRAME Timestamp Module |
homepage | https://paritytech.github.io/polkadot-sdk/ |
repository | https://github.com/paritytech/polkadot-sdk.git |
max_upload_size | |
id | 213021 |
size | 31,747 |
The Timestamp module provides functionality to get and set the on-chain time.
The Timestamp module allows the validators to set and validate a timestamp with each block.
It uses inherents for timestamp data, which is provided by the block author and validated/verified by other validators. The timestamp can be set only once per block and must be set each block. There could be a constraint on how much time must pass before setting the new timestamp.
NOTE: The Timestamp module is the recommended way to query the on-chain time instead of using an approach based on block numbers. The block number based time measurement can cause issues because of cumulative calculation errors and hence should be avoided.
set
- Sets the current time.get
- Gets the current time for the current block. If this function is called prior to
setting the timestamp, it will return the timestamp of the previous block.MinimumPeriod
- Gets the minimum (and advised) period between blocks for the chain.The following example shows how to use the Timestamp module in your custom module to query the current timestamp.
Import the Timestamp module into your custom module and derive the module configuration trait from the timestamp trait.
use pallet_timestamp::{self as timestamp};
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::config]
pub trait Config: frame_system::Config + timestamp::Config {}
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::weight(0)]
pub fn get_time(origin: OriginFor<T>) -> DispatchResult {
let _sender = ensure_signed(origin)?;
let _now = <timestamp::Pallet<T>>::get();
Ok(())
}
}
}
The Session module uses the Timestamp module for session management.
License: Apache-2.0
Polkadot SDK stable2409