[][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 )* },
		}
	) => { ... };
}

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

construct_service_factory! {
	struct Factory {
        // Declare the block type
		Block = Block,
        // Declare the network protocol and give an initializer.
		NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) },
		RuntimeDispatch = node_executor::Executor,
		FullTransactionPoolApi = transaction_pool::ChainApi<FullBackend<Self>, FullExecutor<Self>, Block>
			{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
		LightTransactionPoolApi = transaction_pool::ChainApi<LightBackend<Self>, LightExecutor<Self>, Block>
			{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
		Genesis = GenesisConfig,
		Configuration = (),
		FullService = Service<FullComponents<Self>>
			{ |config, executor| Service::<FullComponents<Factory>>::new(config, executor) },
        // Setup as Consensus Authority (if the role and key are given)
		AuthoritySetup = {
			|service: Self::FullService, executor: TaskExecutor, key: Arc<Pair>| { Ok(service) }},
		LightService = Service<LightComponents<Self>>
			{ |config, executor| Service::<LightComponents<Factory>>::new(config, executor) },
        // Declare the import queue. The import queue is special as it takes two initializers.
        // The first one is for the initializing the full import queue and the second for the
        // light import queue.
		ImportQueue = BasicQueue<Block, NoneVerifier>
			{ |_, client| Ok(BasicQueue::new(Arc::new(NoneVerifier {}, client))) }
			{ |_, client| Ok(BasicQueue::new(Arc::new(NoneVerifier {}, client))) },
	}
}