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

Commit

Permalink
move BlockNumberProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Jun 27, 2021
1 parent eae82ab commit 417f95f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
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 @@ -1460,6 +1460,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` 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

0 comments on commit 417f95f

Please sign in to comment.