123456use std::sync::Arc;78use std::collections::BTreeMap;9use fc_rpc_core::types::{PendingTransactions, FilterPool};10use nft_runtime::{Hash, AccountId, Index, opaque::Block, Balance};11use sp_api::ProvideRuntimeApi;12use sp_blockchain::{Error as BlockChainError, HeaderMetadata, HeaderBackend};13use sc_client_api::{14 backend::{StorageProvider, Backend, StateBackend, AuxStore},15 client::BlockchainEvents16};17use sc_rpc::SubscriptionTaskExecutor;18use sp_runtime::traits::BlakeTwo256;19use sp_block_builder::BlockBuilder;20use sc_rpc_api::DenyUnsafe;21use sp_transaction_pool::TransactionPool;22use sc_network::NetworkService;23use jsonrpc_pubsub::manager::SubscriptionManager;24use pallet_ethereum::EthereumStorageSchema;25use fc_rpc::{StorageOverride, SchemaV1Override};262728pub struct LightDeps<C, F, P> {29 30 pub client: Arc<C>,31 32 pub pool: Arc<P>,33 34 pub remote_blockchain: Arc<dyn sc_client_api::light::RemoteBlockchain<Block>>,35 36 pub fetcher: Arc<F>,37}383940pub struct FullDeps<C, P> {41 42 pub client: Arc<C>,43 44 pub pool: Arc<P>,45 46 pub deny_unsafe: DenyUnsafe,47 48 pub is_authority: bool,49 50 pub enable_dev_signer: bool,51 52 pub network: Arc<NetworkService<Block, Hash>>,53 54 pub pending_transactions: PendingTransactions,55 56 pub filter_pool: Option<FilterPool>,57 58 pub backend: Arc<fc_db::Backend<Block>>,59}606162pub fn create_full<C, P, BE>(63 deps: FullDeps<C, P>,64 subscription_task_executor: SubscriptionTaskExecutor65) -> jsonrpc_core::IoHandler<sc_rpc::Metadata> where66 BE: Backend<Block> + 'static,67 BE::State: StateBackend<BlakeTwo256>,68 C: ProvideRuntimeApi<Block> + StorageProvider<Block, BE> + AuxStore,69 C: BlockchainEvents<Block>,70 C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError>,71 C: Send + Sync + 'static,72 C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,73 C::Api: BlockBuilder<Block>,74 C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,75 C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,76 P: TransactionPool<Block=Block> + 'static,77{78 use substrate_frame_rpc_system::{FullSystem, SystemApi};79 use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};80 use fc_rpc::{81 EthApi, EthApiServer, EthFilterApi, EthFilterApiServer, NetApi, NetApiServer,82 EthPubSubApi, EthPubSubApiServer, Web3Api, Web3ApiServer, EthDevSigner, EthSigner,83 HexEncodedIdProvider,84 };8586 let mut io = jsonrpc_core::IoHandler::default();87 let FullDeps {88 client,89 pool,90 deny_unsafe,91 is_authority,92 network,93 pending_transactions,94 filter_pool,95 backend,96 enable_dev_signer,97 } = deps;9899 io.extend_with(100 SystemApi::to_delegate(FullSystem::new(client.clone(), pool.clone(), deny_unsafe))101 );102103 io.extend_with(104 TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone()))105 );106107 108 109 110111 let mut signers = Vec::new();112 if enable_dev_signer {113 signers.push(Box::new(EthDevSigner::new()) as Box<dyn EthSigner>);114 }115 let mut overrides = BTreeMap::new();116 overrides.insert(117 EthereumStorageSchema::V1,118 Box::new(SchemaV1Override::new(client.clone())) as Box<dyn StorageOverride<_> + Send + Sync>119 );120 io.extend_with(121 EthApiServer::to_delegate(EthApi::new(122 client.clone(),123 pool.clone(),124 nft_runtime::TransactionConverter,125 network.clone(),126 pending_transactions.clone(),127 signers,128 overrides,129 backend,130 is_authority,131 ))132 );133134 if let Some(filter_pool) = filter_pool {135 io.extend_with(136 EthFilterApiServer::to_delegate(EthFilterApi::new(137 client.clone(),138 filter_pool.clone(),139 500 as usize, 140 ))141 );142 }143144 io.extend_with(145 NetApiServer::to_delegate(NetApi::new(146 client.clone(),147 network.clone(),148 ))149 );150151 io.extend_with(152 Web3ApiServer::to_delegate(Web3Api::new(153 client.clone(),154 ))155 );156157 io.extend_with(158 EthPubSubApiServer::to_delegate(EthPubSubApi::new(159 pool.clone(),160 client.clone(),161 network.clone(),162 SubscriptionManager::<HexEncodedIdProvider>::with_id_provider(163 HexEncodedIdProvider::default(),164 Arc::new(subscription_task_executor)165 ),166 ))167 );168169 io170}171172173pub fn create_light<C, P, M, F>(174 deps: LightDeps<C, F, P>,175) -> jsonrpc_core::IoHandler<M> where176 C: sp_blockchain::HeaderBackend<Block>,177 C: Send + Sync + 'static,178 F: sc_client_api::light::Fetcher<Block> + 'static,179 P: TransactionPool + 'static,180 M: jsonrpc_core::Metadata + Default,181{182 use substrate_frame_rpc_system::{LightSystem, SystemApi};183184 let LightDeps {185 client,186 pool,187 remote_blockchain,188 fetcher189 } = deps;190 let mut io = jsonrpc_core::IoHandler::default();191 io.extend_with(192 SystemApi::<Hash, AccountId, Index>::to_delegate(193 LightSystem::new(client, remote_blockchain, fetcher, pool)194 )195 );196197 io198}