mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 08:21:05 +00:00
Merge branch 'staking' of github.com:paritytech/substrate-subxt into staking
* 'staking' of github.com:paritytech/substrate-subxt: Remove more junk Remove a pointless change in Cargo.toml Remove more code not needed for Ledgeracio More deletions Remove some code Ledgeracio does not need Fix header Fix tests If property fetch fails, use dummy values Chill support and update to latest Substrate Add in all default features for debugging Make `PayoutStakersCall` public
This commit is contained in:
+2
-3
@@ -30,7 +30,7 @@ num-traits = { version = "0.2.12", default-features = false }
|
||||
serde = { version = "1.0.115", features = ["derive"] }
|
||||
serde_json = "1.0.57"
|
||||
url = "2.1.1"
|
||||
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive", "full"] }
|
||||
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive", "full"] }
|
||||
|
||||
frame-metadata = { version = "11.0.0-rc6", package = "frame-metadata" }
|
||||
frame-support = { version = "2.0.0-rc6", package = "frame-support" }
|
||||
@@ -38,9 +38,8 @@ sp-runtime = { version = "2.0.0-rc6", package = "sp-runtime" }
|
||||
sp-version = { version = "2.0.0-rc6", package = "sp-version" }
|
||||
pallet-indices = { version = "2.0.0-rc6", package = "pallet-indices" }
|
||||
hex = "0.4.2"
|
||||
|
||||
sp-std = "2.0.0-rc6"
|
||||
application-crypto = { version = "2.0.0-rc6", package = "sp-application-crypto", default-features = false }
|
||||
application-crypto = { version = "2.0.0-rc6", package = "sp-application-crypto" }
|
||||
sp-finality-grandpa = "2.0.0-rc6"
|
||||
sp-consensus-babe = "0.8.0-rc6"
|
||||
pallet-im-online = "2.0.0-rc6"
|
||||
|
||||
+5
-45
@@ -13,7 +13,6 @@
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||
|
||||
//! Session support
|
||||
use crate::frame::system::{
|
||||
@@ -32,7 +31,9 @@ use std::{
|
||||
};
|
||||
use substrate_subxt_proc_macro::Store;
|
||||
|
||||
macro_rules! def {
|
||||
/// Impls `Default::default` for some types that have a `_runtime` field of type
|
||||
/// `PhantomData` as their only field.
|
||||
macro_rules! default_impl {
|
||||
($name:ident) => {
|
||||
impl<T: Session> Default for $name<T> {
|
||||
fn default() -> Self {
|
||||
@@ -50,9 +51,6 @@ pub trait Session: System {
|
||||
/// The validator account identifier type for the runtime.
|
||||
type ValidatorId: Parameter + Debug + Ord + Default + Send + Sync + 'static;
|
||||
|
||||
/// The validator account identifier type for the runtime.
|
||||
type SessionIndex: Parameter + Debug + Ord + Default + Send + Sync + 'static;
|
||||
|
||||
/// The keys.
|
||||
type Keys: OpaqueKeys + Member + Parameter + Default;
|
||||
}
|
||||
@@ -65,30 +63,9 @@ pub struct ValidatorsStore<T: Session> {
|
||||
pub _runtime: PhantomData<T>,
|
||||
}
|
||||
|
||||
def!(ValidatorsStore);
|
||||
default_impl!(ValidatorsStore);
|
||||
|
||||
/// Current index of the session.
|
||||
#[derive(Encode, Store, Debug)]
|
||||
pub struct CurrentIndexStore<T: Session> {
|
||||
#[store(returns = <T as Session>::SessionIndex)]
|
||||
/// Marker for the runtime
|
||||
pub _runtime: PhantomData<T>,
|
||||
}
|
||||
|
||||
def!(CurrentIndexStore);
|
||||
|
||||
/// True if the underlying economic identities or weighting behind the validators
|
||||
/// has changed in the queued validator set.
|
||||
#[derive(Encode, Store, Debug)]
|
||||
pub struct QueuedChangedStore<T: Session> {
|
||||
#[store(returns = bool)]
|
||||
/// Marker for the runtime
|
||||
pub _runtime: PhantomData<T>,
|
||||
}
|
||||
|
||||
def!(QueuedChangedStore);
|
||||
|
||||
/// The current set of validators.
|
||||
/// Set the session keys for a validator.
|
||||
#[derive(Encode, Call, Debug)]
|
||||
pub struct SetKeysCall<T: Session> {
|
||||
/// The keys
|
||||
@@ -96,20 +73,3 @@ pub struct SetKeysCall<T: Session> {
|
||||
/// The proof. This is not currently used and can be set to an empty vector.
|
||||
pub proof: Vec<u8>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::tests::test_client;
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_state_read_free_balance() {
|
||||
env_logger::try_init().ok();
|
||||
let (client, _) = test_client().await;
|
||||
assert!(client
|
||||
.fetch(&QueuedChangedStore::default(), None)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
+31
-149
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Implements support for the frame_staking module.
|
||||
//! Implements support for the pallet_staking module.
|
||||
|
||||
use super::balances::{
|
||||
Balances,
|
||||
@@ -24,11 +24,6 @@ use codec::{
|
||||
Decode,
|
||||
Encode,
|
||||
};
|
||||
use frame_support::Parameter;
|
||||
use sp_runtime::traits::{
|
||||
MaybeSerialize,
|
||||
Member,
|
||||
};
|
||||
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
@@ -47,20 +42,6 @@ pub use pallet_staking::{
|
||||
ValidatorPrefs,
|
||||
};
|
||||
|
||||
/// 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
|
||||
pub index: EraIndex,
|
||||
/// Account ID
|
||||
pub account_id: T::AccountId,
|
||||
}
|
||||
|
||||
/// Rewards for the last `HISTORY_DEPTH` eras.
|
||||
/// If reward hasn't been set or has been removed then 0 reward is returned.
|
||||
#[derive(Clone, Encode, Decode, Debug, Store)]
|
||||
@@ -83,44 +64,7 @@ pub struct SetPayeeCall<T: Staking> {
|
||||
|
||||
/// The subset of the `frame::Trait` that a client must implement.
|
||||
#[module]
|
||||
pub trait Staking: Balances {
|
||||
/// Data type used to index nominators in the compact type
|
||||
type NominatorIndex: Parameter
|
||||
+ codec::Codec
|
||||
+ Member
|
||||
+ Default
|
||||
+ Copy
|
||||
+ MaybeSerialize
|
||||
+ Debug;
|
||||
|
||||
/// Data type used to index validators in the compact type.
|
||||
type ValidatorIndex: Parameter
|
||||
+ codec::Codec
|
||||
+ Send
|
||||
+ Sync
|
||||
+ Default
|
||||
+ Member
|
||||
+ Copy
|
||||
+ MaybeSerialize
|
||||
+ Debug;
|
||||
|
||||
/// Maximum number of validators that can be stored in a snapshot.
|
||||
const MAX_VALIDATORS: usize;
|
||||
|
||||
/// Maximum number of nominators that can be stored in a snapshot.
|
||||
const MAX_NOMINATORS: usize;
|
||||
}
|
||||
|
||||
/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked.
|
||||
#[derive(Clone, Encode, Decode, Debug)]
|
||||
pub struct UnlockChunk<T: Staking> {
|
||||
/// Amount of funds to be unlocked.
|
||||
#[codec(compact)]
|
||||
pub value: T::Balance,
|
||||
/// Era number at which point it'll be unlocked.
|
||||
#[codec(compact)]
|
||||
pub era: EraIndex,
|
||||
}
|
||||
pub trait Staking: Balances {}
|
||||
|
||||
/// Number of eras to keep in history.
|
||||
///
|
||||
@@ -136,34 +80,6 @@ pub struct HistoryDepthStore<T: Staking> {
|
||||
pub _runtime: PhantomData<T>,
|
||||
}
|
||||
|
||||
/// The ideal number of staking participants.
|
||||
#[derive(Encode, Decode, Copy, Clone, Debug, Store)]
|
||||
pub struct ValidatorCountStore<T: Staking> {
|
||||
#[store(returns = u32)]
|
||||
/// Marker for the runtime
|
||||
pub _runtime: PhantomData<T>,
|
||||
}
|
||||
|
||||
/// Minimum number of staking participants before emergency conditions are imposed.
|
||||
#[derive(
|
||||
Encode, Decode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store,
|
||||
)]
|
||||
pub struct MinimumValidatorCountStore<T: Staking> {
|
||||
#[store(returns = u32)]
|
||||
/// Marker for the runtime
|
||||
pub _runtime: PhantomData<T>,
|
||||
}
|
||||
|
||||
/// Any validators that may never be slashed or forcibly kicked. It's a Vec since they're
|
||||
/// easy to initialize and the performance hit is minimal (we expect no more than four
|
||||
/// invulnerables) and restricted to testnets.
|
||||
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
|
||||
pub struct InvulnerablesStore<T: Staking> {
|
||||
#[store(returns = Vec<T::AccountId>)]
|
||||
/// Marker for the runtime
|
||||
pub _runtime: PhantomData<T>,
|
||||
}
|
||||
|
||||
/// Map from all locked "stash" accounts to the controller account.
|
||||
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
|
||||
pub struct BondedStore<T: Staking> {
|
||||
@@ -226,90 +142,56 @@ pub struct EraRewardPoints<AccountId: Ord> {
|
||||
pub individual: BTreeMap<AccountId, RewardPoint>,
|
||||
}
|
||||
|
||||
/// Clipped Exposure of validator at era.
|
||||
/// Declare no desire to either validate or nominate.
|
||||
///
|
||||
/// This is similar to [`ErasStakers`] but number of nominators exposed is reduced to the
|
||||
/// `T::MaxNominatorRewardedPerValidator` biggest stakers.
|
||||
/// (Note: the field `total` and `own` of the exposure remains unchanged).
|
||||
/// This is used to limit the i/o cost for the nominator payout.
|
||||
/// Effective at the beginning of the next era.
|
||||
///
|
||||
/// This is keyed fist by the era index to allow bulk deletion and then the stash account.
|
||||
///
|
||||
/// Is it removed after `HISTORY_DEPTH` eras.
|
||||
/// If stakers hasn't been set or has been removed then empty exposure is returned.
|
||||
#[derive(Encode, Copy, Clone, Debug, Store)]
|
||||
pub struct ErasStakersClippedStore<T: Staking> {
|
||||
#[store(returns = Exposure<T::AccountId, T::Balance>)]
|
||||
/// Era index
|
||||
pub era: EraIndex,
|
||||
/// Stash account of the validator
|
||||
pub validator_stash: T::AccountId,
|
||||
}
|
||||
|
||||
/// The active era information, it holds index and start.
|
||||
///
|
||||
/// The active era is the era currently rewarded.
|
||||
/// Validator set of this era must be equal to `SessionInterface::validators`.
|
||||
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
|
||||
pub struct ActiveEraStore<T: Staking> {
|
||||
#[store(returns = Option<ActiveEraInfo>)]
|
||||
/// Marker for the runtime
|
||||
/// The dispatch origin for this call must be _Signed_ by the controller, not the stash.
|
||||
/// Can only be called when [`EraElectionStatus`] is `Closed`.
|
||||
#[derive(Debug, Call, Encode)]
|
||||
pub struct ChillCall<T: Staking> {
|
||||
/// Runtime marker
|
||||
pub _runtime: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: Staking> Default for ChillCall<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
_runtime: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T: Staking> Clone for ChillCall<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
_runtime: self._runtime,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T: Staking> Copy for ChillCall<T> {}
|
||||
|
||||
/// Declare the desire to validate for the origin controller.
|
||||
///
|
||||
/// Effects will be felt at the beginning of the next era.
|
||||
/// Effective at the beginning of the next era.
|
||||
///
|
||||
/// The dispatch origin for this call must be _Signed_ by the controller, not the stash.
|
||||
/// And, it can be only called when [`EraElectionStatus`] is `Closed`.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - Independent of the arguments. Insignificant complexity.
|
||||
/// - Contains a limited number of reads.
|
||||
/// - Writes are limited to the `origin` account key.
|
||||
/// -----------
|
||||
/// Base Weight: 17.13 µs
|
||||
/// DB Weight:
|
||||
/// - Read: Era Election Status, Ledger
|
||||
/// - Write: Nominators, Validators
|
||||
/// # </weight>
|
||||
/// Can only be called when [`EraElectionStatus`] is `Closed`.
|
||||
#[derive(Clone, Debug, PartialEq, Call, Encode)]
|
||||
pub struct ValidateCall<T: Staking> {
|
||||
/// Runtime marker.
|
||||
/// Runtime marker
|
||||
pub _runtime: PhantomData<T>,
|
||||
/// Validation preferences.
|
||||
/// Validation preferences
|
||||
pub prefs: ValidatorPrefs,
|
||||
}
|
||||
|
||||
/// Declare the desire to nominate `targets` for the origin controller.
|
||||
///
|
||||
/// Effects will be felt at the beginning of the next era. This can only be called when
|
||||
/// [`EraElectionStatus`] is `Closed`.
|
||||
/// Effective at the beginning of the next era.
|
||||
///
|
||||
/// The dispatch origin for this call must be _Signed_ by the controller, not the stash.
|
||||
/// And, it can be only called when [`EraElectionStatus`] is `Closed`.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - The transaction's complexity is proportional to the size of `targets` (N)
|
||||
/// which is capped at CompactAssignments::LIMIT (MAX_NOMINATIONS).
|
||||
/// - Both the reads and writes follow a similar pattern.
|
||||
/// ---------
|
||||
/// Base Weight: 22.34 + .36 * N µs
|
||||
/// where N is the number of targets
|
||||
/// DB Weight:
|
||||
/// - Reads: Era Election Status, Ledger, Current Era
|
||||
/// - Writes: Validators, Nominators
|
||||
/// # </weight>
|
||||
/// Can only be called when [`EraElectionStatus`] is `Closed`.
|
||||
#[derive(Call, Encode, Debug)]
|
||||
pub struct NominateCall<T: Staking> {
|
||||
/// The targets that are being nominated
|
||||
pub targets: Vec<T::Address>,
|
||||
}
|
||||
|
||||
/// Claim a payout.
|
||||
#[derive(PartialEq, Eq, Clone, Call, Encode, Decode, Debug)]
|
||||
struct PayoutStakersCall<'a, T: Staking> {
|
||||
pub validator_stash: &'a T::AccountId,
|
||||
pub era: EraIndex,
|
||||
}
|
||||
|
||||
+5
-5
@@ -94,7 +94,7 @@ pub use crate::{
|
||||
rpc::{
|
||||
BlockNumber,
|
||||
ExtrinsicSuccess,
|
||||
Properties,
|
||||
SystemProperties,
|
||||
},
|
||||
runtimes::*,
|
||||
subscription::*,
|
||||
@@ -167,14 +167,14 @@ impl<T: Runtime> ClientBuilder<T> {
|
||||
rpc.metadata(),
|
||||
rpc.genesis_hash(),
|
||||
rpc.runtime_version(None),
|
||||
rpc.properties(),
|
||||
rpc.system_properties(),
|
||||
)
|
||||
.await;
|
||||
Ok(Client {
|
||||
rpc,
|
||||
genesis_hash: genesis_hash?,
|
||||
metadata: metadata?,
|
||||
properties: properties?,
|
||||
properties: properties.unwrap_or_else(|_| Default::default()),
|
||||
runtime_version: runtime_version?,
|
||||
_marker: PhantomData,
|
||||
page_size: self.page_size.unwrap_or(10),
|
||||
@@ -187,7 +187,7 @@ pub struct Client<T: Runtime> {
|
||||
rpc: Rpc<T>,
|
||||
genesis_hash: T::Hash,
|
||||
metadata: Metadata,
|
||||
properties: Properties,
|
||||
properties: SystemProperties,
|
||||
runtime_version: RuntimeVersion,
|
||||
_marker: PhantomData<(fn() -> T::Signature, T::Extra)>,
|
||||
page_size: u32,
|
||||
@@ -265,7 +265,7 @@ impl<T: Runtime> Client<T> {
|
||||
}
|
||||
|
||||
/// Returns the system properties
|
||||
pub fn properties(&self) -> &Properties {
|
||||
pub fn properties(&self) -> &SystemProperties {
|
||||
&self.properties
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -96,10 +96,10 @@ impl From<u32> for BlockNumber {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
/// System properties for a Substrate-based runtime
|
||||
pub struct Properties {
|
||||
pub struct SystemProperties {
|
||||
/// The address format
|
||||
pub ss58_format: u8,
|
||||
/// The number of digits after the decimal point in the native token
|
||||
@@ -221,7 +221,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
}
|
||||
|
||||
/// Fetch system properties
|
||||
pub async fn properties(&self) -> Result<Properties, Error> {
|
||||
pub async fn system_properties(&self) -> Result<SystemProperties, Error> {
|
||||
Ok(self
|
||||
.client
|
||||
.request("system_properties", Params::None)
|
||||
|
||||
+2
-15
@@ -146,12 +146,7 @@ pub trait Runtime: System + Sized + Send + Sync + 'static {
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct DefaultNodeRuntime;
|
||||
|
||||
impl Staking for DefaultNodeRuntime {
|
||||
type NominatorIndex = u32;
|
||||
type ValidatorIndex = u16;
|
||||
const MAX_VALIDATORS: usize = Self::ValidatorIndex::max_value() as usize;
|
||||
const MAX_NOMINATORS: usize = Self::NominatorIndex::max_value() as usize;
|
||||
}
|
||||
impl Staking for DefaultNodeRuntime {}
|
||||
|
||||
impl Runtime for DefaultNodeRuntime {
|
||||
type Signature = MultiSignature;
|
||||
@@ -175,7 +170,6 @@ impl Balances for DefaultNodeRuntime {
|
||||
}
|
||||
|
||||
impl Session for DefaultNodeRuntime {
|
||||
type SessionIndex = u32;
|
||||
type ValidatorId = <Self as System>::AccountId;
|
||||
type Keys = BasicSessionKeys;
|
||||
}
|
||||
@@ -215,7 +209,6 @@ impl Balances for NodeTemplateRuntime {
|
||||
}
|
||||
|
||||
impl Session for NodeTemplateRuntime {
|
||||
type SessionIndex = u32;
|
||||
type ValidatorId = <Self as System>::AccountId;
|
||||
type Keys = BasicSessionKeys;
|
||||
}
|
||||
@@ -249,17 +242,11 @@ impl System for KusamaRuntime {
|
||||
}
|
||||
|
||||
impl Session for KusamaRuntime {
|
||||
type SessionIndex = u32;
|
||||
type ValidatorId = <Self as System>::AccountId;
|
||||
type Keys = SessionKeys;
|
||||
}
|
||||
|
||||
impl Staking for KusamaRuntime {
|
||||
type NominatorIndex = u32;
|
||||
type ValidatorIndex = u16;
|
||||
const MAX_VALIDATORS: usize = Self::ValidatorIndex::max_value() as usize;
|
||||
const MAX_NOMINATORS: usize = Self::NominatorIndex::max_value() as usize;
|
||||
}
|
||||
impl Staking for KusamaRuntime {}
|
||||
|
||||
impl Balances for KusamaRuntime {
|
||||
type Balance = u128;
|
||||
|
||||
Reference in New Issue
Block a user