mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-22 04:25:42 +00:00
Reformat
This commit is contained in:
+1
-1
@@ -34,8 +34,8 @@ use sp_core::storage::StorageKey;
|
|||||||
|
|
||||||
pub mod balances;
|
pub mod balances;
|
||||||
pub mod contracts;
|
pub mod contracts;
|
||||||
pub mod system;
|
|
||||||
pub mod staking;
|
pub mod staking;
|
||||||
|
pub mod system;
|
||||||
|
|
||||||
/// Store trait.
|
/// Store trait.
|
||||||
pub trait Store<T>: Encode {
|
pub trait Store<T>: Encode {
|
||||||
|
|||||||
+162
-97
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
|
||||||
// This file is part of substrate-subxt.
|
// This file is part of substrate-subxt.
|
||||||
//
|
//
|
||||||
// subxt is free software: you can redistribute it and/or modify
|
// subxt is free software: you can redistribute it and/or modify
|
||||||
@@ -16,48 +16,71 @@
|
|||||||
|
|
||||||
//! Implements support for the frame_staking module.
|
//! Implements support for the frame_staking module.
|
||||||
|
|
||||||
use codec::{Codec, Decode, Encode, HasCompact};
|
use crate::{
|
||||||
|
frame::{
|
||||||
|
Call,
|
||||||
|
Store,
|
||||||
|
},
|
||||||
|
metadata::{
|
||||||
|
Metadata,
|
||||||
|
MetadataError,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use codec::{
|
||||||
|
Codec,
|
||||||
|
Decode,
|
||||||
|
Encode,
|
||||||
|
HasCompact,
|
||||||
|
};
|
||||||
use frame_support::Parameter;
|
use frame_support::Parameter;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use sp_core::storage::StorageKey;
|
use sp_core::storage::StorageKey;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
traits::{
|
traits::{
|
||||||
AtLeast32Bit, Bounded, CheckEqual, Extrinsic, Hash, Header, MaybeDisplay,
|
AtLeast32Bit,
|
||||||
MaybeMallocSizeOf, MaybeSerialize, MaybeSerializeDeserialize, Member,
|
Bounded,
|
||||||
|
CheckEqual,
|
||||||
|
Extrinsic,
|
||||||
|
Hash,
|
||||||
|
Header,
|
||||||
|
MaybeDisplay,
|
||||||
|
MaybeMallocSizeOf,
|
||||||
|
MaybeSerialize,
|
||||||
|
MaybeSerializeDeserialize,
|
||||||
|
Member,
|
||||||
SimpleBitOps,
|
SimpleBitOps,
|
||||||
}, Perbill,
|
},
|
||||||
|
Perbill,
|
||||||
RuntimeDebug,
|
RuntimeDebug,
|
||||||
};
|
};
|
||||||
use std::fmt::Debug;
|
use std::{
|
||||||
use std::marker::PhantomData;
|
fmt::Debug,
|
||||||
use crate::{
|
marker::PhantomData,
|
||||||
frame::{Call, Store},
|
|
||||||
metadata::{Metadata, MetadataError},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// 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, RuntimeDebug)]
|
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||||
pub struct Nominations<AccountId> {
|
pub struct Nominations<AccountId> {
|
||||||
/// The targets of nomination.
|
/// The targets of nomination.
|
||||||
pub targets: Vec<AccountId>,
|
pub targets: Vec<AccountId>,
|
||||||
/// The era the nominations were submitted.
|
/// The era the nominations were submitted.
|
||||||
///
|
///
|
||||||
/// Except for initial nominations which are considered submitted at era 0.
|
/// Except for initial nominations which are considered submitted at era 0.
|
||||||
pub submitted_in: EraIndex,
|
pub submitted_in: EraIndex,
|
||||||
/// Whether the nominations have been suppressed.
|
/// Whether the nominations have been suppressed.
|
||||||
pub suppressed: bool,
|
pub suppressed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information regarding the active era (era in used in session).
|
/// Information regarding the active era (era in used in session).
|
||||||
#[derive(Encode, Decode, RuntimeDebug)]
|
#[derive(Encode, Decode, RuntimeDebug)]
|
||||||
pub struct ActiveEraInfo {
|
pub struct ActiveEraInfo {
|
||||||
/// Index of era.
|
/// Index of era.
|
||||||
pub index: EraIndex,
|
pub index: EraIndex,
|
||||||
/// Moment of start expresed as millisecond from `$UNIX_EPOCH`.
|
/// Moment of start expresed as millisecond from `$UNIX_EPOCH`.
|
||||||
///
|
///
|
||||||
/// Start can be none if start hasn't been set for the era yet,
|
/// Start can be none if start hasn't been set for the era yet,
|
||||||
/// Start is set on the first on_finalize of the era to guarantee usage of `Time`.
|
/// Start is set on the first on_finalize of the era to guarantee usage of `Time`.
|
||||||
start: Option<u64>,
|
start: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Data type used to index nominators in the compact type
|
/// Data type used to index nominators in the compact type
|
||||||
@@ -79,91 +102,89 @@ pub type RewardPoint = u32;
|
|||||||
/// A destination account for payment.
|
/// A destination account for payment.
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug)]
|
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug)]
|
||||||
pub enum RewardDestination {
|
pub enum RewardDestination {
|
||||||
/// Pay into the stash account, increasing the amount at stake accordingly.
|
/// Pay into the stash account, increasing the amount at stake accordingly.
|
||||||
Staked,
|
Staked,
|
||||||
/// Pay into the stash account, not increasing the amount at stake.
|
/// Pay into the stash account, not increasing the amount at stake.
|
||||||
Stash,
|
Stash,
|
||||||
/// Pay into the controller account.
|
/// Pay into the controller account.
|
||||||
Controller,
|
Controller,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RewardDestination {
|
impl Default for RewardDestination {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
RewardDestination::Staked
|
RewardDestination::Staked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Preference of what happens regarding validation.
|
/// Preference of what happens regarding validation.
|
||||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||||
pub struct ValidatorPrefs {
|
pub struct ValidatorPrefs {
|
||||||
/// Reward that validator takes up-front; only the rest is split between themselves and
|
/// Reward that validator takes up-front; only the rest is split between themselves and
|
||||||
/// nominators.
|
/// nominators.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
pub commission: Perbill,
|
pub commission: Perbill,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ValidatorPrefs {
|
impl Default for ValidatorPrefs {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
ValidatorPrefs {
|
ValidatorPrefs {
|
||||||
commission: Default::default(),
|
commission: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// The subset of the `frame::Trait` that a client must implement.
|
/// The subset of the `frame::Trait` that a client must implement.
|
||||||
pub trait Staking: super::system::System {
|
pub trait Staking: super::system::System {
|
||||||
/*
|
// type UnixTime;
|
||||||
type UnixTime;
|
// type CurrencyToVote;
|
||||||
type CurrencyToVote;
|
// type RewardRemainder;
|
||||||
type RewardRemainder;
|
// type Event;
|
||||||
type Event;
|
// type Slash;
|
||||||
type Slash;
|
// type Reward;
|
||||||
type Reward;
|
// type SessionsPerEra;
|
||||||
type SessionsPerEra;
|
// type BondingDuration;
|
||||||
type BondingDuration;
|
// type SlashDeferDuration;
|
||||||
type SlashDeferDuration;
|
// type SlashCancelOrigin;
|
||||||
type SlashCancelOrigin;
|
// type SessionInterface;
|
||||||
type SessionInterface;
|
// type RewardCurve;
|
||||||
type RewardCurve;
|
// type NextNewSession;
|
||||||
type NextNewSession;
|
// type ElectionLookahead;
|
||||||
type ElectionLookahead;
|
// type Call;
|
||||||
type Call;
|
// type MaxIterations;
|
||||||
type MaxIterations;
|
// type MaxNominatorRewardPerValidator;
|
||||||
type MaxNominatorRewardPerValidator;
|
// type UnsignedPriority;
|
||||||
type UnsignedPriority; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked.
|
/// Just a Balance/BlockNumber tuple to encode when a chunk of funds will be unlocked.
|
||||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||||
pub struct UnlockChunk<Balance: HasCompact> {
|
pub struct UnlockChunk<Balance: HasCompact> {
|
||||||
/// Amount of funds to be unlocked.
|
/// Amount of funds to be unlocked.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
value: Balance,
|
value: Balance,
|
||||||
/// Era number at which point it'll be unlocked.
|
/// Era number at which point it'll be unlocked.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
era: EraIndex,
|
era: EraIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The ledger of a (bonded) stash.
|
/// The ledger of a (bonded) stash.
|
||||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||||
pub struct StakingLedger<AccountId, Balance: HasCompact> {
|
pub struct StakingLedger<AccountId, Balance: HasCompact> {
|
||||||
/// The stash account whose balance is actually locked and at stake.
|
/// The stash account whose balance is actually locked and at stake.
|
||||||
pub stash: AccountId,
|
pub stash: AccountId,
|
||||||
/// The total amount of the stash's balance that we are currently accounting for.
|
/// The total amount of the stash's balance that we are currently accounting for.
|
||||||
/// It's just `active` plus all the `unlocking` balances.
|
/// It's just `active` plus all the `unlocking` balances.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
pub total: Balance,
|
pub total: Balance,
|
||||||
/// The total amount of the stash's balance that will be at stake in any forthcoming
|
/// The total amount of the stash's balance that will be at stake in any forthcoming
|
||||||
/// rounds.
|
/// rounds.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
pub active: Balance,
|
pub active: Balance,
|
||||||
/// Any balance that is becoming free, which may eventually be transferred out
|
/// Any balance that is becoming free, which may eventually be transferred out
|
||||||
/// of the stash (assuming it doesn't get slashed first).
|
/// of the stash (assuming it doesn't get slashed first).
|
||||||
pub unlocking: Vec<UnlockChunk<Balance>>,
|
pub unlocking: Vec<UnlockChunk<Balance>>,
|
||||||
/// List of eras for which the stakers behind a validator have claimed rewards. Only updated
|
/// List of eras for which the stakers behind a validator have claimed rewards. Only updated
|
||||||
/// for validators.
|
/// for validators.
|
||||||
pub claimed_rewards: Vec<EraIndex>,
|
pub claimed_rewards: Vec<EraIndex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const MODULE: &str = "Staking";
|
const MODULE: &str = "Staking";
|
||||||
@@ -184,7 +205,11 @@ impl<T: Staking> Store<T> for HistoryDepth<T> {
|
|||||||
type Returns = u32;
|
type Returns = u32;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.plain()?.key())
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.plain()?
|
||||||
|
.key())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +223,11 @@ impl<T: Staking> Store<T> for ValidatorCount<T> {
|
|||||||
type Returns = u32;
|
type Returns = u32;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.plain()?.key())
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.plain()?
|
||||||
|
.key())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +241,11 @@ impl<T: Staking> Store<T> for MinimumValidatorCount<T> {
|
|||||||
type Returns = u32;
|
type Returns = u32;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.plain()?.key())
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.plain()?
|
||||||
|
.key())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,7 +261,11 @@ impl<T: Staking> Store<T> for Invulnerables<T> {
|
|||||||
type Returns = Vec<T::AccountId>;
|
type Returns = Vec<T::AccountId>;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.plain()?.key())
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.plain()?
|
||||||
|
.key())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +279,11 @@ impl<T: Staking> Store<T> for Bonded<T> {
|
|||||||
type Returns = Vec<T::AccountId>;
|
type Returns = Vec<T::AccountId>;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.map()?.key(&self.0))
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.map()?
|
||||||
|
.key(&self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +297,11 @@ impl<T: Staking> Store<T> for Ledger<T> {
|
|||||||
type Returns = Option<StakingLedger<T::AccountId, ()>>;
|
type Returns = Option<StakingLedger<T::AccountId, ()>>;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.map()?.key(&self.0))
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.map()?
|
||||||
|
.key(&self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +315,11 @@ impl<T: Staking> Store<T> for Payee<T> {
|
|||||||
type Returns = RewardDestination;
|
type Returns = RewardDestination;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.map()?.key(&self.0))
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.map()?
|
||||||
|
.key(&self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,7 +333,11 @@ impl<T: Staking> Store<T> for Validators<T> {
|
|||||||
type Returns = ValidatorPrefs;
|
type Returns = ValidatorPrefs;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.map()?.key(&self.0))
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.map()?
|
||||||
|
.key(&self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,7 +351,11 @@ impl<T: Staking> Store<T> for Nominators<T> {
|
|||||||
type Returns = Option<Nominations<T::AccountId>>;
|
type Returns = Option<Nominations<T::AccountId>>;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.map()?.key(&self.0))
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.map()?
|
||||||
|
.key(&self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +372,11 @@ impl<T: Staking> Store<T> for CurrentEra<T> {
|
|||||||
type Returns = Option<EraIndex>;
|
type Returns = Option<EraIndex>;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.map()?.key(&self.0))
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.map()?
|
||||||
|
.key(&self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,9 +390,13 @@ pub struct ActiveEra<T: Staking>(pub PhantomData<T>);
|
|||||||
impl<T: Staking> Store<T> for ActiveEra<T> {
|
impl<T: Staking> Store<T> for ActiveEra<T> {
|
||||||
const MODULE: &'static str = MODULE;
|
const MODULE: &'static str = MODULE;
|
||||||
const FIELD: &'static str = "ActiveEra";
|
const FIELD: &'static str = "ActiveEra";
|
||||||
type Returns = Option<ActiveEraInfo>;
|
type Returns = Option<ActiveEraInfo>;
|
||||||
|
|
||||||
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
fn key(&self, metadata: &Metadata) -> Result<StorageKey, MetadataError> {
|
||||||
Ok(metadata.module(Self::MODULE)?.storage(Self::FIELD)?.map()?.key(&self.0))
|
Ok(metadata
|
||||||
|
.module(Self::MODULE)?
|
||||||
|
.storage(Self::FIELD)?
|
||||||
|
.map()?
|
||||||
|
.key(&self.0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user