referrerpolicy=no-referrer-when-downgrade

parachain_template_node/
rpc.rs

1//! A collection of node-specific RPC methods.
2//! Substrate provides the `sc-rpc` crate, which defines the core RPC layer
3//! used by Substrate nodes. This file extends those RPC definitions with
4//! capabilities that are specific to this project's runtime configuration.
5
6#![warn(missing_docs)]
7
8use std::sync::Arc;
9
10use parachain_template_runtime::{opaque::Block, AccountId, Balance, Nonce};
11
12use polkadot_sdk::*;
13
14use sc_transaction_pool_api::TransactionPool;
15use sp_api::ProvideRuntimeApi;
16use sp_block_builder::BlockBuilder;
17use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
18
19/// A type representing all RPC extensions.
20pub type RpcExtension = jsonrpsee::RpcModule<()>;
21
22/// Full client dependencies
23pub struct FullDeps<C, P> {
24	/// The client instance to use.
25	pub client: Arc<C>,
26	/// Transaction pool instance.
27	pub pool: Arc<P>,
28}
29
30/// Instantiate all RPC extensions.
31pub fn create_full<C, P>(
32	deps: FullDeps<C, P>,
33) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
34where
35	C: ProvideRuntimeApi<Block>
36		+ HeaderBackend<Block>
37		+ HeaderMetadata<Block, Error = BlockChainError>
38		+ Send
39		+ Sync
40		+ 'static,
41	C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
42	C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
43	C::Api: BlockBuilder<Block>,
44	P: TransactionPool + Sync + Send + 'static,
45{
46	use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
47	use substrate_frame_rpc_system::{System, SystemApiServer};
48
49	let mut module = RpcExtension::new(());
50	let FullDeps { client, pool } = deps;
51
52	module.merge(System::new(client.clone(), pool).into_rpc())?;
53	module.merge(TransactionPayment::new(client).into_rpc())?;
54	Ok(module)
55}