use sc_cli::Result;
use sp_core::traits::{RuntimeCode, WrappedRuntimeCode};
use sp_runtime::traits::Hash;
pub enum FetchedCode<'a, B, H> {
FromGenesis { state: sp_state_machine::backend::BackendRuntimeCode<'a, B, H> },
FromFile { wrapped_code: WrappedRuntimeCode<'a>, heap_pages: Option<u64>, hash: Vec<u8> },
}
impl<'a, B, H> FetchedCode<'a, B, H>
where
H: Hash,
B: sc_client_api::StateBackend<H>,
{
pub fn code(&'a self) -> Result<RuntimeCode<'a>> {
match self {
Self::FromGenesis { state } => state.runtime_code().map_err(Into::into),
Self::FromFile { wrapped_code, heap_pages, hash } => Ok(RuntimeCode {
code_fetcher: wrapped_code,
heap_pages: *heap_pages,
hash: hash.clone(),
}),
}
}
}
pub(crate) type ComponentRangeMap =
std::collections::HashMap<(String, String), Vec<ComponentRange>>;
#[derive(serde::Serialize, Debug, Clone, Eq, PartialEq)]
pub(crate) struct ComponentRange {
pub(crate) name: String,
pub(crate) min: u32,
pub(crate) max: u32,
}