Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

move BlockNumberProvider #9209

Merged
4 commits merged into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ use sp_runtime::{
self, CheckEqual, AtLeast32Bit, Zero, Lookup, LookupError,
SimpleBitOps, Hash, Member, MaybeDisplay, BadOrigin,
MaybeSerializeDeserialize, MaybeMallocSizeOf, StaticLookup, One, Bounded,
Dispatchable, AtLeast32BitUnsigned, Saturating, StoredMapError,
Dispatchable, AtLeast32BitUnsigned, Saturating, StoredMapError, BlockNumberProvider,
},
offchain::storage_lock::BlockNumberProvider,
};

use sp_core::{ChangesTrieConfiguration, storage::well_known_keys};
Expand Down
25 changes: 1 addition & 24 deletions primitives/runtime/src/offchain/storage_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
//! ```

use crate::offchain::storage::{StorageRetrievalError, MutateStorageError, StorageValueRef};
use crate::traits::AtLeast32BitUnsigned;
use crate::traits::BlockNumberProvider;
use codec::{Codec, Decode, Encode};
use sp_core::offchain::{Duration, Timestamp};
use sp_io::offchain;
Expand Down Expand Up @@ -440,29 +440,6 @@ where
}
}

/// Bound for a block number source
/// used with [`BlockAndTime<BlockNumberProvider>`](BlockAndTime).
pub trait BlockNumberProvider {
/// Type of `BlockNumber` to provide.
type BlockNumber: Codec + Clone + Ord + Eq + AtLeast32BitUnsigned;
/// 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` without the crate `frame`
/// system, it is already implemented for
/// `frame_system::Pallet<T: Config>` as:
///
/// ```ignore
/// fn current_block_number() -> Self {
/// frame_system::Pallet<Config>::block_number()
/// }
/// ```
/// .
fn current_block_number() -> Self::BlockNumber;
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
23 changes: 23 additions & 0 deletions primitives/runtime/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,29 @@ pub trait BlockIdTo<Block: self::Block> {
) -> Result<Option<NumberFor<Block>>, Self::Error>;
}

/// Get current block number
pub trait BlockNumberProvider {
/// Type of `BlockNumber` to provide.
type BlockNumber: Codec + Clone + Ord + Eq + AtLeast32BitUnsigned;

/// 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:
///
/// ```ignore
/// fn current_block_number() -> Self {
/// frame_system::Pallet<Config>::block_number()
/// }
/// ```
/// .
fn current_block_number() -> Self::BlockNumber;
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down