frequency_service/rpc/
mod.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 common_primitives::node::{AccountId, Balance, Block, Hash, Index as Nonce};
11
12use sc_client_api::{AuxStore, StorageProvider};
13use sc_client_db::Backend as DbBackend;
14use sc_consensus_manual_seal::rpc::{EngineCommand, ManualSeal, ManualSealApiServer};
15pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
16use sc_transaction_pool_api::TransactionPool;
17use sp_api::ProvideRuntimeApi;
18use sp_block_builder::BlockBuilder;
19use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
20
21mod frequency_rpc;
22
23/// A type representing all RPC extensions.
24pub type RpcExtension = jsonrpsee::RpcModule<()>;
25
26/// Full client dependencies
27pub struct FullDeps<C, P> {
28	/// The client instance to use.
29	pub client: Arc<C>,
30	/// Transaction pool instance.
31	pub pool: Arc<P>,
32	/// Manual seal command sink
33	pub command_sink: Option<futures::channel::mpsc::Sender<EngineCommand<Hash>>>,
34}
35
36/// Instantiate all RPC extensions.
37pub fn create_full<OffchainDB, C, P>(
38	deps: FullDeps<C, P>,
39	offchain: Option<OffchainDB>,
40) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
41where
42	C: ProvideRuntimeApi<Block>
43		+ HeaderBackend<Block>
44		+ AuxStore
45		+ HeaderMetadata<Block, Error = BlockChainError>
46		+ StorageProvider<Block, DbBackend<Block>>
47		+ Send
48		+ Sync
49		+ 'static,
50	C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
51	C::Api: pallet_frequency_tx_payment_rpc::CapacityTransactionPaymentRuntimeApi<Block, Balance>,
52	C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
53	C::Api: BlockBuilder<Block>,
54	C::Api: pallet_messages_runtime_api::MessagesRuntimeApi<Block>,
55	C::Api: pallet_schemas_runtime_api::SchemasRuntimeApi<Block>,
56	C::Api: system_runtime_api::AdditionalRuntimeApi<Block>,
57	C::Api: pallet_msa_runtime_api::MsaRuntimeApi<Block, AccountId>,
58	C::Api: pallet_stateful_storage_runtime_api::StatefulStorageRuntimeApi<Block>,
59	C::Api: pallet_handles_runtime_api::HandlesRuntimeApi<Block>,
60	OffchainDB: sp_core::offchain::OffchainStorage + 'static,
61	P: TransactionPool + Sync + Send + 'static,
62{
63	use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
64	use substrate_frame_rpc_system::{System, SystemApiServer};
65
66	// Frequency RPCs
67	use frequency_rpc::{FrequencyRpcApiServer, FrequencyRpcHandler};
68	use pallet_frequency_tx_payment_rpc::{CapacityPaymentApiServer, CapacityPaymentHandler};
69	use pallet_handles_rpc::{HandlesApiServer, HandlesHandler};
70	use pallet_messages_rpc::{MessagesApiServer, MessagesHandler};
71	use pallet_msa_rpc::{MsaApiServer, MsaHandler};
72	use pallet_schemas_rpc::{SchemasApiServer, SchemasHandler};
73	use pallet_stateful_storage_rpc::{StatefulStorageApiServer, StatefulStorageHandler};
74
75	let mut module = RpcExtension::new(());
76	let FullDeps { client, pool, command_sink } = deps;
77
78	module.merge(System::new(client.clone(), pool.clone()).into_rpc())?;
79	module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
80	module.merge(MessagesHandler::new(client.clone()).into_rpc())?;
81	module.merge(SchemasHandler::new(client.clone()).into_rpc())?;
82	module.merge(MsaHandler::new(client.clone(), offchain).into_rpc())?;
83	module.merge(StatefulStorageHandler::new(client.clone()).into_rpc())?;
84	module.merge(HandlesHandler::new(client.clone()).into_rpc())?;
85	module.merge(CapacityPaymentHandler::new(client.clone()).into_rpc())?;
86	module.merge(FrequencyRpcHandler::new(client, pool).into_rpc())?;
87	if let Some(command_sink) = command_sink {
88		module.merge(
89			// We provide the rpc handler with the sending end of the channel to allow the rpc
90			// send EngineCommands to the background block authorship task.
91			ManualSeal::new(command_sink).into_rpc(),
92		)?;
93	}
94	Ok(module)
95}