use anyhow::{Result, anyhow};
use service::{
EntropyBuffer, OpaqueHash, ServiceId,
service::{RefineContext, ServiceAccount},
};
use std::collections::BTreeMap;
#[derive(Clone, Default)]
pub struct Head {
pub hash: OpaqueHash,
pub slot: u32,
}
#[derive(Clone, Default)]
pub struct Chain {
pub best: Head,
pub entropy: EntropyBuffer,
pub finalized: Head,
pub accounts: BTreeMap<u32, ServiceAccount>,
}
impl Chain {
pub fn service(&self, service: ServiceId) -> Result<OpaqueHash> {
self.accounts
.get(&service)
.map(|account| account.info.code)
.ok_or_else(|| anyhow!("Service not found"))
}
pub fn refine_context(&self) -> RefineContext {
RefineContext {
anchor: self.best.hash,
state_root: Default::default(),
beefy_root: Default::default(),
lookup_anchor: self.finalized.hash,
lookup_anchor_slot: self.finalized.slot,
prerequisites: Default::default(),
}
}
}