From 417f95f2266b14ecf590721c454715b2d3b42402 Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Sun, 27 Jun 2021 22:26:01 +1200 Subject: [PATCH 1/3] move BlockNumberProvider --- frame/system/src/lib.rs | 3 +-- .../runtime/src/offchain/storage_lock.rs | 25 +------------------ primitives/runtime/src/traits.rs | 23 +++++++++++++++++ 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index f96c43ee1c98e..1388ea29cb995 100644 --- a/frame/system/src/lib.rs +++ b/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/primitives/runtime/src/offchain/storage_lock.rs b/primitives/runtime/src/offchain/storage_lock.rs index 3189a814e06fd..7ea52775c5e05 100644 --- a/primitives/runtime/src/offchain/storage_lock.rs +++ b/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/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index 2379fce9949e0..d99a0cf940b6e 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -1460,6 +1460,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` 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::*; From 825d56b128383aed9262d8b9df035299dd5cee0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 28 Jun 2021 11:27:59 +0200 Subject: [PATCH 2/3] Update primitives/runtime/src/traits.rs --- primitives/runtime/src/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index d99a0cf940b6e..410d725b4335b 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -1470,7 +1470,7 @@ pub trait BlockNumberProvider { /// Provides an abstraction over an arbitrary way of providing the /// current block number. /// - /// In case of using crate `sp_runtime` without the crate `frame` + /// In case of using crate `sp_runtime` with the crate `frame-system`, /// system, it is already implemented for /// `frame_system::Pallet` as: /// From c227826e020c7cbc437ed16e5c798ed2eba86098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Mon, 28 Jun 2021 11:28:03 +0200 Subject: [PATCH 3/3] Update primitives/runtime/src/traits.rs --- primitives/runtime/src/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/runtime/src/traits.rs b/primitives/runtime/src/traits.rs index 410d725b4335b..4ccbf083397a5 100644 --- a/primitives/runtime/src/traits.rs +++ b/primitives/runtime/src/traits.rs @@ -1471,7 +1471,7 @@ pub trait BlockNumberProvider { /// current block number. /// /// In case of using crate `sp_runtime` with the crate `frame-system`, - /// system, it is already implemented for + /// it is already implemented for /// `frame_system::Pallet` as: /// /// ```ignore