1234567891011121314151617use sp_runtime::traits::BlakeTwo256;18use fc_rpc::{19 EthBlockDataCacheTask, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override,20 StorageOverride, SchemaV2Override, SchemaV3Override,21};22use jsonrpsee::RpcModule;23use fc_rpc_core::types::{FilterPool, FeeHistoryCache};24use fp_storage::EthereumStorageSchema;25use sc_client_api::{26 backend::{AuxStore, StorageProvider},27 client::BlockchainEvents,28 StateBackend, Backend,29};30use sc_finality_grandpa::{31 FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,32};33use sc_network::NetworkService;34use sc_rpc::SubscriptionTaskExecutor;35pub use sc_rpc_api::DenyUnsafe;36use sc_transaction_pool::{ChainApi, Pool};37use sp_api::ProvideRuntimeApi;38use sp_block_builder::BlockBuilder;39use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};40use sc_service::TransactionPool;41use std::{collections::BTreeMap, sync::Arc};4243use up_common::types::opaque::*;4445#[cfg(feature = "pov-estimate")]46type FullBackend = sc_service::TFullBackend<Block>;474849pub struct GrandpaDeps<B> {50 51 pub shared_voter_state: SharedVoterState,52 53 pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,54 55 pub justification_stream: GrandpaJustificationStream<Block>,56 57 pub subscription_executor: SubscriptionTaskExecutor,58 59 pub finality_provider: Arc<FinalityProofProvider<B, Block>>,60}616263pub struct FullDeps<C, P, SC, CA: ChainApi> {64 65 pub client: Arc<C>,66 67 pub pool: Arc<P>,68 69 pub graph: Arc<Pool<CA>>,70 71 pub select_chain: SC,72 73 pub is_authority: bool,74 75 pub enable_dev_signer: bool,76 77 pub network: Arc<NetworkService<Block, Hash>>,78 79 pub deny_unsafe: DenyUnsafe,80 81 pub filter_pool: Option<FilterPool>,8283 #[cfg(feature = "pov-estimate")]84 pub runtime_id: RuntimeId,85 86 #[cfg(feature = "pov-estimate")]87 pub exec_params: uc_rpc::pov_estimate::ExecutorParams,88 89 #[cfg(feature = "pov-estimate")]90 pub backend: Arc<FullBackend>,9192 93 pub eth_backend: Arc<fc_db::Backend<Block>>,94 95 pub max_past_logs: u32,96 97 pub fee_history_limit: u64,98 99 pub fee_history_cache: FeeHistoryCache,100 101 pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,102}103104pub fn overrides_handle<C, BE, R>(client: Arc<C>) -> Arc<OverrideHandle<Block>>105where106 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,107 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,108 C: Send + Sync + 'static,109 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,110 C::Api: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,111 BE: Backend<Block> + 'static,112 BE::State: StateBackend<BlakeTwo256>,113 R: RuntimeInstance + Send + Sync + 'static,114{115 let mut overrides_map = BTreeMap::new();116 overrides_map.insert(117 EthereumStorageSchema::V1,118 Box::new(SchemaV1Override::new(client.clone()))119 as Box<dyn StorageOverride<_> + Send + Sync>,120 );121 overrides_map.insert(122 EthereumStorageSchema::V2,123 Box::new(SchemaV2Override::new(client.clone()))124 as Box<dyn StorageOverride<_> + Send + Sync>,125 );126 overrides_map.insert(127 EthereumStorageSchema::V3,128 Box::new(SchemaV3Override::new(client.clone()))129 as Box<dyn StorageOverride<_> + Send + Sync>,130 );131132 Arc::new(OverrideHandle {133 schemas: overrides_map,134 fallback: Box::new(RuntimeApiStorageOverride::new(client)),135 })136}137138139pub fn create_full<C, P, SC, CA, R, A, B>(140 deps: FullDeps<C, P, SC, CA>,141 subscription_task_executor: SubscriptionTaskExecutor,142) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>143where144 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,145 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,146 C: Send + Sync + 'static,147 C: BlockchainEvents<Block>,148 C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,149 C::Api: BlockBuilder<Block>,150 151 C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,152 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,153 C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,154 C::Api: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,155 C::Api: app_promotion_rpc::AppPromotionApi<156 Block,157 BlockNumber,158 <R as RuntimeInstance>::CrossAccountId,159 AccountId,160 >,161 C::Api: up_pov_estimate_rpc::PovEstimateApi<Block>,162 B: sc_client_api::Backend<Block> + Send + Sync + 'static,163 B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,164 P: TransactionPool<Block = Block> + 'static,165 CA: ChainApi<Block = Block> + 'static,166 R: RuntimeInstance + Send + Sync + 'static,167 <R as RuntimeInstance>::CrossAccountId: serde::Serialize,168 for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,169{170 use fc_rpc::{171 Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,172 EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,173 };174 use uc_rpc::{UniqueApiServer, Unique};175176 #[cfg(not(feature = "unique-runtime"))]177 use uc_rpc::{AppPromotionApiServer, AppPromotion};178179 #[cfg(feature = "pov-estimate")]180 use uc_rpc::pov_estimate::{PovEstimateApiServer, PovEstimate};181182 183 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};184 use substrate_frame_rpc_system::{System, SystemApiServer};185186 let mut io = RpcModule::new(());187 let FullDeps {188 client,189 pool,190 graph,191 select_chain: _,192 fee_history_limit,193 fee_history_cache,194 block_data_cache,195 enable_dev_signer,196 is_authority,197 network,198 deny_unsafe,199 filter_pool,200201 #[cfg(feature = "pov-estimate")]202 runtime_id,203204 #[cfg(feature = "pov-estimate")]205 exec_params,206207 #[cfg(feature = "pov-estimate")]208 backend,209210 eth_backend,211 max_past_logs,212 } = deps;213214 io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;215 io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;216217 218219 let mut signers = Vec::new();220 if enable_dev_signer {221 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);222 }223224 let overrides = overrides_handle::<_, _, R>(client.clone());225226 let execute_gas_limit_multiplier = 10;227 io.merge(228 Eth::new(229 client.clone(),230 pool.clone(),231 graph,232 Some(<R as RuntimeInstance>::get_transaction_converter()),233 network.clone(),234 signers,235 overrides.clone(),236 eth_backend.clone(),237 is_authority,238 block_data_cache.clone(),239 fee_history_cache,240 fee_history_limit,241 execute_gas_limit_multiplier,242 )243 .into_rpc(),244 )?;245246 io.merge(Unique::new(client.clone()).into_rpc())?;247248 #[cfg(not(feature = "unique-runtime"))]249 io.merge(AppPromotion::new(client.clone()).into_rpc())?;250251 #[cfg(feature = "pov-estimate")]252 io.merge(253 PovEstimate::new(254 client.clone(),255 backend,256 deny_unsafe,257 exec_params,258 runtime_id,259 )260 .into_rpc(),261 )?;262263 if let Some(filter_pool) = filter_pool {264 io.merge(265 EthFilter::new(266 client.clone(),267 eth_backend,268 filter_pool,269 500_usize, 270 max_past_logs,271 block_data_cache,272 )273 .into_rpc(),274 )?;275 }276277 io.merge(278 Net::new(279 client.clone(),280 network.clone(),281 282 true,283 )284 .into_rpc(),285 )?;286287 io.merge(Web3::new(client.clone()).into_rpc())?;288289 io.merge(290 EthPubSub::new(pool, client, network, subscription_task_executor, overrides).into_rpc(),291 )?;292293 Ok(io)294}