moonbeam_service/lazy_loading/
client.rs1use crate::lazy_loading;
18use crate::lazy_loading::{TLazyLoadingBackend, TLazyLoadingCallExecutor};
19use cumulus_primitives_core::BlockT;
20use sc_chain_spec::BuildGenesisBlock;
21use sc_client_api::execution_extensions::ExecutionExtensions;
22use sc_client_api::{BadBlocks, ForkBlocks};
23use sc_executor::RuntimeVersionOf;
24use sc_service::client::Client;
25use sc_service::{ClientConfig, LocalCallExecutor};
26use sc_telemetry::TelemetryHandle;
27use sp_core::traits::{CodeExecutor, SpawnNamed};
28use std::sync::Arc;
29
30pub fn new_client<E, Block, RA, G>(
31 backend: Arc<TLazyLoadingBackend<Block>>,
32 executor: E,
33 genesis_block_builder: G,
34 fork_blocks: ForkBlocks<Block>,
35 bad_blocks: BadBlocks<Block>,
36 execution_extensions: ExecutionExtensions<Block>,
37 spawn_handle: Box<dyn SpawnNamed>,
38 prometheus_registry: Option<substrate_prometheus_endpoint::Registry>,
39 telemetry: Option<TelemetryHandle>,
40 config: ClientConfig<Block>,
41) -> Result<
42 Client<TLazyLoadingBackend<Block>, TLazyLoadingCallExecutor<Block, E>, Block, RA>,
43 sp_blockchain::Error,
44>
45where
46 Block: BlockT + sp_runtime::DeserializeOwned,
47 Block::Hash: From<sp_core::H256>,
48 E: CodeExecutor + RuntimeVersionOf,
49 TLazyLoadingBackend<Block>: sc_client_api::Backend<Block> + 'static,
50 G: BuildGenesisBlock<
51 Block,
52 BlockImportOperation = <TLazyLoadingBackend<Block> as sc_client_api::backend::Backend<
53 Block,
54 >>::BlockImportOperation,
55 >,
56{
57 let executor =
58 lazy_loading::call_executor::LazyLoadingCallExecutor::new(LocalCallExecutor::new(
59 backend.clone(),
60 executor,
61 config.clone(),
62 execution_extensions,
63 )?)?;
64
65 Client::new(
66 backend,
67 executor,
68 spawn_handle,
69 genesis_block_builder,
70 fork_blocks,
71 bad_blocks,
72 prometheus_registry,
73 telemetry,
74 config,
75 )
76}