pub trait StakingInterface {
type Balance: Sub<Output = Self::Balance> + Ord + PartialEq + Default + Copy + MaxEncodedLen + FullCodec + TypeInfo + Saturating;
type AccountId: Clone + Debug;
type CurrencyToVote: CurrencyToVote<Self::Balance>;
Show 26 methods
// Required methods
fn minimum_nominator_bond() -> Self::Balance;
fn minimum_validator_bond() -> Self::Balance;
fn stash_by_ctrl(
controller: &Self::AccountId,
) -> Result<Self::AccountId, DispatchError>;
fn bonding_duration() -> EraIndex;
fn current_era() -> EraIndex;
fn stake(
who: &Self::AccountId,
) -> Result<Stake<Self::Balance>, DispatchError>;
fn bond(
who: &Self::AccountId,
value: Self::Balance,
payee: &Self::AccountId,
) -> DispatchResult;
fn nominate(
who: &Self::AccountId,
validators: Vec<Self::AccountId>,
) -> DispatchResult;
fn chill(who: &Self::AccountId) -> DispatchResult;
fn bond_extra(who: &Self::AccountId, extra: Self::Balance) -> DispatchResult;
fn unbond(stash: &Self::AccountId, value: Self::Balance) -> DispatchResult;
fn set_payee(
stash: &Self::AccountId,
reward_acc: &Self::AccountId,
) -> DispatchResult;
fn withdraw_unbonded(
stash: Self::AccountId,
num_slashing_spans: u32,
) -> Result<bool, DispatchError>;
fn desired_validator_count() -> u32;
fn election_ongoing() -> bool;
fn force_unstake(who: Self::AccountId) -> DispatchResult;
fn is_exposed_in_era(who: &Self::AccountId, era: &EraIndex) -> bool;
fn status(
who: &Self::AccountId,
) -> Result<StakerStatus<Self::AccountId>, DispatchError>;
fn is_virtual_staker(who: &Self::AccountId) -> bool;
fn slash_reward_fraction() -> Perbill;
// Provided methods
fn total_stake(
who: &Self::AccountId,
) -> Result<Self::Balance, DispatchError> { ... }
fn active_stake(
who: &Self::AccountId,
) -> Result<Self::Balance, DispatchError> { ... }
fn is_unbonding(who: &Self::AccountId) -> Result<bool, DispatchError> { ... }
fn fully_unbond(who: &Self::AccountId) -> DispatchResult { ... }
fn is_validator(who: &Self::AccountId) -> bool { ... }
fn nominations(who: &Self::AccountId) -> Option<Vec<Self::AccountId>> { ... }
}
Expand description
A generic representation of a staking implementation.
This interface uses the terminology of NPoS, but it is aims to be generic enough to cover other implementations as well.
Required Associated Types§
sourcetype Balance: Sub<Output = Self::Balance> + Ord + PartialEq + Default + Copy + MaxEncodedLen + FullCodec + TypeInfo + Saturating
type Balance: Sub<Output = Self::Balance> + Ord + PartialEq + Default + Copy + MaxEncodedLen + FullCodec + TypeInfo + Saturating
Balance type used by the staking system.
sourcetype CurrencyToVote: CurrencyToVote<Self::Balance>
type CurrencyToVote: CurrencyToVote<Self::Balance>
Means of converting Currency to VoteWeight.
Required Methods§
sourcefn minimum_nominator_bond() -> Self::Balance
fn minimum_nominator_bond() -> Self::Balance
The minimum amount required to bond in order to set nomination intentions. This does not necessarily mean the nomination will be counted in an election, but instead just enough to be stored as a nominator. In other words, this is the minimum amount to register the intention to nominate.
sourcefn minimum_validator_bond() -> Self::Balance
fn minimum_validator_bond() -> Self::Balance
The minimum amount required to bond in order to set validation intentions.
sourcefn stash_by_ctrl(
controller: &Self::AccountId,
) -> Result<Self::AccountId, DispatchError>
fn stash_by_ctrl( controller: &Self::AccountId, ) -> Result<Self::AccountId, DispatchError>
Return a stash account that is controlled by a controller
.
§Note
The controller abstraction is not permanent and might go away. Avoid using this as much as possible.
sourcefn bonding_duration() -> EraIndex
fn bonding_duration() -> EraIndex
Number of eras that staked funds must remain bonded for.
sourcefn current_era() -> EraIndex
fn current_era() -> EraIndex
The current era index.
This should be the latest planned era that the staking system knows about.
sourcefn stake(who: &Self::AccountId) -> Result<Stake<Self::Balance>, DispatchError>
fn stake(who: &Self::AccountId) -> Result<Stake<Self::Balance>, DispatchError>
Returns the Stake
of who
.
sourcefn bond(
who: &Self::AccountId,
value: Self::Balance,
payee: &Self::AccountId,
) -> DispatchResult
fn bond( who: &Self::AccountId, value: Self::Balance, payee: &Self::AccountId, ) -> DispatchResult
Bond (lock) value
of who
’s balance, while forwarding any rewards to payee
.
sourcefn nominate(
who: &Self::AccountId,
validators: Vec<Self::AccountId>,
) -> DispatchResult
fn nominate( who: &Self::AccountId, validators: Vec<Self::AccountId>, ) -> DispatchResult
Have who
nominate validators
.
sourcefn chill(who: &Self::AccountId) -> DispatchResult
fn chill(who: &Self::AccountId) -> DispatchResult
Chill who
.
sourcefn bond_extra(who: &Self::AccountId, extra: Self::Balance) -> DispatchResult
fn bond_extra(who: &Self::AccountId, extra: Self::Balance) -> DispatchResult
Bond some extra amount in who
’s free balance against the active bonded balance of
the account. The amount extra actually bonded will never be more than who
’s free
balance.
sourcefn unbond(stash: &Self::AccountId, value: Self::Balance) -> DispatchResult
fn unbond(stash: &Self::AccountId, value: Self::Balance) -> DispatchResult
Schedule a portion of the active bonded balance to be unlocked at era
Self::current_era + Self::bonding_duration
.
Once the unlock era has been reached, Self::withdraw_unbonded
can be called to unlock
the funds.
The amount of times this can be successfully called is limited based on how many distinct
eras funds are schedule to unlock in. Calling Self::withdraw_unbonded
after some unlock
schedules have reached their unlocking era should allow more calls to this function.
sourcefn set_payee(
stash: &Self::AccountId,
reward_acc: &Self::AccountId,
) -> DispatchResult
fn set_payee( stash: &Self::AccountId, reward_acc: &Self::AccountId, ) -> DispatchResult
Set the reward destination for the ledger associated with the stash.
sourcefn withdraw_unbonded(
stash: Self::AccountId,
num_slashing_spans: u32,
) -> Result<bool, DispatchError>
fn withdraw_unbonded( stash: Self::AccountId, num_slashing_spans: u32, ) -> Result<bool, DispatchError>
Unlock any funds schedule to unlock before or at the current era.
Returns whether the stash was killed because of this withdraw or not.
sourcefn desired_validator_count() -> u32
fn desired_validator_count() -> u32
The ideal number of active validators.
sourcefn election_ongoing() -> bool
fn election_ongoing() -> bool
Whether or not there is an ongoing election.
sourcefn force_unstake(who: Self::AccountId) -> DispatchResult
fn force_unstake(who: Self::AccountId) -> DispatchResult
Force a current staker to become completely unstaked, immediately.
sourcefn is_exposed_in_era(who: &Self::AccountId, era: &EraIndex) -> bool
fn is_exposed_in_era(who: &Self::AccountId, era: &EraIndex) -> bool
Checks whether an account staker
has been exposed in an era.
sourcefn status(
who: &Self::AccountId,
) -> Result<StakerStatus<Self::AccountId>, DispatchError>
fn status( who: &Self::AccountId, ) -> Result<StakerStatus<Self::AccountId>, DispatchError>
Return the status of the given staker, Err
if not staked at all.
sourcefn is_virtual_staker(who: &Self::AccountId) -> bool
fn is_virtual_staker(who: &Self::AccountId) -> bool
Checks whether the staker is a virtual account.
A virtual staker is an account whose locks are not managed by the StakingInterface
implementation but by an external pallet. See StakingUnchecked::virtual_bond
for more
details.
sourcefn slash_reward_fraction() -> Perbill
fn slash_reward_fraction() -> Perbill
Returns the fraction of the slash to be rewarded to reporter.
Provided Methods§
sourcefn total_stake(who: &Self::AccountId) -> Result<Self::Balance, DispatchError>
fn total_stake(who: &Self::AccountId) -> Result<Self::Balance, DispatchError>
Total stake of a staker, Err
if not a staker.
sourcefn active_stake(who: &Self::AccountId) -> Result<Self::Balance, DispatchError>
fn active_stake(who: &Self::AccountId) -> Result<Self::Balance, DispatchError>
Total active portion of a staker’s Stake
, Err
if not a staker.
sourcefn is_unbonding(who: &Self::AccountId) -> Result<bool, DispatchError>
fn is_unbonding(who: &Self::AccountId) -> Result<bool, DispatchError>
Returns whether a staker is unbonding, Err
if not a staker at all.
sourcefn fully_unbond(who: &Self::AccountId) -> DispatchResult
fn fully_unbond(who: &Self::AccountId) -> DispatchResult
Returns whether a staker is FULLY unbonding, Err
if not a staker at all.
sourcefn is_validator(who: &Self::AccountId) -> bool
fn is_validator(who: &Self::AccountId) -> bool
Checks whether or not this is a validator account.