referrerpolicy=no-referrer-when-downgrade
pub trait BlockNumberProvider {
    type BlockNumber: Codec + Clone + Ord + Eq + AtLeast32BitUnsigned + TypeInfo + Debug + MaxEncodedLen + Copy;

    // Required method
    fn current_block_number() -> Self::BlockNumber;

    // Provided method
    fn set_block_number(_block: Self::BlockNumber) { ... }
}
Expand description

Get current block number

Required Associated Types§

source

type BlockNumber: Codec + Clone + Ord + Eq + AtLeast32BitUnsigned + TypeInfo + Debug + MaxEncodedLen + Copy

Type of BlockNumber to provide.

Required Methods§

source

fn current_block_number() -> Self::BlockNumber

Returns the current block number.

Provides an abstraction over an arbitrary way of providing the current block number.

In case of using crate sp_runtime with the crate frame-system, it is already implemented for frame_system::Pallet<T: Config> as:

fn current_block_number() -> Self {
    frame_system::Pallet<Config>::block_number()
}

.

Provided Methods§

source

fn set_block_number(_block: Self::BlockNumber)

Utility function only to be used in benchmarking scenarios or tests, to be implemented optionally, else a noop.

It allows for setting the block number that will later be fetched This is useful in case the block number provider is different than System

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl BlockNumberProvider for ()

source§

impl<T> BlockNumberProvider for Pallet<T>
where T: Config,

§

type BlockNumber = <<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number

source§

fn current_block_number() -> <Pallet<T> as BlockNumberProvider>::BlockNumber

source§

fn set_block_number( n: <<<T as Config>::Block as HeaderProvider>::HeaderT as Header>::Number, )

Implementors§