git.delta.rocks / unique-network / refs/commits / 41e5db73da23

difftreelog

source

node/cli/src/rpc.rs7.6 KiBsourcehistory
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use std::sync::Arc;1819use fc_mapping_sync::{EthereumBlockNotification, EthereumBlockNotificationSinks};20use fc_rpc::{EthBlockDataCacheTask, EthConfig, OverrideHandle};21use fc_rpc_core::types::{FeeHistoryCache, FilterPool};22use fp_rpc::NoTransactionConverter;23use jsonrpsee::RpcModule;24use sc_client_api::{25	backend::{AuxStore, StorageProvider},26	client::BlockchainEvents,27	UsageProvider,28};29use sc_network::NetworkService;30use sc_network_sync::SyncingService;31use sc_rpc::SubscriptionTaskExecutor;32pub use sc_rpc_api::DenyUnsafe;33use sc_service::TransactionPool;34use sc_transaction_pool::{ChainApi, Pool};35use sp_api::ProvideRuntimeApi;36use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};37use sp_inherents::CreateInherentDataProviders;38use up_common::types::opaque::*;3940use crate::service::RuntimeApiDep;4142#[cfg(feature = "pov-estimate")]43type FullBackend = sc_service::TFullBackend<Block>;4445/// Full client dependencies.46pub struct FullDeps<C, P, SC> {47	/// The client instance to use.48	pub client: Arc<C>,49	/// Transaction pool instance.50	pub pool: Arc<P>,51	/// The SelectChain Strategy52	pub select_chain: SC,53	/// Whether to deny unsafe calls54	pub deny_unsafe: DenyUnsafe,5556	/// Runtime identification (read from the chain spec)57	pub runtime_id: RuntimeId,58	/// Executor params for PoV estimating59	#[cfg(feature = "pov-estimate")]60	pub exec_params: uc_rpc::pov_estimate::ExecutorParams,61	/// Substrate Backend.62	#[cfg(feature = "pov-estimate")]63	pub backend: Arc<FullBackend>,64}6566/// Instantiate all Full RPC extensions.67pub fn create_full<C, P, SC, R, B>(68	io: &mut RpcModule<()>,69	deps: FullDeps<C, P, SC>,70) -> Result<(), Box<dyn std::error::Error + Send + Sync>>71where72	C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,73	C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,74	C: Send + Sync + 'static,75	C: BlockchainEvents<Block>,76	C::Api: RuntimeApiDep<R>,77	B: sc_client_api::Backend<Block> + Send + Sync + 'static,78	P: TransactionPool<Block = Block> + 'static,79	R: RuntimeInstance + Send + Sync + 'static,80	<R as RuntimeInstance>::CrossAccountId: serde::Serialize,81	C: sp_api::CallApiAt<82		generic::Block<generic::Header<u32, BlakeTwo256>, sp_runtime::OpaqueExtrinsic>,83	>,84	for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,85{86	// use pallet_contracts_rpc::{Contracts, ContractsApi};87	use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};88	use substrate_frame_rpc_system::{System, SystemApiServer};89	#[cfg(feature = "pov-estimate")]90	use uc_rpc::pov_estimate::{PovEstimate, PovEstimateApiServer};91	use uc_rpc::{AppPromotion, AppPromotionApiServer, Unique, UniqueApiServer};9293	let FullDeps {94		client,95		pool,96		select_chain: _,97		deny_unsafe,9899		runtime_id: _,100101		#[cfg(feature = "pov-estimate")]102		exec_params,103104		#[cfg(feature = "pov-estimate")]105		backend,106	} = deps;107108	io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;109	io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;110111	io.merge(Unique::new(client.clone()).into_rpc())?;112113	io.merge(AppPromotion::new(client).into_rpc())?;114115	#[cfg(feature = "pov-estimate")]116	io.merge(117		PovEstimate::new(118			client.clone(),119			backend,120			deny_unsafe,121			exec_params,122			runtime_id,123		)124		.into_rpc(),125	)?;126127	Ok(())128}129130pub struct EthDeps<C, P, CA: ChainApi, CIDP> {131	/// The client instance to use.132	pub client: Arc<C>,133	/// Transaction pool instance.134	pub pool: Arc<P>,135	/// Graph pool instance.136	pub graph: Arc<Pool<CA>>,137	/// Syncing service138	pub sync: Arc<SyncingService<Block>>,139	/// The Node authority flag140	pub is_authority: bool,141	/// Network service142	pub network: Arc<NetworkService<Block, Hash>>,143144	/// Ethereum Backend.145	pub eth_backend: Arc<dyn fc_api::Backend<Block> + Send + Sync>,146	/// Maximum number of logs in a query.147	pub max_past_logs: u32,148	/// Maximum fee history cache size.149	pub fee_history_limit: u64,150	/// Fee history cache.151	pub fee_history_cache: FeeHistoryCache,152	pub eth_block_data_cache: Arc<EthBlockDataCacheTask<Block>>,153	/// EthFilterApi pool.154	pub eth_filter_pool: Option<FilterPool>,155	pub eth_pubsub_notification_sinks:156		Arc<EthereumBlockNotificationSinks<EthereumBlockNotification<Block>>>,157	/// Whether to enable eth dev signer158	pub enable_dev_signer: bool,159160	pub overrides: Arc<OverrideHandle<Block>>,161	pub pending_create_inherent_data_providers: CIDP,162}163164pub fn create_eth<C, R, P, CA, B, CIDP, EC>(165	io: &mut RpcModule<()>,166	deps: EthDeps<C, P, CA, CIDP>,167	subscription_task_executor: SubscriptionTaskExecutor,168) -> Result<(), Box<dyn std::error::Error + Send + Sync>>169where170	C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,171	C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,172	C: Send + Sync + 'static,173	C: BlockchainEvents<Block>,174	C: UsageProvider<Block>,175	C::Api: RuntimeApiDep<R>,176	P: TransactionPool<Block = Block> + 'static,177	CA: ChainApi<Block = Block> + 'static,178	B: sc_client_api::Backend<Block> + Send + Sync + 'static,179	C: sp_api::CallApiAt<Block>,180	CIDP: CreateInherentDataProviders<Block, ()> + Send + 'static,181	EC: EthConfig<Block, C>,182	R: RuntimeInstance,183{184	use fc_rpc::{185		Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,186		EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,187	};188189	let EthDeps {190		client,191		pool,192		graph,193		eth_backend,194		max_past_logs,195		fee_history_limit,196		fee_history_cache,197		eth_block_data_cache,198		eth_filter_pool,199		eth_pubsub_notification_sinks,200		enable_dev_signer,201		sync,202		is_authority,203		network,204		overrides,205		pending_create_inherent_data_providers,206	} = deps;207208	let mut signers = Vec::new();209	if enable_dev_signer {210		signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);211	}212	let execute_gas_limit_multiplier = 10;213	io.merge(214		Eth::<_, _, _, _, _, _, _, EC>::new(215			client.clone(),216			pool.clone(),217			graph.clone(),218			// We have no runtimes old enough to only accept converted transactions.219			None::<NoTransactionConverter>,220			sync.clone(),221			signers,222			overrides.clone(),223			eth_backend.clone(),224			is_authority,225			eth_block_data_cache.clone(),226			fee_history_cache,227			fee_history_limit,228			execute_gas_limit_multiplier,229			None,230			pending_create_inherent_data_providers,231			// Our extrinsics have nothing to do with consensus digest items yet.232			None,233		)234		.into_rpc(),235	)?;236237	if let Some(filter_pool) = eth_filter_pool {238		io.merge(239			EthFilter::new(240				client.clone(),241				eth_backend,242				graph,243				filter_pool,244				500_usize, // max stored filters245				max_past_logs,246				eth_block_data_cache,247			)248			.into_rpc(),249		)?;250	}251	io.merge(252		Net::new(253			client.clone(),254			network,255			// Whether to format the `peer_count` response as Hex (default) or not.256			true,257		)258		.into_rpc(),259	)?;260	io.merge(Web3::new(client.clone()).into_rpc())?;261	io.merge(262		EthPubSub::new(263			pool,264			client,265			sync,266			subscription_task_executor,267			overrides,268			eth_pubsub_notification_sinks,269		)270		.into_rpc(),271	)?;272273	Ok(())274}