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_service::TransactionPool;
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::{AccountId, Balance, Hash, Nonce};
mod eth;
pub use self::eth::{create_eth, EthDeps};
pub struct FullDeps<B: BlockT, C, P, CT, CIDP> {
pub client: Arc<C>,
pub pool: Arc<P>,
pub command_sink: Option<mpsc::Sender<EngineCommand<Hash>>>,
pub eth: EthDeps<B, C, P, CT, CIDP>,
}
pub struct DefaultEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);
impl<B, C, BE> fc_rpc::EthConfig<B, C> for DefaultEthConfig<C, BE>
where
B: BlockT,
C: StorageProvider<B, BE> + Sync + Send + 'static,
BE: Backend<B> + 'static,
{
type EstimateGasAdapter = ();
type RuntimeStorageOverride =
fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride<B, C, BE>;
}
pub fn create_full<B, C, P, BE, CT, CIDP>(
deps: FullDeps<B, C, P, CT, CIDP>,
subscription_task_executor: SubscriptionTaskExecutor,
pubsub_notification_sinks: Arc<
fc_mapping_sync::EthereumBlockNotificationSinks<
fc_mapping_sync::EthereumBlockNotification<B>,
>,
>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
B: BlockT,
C: CallApiAt<B> + ProvideRuntimeApi<B>,
C::Api: sp_block_builder::BlockBuilder<B>,
C::Api: sp_consensus_aura::AuraApi<B, AuraId>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<B, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<B, Balance>,
C::Api: fp_rpc::ConvertTransactionRuntimeApi<B>,
C::Api: fp_rpc::EthereumRuntimeRPCApi<B>,
C: HeaderBackend<B> + HeaderMetadata<B, Error = BlockChainError> + 'static,
C: BlockchainEvents<B> + AuxStore + UsageProvider<B> + StorageProvider<B, BE>,
BE: Backend<B> + 'static,
P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
CIDP: CreateInherentDataProviders<B, ()> + Send + 'static,
CT: fp_rpc::ConvertTransaction<<B 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,
command_sink,
eth,
} = deps;
io.merge(System::new(client.clone(), pool).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)
}