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 uc_rpc::AppPromotion;42use std::{collections::BTreeMap, sync::Arc};4344use up_common::types::opaque::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance};454647use up_data_structs::{48 RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo, RmrkBaseInfo,49 RmrkPartType, RmrkTheme,50};515253pub struct GrandpaDeps<B> {54 55 pub shared_voter_state: SharedVoterState,56 57 pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,58 59 pub justification_stream: GrandpaJustificationStream<Block>,60 61 pub subscription_executor: SubscriptionTaskExecutor,62 63 pub finality_provider: Arc<FinalityProofProvider<B, Block>>,64}656667pub struct FullDeps<C, P, SC, CA: ChainApi> {68 69 pub client: Arc<C>,70 71 pub pool: Arc<P>,72 73 pub graph: Arc<Pool<CA>>,74 75 pub select_chain: SC,76 77 pub is_authority: bool,78 79 pub enable_dev_signer: bool,80 81 pub network: Arc<NetworkService<Block, Hash>>,82 83 pub deny_unsafe: DenyUnsafe,84 85 pub filter_pool: Option<FilterPool>,86 87 pub backend: Arc<fc_db::Backend<Block>>,88 89 pub max_past_logs: u32,90 91 pub fee_history_limit: u64,92 93 pub fee_history_cache: FeeHistoryCache,94 95 pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,96}9798pub fn overrides_handle<C, BE, R>(client: Arc<C>) -> Arc<OverrideHandle<Block>>99where100 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,101 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,102 C: Send + Sync + 'static,103 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,104 C::Api:105 up_rpc::UniqueApi<Block, BlockNumber, <R as RuntimeInstance>::CrossAccountId, AccountId>,106 BE: Backend<Block> + 'static,107 BE::State: StateBackend<BlakeTwo256>,108 R: RuntimeInstance + Send + Sync + 'static,109{110 let mut overrides_map = BTreeMap::new();111 overrides_map.insert(112 EthereumStorageSchema::V1,113 Box::new(SchemaV1Override::new(client.clone()))114 as Box<dyn StorageOverride<_> + Send + Sync>,115 );116 overrides_map.insert(117 EthereumStorageSchema::V2,118 Box::new(SchemaV2Override::new(client.clone()))119 as Box<dyn StorageOverride<_> + Send + Sync>,120 );121 overrides_map.insert(122 EthereumStorageSchema::V3,123 Box::new(SchemaV3Override::new(client.clone()))124 as Box<dyn StorageOverride<_> + Send + Sync>,125 );126127 Arc::new(OverrideHandle {128 schemas: overrides_map,129 fallback: Box::new(RuntimeApiStorageOverride::new(client)),130 })131}132133134pub fn create_full<C, P, SC, CA, R, A, B>(135 deps: FullDeps<C, P, SC, CA>,136 subscription_task_executor: SubscriptionTaskExecutor,137) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>138where139 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,140 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,141 C: Send + Sync + 'static,142 C: BlockchainEvents<Block>,143 C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,144 C::Api: BlockBuilder<Block>,145 146 C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,147 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,148 C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,149 C::Api:150 up_rpc::UniqueApi<Block, BlockNumber, <R as RuntimeInstance>::CrossAccountId, AccountId>,151 C::Api: app_promotion_rpc::AppPromotionApi<Block, BlockNumber, <R as RuntimeInstance>::CrossAccountId, AccountId>,152 C::Api: rmrk_rpc::RmrkApi<153 Block,154 AccountId,155 RmrkCollectionInfo<AccountId>,156 RmrkInstanceInfo<AccountId>,157 RmrkResourceInfo,158 RmrkPropertyInfo,159 RmrkBaseInfo<AccountId>,160 RmrkPartType,161 RmrkTheme,162 >,163 B: sc_client_api::Backend<Block> + Send + Sync + 'static,164 B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,165 P: TransactionPool<Block = Block> + 'static,166 CA: ChainApi<Block = Block> + 'static,167 R: RuntimeInstance + Send + Sync + 'static,168 <R as RuntimeInstance>::CrossAccountId: serde::Serialize,169 for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,170{171 use fc_rpc::{172 Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,173 EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,174 };175 use uc_rpc::{UniqueApiServer, Unique};176 use uc_rpc::{AppPromotionApiServer, AppPromotion};177178 #[cfg(not(feature = "unique-runtime"))]179 use uc_rpc::{RmrkApiServer, Rmrk};180181 182 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};183 use substrate_frame_rpc_system::{System, SystemApiServer};184185 let mut io = RpcModule::new(());186 let FullDeps {187 client,188 pool,189 graph,190 select_chain: _,191 fee_history_limit,192 fee_history_cache,193 block_data_cache,194 enable_dev_signer,195 is_authority,196 network,197 deny_unsafe,198 filter_pool,199 backend,200 max_past_logs,201 } = deps;202203 io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;204 io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;205206 207208 let mut signers = Vec::new();209 if enable_dev_signer {210 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);211 }212213 let overrides = overrides_handle::<_, _, R>(client.clone());214215 io.merge(216 Eth::new(217 client.clone(),218 pool.clone(),219 graph,220 Some(<R as RuntimeInstance>::get_transaction_converter()),221 network.clone(),222 signers,223 overrides.clone(),224 backend.clone(),225 is_authority,226 block_data_cache.clone(),227 fee_history_cache,228 fee_history_limit,229 )230 .into_rpc(),231 )?;232233 io.merge(Unique::new(client.clone()).into_rpc())?;234235 236 io.merge(AppPromotion::new(client.clone()).into_rpc())?;237238 #[cfg(not(feature = "unique-runtime"))]239 io.merge(Rmrk::new(client.clone()).into_rpc())?;240241 if let Some(filter_pool) = filter_pool {242 io.merge(243 EthFilter::new(244 client.clone(),245 backend,246 filter_pool,247 500_usize, 248 max_past_logs,249 block_data_cache,250 )251 .into_rpc(),252 )?;253 }254255 io.merge(256 Net::new(257 client.clone(),258 network.clone(),259 260 true,261 )262 .into_rpc(),263 )?;264265 io.merge(Web3::new(client.clone()).into_rpc())?;266267 io.merge(268 EthPubSub::new(pool, client, network, subscription_task_executor, overrides).into_rpc(),269 )?;270271 Ok(io)272}