frontier_template_node/rpc/
mod.rs

1//! A collection of node-specific RPC methods.
2
3use std::sync::Arc;
4
5use futures::channel::mpsc;
6use jsonrpsee::RpcModule;
7// Substrate
8use 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;
21// Runtime
22use frontier_template_runtime::{AccountId, Balance, Hash, Nonce};
23
24mod eth;
25pub use self::eth::{create_eth, EthDeps};
26
27/// Full client dependencies.
28pub struct FullDeps<B: BlockT, C, P, CT, CIDP> {
29	/// The client instance to use.
30	pub client: Arc<C>,
31	/// Transaction pool instance.
32	pub pool: Arc<P>,
33	/// Manual seal command sink
34	pub command_sink: Option<mpsc::Sender<EngineCommand<Hash>>>,
35	/// Ethereum-compatibility specific dependencies.
36	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
52/// Instantiate all Full RPC extensions.
53pub 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			// We provide the rpc handler with the sending end of the channel to allow the rpc
96			// send EngineCommands to the background block authorship task.
97			ManualSeal::new(command_sink).into_rpc(),
98		)?;
99	}
100
101	// Ethereum compatibility RPCs
102	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}