1234567891011121314151617use std::sync::Arc;1819use fc_mapping_sync::{EthereumBlockNotification, EthereumBlockNotificationSinks};20use fc_rpc::{21 pending::AuraConsensusDataProvider, EthBlockDataCacheTask, EthConfig, OverrideHandle,22};23use fc_rpc_core::types::{FeeHistoryCache, FilterPool};24use fp_rpc::NoTransactionConverter;25use jsonrpsee::RpcModule;26use sc_client_api::{27 backend::{AuxStore, StorageProvider},28 client::BlockchainEvents,29 UsageProvider,30};31use sc_network::NetworkService;32use sc_network_sync::SyncingService;33use sc_rpc::SubscriptionTaskExecutor;34pub use sc_rpc_api::DenyUnsafe;35use sc_service::TransactionPool;36use sc_transaction_pool::{ChainApi, Pool};37use sp_api::ProvideRuntimeApi;38use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};39use sp_inherents::CreateInherentDataProviders;40use sp_runtime::traits::BlakeTwo256;41use up_common::types::opaque::*;4243use crate::service::RuntimeApiDep;4445#[cfg(feature = "pov-estimate")]46type FullBackend = sc_service::TFullBackend<Block>;474849pub struct FullDeps<C, P, SC> {50 51 pub client: Arc<C>,52 53 pub pool: Arc<P>,54 55 pub select_chain: SC,56 57 pub deny_unsafe: DenyUnsafe,5859 60 pub runtime_id: RuntimeId,61 62 #[cfg(feature = "pov-estimate")]63 pub exec_params: uc_rpc::pov_estimate::ExecutorParams,64 65 #[cfg(feature = "pov-estimate")]66 pub backend: Arc<FullBackend>,67}686970pub fn create_full<C, P, SC, R, B>(71 io: &mut RpcModule<()>,72 deps: FullDeps<C, P, SC>,73) -> Result<(), Box<dyn std::error::Error + Send + Sync>>74where75 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,76 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,77 C: Send + Sync + 'static,78 C: BlockchainEvents<Block>,79 C::Api: RuntimeApiDep<R>,80 B: sc_client_api::Backend<Block> + Send + Sync + 'static,81 P: TransactionPool<Block = Block> + 'static,82 R: RuntimeInstance + Send + Sync + 'static,83 <R as RuntimeInstance>::CrossAccountId: serde::Serialize,84 C: sp_api::CallApiAt<85 sp_runtime::generic::Block<86 sp_runtime::generic::Header<u32, BlakeTwo256>,87 sp_runtime::OpaqueExtrinsic,88 >,89 >,90 for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,91{92 93 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};94 use substrate_frame_rpc_system::{System, SystemApiServer};95 #[cfg(feature = "pov-estimate")]96 use uc_rpc::pov_estimate::{PovEstimate, PovEstimateApiServer};97 use uc_rpc::{AppPromotion, AppPromotionApiServer, Unique, UniqueApiServer};9899 let FullDeps {100 client,101 pool,102 select_chain: _,103 deny_unsafe,104105 runtime_id: _,106107 #[cfg(feature = "pov-estimate")]108 exec_params,109110 #[cfg(feature = "pov-estimate")]111 backend,112 } = deps;113114 io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;115 io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;116117 io.merge(Unique::new(client.clone()).into_rpc())?;118119 io.merge(AppPromotion::new(client).into_rpc())?;120121 #[cfg(feature = "pov-estimate")]122 io.merge(123 PovEstimate::new(124 client.clone(),125 backend,126 deny_unsafe,127 exec_params,128 runtime_id,129 )130 .into_rpc(),131 )?;132133 Ok(())134}135136pub struct EthDeps<C, P, CA: ChainApi, CIDP> {137 138 pub client: Arc<C>,139 140 pub pool: Arc<P>,141 142 pub graph: Arc<Pool<CA>>,143 144 pub sync: Arc<SyncingService<Block>>,145 146 pub is_authority: bool,147 148 pub network: Arc<NetworkService<Block, Hash>>,149150 151 pub eth_backend: Arc<dyn fc_api::Backend<Block> + Send + Sync>,152 153 pub max_past_logs: u32,154 155 pub fee_history_limit: u64,156 157 pub fee_history_cache: FeeHistoryCache,158 pub eth_block_data_cache: Arc<EthBlockDataCacheTask<Block>>,159 160 pub eth_filter_pool: Option<FilterPool>,161 pub eth_pubsub_notification_sinks:162 Arc<EthereumBlockNotificationSinks<EthereumBlockNotification<Block>>>,163 164 pub enable_dev_signer: bool,165166 pub overrides: Arc<OverrideHandle<Block>>,167 pub pending_create_inherent_data_providers: CIDP,168}169170pub fn create_eth<C, R, P, CA, B, CIDP, EC>(171 io: &mut RpcModule<()>,172 deps: EthDeps<C, P, CA, CIDP>,173 subscription_task_executor: SubscriptionTaskExecutor,174) -> Result<(), Box<dyn std::error::Error + Send + Sync>>175where176 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,177 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,178 C: Send + Sync + 'static,179 C: BlockchainEvents<Block>,180 C: UsageProvider<Block>,181 C::Api: RuntimeApiDep<R>,182 P: TransactionPool<Block = Block> + 'static,183 CA: ChainApi<Block = Block> + 'static,184 B: sc_client_api::Backend<Block> + Send + Sync + 'static,185 C: sp_api::CallApiAt<Block>,186 CIDP: CreateInherentDataProviders<Block, ()> + Send + 'static,187 EC: EthConfig<Block, C>,188 R: RuntimeInstance,189{190 use fc_rpc::{191 Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,192 EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,193 };194195 let EthDeps {196 client,197 pool,198 graph,199 eth_backend,200 max_past_logs,201 fee_history_limit,202 fee_history_cache,203 eth_block_data_cache,204 eth_filter_pool,205 eth_pubsub_notification_sinks,206 enable_dev_signer,207 sync,208 is_authority,209 network,210 overrides,211 pending_create_inherent_data_providers,212 } = deps;213214 let mut signers = Vec::new();215 if enable_dev_signer {216 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);217 }218 let execute_gas_limit_multiplier = 10;219 io.merge(220 Eth::<_, _, _, _, _, _, _, EC>::new(221 client.clone(),222 pool.clone(),223 graph.clone(),224 225 None::<NoTransactionConverter>,226 sync.clone(),227 signers,228 overrides.clone(),229 eth_backend.clone(),230 is_authority,231 eth_block_data_cache.clone(),232 fee_history_cache,233 fee_history_limit,234 execute_gas_limit_multiplier,235 None,236 pending_create_inherent_data_providers,237 Some(Box::new(AuraConsensusDataProvider::new(client.clone()))),238 )239 .into_rpc(),240 )?;241242 if let Some(filter_pool) = eth_filter_pool {243 io.merge(244 EthFilter::new(245 client.clone(),246 eth_backend,247 graph,248 filter_pool,249 500_usize, 250 max_past_logs,251 eth_block_data_cache,252 )253 .into_rpc(),254 )?;255 }256 io.merge(257 Net::new(258 client.clone(),259 network,260 261 true,262 )263 .into_rpc(),264 )?;265 io.merge(Web3::new(client.clone()).into_rpc())?;266 io.merge(267 EthPubSub::new(268 pool,269 client,270 sync,271 subscription_task_executor,272 overrides,273 eth_pubsub_notification_sinks,274 )275 .into_rpc(),276 )?;277278 Ok(())279}