use std::sync::Arc;
use futures::channel::mpsc;
use jsonrpsee::RpcModule;
use sc_client_api::{
backend::{Backend, StorageProvider},
client::BlockchainEvents,
AuxStore, UsageProvider,
};
use sc_consensus_manual_seal::rpc::EngineCommand;
use sc_rpc::SubscriptionTaskExecutor;
use sc_rpc_api::DenyUnsafe;
use sc_service::TransactionPool;
use sc_transaction_pool::ChainApi;
use sp_api::{CallApiAt, ProvideRuntimeApi};
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_inherents::CreateInherentDataProviders;
use sp_runtime::traits::Block as BlockT;
use frontier_template_runtime::{opaque::Block, AccountId, Balance, Hash, Nonce};
mod eth;
pub use self::eth::{create_eth, overrides_handle, EthDeps};
pub struct FullDeps<C, P, A: ChainApi, CT, CIDP> {
pub client: Arc<C>,
pub pool: Arc<P>,
pub deny_unsafe: DenyUnsafe,
pub command_sink: Option<mpsc::Sender<EngineCommand<Hash>>>,
pub eth: EthDeps<Block, C, P, A, CT, CIDP>,
}
pub struct DefaultEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);
impl<C, BE> fc_rpc::EthConfig<Block, C> for DefaultEthConfig<C, BE>
where
C: StorageProvider<Block, BE> + Sync + Send + 'static,
BE: Backend<Block> + 'static,
{
type EstimateGasAdapter = ();
type RuntimeStorageOverride =
fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride<Block, C, BE>;
}
pub fn create_full<C, P, BE, A, CT, CIDP>(
deps: FullDeps<C, P, A, CT, CIDP>,
subscription_task_executor: SubscriptionTaskExecutor,
pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<Block>,
>,
>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: CallApiAt<Block> + ProvideRuntimeApi<Block>,
C::Api: sp_block_builder::BlockBuilder<Block>,
C::Api: sp_consensus_aura::AuraApi<Block, AuraId>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,
C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
C: BlockchainEvents<Block> + AuxStore + UsageProvider<Block> + StorageProvider<Block, BE>,
BE: Backend<Block> + 'static,
P: TransactionPool<Block = Block> + 'static,
A: ChainApi<Block = Block> + 'static,
CIDP: CreateInherentDataProviders<Block, ()> + Send + 'static,
CT: fp_rpc::ConvertTransaction<<Block as BlockT>::Extrinsic> + Send + Sync + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
let mut io = RpcModule::new(());
let FullDeps {
client,
pool,
deny_unsafe,
command_sink,
eth,
} = deps;
io.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
io.merge(TransactionPayment::new(client).into_rpc())?;
if let Some(command_sink) = command_sink {
io.merge(
ManualSeal::new(command_sink).into_rpc(),
)?;
}
let io = create_eth::<_, _, _, _, _, _, _, DefaultEthConfig<C, BE>>(
io,
eth,
subscription_task_executor,
pubsub_notification_sinks,
)?;
Ok(io)
}