move BlockNumberProvider (#9209)

* move BlockNumberProvider

* Update primitives/runtime/src/traits.rs

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Xiliang Chen
2021-07-07 18:25:00 +12:00
committed by GitHub
parent 9cd04f3559
commit fc1199b6a1
3 changed files with 25 additions and 26 deletions
@@ -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;
@@ -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::*;
@@ -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::*;