pub enum ValidatorStake {
    V1(ValidatorStakeV1),
}
Expand description

Stores validator and its stake.

Variants§

Implementations§

source§

impl ValidatorStake

source

pub fn new_v1( account_id: AccountId, public_key: PublicKey, stake: Balance ) -> Self

source

pub fn new(account_id: AccountId, public_key: PublicKey, stake: Balance) -> Self

source

pub fn into_v1(self) -> ValidatorStakeV1

source

pub fn account_and_stake(self) -> (AccountId, Balance)

source

pub fn destructure(self) -> (AccountId, PublicKey, Balance)

source

pub fn take_account_id(self) -> AccountId

source

pub fn account_id(&self) -> &AccountId

source

pub fn take_public_key(self) -> PublicKey

source

pub fn public_key(&self) -> &PublicKey

source

pub fn stake(&self) -> Balance

source

pub fn stake_mut(&mut self) -> &mut Balance

source

pub fn get_approval_stake(&self, is_next_epoch: bool) -> ApprovalStake

source

pub fn num_mandates(&self, stake_per_mandate: Balance) -> u16

Returns the validator’s number of mandates (rounded down) at stake_per_seat.

It returns u16 since it allows infallible conversion to usize and with u16::MAX equalling 65_535 it should be sufficient to hold the number of mandates per validator.

§Why u16 should be sufficient

As of October 2023, a recommended lower bound for the stake required per mandate is 25k $NEAR. At this price, the validator with highest stake would have 1_888 mandates, which is well below u16::MAX.

From another point of view, with more than u16::MAX mandates for validators, sampling mandates might become computationally too expensive. This might trigger an increase in the required stake per mandate, bringing down the number of mandates per validator.

§Panics

Panics if the number of mandates overflows u16.

source

pub fn partial_mandate_weight(&self, stake_per_mandate: Balance) -> Balance

Returns the weight attributed to the validator’s partial mandate.

A validator has a partial mandate if its stake cannot be divided evenly by stake_per_mandate. The remainder of that division is the weight of the partial mandate.

Due to this definintion a validator has exactly one partial mandate with 0 <= weight < stake_per_mandate.

§Example

Let V be a validator with stake of 12. If stake_per_mandate equals 5 then the weight of V’s partial mandate is 12 % 5 = 2.

Trait Implementations§

source§

impl BorshDeserialize for ValidatorStake

source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

source§

impl BorshSerialize for ValidatorStake

source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

source§

impl Clone for ValidatorStake

source§

fn clone(&self) -> ValidatorStake

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ValidatorStake

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl EnumExt for ValidatorStake

source§

fn deserialize_variant<__R: Read>( reader: &mut __R, variant_tag: u8 ) -> Result<Self, Error>

Deserialises given variant of an enum from the reader. Read more
source§

impl From<ValidatorStake> for ValidatorStakeView

source§

fn from(stake: ValidatorStake) -> Self

Converts to this type from the input type.
source§

impl From<ValidatorStakeView> for ValidatorStake

source§

fn from(view: ValidatorStakeView) -> Self

Converts to this type from the input type.
source§

impl PartialEq for ValidatorStake

source§

fn eq(&self, other: &ValidatorStake) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for ValidatorStake

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for ValidatorStake

source§

impl StructuralPartialEq for ValidatorStake

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more