mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Enhance decl storage (#777)
* enhance macro decl_storage() * update the state root hash * fix one comment
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[cfg_attr(feature = "std", macro_use)]
|
||||
extern crate sr_std as rstd;
|
||||
|
||||
#[macro_use]
|
||||
@@ -87,23 +86,23 @@ decl_storage! {
|
||||
trait Store for Module<T: Trait> as Session {
|
||||
|
||||
/// The current set of validators.
|
||||
pub Validators get(validators): required Vec<T::AccountId>;
|
||||
pub Validators get(validators) config(): Vec<T::AccountId>;
|
||||
/// Current length of the session.
|
||||
pub SessionLength get(length): required T::BlockNumber;
|
||||
pub SessionLength get(length) config(session_length): T::BlockNumber = T::BlockNumber::sa(1000);
|
||||
/// Current index of the session.
|
||||
pub CurrentIndex get(current_index): required T::BlockNumber;
|
||||
pub CurrentIndex get(current_index) build(|_| T::BlockNumber::sa(0)): T::BlockNumber;
|
||||
/// Timestamp when current session started.
|
||||
pub CurrentStart get(current_start): required T::Moment;
|
||||
pub CurrentStart get(current_start) build(|_| T::Moment::zero()): T::Moment;
|
||||
|
||||
/// New session is being forced is this entry exists; in which case, the boolean value is whether
|
||||
/// the new session should be considered a normal rotation (rewardable) or exceptional (slashable).
|
||||
pub ForcingNewSession get(forcing_new_session): bool;
|
||||
pub ForcingNewSession get(forcing_new_session): Option<bool>;
|
||||
/// Block at which the session length last changed.
|
||||
LastLengthChange: T::BlockNumber;
|
||||
LastLengthChange: Option<T::BlockNumber>;
|
||||
/// The next key for a given validator.
|
||||
NextKeyFor: map [ T::AccountId => T::SessionKey ];
|
||||
NextKeyFor: map T::AccountId => Option<T::SessionKey>;
|
||||
/// The next session length.
|
||||
NextSessionLength: T::BlockNumber;
|
||||
NextSessionLength: Option<T::BlockNumber>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,41 +233,6 @@ impl<T: Trait> OnFinalise<T::BlockNumber> for Module<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GenesisConfig<T: Trait> {
|
||||
pub session_length: T::BlockNumber,
|
||||
pub validators: Vec<T::AccountId>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> Default for GenesisConfig<T> {
|
||||
fn default() -> Self {
|
||||
use primitives::traits::As;
|
||||
GenesisConfig {
|
||||
session_length: T::BlockNumber::sa(1000),
|
||||
validators: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", test))]
|
||||
impl<T: Trait> primitives::BuildStorage for GenesisConfig<T>
|
||||
{
|
||||
fn build_storage(self) -> ::std::result::Result<primitives::StorageMap, String> {
|
||||
use codec::Encode;
|
||||
use primitives::traits::As;
|
||||
Ok(map![
|
||||
Self::hash(<SessionLength<T>>::key()).to_vec() => self.session_length.encode(),
|
||||
Self::hash(<CurrentIndex<T>>::key()).to_vec() => T::BlockNumber::sa(0).encode(),
|
||||
Self::hash(<CurrentStart<T>>::key()).to_vec() => T::Moment::zero().encode(),
|
||||
Self::hash(<Validators<T>>::key()).to_vec() => self.validators.encode()
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user