[][src]Macro substrate_service::construct_service_factory

macro_rules! construct_service_factory {
    (
		$(#[$attr:meta])*
		struct $name:ident {
			Block = $block:ty,
			RuntimeApi = $runtime_api:ty,
			NetworkProtocol = $protocol:ty { $( $protocol_init:tt )* },
			RuntimeDispatch = $dispatch:ty,
			FullTransactionPoolApi = $full_transaction:ty { $( $full_transaction_init:tt )* },
			LightTransactionPoolApi = $light_transaction:ty { $( $light_transaction_init:tt )* },
			Genesis = $genesis:ty,
			Configuration = $config:ty,
			FullService = $full_service:ty { $( $full_service_init:tt )* },
			AuthoritySetup = { $( $authority_setup:tt )* },
			LightService = $light_service:ty { $( $light_service_init:tt )* },
			FullImportQueue = $full_import_queue:ty
				{ $( $full_import_queue_init:tt )* },
			LightImportQueue = $light_import_queue:ty
				{ $( $light_import_queue_init:tt )* },
			SelectChain = $select_chain:ty
				{ $( $select_chain_init:tt )* },
			FinalityProofProvider = { $( $finality_proof_provider_init:tt )* },
		}
	) => { ... };
}

Constructs a service factory with the given name that implements the ServiceFactory trait. The required parameters are required to be given in the exact order. Some parameters are followed by {} blocks. These blocks are required and used to initialize the given parameter. In these block it is required to write a closure that takes the same number of arguments, the corresponding function in the ServiceFactory trait provides.

Example

type FullChainApi<T> = transaction_pool::ChainApi<
	client::Client<FullBackend<T>, FullExecutor<T>, Block, RuntimeApi>, Block>;
type LightChainApi<T> = transaction_pool::ChainApi<
	client::Client<LightBackend<T>, LightExecutor<T>, Block, RuntimeApi>, Block>;

construct_service_factory! {
	struct Factory {
		// Declare the block type
		Block = Block,
		RuntimeApi = RuntimeApi,
		// Declare the network protocol and give an initializer.
		NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) },
		RuntimeDispatch = node_executor::Executor,
		FullTransactionPoolApi = FullChainApi<Self>
			{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
		LightTransactionPoolApi = LightChainApi<Self>
			{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
		Genesis = GenesisConfig,
		Configuration = (),
		FullService = FullComponents<Self>
			{ |config| <FullComponents<Factory>>::new(config) },
		// Setup as Consensus Authority (if the role and key are given)
		AuthoritySetup = {
			|service: Self::FullService| {
				Ok(service)
			}},
		LightService = LightComponents<Self>
			{ |config| <LightComponents<Factory>>::new(config) },
		FullImportQueue = BasicQueue<Block>
			{ |_, client, _, _| Ok(BasicQueue::new(MyVerifier, Box::new(client), None, None)) },
		LightImportQueue = BasicQueue<Block>
			{ |_, client| {
				let fprb = Box::new(DummyFinalityProofRequestBuilder::default()) as Box<_>;
				Ok((BasicQueue::new(MyVerifier, Box::new(client), None, None), fprb))
			}},
		SelectChain = LongestChain<FullBackend<Self>, Self::Block>
			{ |config: &FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>| {
				#[allow(deprecated)]
				Ok(LongestChain::new(client.backend().clone()))
			}},
		FinalityProofProvider = { |client: Arc<FullClient<Self>>| {
				Ok(Some(Arc::new(grandpa::FinalityProofProvider::new(client.clone(), client)) as _))
			}},
	}
}