From fc1199b6a19c056da7fa0e23b3bb002c6c1a2025 Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Wed, 7 Jul 2021 18:25:00 +1200 Subject: [PATCH] move BlockNumberProvider (#9209) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * move BlockNumberProvider * Update primitives/runtime/src/traits.rs * Update primitives/runtime/src/traits.rs Co-authored-by: Bastian Köcher --- substrate/frame/system/src/lib.rs | 3 +-- .../runtime/src/offchain/storage_lock.rs | 25 +------------------ substrate/primitives/runtime/src/traits.rs | 23 +++++++++++++++++ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index da9e5fabd3..e3fa45e70f 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -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}; diff --git a/substrate/primitives/runtime/src/offchain/storage_lock.rs b/substrate/primitives/runtime/src/offchain/storage_lock.rs index 3189a814e0..7ea52775c5 100644 --- a/substrate/primitives/runtime/src/offchain/storage_lock.rs +++ b/substrate/primitives/runtime/src/offchain/storage_lock.rs @@ -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`](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` as: - /// - /// ```ignore - /// fn current_block_number() -> Self { - /// frame_system::Pallet::block_number() - /// } - /// ``` - /// . - fn current_block_number() -> Self::BlockNumber; -} - #[cfg(test)] mod tests { use super::*; diff --git a/substrate/primitives/runtime/src/traits.rs b/substrate/primitives/runtime/src/traits.rs index fac4adf48c..f03e1be2a5 100644 --- a/substrate/primitives/runtime/src/traits.rs +++ b/substrate/primitives/runtime/src/traits.rs @@ -1459,6 +1459,29 @@ pub trait BlockIdTo { ) -> Result>, 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` as: + /// + /// ```ignore + /// fn current_block_number() -> Self { + /// frame_system::Pallet::block_number() + /// } + /// ``` + /// . + fn current_block_number() -> Self::BlockNumber; +} + #[cfg(test)] mod tests { use super::*;