use std::sync::Arc;
use cfg_primitives::{AccountId, Balance, Block, BlockNumber, Hash, Nonce};
use jsonrpsee::types::error::{ErrorCode, ErrorObject};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use runtime_common::apis::AnchorApi;
use sc_rpc_api::DenyUnsafe;
use sc_service::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use substrate_frame_rpc_system::{System, SystemApiServer};
use crate::rpc::anchors::{AnchorApiServer, Anchors};
pub mod anchors;
pub mod evm;
pub type RpcExtension = jsonrpsee::RpcModule<()>;
pub fn create_full<C, P>(
client: Arc<C>,
pool: Arc<P>,
deny_unsafe: DenyUnsafe,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: BlockBuilder<Block>,
C::Api: AnchorApi<Block, Hash, BlockNumber>,
P: TransactionPool + Sync + Send + 'static,
{
let mut module = RpcExtension::new(());
module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
module.merge(Anchors::new(client.clone()).into_rpc())?;
Ok(module)
}
pub fn invalid_params_error(msg: &'static str) -> ErrorObject {
ErrorObject::owned(ErrorCode::InvalidParams.code(), msg, Option::<()>::None)
}