From c31888337da04a7441bbedf7e41aeaf486bcc760 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Mon, 02 Oct 2023 22:07:15 +0000 Subject: [PATCH] refactor: move rpc to node --- --- a/node/rpc/CHANGELOG.md +++ /dev/null @@ -1,15 +0,0 @@ - -## [v0.1.2] 2022-09-08 - -### Added -- Support RPC for `AppPromotion` pallet. - -## [v0.1.1] 2022-08-16 - -### Other changes - -- build: Upgrade polkadot to v0.9.27 2c498572636f2b34d53b1c51b7283a761a7dc90a - -- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf8 - -- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b \ No newline at end of file --- a/node/rpc/Cargo.toml +++ /dev/null @@ -1,48 +0,0 @@ -[package] -authors = ['Unique Network '] -description = "Unique chain rpc" -edition = "2021" -license = 'GPLv3' -name = "unique-rpc" -version = "0.1.2" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -jsonrpsee = { workspace = true } -# pallet-contracts-rpc = { git = 'https://github.com/paritytech/substrate', branch = 'master' } -pallet-transaction-payment-rpc = { workspace = true } -sc-client-api = { workspace = true } -sc-network = { workspace = true } -sc-network-sync = { workspace = true } -sc-rpc = { workspace = true } -sc-rpc-api = { workspace = true } -sc-service = { workspace = true } -sc-transaction-pool = { workspace = true } -sp-api = { workspace = true } -sp-block-builder = { workspace = true } -sp-blockchain = { workspace = true } -sp-runtime = { workspace = true } -substrate-frame-rpc-system = { workspace = true } - -fc-db = { workspace = true } -fc-mapping-sync = { workspace = true } -fc-rpc = { workspace = true } -fc-rpc-core = { workspace = true } -fp-rpc = { workspace = true } -fp-storage = { workspace = true } - -app-promotion-rpc = { workspace = true } -pallet-ethereum.workspace = true -serde = { workspace = true } -uc-rpc = { workspace = true } -up-common = { workspace = true } -up-data-structs = { workspace = true } -up-pov-estimate-rpc = { workspace = true, default-features = true } -up-rpc = { workspace = true } - -[features] -default = [] -pov-estimate = ['uc-rpc/pov-estimate'] -std = [] --- a/node/rpc/src/lib.rs +++ /dev/null @@ -1,339 +0,0 @@ -// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. -// This file is part of Unique Network. - -// Unique Network is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Unique Network is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Unique Network. If not, see . - -use fc_mapping_sync::{EthereumBlockNotificationSinks, EthereumBlockNotification}; -use sp_runtime::traits::BlakeTwo256; -use fc_rpc::{ - EthBlockDataCacheTask, OverrideHandle, RuntimeApiStorageOverride, SchemaV1Override, - StorageOverride, SchemaV2Override, SchemaV3Override, -}; -use jsonrpsee::RpcModule; -use fc_rpc_core::types::{FilterPool, FeeHistoryCache}; -use fp_storage::EthereumStorageSchema; -use sc_client_api::{ - backend::{AuxStore, StorageProvider}, - client::BlockchainEvents, - StateBackend, Backend, -}; -use sc_network::NetworkService; -use sc_network_sync::SyncingService; -use sc_rpc::SubscriptionTaskExecutor; -pub use sc_rpc_api::DenyUnsafe; -use sc_transaction_pool::{ChainApi, Pool}; -use sp_api::ProvideRuntimeApi; -use sp_block_builder::BlockBuilder; -use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use sc_service::TransactionPool; -use std::{collections::BTreeMap, sync::Arc}; - -use up_common::types::opaque::*; - -#[cfg(feature = "pov-estimate")] -type FullBackend = sc_service::TFullBackend; - -/// Full client dependencies. -pub struct FullDeps { - /// The client instance to use. - pub client: Arc, - /// Transaction pool instance. - pub pool: Arc

