frontier_template_node/rpc/
mod.rs
1use std::sync::Arc;
4
5use futures::channel::mpsc;
6use jsonrpsee::RpcModule;
7use sc_client_api::{
9 backend::{Backend, StorageProvider},
10 client::BlockchainEvents,
11 AuxStore, UsageProvider,
12};
13use sc_consensus_manual_seal::rpc::EngineCommand;
14use sc_rpc::SubscriptionTaskExecutor;
15use sc_service::TransactionPool;
16use sp_api::{CallApiAt, ProvideRuntimeApi};
17use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
18use sp_consensus_aura::sr25519::AuthorityId as AuraId;
19use sp_inherents::CreateInherentDataProviders;
20use sp_runtime::traits::Block as BlockT;
21use frontier_template_runtime::{AccountId, Balance, Hash, Nonce};
23
24mod eth;
25pub use self::eth::{create_eth, EthDeps};
26
27pub struct FullDeps<B: BlockT, C, P, CT, CIDP> {
29 pub client: Arc<C>,
31 pub pool: Arc<P>,
33 pub command_sink: Option<mpsc::Sender<EngineCommand<Hash>>>,
35 pub eth: EthDeps<B, C, P, CT, CIDP>,
37}
38
39pub struct DefaultEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);
40
41impl<B, C, BE> fc_rpc::EthConfig<B, C> for DefaultEthConfig<C, BE>
42where
43 B: BlockT,
44 C: StorageProvider<B, BE> + Sync + Send + 'static,
45 BE: Backend<B> + 'static,
46{
47 type EstimateGasAdapter = ();
48 type RuntimeStorageOverride =
49 fc_rpc::frontier_backend_client::SystemAccountId20StorageOverride<B, C, BE>;
50}
51
52pub fn create_full<B, C, P, BE, CT, CIDP>(
54 deps: FullDeps<B, C, P, CT, CIDP>,
55 subscription_task_executor: SubscriptionTaskExecutor,
56 pubsub_notification_sinks: Arc<
57 fc_mapping_sync::EthereumBlockNotificationSinks<
58 fc_mapping_sync::EthereumBlockNotification<B>,
59 >,
60 >,
61) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
62where
63 B: BlockT,
64 C: CallApiAt<B> + ProvideRuntimeApi<B>,
65 C::Api: sp_block_builder::BlockBuilder<B>,
66 C::Api: sp_consensus_aura::AuraApi<B, AuraId>,
67 C::Api: substrate_frame_rpc_system::AccountNonceApi<B, AccountId, Nonce>,
68 C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<B, Balance>,
69 C::Api: fp_rpc::ConvertTransactionRuntimeApi<B>,
70 C::Api: fp_rpc::EthereumRuntimeRPCApi<B>,
71 C: HeaderBackend<B> + HeaderMetadata<B, Error = BlockChainError> + 'static,
72 C: BlockchainEvents<B> + AuxStore + UsageProvider<B> + StorageProvider<B, BE>,
73 BE: Backend<B> + 'static,
74 P: TransactionPool<Block = B, Hash = B::Hash> + 'static,
75 CIDP: CreateInherentDataProviders<B, ()> + Send + 'static,
76 CT: fp_rpc::ConvertTransaction<<B as BlockT>::Extrinsic> + Send + Sync + 'static,
77{
78 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
79 use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApiServer};
80 use substrate_frame_rpc_system::{System, SystemApiServer};
81
82 let mut io = RpcModule::new(());
83 let FullDeps {
84 client,
85 pool,
86 command_sink,
87 eth,
88 } = deps;
89
90 io.merge(System::new(client.clone(), pool).into_rpc())?;
91 io.merge(TransactionPayment::new(client).into_rpc())?;
92
93 if let Some(command_sink) = command_sink {
94 io.merge(
95 ManualSeal::new(command_sink).into_rpc(),
98 )?;
99 }
100
101 let io = create_eth::<_, _, _, _, _, _, DefaultEthConfig<C, BE>>(
103 io,
104 eth,
105 subscription_task_executor,
106 pubsub_notification_sinks,
107 )?;
108
109 Ok(io)
110}