git.delta.rocks / unique-network / refs/commits / 502239632ae7

difftreelog

source

node/src/rpc.rs2.0 KiBsourcehistory
1//! A collection of node-specific RPC methods.2//! Substrate provides the `sc-rpc` crate, which defines the core RPC layer3//! used by Substrate nodes. This file extends those RPC definitions with4//! capabilities that are specific to this project's runtime configuration.56#![warn(missing_docs)]78use std::sync::Arc;910use nft_runtime::{opaque::Block, AccountId, Balance, Index};11use sp_api::ProvideRuntimeApi;12use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend};13use sp_block_builder::BlockBuilder;14pub use sc_rpc_api::DenyUnsafe;15use sp_transaction_pool::TransactionPool;161718/// Full client dependencies.19pub struct FullDeps<C, P> {20	/// The client instance to use.21	pub client: Arc<C>,22	/// Transaction pool instance.23	pub pool: Arc<P>,24	/// Whether to deny unsafe calls25	pub deny_unsafe: DenyUnsafe,26}2728/// Instantiate all full RPC extensions.29pub fn create_full<C, P>(30	deps: FullDeps<C, P>,31) -> jsonrpc_core::IoHandler<sc_rpc::Metadata> where32	C: ProvideRuntimeApi<Block>,33	C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError> + 'static,34	C: Send + Sync + 'static,35	C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,36	C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,37	C::Api: BlockBuilder<Block>,38	P: TransactionPool + 'static,39{40	use substrate_frame_rpc_system::{FullSystem, SystemApi};41	use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};4243	let mut io = jsonrpc_core::IoHandler::default();44	let FullDeps {45		client,46		pool,47		deny_unsafe,48	} = deps;4950	io.extend_with(51		SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe))52	);5354	io.extend_with(55		TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone()))56	);5758	// Extend this RPC with a custom API by using the following syntax.59	// `YourRpcStruct` should have a reference to a client, which is needed60	// to call into the runtime.61	// `io.extend_with(YourRpcTrait::to_delegate(YourRpcStruct::new(ReferenceToClient, ...)));`6263	io64}