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_consensus_grandpa::{31 FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,32};33use sc_network::NetworkService;34use sc_network_sync::SyncingService;35use sc_rpc::SubscriptionTaskExecutor;36pub use sc_rpc_api::DenyUnsafe;37use sc_transaction_pool::{ChainApi, Pool};38use sp_api::ProvideRuntimeApi;39use sp_block_builder::BlockBuilder;40use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};41use sc_service::TransactionPool;42use std::{collections::BTreeMap, sync::Arc};4344use up_common::types::opaque::*;4546#[cfg(feature = "pov-estimate")]47type FullBackend = sc_service::TFullBackend<Block>;484950pub struct GrandpaDeps<B> {51 52 pub shared_voter_state: SharedVoterState,53 54 pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,55 56 pub justification_stream: GrandpaJustificationStream<Block>,57 58 pub subscription_executor: SubscriptionTaskExecutor,59 60 pub finality_provider: Arc<FinalityProofProvider<B, Block>>,61}626364pub struct FullDeps<C, P, SC, CA: ChainApi> {65 66 pub client: Arc<C>,67 68 pub pool: Arc<P>,69 70 pub graph: Arc<Pool<CA>>,71 72 pub select_chain: SC,73 74 pub is_authority: bool,75 76 pub enable_dev_signer: bool,77 78 pub network: Arc<NetworkService<Block, Hash>>,79 80 pub sync: Arc<SyncingService<Block>>,81 82 pub deny_unsafe: DenyUnsafe,83 84 pub filter_pool: Option<FilterPool>,8586 87 pub runtime_id: RuntimeId,88 89 #[cfg(feature = "pov-estimate")]90 pub exec_params: uc_rpc::pov_estimate::ExecutorParams,91 92 #[cfg(feature = "pov-estimate")]93 pub backend: Arc<FullBackend>,9495 96 pub eth_backend: Arc<fc_db::Backend<Block>>,97 98 pub max_past_logs: u32,99 100 pub fee_history_limit: u64,101 102 pub fee_history_cache: FeeHistoryCache,103 104 pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,105}106107pub fn overrides_handle<C, BE, R>(client: Arc<C>) -> Arc<OverrideHandle<Block>>108where109 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,110 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,111 C: Send + Sync + 'static,112 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,113 C::Api: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,114 BE: Backend<Block> + 'static,115 BE::State: StateBackend<BlakeTwo256>,116 R: RuntimeInstance + Send + Sync + 'static,117{118 let mut overrides_map = BTreeMap::new();119 overrides_map.insert(120 EthereumStorageSchema::V1,121 Box::new(SchemaV1Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,122 );123 overrides_map.insert(124 EthereumStorageSchema::V2,125 Box::new(SchemaV2Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,126 );127 overrides_map.insert(128 EthereumStorageSchema::V3,129 Box::new(SchemaV3Override::new(client.clone())) as Box<dyn StorageOverride<_> + 'static>,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 C: sp_api::CallApiAt<169 sp_runtime::generic::Block<170 sp_runtime::generic::Header<u32, BlakeTwo256>,171 sp_runtime::OpaqueExtrinsic,172 >,173 >,174 for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,175{176 use fc_rpc::{177 Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,178 EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,179 };180 use uc_rpc::{UniqueApiServer, Unique};181182 use uc_rpc::{AppPromotionApiServer, AppPromotion};183184 #[cfg(feature = "pov-estimate")]185 use uc_rpc::pov_estimate::{PovEstimateApiServer, PovEstimate};186187 188 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};189 use substrate_frame_rpc_system::{System, SystemApiServer};190191 let mut io = RpcModule::new(());192 let FullDeps {193 client,194 pool,195 graph,196 select_chain: _,197 fee_history_limit,198 fee_history_cache,199 block_data_cache,200 enable_dev_signer,201 is_authority,202 network,203 sync,204 deny_unsafe,205 filter_pool,206207 runtime_id: _,208209 #[cfg(feature = "pov-estimate")]210 exec_params,211212 #[cfg(feature = "pov-estimate")]213 backend,214215 eth_backend,216 max_past_logs,217 } = deps;218219 io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;220 io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;221222 223224 let mut signers = Vec::new();225 if enable_dev_signer {226 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);227 }228229 let overrides = overrides_handle::<_, _, R>(client.clone());230231 let execute_gas_limit_multiplier = 10;232 io.merge(233 Eth::new(234 client.clone(),235 pool.clone(),236 graph,237 Some(<R as RuntimeInstance>::get_transaction_converter()),238 sync.clone(),239 signers,240 overrides.clone(),241 eth_backend.clone(),242 is_authority,243 block_data_cache.clone(),244 fee_history_cache,245 fee_history_limit,246 execute_gas_limit_multiplier,247 )248 .into_rpc(),249 )?;250251 io.merge(Unique::new(client.clone()).into_rpc())?;252253 io.merge(AppPromotion::new(client.clone()).into_rpc())?;254255 #[cfg(feature = "pov-estimate")]256 io.merge(257 PovEstimate::new(258 client.clone(),259 backend,260 deny_unsafe,261 exec_params,262 runtime_id,263 )264 .into_rpc(),265 )?;266267 if let Some(filter_pool) = filter_pool {268 io.merge(269 EthFilter::new(270 client.clone(),271 eth_backend,272 filter_pool,273 500_usize, 274 max_past_logs,275 block_data_cache,276 )277 .into_rpc(),278 )?;279 }280281 io.merge(282 Net::new(283 client.clone(),284 network.clone(),285 286 true,287 )288 .into_rpc(),289 )?;290291 io.merge(Web3::new(client.clone()).into_rpc())?;292293 io.merge(EthPubSub::new(pool, client, sync, subscription_task_executor, overrides).into_rpc())?;294295 Ok(io)296}