mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 08:41:07 +00:00
Era rewards point support
I also did some refactoring.
This commit is contained in:
+25
-69
@@ -25,37 +25,28 @@ use codec::{
|
|||||||
Encode,
|
Encode,
|
||||||
};
|
};
|
||||||
use frame_support::Parameter;
|
use frame_support::Parameter;
|
||||||
use sp_runtime::{
|
use sp_runtime::traits::{
|
||||||
traits::{
|
AtLeast32Bit,
|
||||||
AtLeast32Bit,
|
MaybeSerialize,
|
||||||
MaybeSerialize,
|
Member,
|
||||||
Member,
|
|
||||||
},
|
|
||||||
Perbill,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Debug,
|
fmt::Debug,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use pallet_staking::{
|
pub use pallet_staking::{
|
||||||
|
ActiveEraInfo,
|
||||||
EraIndex,
|
EraIndex,
|
||||||
|
EraRewardPoints,
|
||||||
|
Nominations,
|
||||||
|
RewardDestination,
|
||||||
|
RewardPoint,
|
||||||
StakingLedger,
|
StakingLedger,
|
||||||
|
ValidatorPrefs,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// 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> {
|
|
||||||
/// The targets of nomination.
|
|
||||||
pub targets: Vec<T::AccountId>,
|
|
||||||
/// The era the nominations were submitted.
|
|
||||||
///
|
|
||||||
/// Except for initial nominations which are considered submitted at era 0.
|
|
||||||
pub submitted_in: T::EraIndex,
|
|
||||||
/// Whether the nominations have been suppressed.
|
|
||||||
pub suppressed: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Similar to `ErasStakers`, this holds the preferences of validators.
|
/// 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.
|
/// This is keyed first by the era index to allow bulk deletion and then the stash account.
|
||||||
@@ -70,31 +61,17 @@ pub struct ErasValidatorPrefsStore<T: Staking> {
|
|||||||
account_id: T::AccountId,
|
account_id: T::AccountId,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information regarding the active era (era in used in session).
|
/// Rewards for the last `HISTORY_DEPTH` eras.
|
||||||
#[derive(Encode, Decode, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
/// If reward hasn't been set or has been removed then 0 reward is returned.
|
||||||
pub struct ActiveEraInfo<T: Staking> {
|
#[derive(Clone, Encode, Decode, Debug, Store)]
|
||||||
/// Index of era.
|
pub struct ErasRewardPoints<T: Staking> {
|
||||||
pub index: T::EraIndex,
|
#[store(returns = EraRewardPoints<T::AccountId>)]
|
||||||
/// Moment of start expresed as millisecond from `$UNIX_EPOCH`.
|
index: EraIndex,
|
||||||
///
|
_phantom: PhantomData<T>,
|
||||||
/// 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`.
|
|
||||||
pub start: Option<u64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A destination account for payment.
|
|
||||||
#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, Debug)]
|
|
||||||
pub enum RewardDestination {
|
|
||||||
/// Pay into the stash account, increasing the amount at stake accordingly.
|
|
||||||
Staked,
|
|
||||||
/// Pay into the stash account, not increasing the amount at stake.
|
|
||||||
Stash,
|
|
||||||
/// Pay into the controller account.
|
|
||||||
Controller,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Preference of what happens regarding validation.
|
/// Preference of what happens regarding validation.
|
||||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug, Call)]
|
#[derive(Clone, Encode, Decode, Debug, Call)]
|
||||||
pub struct SetPayeeCall<T: Staking> {
|
pub struct SetPayeeCall<T: Staking> {
|
||||||
/// The payee
|
/// The payee
|
||||||
pub payee: RewardDestination,
|
pub payee: RewardDestination,
|
||||||
@@ -102,23 +79,6 @@ pub struct SetPayeeCall<T: Staking> {
|
|||||||
pub _runtime: PhantomData<T>,
|
pub _runtime: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Preference of what happens regarding validation.
|
|
||||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, Debug)]
|
|
||||||
pub struct ValidatorPrefs {
|
|
||||||
/// Reward that validator takes up-front; only the rest is split between themselves and
|
|
||||||
/// nominators.
|
|
||||||
#[codec(compact)]
|
|
||||||
pub commission: Perbill,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ValidatorPrefs {
|
|
||||||
fn default() -> Self {
|
|
||||||
ValidatorPrefs {
|
|
||||||
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.
|
||||||
#[module]
|
#[module]
|
||||||
pub trait Staking: Balances {
|
pub trait Staking: Balances {
|
||||||
@@ -170,7 +130,7 @@ pub trait Staking: Balances {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 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, Ord, PartialOrd, Hash, Debug)]
|
#[derive(Clone, Encode, Decode, Debug)]
|
||||||
pub struct UnlockChunk<T: Staking> {
|
pub struct UnlockChunk<T: Staking> {
|
||||||
/// Amount of funds to be unlocked.
|
/// Amount of funds to be unlocked.
|
||||||
#[codec(compact)]
|
#[codec(compact)]
|
||||||
@@ -187,9 +147,7 @@ pub struct UnlockChunk<T: Staking> {
|
|||||||
/// Must be more than the number of eras delayed by session otherwise.
|
/// Must be more than the number of eras delayed by session otherwise.
|
||||||
/// I.e. active era must always be in history.
|
/// I.e. active era must always be in history.
|
||||||
/// I.e. `active_era > current_era - history_depth` must be guaranteed.
|
/// I.e. `active_era > current_era - history_depth` must be guaranteed.
|
||||||
#[derive(
|
#[derive(Encode, Decode, Copy, Clone, Debug, Default, Store)]
|
||||||
Encode, Decode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store,
|
|
||||||
)]
|
|
||||||
pub struct HistoryDepthStore<T: Staking> {
|
pub struct HistoryDepthStore<T: Staking> {
|
||||||
#[store(returns = u32)]
|
#[store(returns = u32)]
|
||||||
/// Marker for the runtime
|
/// Marker for the runtime
|
||||||
@@ -197,9 +155,7 @@ pub struct HistoryDepthStore<T: Staking> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The ideal number of staking participants.
|
/// The ideal number of staking participants.
|
||||||
#[derive(
|
#[derive(Encode, Decode, Copy, Clone, Debug, Store)]
|
||||||
Encode, Decode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store,
|
|
||||||
)]
|
|
||||||
pub struct ValidatorCountStore<T: Staking> {
|
pub struct ValidatorCountStore<T: Staking> {
|
||||||
#[store(returns = u32)]
|
#[store(returns = u32)]
|
||||||
/// Marker for the runtime
|
/// Marker for the runtime
|
||||||
@@ -259,9 +215,9 @@ pub struct ValidatorsStore<T: Staking> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The map from nominator stash key to the set of stash keys of all validators to nominate.
|
/// The map from nominator stash key to the set of stash keys of all validators to nominate.
|
||||||
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
|
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Store)]
|
||||||
pub struct NominatorsStore<T: Staking> {
|
pub struct NominatorsStore<T: Staking> {
|
||||||
#[store(returns = Option<Nominations<T>>)]
|
#[store(returns = Option<Nominations<T::AccountId>>)]
|
||||||
/// Tٗhe stash account
|
/// Tٗhe stash account
|
||||||
pub stash: T::AccountId,
|
pub stash: T::AccountId,
|
||||||
}
|
}
|
||||||
@@ -283,7 +239,7 @@ pub struct CurrentEraStore<T: Staking> {
|
|||||||
/// Validator set of this era must be equal to `SessionInterface::validators`.
|
/// Validator set of this era must be equal to `SessionInterface::validators`.
|
||||||
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
|
#[derive(Encode, Copy, Clone, Debug, Hash, PartialEq, Eq, Ord, PartialOrd, Store)]
|
||||||
pub struct ActiveEraStore<T: Staking> {
|
pub struct ActiveEraStore<T: Staking> {
|
||||||
#[store(returns = Option<ActiveEraInfo<T>>)]
|
#[store(returns = Option<ActiveEraInfo>)]
|
||||||
/// Marker for the runtime
|
/// Marker for the runtime
|
||||||
pub _runtime: PhantomData<T>,
|
pub _runtime: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user