1234567891011121314151617use 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>;444546pub struct FullDeps<C, P> {47 48 pub client: Arc<C>,49 50 pub pool: Arc<P>,51 52 pub deny_unsafe: DenyUnsafe,53 54 #[cfg(feature = "pov-estimate")]55 pub exec_params: uc_rpc::pov_estimate::ExecutorParams,56 57 #[cfg(feature = "pov-estimate")]58 pub backend: Arc<FullBackend>,59}606162pub fn create_full<C, P, R, B>(63 io: &mut RpcModule<()>,64 deps: FullDeps<C, P>,65) -> Result<(), Box<dyn std::error::Error + Send + Sync>>66where67 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,68 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,69 C: Send + Sync + 'static,70 C: BlockchainEvents<Block>,71 C::Api: RuntimeApiDep<R>,72 B: sc_client_api::Backend<Block> + Send + Sync + 'static,73 P: TransactionPool<Block = Block> + 'static,74 R: RuntimeInstance + Send + Sync + 'static,75 <R as RuntimeInstance>::CrossAccountId: serde::Serialize,76 C: sp_api::CallApiAt<77 generic::Block<generic::Header<u32, BlakeTwo256>, sp_runtime::OpaqueExtrinsic>,78 >,79 for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,80{81 82 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};83 use substrate_frame_rpc_system::{System, SystemApiServer};84 #[cfg(feature = "pov-estimate")]85 use uc_rpc::pov_estimate::{PovEstimate, PovEstimateApiServer};86 use uc_rpc::{AppPromotion, AppPromotionApiServer, Unique, UniqueApiServer};8788 let FullDeps {89 client,90 pool,91 deny_unsafe,9293 #[cfg(feature = "pov-estimate")]94 exec_params,9596 #[cfg(feature = "pov-estimate")]97 backend,98 } = deps;99100 io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;101 io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;102103 io.merge(Unique::new(client.clone()).into_rpc())?;104105 io.merge(AppPromotion::new(client).into_rpc())?;106107 #[cfg(feature = "pov-estimate")]108 io.merge(109 PovEstimate::new(110 client.clone(),111 backend,112 deny_unsafe,113 exec_params,114 runtime_id,115 )116 .into_rpc(),117 )?;118119 Ok(())120}121122pub struct EthDeps<C, P, CA: ChainApi, CIDP> {123 124 pub client: Arc<C>,125 126 pub pool: Arc<P>,127 128 pub graph: Arc<Pool<CA>>,129 130 pub sync: Arc<SyncingService<Block>>,131 132 pub is_authority: bool,133 134 pub network: Arc<NetworkService<Block, Hash>>,135136 137 pub eth_backend: Arc<dyn fc_api::Backend<Block> + Send + Sync>,138 139 pub max_past_logs: u32,140 141 pub fee_history_limit: u64,142 143 pub fee_history_cache: FeeHistoryCache,144 pub eth_block_data_cache: Arc<EthBlockDataCacheTask<Block>>,145 146 pub eth_filter_pool: Option<FilterPool>,147 pub eth_pubsub_notification_sinks:148 Arc<EthereumBlockNotificationSinks<EthereumBlockNotification<Block>>>,149 150 pub enable_dev_signer: bool,151152 pub overrides: Arc<OverrideHandle<Block>>,153 pub pending_create_inherent_data_providers: CIDP,154}155156pub fn create_eth<C, R, P, CA, B, CIDP, EC>(157 io: &mut RpcModule<()>,158 deps: EthDeps<C, P, CA, CIDP>,159 subscription_task_executor: SubscriptionTaskExecutor,160) -> Result<(), Box<dyn std::error::Error + Send + Sync>>161where162 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,163 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,164 C: Send + Sync + 'static,165 C: BlockchainEvents<Block>,166 C: UsageProvider<Block>,167 C::Api: RuntimeApiDep<R>,168 P: TransactionPool<Block = Block> + 'static,169 CA: ChainApi<Block = Block> + 'static,170 B: sc_client_api::Backend<Block> + Send + Sync + 'static,171 C: sp_api::CallApiAt<Block>,172 CIDP: CreateInherentDataProviders<Block, ()> + Send + 'static,173 EC: EthConfig<Block, C>,174 R: RuntimeInstance,175{176 use fc_rpc::{177 Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,178 EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,179 };180181 let EthDeps {182 client,183 pool,184 graph,185 eth_backend,186 max_past_logs,187 fee_history_limit,188 fee_history_cache,189 eth_block_data_cache,190 eth_filter_pool,191 eth_pubsub_notification_sinks,192 enable_dev_signer,193 sync,194 is_authority,195 network,196 overrides,197 pending_create_inherent_data_providers,198 } = deps;199200 let mut signers = Vec::new();201 if enable_dev_signer {202 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);203 }204 let execute_gas_limit_multiplier = 10;205 io.merge(206 Eth::<_, _, _, _, _, _, _, EC>::new(207 client.clone(),208 pool.clone(),209 graph.clone(),210 211 None::<NoTransactionConverter>,212 sync.clone(),213 signers,214 overrides.clone(),215 eth_backend.clone(),216 is_authority,217 eth_block_data_cache.clone(),218 fee_history_cache,219 fee_history_limit,220 execute_gas_limit_multiplier,221 None,222 pending_create_inherent_data_providers,223 224 None,225 )226 .into_rpc(),227 )?;228229 if let Some(filter_pool) = eth_filter_pool {230 io.merge(231 EthFilter::new(232 client.clone(),233 eth_backend,234 graph,235 filter_pool,236 500_usize, 237 max_past_logs,238 eth_block_data_cache,239 )240 .into_rpc(),241 )?;242 }243 io.merge(244 Net::new(245 client.clone(),246 network,247 248 true,249 )250 .into_rpc(),251 )?;252 io.merge(Web3::new(client.clone()).into_rpc())?;253 io.merge(254 EthPubSub::new(255 pool,256 client,257 sync,258 subscription_task_executor,259 overrides,260 eth_pubsub_notification_sinks,261 )262 .into_rpc(),263 )?;264265 Ok(())266}