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::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance};444546use up_data_structs::{47 RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo, RmrkBaseInfo,48 RmrkPartType, RmrkTheme,49};505152pub struct GrandpaDeps<B> {53 54 pub shared_voter_state: SharedVoterState,55 56 pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,57 58 pub justification_stream: GrandpaJustificationStream<Block>,59 60 pub subscription_executor: SubscriptionTaskExecutor,61 62 pub finality_provider: Arc<FinalityProofProvider<B, Block>>,63}646566pub struct FullDeps<C, P, SC, CA: ChainApi> {67 68 pub client: Arc<C>,69 70 pub pool: Arc<P>,71 72 pub graph: Arc<Pool<CA>>,73 74 pub select_chain: SC,75 76 pub is_authority: bool,77 78 pub enable_dev_signer: bool,79 80 pub network: Arc<NetworkService<Block, Hash>>,81 82 pub deny_unsafe: DenyUnsafe,83 84 pub filter_pool: Option<FilterPool>,85 86 pub backend: Arc<fc_db::Backend<Block>>,87 88 pub max_past_logs: u32,89 90 pub fee_history_limit: u64,91 92 pub fee_history_cache: FeeHistoryCache,93 94 pub block_data_cache: Arc<EthBlockDataCacheTask<Block>>,95}9697pub fn overrides_handle<C, BE, R>(client: Arc<C>) -> Arc<OverrideHandle<Block>>98where99 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,100 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError>,101 C: Send + Sync + 'static,102 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,103 C::Api:104 up_rpc::UniqueApi<Block, BlockNumber, <R as RuntimeInstance>::CrossAccountId, AccountId>,105 BE: Backend<Block> + 'static,106 BE::State: StateBackend<BlakeTwo256>,107 R: RuntimeInstance + Send + Sync + 'static,108{109 let mut overrides_map = BTreeMap::new();110 overrides_map.insert(111 EthereumStorageSchema::V1,112 Box::new(SchemaV1Override::new(client.clone()))113 as Box<dyn StorageOverride<_> + Send + Sync>,114 );115 overrides_map.insert(116 EthereumStorageSchema::V2,117 Box::new(SchemaV2Override::new(client.clone()))118 as Box<dyn StorageOverride<_> + Send + Sync>,119 );120 overrides_map.insert(121 EthereumStorageSchema::V3,122 Box::new(SchemaV3Override::new(client.clone()))123 as Box<dyn StorageOverride<_> + Send + Sync>,124 );125126 Arc::new(OverrideHandle {127 schemas: overrides_map,128 fallback: Box::new(RuntimeApiStorageOverride::new(client)),129 })130}131132133pub fn create_full<C, P, SC, CA, R, A, B>(134 deps: FullDeps<C, P, SC, CA>,135 subscription_task_executor: SubscriptionTaskExecutor,136) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>137where138 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,139 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,140 C: Send + Sync + 'static,141 C: BlockchainEvents<Block>,142 C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,143 C::Api: BlockBuilder<Block>,144 145 C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,146 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,147 C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,148 C::Api:149 up_rpc::UniqueApi<Block, BlockNumber, <R as RuntimeInstance>::CrossAccountId, AccountId>,150 C::Api: app_promotion_rpc::AppPromotionApi<Block, BlockNumber, <R as RuntimeInstance>::CrossAccountId, AccountId>,151 C::Api: rmrk_rpc::RmrkApi<152 Block,153 AccountId,154 RmrkCollectionInfo<AccountId>,155 RmrkInstanceInfo<AccountId>,156 RmrkResourceInfo,157 RmrkPropertyInfo,158 RmrkBaseInfo<AccountId>,159 RmrkPartType,160 RmrkTheme,161 >,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};175 use uc_rpc::{AppPromotionApiServer, AppPromotion};176177 #[cfg(not(feature = "unique-runtime"))]178 use uc_rpc::{RmrkApiServer, Rmrk};179180 181 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};182 use substrate_frame_rpc_system::{System, SystemApiServer};183184 let mut io = RpcModule::new(());185 let FullDeps {186 client,187 pool,188 graph,189 select_chain: _,190 fee_history_limit,191 fee_history_cache,192 block_data_cache,193 enable_dev_signer,194 is_authority,195 network,196 deny_unsafe,197 filter_pool,198 backend,199 max_past_logs,200 } = deps;201202 io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;203 io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;204205 206207 let mut signers = Vec::new();208 if enable_dev_signer {209 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);210 }211212 let overrides = overrides_handle::<_, _, R>(client.clone());213214 io.merge(215 Eth::new(216 client.clone(),217 pool.clone(),218 graph,219 Some(<R as RuntimeInstance>::get_transaction_converter()),220 network.clone(),221 signers,222 overrides.clone(),223 backend.clone(),224 is_authority,225 block_data_cache.clone(),226 fee_history_cache,227 fee_history_limit,228 )229 .into_rpc(),230 )?;231232 io.merge(Unique::new(client.clone()).into_rpc())?;233234 #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]235 io.merge(AppPromotion::new(client.clone()).into_rpc())?;236237 #[cfg(not(feature = "unique-runtime"))]238 io.merge(Rmrk::new(client.clone()).into_rpc())?;239240 if let Some(filter_pool) = filter_pool {241 io.merge(242 EthFilter::new(243 client.clone(),244 backend,245 filter_pool,246 500_usize, 247 max_past_logs,248 block_data_cache,249 )250 .into_rpc(),251 )?;252 }253254 io.merge(255 Net::new(256 client.clone(),257 network.clone(),258 259 true,260 )261 .into_rpc(),262 )?;263264 io.merge(Web3::new(client.clone()).into_rpc())?;265266 io.merge(267 EthPubSub::new(pool, client, network, subscription_task_executor, overrides).into_rpc(),268 )?;269270 Ok(io)271}