diff --git a/src/frame/staking.rs b/src/frame/staking.rs index 56ab8ca210..1830d70564 100644 --- a/src/frame/staking.rs +++ b/src/frame/staking.rs @@ -38,6 +38,11 @@ use std::{ marker::PhantomData, }; +pub use pallet_staking::{ + EraIndex, + StakingLedger, +}; + /// A record of the nominations made by a specific account. #[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, Ord, PartialOrd, Hash)] pub struct Nominations { @@ -51,6 +56,20 @@ pub struct Nominations { pub suppressed: bool, } +/// Similar to `ErasStakers`, this holds the preferences of validators. +/// +/// This is keyed first by the era index to allow bulk deletion and then the stash account. +/// +/// Is it removed after `HISTORY_DEPTH` eras. +#[derive(Encode, Decode, Debug, Store)] +pub struct ErasValidatorPrefsStore { + #[store(returns = ValidatorPrefs)] + /// Era index + index: EraIndex, + /// Account ID + account_id: T::AccountId, +} + /// Information regarding the active era (era in used in session). #[derive(Encode, Decode, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct ActiveEraInfo { @@ -161,8 +180,6 @@ pub struct UnlockChunk { pub era: T::EraIndex, } -pub use pallet_staking::StakingLedger; - /// Number of eras to keep in history. /// /// Information is kept for eras in `[current_era - history_depth; current_era]`. diff --git a/src/lib.rs b/src/lib.rs index b790083cd8..f2ffac1507 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,7 +35,8 @@ while_true, trivial_casts, trivial_numeric_casts, - unused_extern_crates + unused_extern_crates, + clippy::all )] #![allow(clippy::type_complexity)] @@ -93,6 +94,7 @@ pub use crate::{ rpc::{ BlockNumber, ExtrinsicSuccess, + Properties, }, runtimes::*, subscription::*, @@ -161,16 +163,18 @@ impl ClientBuilder { } }; let rpc = Rpc::new(client); - let (metadata, genesis_hash, runtime_version) = future::join3( + let (metadata, genesis_hash, runtime_version, properties) = future::join4( rpc.metadata(), rpc.genesis_hash(), rpc.runtime_version(None), + rpc.properties(), ) .await; Ok(Client { rpc, genesis_hash: genesis_hash?, metadata: metadata?, + properties: properties?, runtime_version: runtime_version?, _marker: PhantomData, page_size: self.page_size.unwrap_or(10), @@ -183,6 +187,7 @@ pub struct Client { rpc: Rpc, genesis_hash: T::Hash, metadata: Metadata, + properties: Properties, runtime_version: RuntimeVersion, _marker: PhantomData<(fn() -> T::Signature, T::Extra)>, page_size: u32, @@ -194,6 +199,7 @@ impl Clone for Client { rpc: self.rpc.clone(), genesis_hash: self.genesis_hash, metadata: self.metadata.clone(), + properties: self.properties.clone(), runtime_version: self.runtime_version.clone(), _marker: PhantomData, page_size: self.page_size, @@ -258,6 +264,11 @@ impl Client { &self.metadata } + /// Returns the system properties + pub fn properties(&self) -> &Properties { + &self.properties + } + /// Fetch a StorageKey with an optional block hash. pub async fn fetch>( &self, diff --git a/src/rpc.rs b/src/rpc.rs index dd2aeff40e..a29582abd0 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -96,6 +96,18 @@ impl From for BlockNumber { } } +#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)] +#[serde(rename_all = "camelCase")] +/// System properties for a Substrate-based runtime +pub struct Properties { + /// The address format + pub ss58_format: u8, + /// The number of digits after the decimal point in the native token + pub token_decimals: u8, + /// The symbol of the native token + pub token_symbol: String, +} + /// Client for substrate rpc interfaces pub struct Rpc { client: Client, @@ -208,6 +220,14 @@ impl Rpc { Ok(metadata) } + /// Fetch system properties + pub async fn properties(&self) -> Result { + Ok(self + .client + .request("system_properties", Params::None) + .await?) + } + /// Get a header pub async fn header( &self, diff --git a/src/runtimes.rs b/src/runtimes.rs index a51a331a8c..f2064ac4e5 100644 --- a/src/runtimes.rs +++ b/src/runtimes.rs @@ -127,7 +127,6 @@ use crate::{ session::Session, staking::Staking, system::System, - Encoded, }; /// Runtime trait.