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;
|
|
|
|
|
|
|
|
use node_template_runtime::{opaque::Block, AccountId, Balance, Index};
|
2021-07-20 12:44:58 +00:00
|
|
|
pub use sc_rpc_api::DenyUnsafe;
|
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
|
|
|
|
|
|
|
/// 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.
|
2021-07-20 12:44:58 +00:00
|
|
|
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> jsonrpc_core::IoHandler<sc_rpc::Metadata>
|
|
|
|
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,
|
|
|
|
{
|
|
|
|
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
|
2021-07-20 12:44:58 +00:00
|
|
|
use substrate_frame_rpc_system::{FullSystem, SystemApi};
|
2020-08-21 11:20:35 +00:00
|
|
|
|
|
|
|
let mut io = jsonrpc_core::IoHandler::default();
|
2021-07-20 12:44:58 +00:00
|
|
|
let FullDeps { client, pool, deny_unsafe } = deps;
|
2020-08-21 11:20:35 +00:00
|
|
|
|
2021-07-20 12:44:58 +00:00
|
|
|
io.extend_with(SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe)));
|
2020-08-21 11:20:35 +00:00
|
|
|
|
2021-07-20 12:44:58 +00:00
|
|
|
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));
|
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.
|
|
|
|
// `io.extend_with(YourRpcTrait::to_delegate(YourRpcStruct::new(ReferenceToClient, ...)));`
|
|
|
|
|
|
|
|
io
|
|
|
|
}
|