, - /// The SelectChain Strategy - pub select_chain: SC, - /// Whether to deny unsafe calls - pub deny_unsafe: DenyUnsafe, - - /// Runtime identification (read from the chain spec) - pub runtime_id: RuntimeId, - /// Executor params for PoV estimating - #[cfg(feature = "pov-estimate")] - pub exec_params: uc_rpc::pov_estimate::ExecutorParams, - /// Substrate Backend. - #[cfg(feature = "pov-estimate")] - pub backend: Arc, -} - -pub fn overrides_handle(client: Arc) -> Arc> -where - C: ProvideRuntimeApi + StorageProvider + AuxStore, - C: HeaderBackend + HeaderMetadata, - C: Send + Sync + 'static, - C::Api: fp_rpc::EthereumRuntimeRPCApi, - C::Api: up_rpc::UniqueApi::CrossAccountId, AccountId>, - BE: Backend + 'static, - BE::State: StateBackend, - R: RuntimeInstance + Send + Sync + 'static, -{ - let mut overrides_map = BTreeMap::new(); - overrides_map.insert( - EthereumStorageSchema::V1, - Box::new(SchemaV1Override::new(client.clone())) as Box + 'static>, - ); - overrides_map.insert( - EthereumStorageSchema::V2, - Box::new(SchemaV2Override::new(client.clone())) as Box + 'static>, - ); - overrides_map.insert( - EthereumStorageSchema::V3, - Box::new(SchemaV3Override::new(client.clone())) as Box + 'static>, - ); - - Arc::new(OverrideHandle { - schemas: overrides_map, - fallback: Box::new(RuntimeApiStorageOverride::new(client)), - }) -} - -/// Instantiate all Full RPC extensions. -pub fn create_full( - io: &mut RpcModule<()>, - deps: FullDeps, -) -> Result<(), Box> -where - C: ProvideRuntimeApi + StorageProvider + AuxStore, - C: HeaderBackend + HeaderMetadata + 'static, - C: Send + Sync + 'static, - C: BlockchainEvents, - C::Api: substrate_frame_rpc_system::AccountNonceApi, - C::Api: BlockBuilder, - // C::Api: pallet_contracts_rpc::ContractsRuntimeApi, - C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, - C::Api: up_rpc::UniqueApi::CrossAccountId, AccountId>, - C::Api: app_promotion_rpc::AppPromotionApi< - Block, - BlockNumber, - ::CrossAccountId, - AccountId, - >, - C::Api: up_pov_estimate_rpc::PovEstimateApi, - B: sc_client_api::Backend + Send + Sync + 'static, - B::State: sc_client_api::backend::StateBackend>, - P: TransactionPool + 'static, - R: RuntimeInstance + Send + Sync + 'static, - ::CrossAccountId: serde::Serialize, - C: sp_api::CallApiAt< - sp_runtime::generic::Block< - sp_runtime::generic::Header, - sp_runtime::OpaqueExtrinsic, - >, - >, - for<'de> ::CrossAccountId: serde::Deserialize<'de>, -{ - use uc_rpc::{UniqueApiServer, Unique}; - - use uc_rpc::{AppPromotionApiServer, AppPromotion}; - - #[cfg(feature = "pov-estimate")] - use uc_rpc::pov_estimate::{PovEstimateApiServer, PovEstimate}; - - // use pallet_contracts_rpc::{Contracts, ContractsApi}; - use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; - use substrate_frame_rpc_system::{System, SystemApiServer}; - - let FullDeps { - client, - pool, - select_chain: _, - deny_unsafe, - - runtime_id: _, - - #[cfg(feature = "pov-estimate")] - exec_params, - - #[cfg(feature = "pov-estimate")] - backend, - } = deps; - - io.merge(System::new(Arc::clone(&client), Arc::clone(&pool), deny_unsafe).into_rpc())?; - io.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?; - - io.merge(Unique::new(client.clone()).into_rpc())?; - - io.merge(AppPromotion::new(client).into_rpc())?; - - #[cfg(feature = "pov-estimate")] - io.merge( - PovEstimate::new( - client.clone(), - backend, - deny_unsafe, - exec_params, - runtime_id, - ) - .into_rpc(), - )?; - - Ok(()) -} - -pub struct EthDeps { - /// The client instance to use. - pub client: Arc, - /// Transaction pool instance. - pub pool: Arc

