mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 16:17:59 +00:00
Make Staking pallet using a proper Time module. (#4662)
* add new trait, still migration to make * Apply suggestions from code review Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * implement migration * better naming * fix test * no longer require DeprecatedTime * add test * fix version * upgrade only from kusama * add test * fix test * Update frame/timestamp/src/lib.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -95,15 +95,17 @@ mod benchmarking;
|
||||
|
||||
use sp_std::{result, cmp};
|
||||
use sp_inherents::{ProvideInherent, InherentData, InherentIdentifier};
|
||||
use frame_support::{Parameter, decl_storage, decl_module};
|
||||
use frame_support::traits::{Time, Get};
|
||||
use frame_support::{
|
||||
Parameter, decl_storage, decl_module, debug,
|
||||
traits::{Time, UnixTime, Get},
|
||||
weights::SimpleDispatchInfo,
|
||||
};
|
||||
use sp_runtime::{
|
||||
RuntimeString,
|
||||
traits::{
|
||||
AtLeast32Bit, Zero, SaturatedConversion, Scale
|
||||
}
|
||||
};
|
||||
use frame_support::weights::SimpleDispatchInfo;
|
||||
use frame_system::ensure_none;
|
||||
use sp_timestamp::{
|
||||
InherentError, INHERENT_IDENTIFIER, InherentType,
|
||||
@@ -239,6 +241,25 @@ impl<T: Trait> Time for Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Before the timestamp inherent is applied, it returns the time of previous block.
|
||||
///
|
||||
/// On genesis the time returned is not valid.
|
||||
impl<T: Trait> UnixTime for Module<T> {
|
||||
fn now() -> core::time::Duration {
|
||||
// now is duration since unix epoch in millisecond as documented in
|
||||
// `sp_timestamp::InherentDataProvider`.
|
||||
let now = Self::now();
|
||||
sp_std::if_std! {
|
||||
if now == T::Moment::zero() {
|
||||
debug::error!(
|
||||
"`pallet_timestamp::UnixTime::now` is called at genesis, invalid value returned: 0"
|
||||
);
|
||||
}
|
||||
}
|
||||
core::time::Duration::from_millis(now.saturated_into::<u64>())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user