1use anyhow::{Result, anyhow};
4use service::{
5 EntropyBuffer, OpaqueHash, ServiceId,
6 service::{RefineContext, ServiceAccount},
7};
8use std::collections::BTreeMap;
9
10#[derive(Clone, Default)]
12pub struct Head {
13 pub hash: OpaqueHash,
15
16 pub slot: u32,
18}
19
20#[derive(Clone, Default)]
22pub struct Chain {
23 pub best: Head,
25
26 pub entropy: EntropyBuffer,
28
29 pub finalized: Head,
31
32 pub accounts: BTreeMap<u32, ServiceAccount>,
34}
35
36impl Chain {
37 pub fn service(&self, service: ServiceId) -> Result<OpaqueHash> {
39 self.accounts
40 .get(&service)
41 .map(|account| account.info.code)
42 .ok_or_else(|| anyhow!("Service not found"))
43 }
44
45 pub fn refine_context(&self) -> RefineContext {
49 RefineContext {
50 anchor: self.best.hash,
51 state_root: Default::default(),
52 beefy_root: Default::default(),
53 lookup_anchor: self.finalized.hash,
54 lookup_anchor_slot: self.finalized.slot,
55 prerequisites: Default::default(),
56 }
57 }
58}