#![warn(missing_docs)]
use std::sync::Arc;
use common_primitives::node::{AccountId, Balance, Block, Hash, Index as Nonce};
use sc_client_api::{AuxStore, StorageProvider};
use sc_client_db::Backend as DbBackend;
use sc_consensus_manual_seal::rpc::{EngineCommand, ManualSeal, ManualSealApiServer};
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
mod frequency_rpc;
pub type RpcExtension = jsonrpsee::RpcModule<()>;
pub struct FullDeps<C, P> {
pub client: Arc<C>,
pub pool: Arc<P>,
pub deny_unsafe: DenyUnsafe,
pub command_sink: Option<futures::channel::mpsc::Sender<EngineCommand<Hash>>>,
}
pub fn create_full<OffchainDB, C, P>(
deps: FullDeps<C, P>,
offchain: Option<OffchainDB>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ HeaderMetadata<Block, Error = BlockChainError>
+ StorageProvider<Block, DbBackend<Block>>
+ Send
+ Sync
+ 'static,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: pallet_frequency_tx_payment_rpc::CapacityTransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: BlockBuilder<Block>,
C::Api: pallet_messages_runtime_api::MessagesRuntimeApi<Block>,
C::Api: pallet_schemas_runtime_api::SchemasRuntimeApi<Block>,
C::Api: system_runtime_api::AdditionalRuntimeApi<Block>,
C::Api: pallet_msa_runtime_api::MsaRuntimeApi<Block, AccountId>,
C::Api: pallet_stateful_storage_runtime_api::StatefulStorageRuntimeApi<Block>,
C::Api: pallet_handles_runtime_api::HandlesRuntimeApi<Block>,
OffchainDB: sp_core::offchain::OffchainStorage + 'static,
P: TransactionPool + Sync + Send + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
use frequency_rpc::{FrequencyRpcApiServer, FrequencyRpcHandler};
use pallet_frequency_tx_payment_rpc::{CapacityPaymentApiServer, CapacityPaymentHandler};
use pallet_handles_rpc::{HandlesApiServer, HandlesHandler};
use pallet_messages_rpc::{MessagesApiServer, MessagesHandler};
use pallet_msa_rpc::{MsaApiServer, MsaHandler};
use pallet_schemas_rpc::{SchemasApiServer, SchemasHandler};
use pallet_stateful_storage_rpc::{StatefulStorageApiServer, StatefulStorageHandler};
let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe, command_sink } = deps;
module.merge(System::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(MessagesHandler::new(client.clone()).into_rpc())?;
module.merge(SchemasHandler::new(client.clone()).into_rpc())?;
module.merge(MsaHandler::new(client.clone(), offchain).into_rpc())?;
module.merge(StatefulStorageHandler::new(client.clone()).into_rpc())?;
module.merge(HandlesHandler::new(client.clone()).into_rpc())?;
module.merge(CapacityPaymentHandler::new(client.clone()).into_rpc())?;
module.merge(FrequencyRpcHandler::new(client, pool).into_rpc())?;
if let Some(command_sink) = command_sink {
module.merge(
ManualSeal::new(command_sink).into_rpc(),
)?;
}
Ok(module)
}