referrerpolicy=no-referrer-when-downgrade

solochain_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 jsonrpsee::RpcModule;
11use sc_transaction_pool_api::TransactionPool;
12use solochain_template_runtime::{opaque::Block, AccountId, Balance, Nonce};
13use sp_api::ProvideRuntimeApi;
14use sp_block_builder::BlockBuilder;
15use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
16
17/// Full client dependencies.
18pub struct FullDeps<C, P> {
19	/// The client instance to use.
20	pub client: Arc<C>,
21	/// Transaction pool instance.
22	pub pool: Arc<P>,
23}
24
25/// Instantiate all full RPC extensions.
26pub fn create_full<C, P>(
27	deps: FullDeps<C, P>,
28) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
29where
30	C: ProvideRuntimeApi<Block>,
31	C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
32	C: Send + Sync + 'static,
33	C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
34	C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
35	C::Api: BlockBuilder<Block>,
36	P: TransactionPool + 'static,
37{
38	use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
39	use substrate_frame_rpc_system::{System, SystemApiServer};
40
41	let mut module = RpcModule::new(());
42	let FullDeps { client, pool } = deps;
43
44	module.merge(System::new(client.clone(), pool).into_rpc())?;
45	module.merge(TransactionPayment::new(client).into_rpc())?;
46
47	// Extend this RPC with a custom API by using the following syntax.
48	// `YourRpcStruct` should have a reference to a client, which is needed
49	// to call into the runtime.
50	// `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...)))?;`
51
52	// You probably want to enable the `rpc v2 chainSpec` API as well
53	//
54	// let chain_name = chain_spec.name().to_string();
55	// let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
56	// let properties = chain_spec.properties();
57	// module.merge(ChainSpec::new(chain_name, genesis_hash, properties).into_rpc())?;
58
59	Ok(module)
60}