use crate::{dispatch::Parameter, weights::Weight};
use alloc::{vec, vec::Vec};
use codec::{Codec, Decode, MaxEncodedLen};
use sp_runtime::{
traits::{Convert, Zero},
BoundToRuntimeAppPublic, ConsensusEngineId, Permill, RuntimeAppPublic,
};
use sp_staking::SessionIndex;
pub trait ValidatorSet<AccountId> {
type ValidatorId: Parameter + MaxEncodedLen;
type ValidatorIdOf: Convert<AccountId, Option<Self::ValidatorId>>;
fn session_index() -> SessionIndex;
fn validators() -> Vec<Self::ValidatorId>;
}
pub trait ValidatorSetWithIdentification<AccountId>: ValidatorSet<AccountId> {
type Identification: Parameter;
type IdentificationOf: Convert<Self::ValidatorId, Option<Self::Identification>>;
}
pub trait FindAuthor<Author> {
fn find_author<'a, I>(digests: I) -> Option<Author>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>;
}
impl<A> FindAuthor<A> for () {
fn find_author<'a, I>(_: I) -> Option<A>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
{
None
}
}
pub trait VerifySeal<Header, Author> {
fn verify_seal(header: &Header) -> Result<Option<Author>, &'static str>;
}
pub trait OneSessionHandler<ValidatorId>: BoundToRuntimeAppPublic {
type Key: Decode + RuntimeAppPublic;
fn on_genesis_session<'a, I: 'a>(validators: I)
where
I: Iterator<Item = (&'a ValidatorId, Self::Key)>,
ValidatorId: 'a;
fn on_new_session<'a, I: 'a>(changed: bool, validators: I, queued_validators: I)
where
I: Iterator<Item = (&'a ValidatorId, Self::Key)>,
ValidatorId: 'a;
fn on_before_session_ending() {}
fn on_disabled(_validator_index: u32);
}
pub trait EstimateNextSessionRotation<BlockNumber> {
fn average_session_length() -> BlockNumber;
fn estimate_current_session_progress(now: BlockNumber) -> (Option<Permill>, Weight);
fn estimate_next_session_rotation(now: BlockNumber) -> (Option<BlockNumber>, Weight);
}
impl<BlockNumber: Zero> EstimateNextSessionRotation<BlockNumber> for () {
fn average_session_length() -> BlockNumber {
Zero::zero()
}
fn estimate_current_session_progress(_: BlockNumber) -> (Option<Permill>, Weight) {
(None, Zero::zero())
}
fn estimate_next_session_rotation(_: BlockNumber) -> (Option<BlockNumber>, Weight) {
(None, Zero::zero())
}
}
pub trait EstimateNextNewSession<BlockNumber> {
fn average_session_length() -> BlockNumber;
fn estimate_next_new_session(_: BlockNumber) -> (Option<BlockNumber>, Weight);
}
impl<BlockNumber: Zero> EstimateNextNewSession<BlockNumber> for () {
fn average_session_length() -> BlockNumber {
Zero::zero()
}
fn estimate_next_new_session(_: BlockNumber) -> (Option<BlockNumber>, Weight) {
(None, Zero::zero())
}
}
pub trait KeyOwnerProofSystem<Key> {
type Proof: Codec;
type IdentificationTuple: Codec;
fn prove(key: Key) -> Option<Self::Proof>;
fn check_proof(key: Key, proof: Self::Proof) -> Option<Self::IdentificationTuple>;
}
impl<Key> KeyOwnerProofSystem<Key> for () {
type Proof = sp_core::Void;
type IdentificationTuple = sp_core::Void;
fn prove(_key: Key) -> Option<Self::Proof> {
None
}
fn check_proof(_key: Key, _proof: Self::Proof) -> Option<Self::IdentificationTuple> {
None
}
}
pub trait Lateness<N> {
fn lateness(&self) -> N;
}
impl<N: Zero> Lateness<N> for () {
fn lateness(&self) -> N {
Zero::zero()
}
}
pub trait ValidatorRegistration<ValidatorId> {
fn is_registered(id: &ValidatorId) -> bool;
}
pub trait DisabledValidators {
fn is_disabled(index: u32) -> bool;
fn disabled_validators() -> Vec<u32>;
}
impl DisabledValidators for () {
fn is_disabled(_index: u32) -> bool {
false
}
fn disabled_validators() -> Vec<u32> {
vec![]
}
}