#![warn(missing_docs)]
use smallvec::SmallVec;
use std::fmt;
pub use pezkuwi_primitives::{Block, BlockNumber, Hash};
pub type UnpinHandle = pezsc_client_api::UnpinHandle<Block>;
pub mod errors;
pub mod messages;
mod runtime_client;
pub use runtime_client::{ChainApiBackend, DefaultSubsystemClient, RuntimeApiSubsystemClient};
const ACTIVE_LEAVES_SMALLVEC_CAPACITY: usize = 8;
#[derive(Debug, Clone)]
pub struct ActivatedLeaf {
pub hash: Hash,
pub number: BlockNumber,
pub unpin_handle: UnpinHandle,
}
#[derive(Clone, Default)]
pub struct ActiveLeavesUpdate {
pub activated: Option<ActivatedLeaf>,
pub deactivated: SmallVec<[Hash; ACTIVE_LEAVES_SMALLVEC_CAPACITY]>,
}
impl ActiveLeavesUpdate {
pub fn start_work(activated: ActivatedLeaf) -> Self {
Self { activated: Some(activated), ..Default::default() }
}
pub fn stop_work(hash: Hash) -> Self {
Self { deactivated: [hash][..].into(), ..Default::default() }
}
pub fn is_empty(&self) -> bool {
self.activated.is_none() && self.deactivated.is_empty()
}
}
impl PartialEq for ActiveLeavesUpdate {
fn eq(&self, other: &Self) -> bool {
self.activated.as_ref().map(|a| a.hash) == other.activated.as_ref().map(|a| a.hash)
&& self.deactivated.len() == other.deactivated.len()
&& self.deactivated.iter().all(|a| other.deactivated.contains(a))
}
}
impl fmt::Debug for ActiveLeavesUpdate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ActiveLeavesUpdate")
.field("activated", &self.activated)
.field("deactivated", &self.deactivated)
.finish()
}
}
#[derive(PartialEq, Clone, Debug)]
pub enum OverseerSignal {
ActiveLeaves(ActiveLeavesUpdate),
BlockFinalized(Hash, BlockNumber),
Conclude,
}