mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
Enhance decl storage (#777)
* enhance macro decl_storage() * update the state root hash * fix one comment
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[cfg_attr(any(feature = "std", test), macro_use)]
|
||||
extern crate sr_std as rstd;
|
||||
|
||||
#[macro_use]
|
||||
@@ -78,12 +77,12 @@ decl_module! {
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as Timestamp {
|
||||
/// Current time for the current block.
|
||||
pub Now get(now): required T::Moment;
|
||||
pub Now get(now) build(|_| T::Moment::sa(0)): T::Moment;
|
||||
/// The minimum (and advised) period between blocks.
|
||||
pub BlockPeriod get(block_period): required T::Moment;
|
||||
pub BlockPeriod get(block_period) config(period): T::Moment = T::Moment::sa(5);
|
||||
|
||||
/// Did the timestamp get updated in this block?
|
||||
DidUpdate: default bool;
|
||||
DidUpdate: bool;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,37 +134,6 @@ impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration of a genesis block for the timestamp module.
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
/// The minimum (and advised) period between blocks.
|
||||
pub period: T::Moment,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> Default for GenesisConfig<T> {
|
||||
fn default() -> Self {
|
||||
GenesisConfig {
|
||||
period: T::Moment::sa(5),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> runtime_primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> ::std::result::Result<runtime_primitives::StorageMap, String> {
|
||||
use codec::Encode;
|
||||
Ok(map![
|
||||
Self::hash(<BlockPeriod<T>>::key()).to_vec() => self.period.encode(),
|
||||
Self::hash(<Now<T>>::key()).to_vec() => T::Moment::sa(0).encode()
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user