2020-08-21 11:20:35 +00:00
|
|
|
//! A collection of node-specific RPC methods.
|
|
|
|
//! Substrate provides the `sc-rpc` crate, which defines the core RPC layer
|
|
|
|
//! used by Substrate nodes. This file extends those RPC definitions with
|
|
|
|
//! capabilities that are specific to this project's runtime configuration.
|
|
|
|
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-05-21 15:19:48 +00:00
|
|
|
use jsonrpsee::RpcModule;
|
2020-08-21 11:20:35 +00:00
|
|
|
use node_template_runtime::{opaque::Block, AccountId, Balance, Index};
|
2021-08-06 14:51:49 +00:00
|
|
|
use sc_transaction_pool_api::TransactionPool;
|
2020-08-21 11:20:35 +00:00
|
|
|
use sp_api::ProvideRuntimeApi;
|
|
|
|
use sp_block_builder::BlockBuilder;
|
2021-07-20 12:44:58 +00:00
|
|
|
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
|
2020-08-21 11:20:35 +00:00
|
|
|
|
2022-05-21 15:19:48 +00:00
|
|
|
pub use sc_rpc_api::DenyUnsafe;
|
|
|
|
|
2020-08-21 11:20:35 +00:00
|
|
|
/// Full client dependencies.
|
|
|
|
pub struct FullDeps<C, P> {
|
|
|
|
/// The client instance to use.
|
|
|
|
pub client: Arc<C>,
|
|
|
|
/// Transaction pool instance.
|
|
|
|
pub pool: Arc<P>,
|
|
|
|
/// Whether to deny unsafe calls
|
|
|
|
pub deny_unsafe: DenyUnsafe,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Instantiate all full RPC extensions.
|
2022-05-21 15:19:48 +00:00
|
|
|
pub fn create_full<C, P>(
|
|
|
|
deps: FullDeps<C, P>,
|
|
|
|
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
|
2021-07-20 12:44:58 +00:00
|
|
|
where
|
2020-08-21 11:20:35 +00:00
|
|
|
C: ProvideRuntimeApi<Block>,
|
2021-07-20 12:44:58 +00:00
|
|
|
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
|
2020-08-21 11:20:35 +00:00
|
|
|
C: Send + Sync + 'static,
|
|
|
|
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
|
|
|
|
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
|
|
|
|
C::Api: BlockBuilder<Block>,
|
|
|
|
P: TransactionPool + 'static,
|
|
|
|
{
|
2022-05-21 15:19:48 +00:00
|
|
|
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
|
|
|
|
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc};
|
2020-08-21 11:20:35 +00:00
|
|
|
|
2022-05-21 15:19:48 +00:00
|
|
|
let mut module = RpcModule::new(());
|
2021-07-20 12:44:58 +00:00
|
|
|
let FullDeps { client, pool, deny_unsafe } = deps;
|
2020-08-21 11:20:35 +00:00
|
|
|
|
2022-05-21 15:19:48 +00:00
|
|
|
module.merge(SystemRpc::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
|
|
|
|
module.merge(TransactionPaymentRpc::new(client).into_rpc())?;
|
2020-08-21 11:20:35 +00:00
|
|
|
|
|
|
|
// Extend this RPC with a custom API by using the following syntax.
|
|
|
|
// `YourRpcStruct` should have a reference to a client, which is needed
|
|
|
|
// to call into the runtime.
|
2022-05-21 15:19:48 +00:00
|
|
|
// `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...)))?;`
|
2020-08-21 11:20:35 +00:00
|
|
|
|
2022-05-21 15:19:48 +00:00
|
|
|
Ok(module)
|
2020-08-21 11:20:35 +00:00
|
|
|
}
|