mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-10 17:11:03 +00:00
Expose properties and per-era preferences
This commit is contained in:
+19
-2
@@ -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<T: Staking> {
|
||||
@@ -51,6 +56,20 @@ pub struct Nominations<T: Staking> {
|
||||
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).
|
||||
#[derive(Encode, Decode, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct ActiveEraInfo<T: Staking> {
|
||||
@@ -161,8 +180,6 @@ pub struct UnlockChunk<T: Staking> {
|
||||
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]`.
|
||||
|
||||
+13
-2
@@ -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<T: Runtime> ClientBuilder<T> {
|
||||
}
|
||||
};
|
||||
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<T: Runtime> {
|
||||
rpc: Rpc<T>,
|
||||
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<T: Runtime> Clone for Client<T> {
|
||||
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<T: Runtime> Client<T> {
|
||||
&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<F: Store<T>>(
|
||||
&self,
|
||||
|
||||
+20
@@ -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
|
||||
pub struct Rpc<T: Runtime> {
|
||||
client: Client,
|
||||
@@ -208,6 +220,14 @@ impl<T: Runtime> Rpc<T> {
|
||||
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
|
||||
pub async fn header(
|
||||
&self,
|
||||
|
||||
@@ -127,7 +127,6 @@ use crate::{
|
||||
session::Session,
|
||||
staking::Staking,
|
||||
system::System,
|
||||
Encoded,
|
||||
};
|
||||
|
||||
/// Runtime trait.
|
||||
|
||||
Reference in New Issue
Block a user