Expose properties and per-era preferences

This commit is contained in:
Demi M. Obenour
2020-08-11 21:24:46 -04:00
parent 7bad6c6909
commit da3667572b
4 changed files with 52 additions and 5 deletions
+19 -2
View File
@@ -38,6 +38,11 @@ use std::{
marker::PhantomData, marker::PhantomData,
}; };
pub use pallet_staking::{
EraIndex,
StakingLedger,
};
/// A record of the nominations made by a specific account. /// A record of the nominations made by a specific account.
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, Ord, PartialOrd, Hash)] #[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, Ord, PartialOrd, Hash)]
pub struct Nominations<T: Staking> { pub struct Nominations<T: Staking> {
@@ -51,6 +56,20 @@ pub struct Nominations<T: Staking> {
pub suppressed: bool, 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<T: Staking> {
#[store(returns = ValidatorPrefs)]
/// Era index
index: EraIndex,
/// Account ID
account_id: T::AccountId,
}
/// Information regarding the active era (era in used in session). /// Information regarding the active era (era in used in session).
#[derive(Encode, Decode, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Encode, Decode, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct ActiveEraInfo<T: Staking> { pub struct ActiveEraInfo<T: Staking> {
@@ -161,8 +180,6 @@ pub struct UnlockChunk<T: Staking> {
pub era: T::EraIndex, pub era: T::EraIndex,
} }
pub use pallet_staking::StakingLedger;
/// Number of eras to keep in history. /// Number of eras to keep in history.
/// ///
/// Information is kept for eras in `[current_era - history_depth; current_era]`. /// Information is kept for eras in `[current_era - history_depth; current_era]`.
+13 -2
View File
@@ -35,7 +35,8 @@
while_true, while_true,
trivial_casts, trivial_casts,
trivial_numeric_casts, trivial_numeric_casts,
unused_extern_crates unused_extern_crates,
clippy::all
)] )]
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity)]
@@ -93,6 +94,7 @@ pub use crate::{
rpc::{ rpc::{
BlockNumber, BlockNumber,
ExtrinsicSuccess, ExtrinsicSuccess,
Properties,
}, },
runtimes::*, runtimes::*,
subscription::*, subscription::*,
@@ -161,16 +163,18 @@ impl<T: Runtime> ClientBuilder<T> {
} }
}; };
let rpc = Rpc::new(client); 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.metadata(),
rpc.genesis_hash(), rpc.genesis_hash(),
rpc.runtime_version(None), rpc.runtime_version(None),
rpc.properties(),
) )
.await; .await;
Ok(Client { Ok(Client {
rpc, rpc,
genesis_hash: genesis_hash?, genesis_hash: genesis_hash?,
metadata: metadata?, metadata: metadata?,
properties: properties?,
runtime_version: runtime_version?, runtime_version: runtime_version?,
_marker: PhantomData, _marker: PhantomData,
page_size: self.page_size.unwrap_or(10), page_size: self.page_size.unwrap_or(10),
@@ -183,6 +187,7 @@ pub struct Client<T: Runtime> {
rpc: Rpc<T>, rpc: Rpc<T>,
genesis_hash: T::Hash, genesis_hash: T::Hash,
metadata: Metadata, metadata: Metadata,
properties: Properties,
runtime_version: RuntimeVersion, runtime_version: RuntimeVersion,
_marker: PhantomData<(fn() -> T::Signature, T::Extra)>, _marker: PhantomData<(fn() -> T::Signature, T::Extra)>,
page_size: u32, page_size: u32,
@@ -194,6 +199,7 @@ impl<T: Runtime> Clone for Client<T> {
rpc: self.rpc.clone(), rpc: self.rpc.clone(),
genesis_hash: self.genesis_hash, genesis_hash: self.genesis_hash,
metadata: self.metadata.clone(), metadata: self.metadata.clone(),
properties: self.properties.clone(),
runtime_version: self.runtime_version.clone(), runtime_version: self.runtime_version.clone(),
_marker: PhantomData, _marker: PhantomData,
page_size: self.page_size, page_size: self.page_size,
@@ -258,6 +264,11 @@ impl<T: Runtime> Client<T> {
&self.metadata &self.metadata
} }
/// Returns the system properties
pub fn properties(&self) -> &Properties {
&self.properties
}
/// Fetch a StorageKey with an optional block hash. /// Fetch a StorageKey with an optional block hash.
pub async fn fetch<F: Store<T>>( pub async fn fetch<F: Store<T>>(
&self, &self,
+20
View File
@@ -96,6 +96,18 @@ impl From<u32> 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 /// Client for substrate rpc interfaces
pub struct Rpc<T: Runtime> { pub struct Rpc<T: Runtime> {
client: Client, client: Client,
@@ -208,6 +220,14 @@ impl<T: Runtime> Rpc<T> {
Ok(metadata) Ok(metadata)
} }
/// Fetch system properties
pub async fn properties(&self) -> Result<Properties, Error> {
Ok(self
.client
.request("system_properties", Params::None)
.await?)
}
/// Get a header /// Get a header
pub async fn header( pub async fn header(
&self, &self,
-1
View File
@@ -127,7 +127,6 @@ use crate::{
session::Session, session::Session,
staking::Staking, staking::Staking,
system::System, system::System,
Encoded,
}; };
/// Runtime trait. /// Runtime trait.