git.delta.rocks / unique-network / refs/commits / bc2aff487603

difftreelog

source

node/src/rpc.rs2.3 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, BlockNumber};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;16use pallet_contracts_rpc::{Contracts, ContractsApi};1718/// 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	C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber>,39	P: TransactionPool + 'static,40{41	use substrate_frame_rpc_system::{FullSystem, SystemApi};42	use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};4344	let mut io = jsonrpc_core::IoHandler::default();45	let FullDeps {46		client,47		pool,48		deny_unsafe,49	} = deps;5051	io.extend_with(52		SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe))53	);5455	io.extend_with(56		TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone()))57	);5859    io.extend_with(60        ContractsApi::to_delegate(Contracts::new(client.clone()))61	);62		63	// Extend this RPC with a custom API by using the following syntax.64	// `YourRpcStruct` should have a reference to a client, which is needed65	// to call into the runtime.66	// `io.extend_with(YourRpcTrait::to_delegate(YourRpcStruct::new(ReferenceToClient, ...)));`6768	io69}