domain_service/
rpc.rs

1//! A collection of node-specific RPC methods.
2//!
3//! Substrate provides the `sc-rpc` crate, which defines the core RPC layer
4//! used by Substrate nodes. This file extends those RPC definitions with
5//! capabilities that are specific to this project's runtime configuration.
6
7#![warn(missing_docs)]
8
9use domain_runtime_primitives::{Balance, Nonce};
10use jsonrpsee::RpcModule;
11use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
12use sc_client_api::{AuxStore, BlockBackend};
13use sc_network::service::traits::NetworkService;
14use sc_network_sync::SyncingService;
15use sc_service::{DatabaseSource, SpawnTaskHandle};
16use sc_transaction_pool::{ChainApi, Pool};
17use sc_transaction_pool_api::TransactionPool;
18use serde::de::DeserializeOwned;
19use sp_api::ProvideRuntimeApi;
20use sp_block_builder::BlockBuilder;
21use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
22use sp_core::{Decode, Encode};
23use sp_runtime::traits::Block as BlockT;
24use std::fmt::{Debug, Display};
25use std::sync::Arc;
26use substrate_frame_rpc_system::{System, SystemApiServer};
27use substrate_prometheus_endpoint::Registry;
28
29/// Full RPC dependencies.
30pub struct FullDeps<Block: BlockT, Client, TP, CA: ChainApi, BE, CIDP> {
31    /// The client instance to use.
32    pub client: Arc<Client>,
33    /// The chain backend.
34    pub backend: Arc<BE>,
35    /// Transaction pool instance.
36    pub pool: Arc<TP>,
37    /// Graph pool instance.
38    pub graph: Arc<Pool<CA>>,
39    /// Network service
40    pub network: Arc<dyn NetworkService>,
41    /// Chain syncing service
42    pub sync: Arc<SyncingService<Block>>,
43    /// Is node running as authority.
44    pub is_authority: bool,
45    /// Prometheus registry
46    pub prometheus_registry: Option<Registry>,
47    /// Database source
48    pub database_source: DatabaseSource,
49    /// Task Spawner.
50    pub task_spawner: SpawnTaskHandle,
51    /// Create inherent data provider
52    pub create_inherent_data_provider: CIDP,
53}
54
55impl<Block: BlockT, Client, TP, CA: ChainApi, BE, CIDP: Clone> Clone
56    for FullDeps<Block, Client, TP, CA, BE, CIDP>
57{
58    fn clone(&self) -> Self {
59        Self {
60            client: self.client.clone(),
61            backend: self.backend.clone(),
62            pool: self.pool.clone(),
63            graph: self.graph.clone(),
64            network: self.network.clone(),
65            sync: self.sync.clone(),
66            is_authority: self.is_authority,
67            task_spawner: self.task_spawner.clone(),
68            prometheus_registry: self.prometheus_registry.clone(),
69            database_source: self.database_source.clone(),
70            create_inherent_data_provider: self.create_inherent_data_provider.clone(),
71        }
72    }
73}
74
75/// Instantiate all RPC extensions.
76pub fn create_full<Block, Client, P, CA, AccountId, BE, CIDP>(
77    deps: FullDeps<Block, Client, P, CA, BE, CIDP>,
78) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
79where
80    Block: BlockT,
81    Client: ProvideRuntimeApi<Block>
82        + BlockBackend<Block>
83        + HeaderBackend<Block>
84        + AuxStore
85        + HeaderMetadata<Block, Error = BlockChainError>
86        + Send
87        + Sync
88        + 'static,
89    Client::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
90        + substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
91        + BlockBuilder<Block>,
92    P: TransactionPool + Sync + Send + 'static,
93    CA: ChainApi,
94    AccountId: DeserializeOwned + Encode + Debug + Decode + Display + Clone + Sync + Send + 'static,
95{
96    let mut module = RpcModule::new(());
97    let FullDeps { client, pool, .. } = deps;
98
99    module.merge(System::new(client.clone(), pool).into_rpc())?;
100    module.merge(TransactionPayment::new(client).into_rpc())?;
101
102    Ok(module)
103}