, - /// Graph pool instance. - pub graph: Arc>, - /// Syncing service - pub sync: Arc>, - /// The Node authority flag - pub is_authority: bool, - /// Network service - pub network: Arc>, - - /// Ethereum Backend. - pub eth_backend: Arc + Send + Sync>, - /// Maximum number of logs in a query. - pub max_past_logs: u32, - /// Maximum fee history cache size. - pub fee_history_limit: u64, - /// Fee history cache. - pub fee_history_cache: FeeHistoryCache, - pub eth_block_data_cache: Arc>, - /// EthFilterApi pool. - pub eth_filter_pool: Option, - pub eth_pubsub_notification_sinks: - Arc>>, - /// Whether to enable eth dev signer - pub enable_dev_signer: bool, - - pub overrides: Arc>, -} - -/// This converter is never used, but we have a generic -/// Option, where T should implement ConvertTransaction -/// -/// TODO: remove after never-type (`!`) stabilization -enum NeverConvert {} -impl fp_rpc::ConvertTransaction for NeverConvert { - fn convert_transaction(&self, _transaction: pallet_ethereum::Transaction) -> T { - unreachable!() - } -} - -pub fn create_eth( - io: &mut RpcModule<()>, - deps: EthDeps, - subscription_task_executor: SubscriptionTaskExecutor, -) -> Result<(), Box> -where - C: ProvideRuntimeApi + StorageProvider + AuxStore, - C: HeaderBackend + HeaderMetadata + 'static, - C: Send + Sync + 'static, - C: BlockchainEvents, - C::Api: BlockBuilder, - C::Api: fp_rpc::EthereumRuntimeRPCApi, - C::Api: fp_rpc::ConvertTransactionRuntimeApi, - P: TransactionPool + 'static, - CA: ChainApi + 'static, - B: sc_client_api::Backend + Send + Sync + 'static, - C: sp_api::CallApiAt< - sp_runtime::generic::Block< - sp_runtime::generic::Header, - sp_runtime::OpaqueExtrinsic, - >, - >, -{ - use fc_rpc::{ - Eth, EthApiServer, EthDevSigner, EthFilter, EthFilterApiServer, EthPubSub, - EthPubSubApiServer, EthSigner, Net, NetApiServer, Web3, Web3ApiServer, TxPool, - TxPoolApiServer, - }; - - let EthDeps { - client, - pool, - graph, - eth_backend, - max_past_logs, - fee_history_limit, - fee_history_cache, - eth_block_data_cache, - eth_filter_pool, - eth_pubsub_notification_sinks, - enable_dev_signer, - sync, - is_authority, - network, - overrides, - } = deps; - - let mut signers = Vec::new(); - if enable_dev_signer { - signers.push(Box::new(EthDevSigner::new()) as Box); - } - let execute_gas_limit_multiplier = 10; - io.merge( - Eth::new( - client.clone(), - pool.clone(), - graph.clone(), - // We have no runtimes old enough to only accept converted transactions - None::, - sync.clone(), - signers, - overrides.clone(), - eth_backend.clone(), - is_authority, - eth_block_data_cache.clone(), - fee_history_cache, - fee_history_limit, - execute_gas_limit_multiplier, - None, - ) - .into_rpc(), - )?; - - let tx_pool = TxPool::new(client.clone(), graph); - - if let Some(filter_pool) = eth_filter_pool { - io.merge( - EthFilter::new( - client.clone(), - eth_backend, - tx_pool.clone(), - filter_pool, - 500_usize, // max stored filters - max_past_logs, - eth_block_data_cache, - ) - .into_rpc(), - )?; - } - io.merge( - Net::new( - client.clone(), - network, - // Whether to format the `peer_count` response as Hex (default) or not. - true, - ) - .into_rpc(), - )?; - io.merge(Web3::new(client.clone()).into_rpc())?; - io.merge( - EthPubSub::new( - pool, - client, - sync, - subscription_task_executor, - overrides, - eth_pubsub_notification_sinks, - ) - .into_rpc(), - )?; - io.merge(tx_pool.into_rpc())?; - - Ok(()) -} -- gitstuff