use alloc::vec::Vec;
use codec::{Decode, Encode};
use polkadot_primitives::{ApprovedPeerId, CoreSelector, Header as RelayChainHeader};
use sp_runtime::traits::{BlakeTwo256, Hash as HashT};
#[derive(Clone, Encode, Decode, Debug, PartialEq, Eq)]
pub struct SchedulingInfoPayload {
pub core_selector: CoreSelector,
pub claim_queue_offset: u8,
pub peer_id: ApprovedPeerId,
pub internal_scheduling_parent: polkadot_primitives::Hash,
}
#[derive(Clone, Encode, Decode, Debug, PartialEq, Eq)]
pub struct SignedSchedulingInfo {
pub payload: SchedulingInfoPayload,
pub signature: [u8; 64],
}
impl SchedulingInfoPayload {
pub fn new(
core_selector: CoreSelector,
claim_queue_offset: u8,
peer_id: ApprovedPeerId,
internal_scheduling_parent: polkadot_primitives::Hash,
) -> Self {
Self { core_selector, claim_queue_offset, peer_id, internal_scheduling_parent }
}
}
#[derive(Clone, Encode, Decode, Debug, PartialEq, Eq)]
pub struct SchedulingProof {
pub header_chain: Vec<RelayChainHeader>,
pub internal_scheduling_parent_header: RelayChainHeader,
pub signed_scheduling_info: Option<SignedSchedulingInfo>,
}
impl SchedulingProof {
pub fn scheduling_parent(&self) -> polkadot_primitives::Hash {
self.header_chain
.first()
.map(BlakeTwo256::hash_of)
.unwrap_or_else(|| self.internal_scheduling_parent_header.hash())
}
}
pub trait VerifySchedulingSignature {
const V3_SCHEDULING_ENABLED: bool;
fn verify(
signed_info: &SignedSchedulingInfo,
internal_scheduling_parent_header: &RelayChainHeader,
) -> bool;
}
impl VerifySchedulingSignature for () {
const V3_SCHEDULING_ENABLED: bool = false;
fn verify(
_signed_info: &SignedSchedulingInfo,
_internal_scheduling_parent_header: &RelayChainHeader,
) -> bool {
true
}
}