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: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,104 BE: Backend<Block> + 'static,105 BE::State: StateBackend<BlakeTwo256>,106 R: RuntimeInstance + Send + Sync + 'static,107{108 let mut overrides_map = BTreeMap::new();109 overrides_map.insert(110 EthereumStorageSchema::V1,111 Box::new(SchemaV1Override::new(client.clone()))112 as Box<dyn StorageOverride<_> + Send + Sync>,113 );114 overrides_map.insert(115 EthereumStorageSchema::V2,116 Box::new(SchemaV2Override::new(client.clone()))117 as Box<dyn StorageOverride<_> + Send + Sync>,118 );119 overrides_map.insert(120 EthereumStorageSchema::V3,121 Box::new(SchemaV3Override::new(client.clone()))122 as Box<dyn StorageOverride<_> + Send + Sync>,123 );124125 Arc::new(OverrideHandle {126 schemas: overrides_map,127 fallback: Box::new(RuntimeApiStorageOverride::new(client)),128 })129}130131132pub fn create_full<C, P, SC, CA, R, A, B>(133 deps: FullDeps<C, P, SC, CA>,134 subscription_task_executor: SubscriptionTaskExecutor,135) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>136where137 C: ProvideRuntimeApi<Block> + StorageProvider<Block, B> + AuxStore,138 C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,139 C: Send + Sync + 'static,140 C: BlockchainEvents<Block>,141 C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,142 C::Api: BlockBuilder<Block>,143 144 C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,145 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,146 C::Api: fp_rpc::ConvertTransactionRuntimeApi<Block>,147 C::Api: up_rpc::UniqueApi<Block, <R as RuntimeInstance>::CrossAccountId, AccountId>,148 C::Api: app_promotion_rpc::AppPromotionApi<149 Block,150 BlockNumber,151 <R as RuntimeInstance>::CrossAccountId,152 AccountId,153 >,154 C::Api: rmrk_rpc::RmrkApi<155 Block,156 AccountId,157 RmrkCollectionInfo<AccountId>,158 RmrkInstanceInfo<AccountId>,159 RmrkResourceInfo,160 RmrkPropertyInfo,161 RmrkBaseInfo<AccountId>,162 RmrkPartType,163 RmrkTheme,164 >,165 B: sc_client_api::Backend<Block> + Send + Sync + 'static,166 B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,167 P: TransactionPool<Block = Block> + 'static,168 CA: ChainApi<Block = Block> + 'static,169 R: RuntimeInstance + Send + Sync + 'static,170 <R as RuntimeInstance>::CrossAccountId: serde::Serialize,171 for<'de> <R as RuntimeInstance>::CrossAccountId: serde::Deserialize<'de>,172{173 use fc_rpc::{174 Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub,175 EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer,176 };177 use uc_rpc::{UniqueApiServer, Unique};178179 #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]180 use uc_rpc::{AppPromotionApiServer, AppPromotion};181182 #[cfg(not(feature = "unique-runtime"))]183 use uc_rpc::{RmrkApiServer, Rmrk};184185 186 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};187 use substrate_frame_rpc_system::{System, SystemApiServer};188189 let mut io = RpcModule::new(());190 let FullDeps {191 client,192 pool,193 graph,194 select_chain: _,195 fee_history_limit,196 fee_history_cache,197 block_data_cache,198 enable_dev_signer,199 is_authority,200 network,201 deny_unsafe,202 filter_pool,203 backend,204 max_past_logs,205 } = deps;206207 io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?;208 io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;209210 211212 let mut signers = Vec::new();213 if enable_dev_signer {214 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);215 }216217 let overrides = overrides_handle::<_, _, R>(client.clone());218219 let execute_gas_limit_multiplier = 10;220 io.merge(221 Eth::new(222 client.clone(),223 pool.clone(),224 graph,225 Some(<R as RuntimeInstance>::get_transaction_converter()),226 network.clone(),227 signers,228 overrides.clone(),229 backend.clone(),230 is_authority,231 block_data_cache.clone(),232 fee_history_cache,233 fee_history_limit,234 execute_gas_limit_multiplier,235 )236 .into_rpc(),237 )?;238239 io.merge(Unique::new(client.clone()).into_rpc())?;240241 #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]242 io.merge(AppPromotion::new(client.clone()).into_rpc())?;243244 #[cfg(not(feature = "unique-runtime"))]245 io.merge(Rmrk::new(client.clone()).into_rpc())?;246247 if let Some(filter_pool) = filter_pool {248 io.merge(249 EthFilter::new(250 client.clone(),251 backend,252 filter_pool,253 500_usize, 254 max_past_logs,255 block_data_cache,256 )257 .into_rpc(),258 )?;259 }260261 io.merge(262 Net::new(263 client.clone(),264 network.clone(),265 266 true,267 )268 .into_rpc(),269 )?;270271 io.merge(Web3::new(client.clone()).into_rpc())?;272273 io.merge(274 EthPubSub::new(pool, client, network, subscription_task_executor, overrides).into_rpc(),275 )?;276277 Ok(io)278}