difftreelog
fix some rpc fixes
in: master
3 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -412,47 +412,27 @@
}
}
-pub struct Unique<C, P> {
- client: Arc<C>,
- _marker: std::marker::PhantomData<P>,
-}
-
-impl<C, P> Unique<C, P> {
- pub fn new(client: Arc<C>) -> Self {
- Self {
- client,
- _marker: Default::default(),
+macro_rules! define_struct_for_server_api {
+ ($name:ident) => {
+ pub struct $name<C, P> {
+ client: Arc<C>,
+ _marker: std::marker::PhantomData<P>,
}
- }
-}
-
-pub struct AppPromotion<C, P> {
- client: Arc<C>,
- _marker: std::marker::PhantomData<P>,
-}
-
-impl<C, P> AppPromotion<C, P> {
- pub fn new(client: Arc<C>) -> Self {
- Self {
- client,
- _marker: Default::default(),
+
+ impl<C, P> $name<C, P> {
+ pub fn new(client: Arc<C>) -> Self {
+ Self {
+ client,
+ _marker: Default::default(),
+ }
+ }
}
- }
-}
-
-pub struct Rmrk<C, P> {
- client: Arc<C>,
- _marker: std::marker::PhantomData<P>,
+ };
}
-impl<C, P> Rmrk<C, P> {
- pub fn new(client: Arc<C>) -> Self {
- Self {
- client,
- _marker: Default::default(),
- }
- }
-}
+define_struct_for_server_api!(Unique);
+define_struct_for_server_api!(AppPromotion);
+define_struct_for_server_api!(Rmrk);
macro_rules! pass_method {
(
@@ -605,14 +585,14 @@
|v| v
.into_iter()
.map(|(b, a)| (b, a.to_string()))
- .collect::<Vec<_>>(), unique_api);
- pass_method!(total_staking_locked(staker: CrossAccountId) -> String => |v| v.to_string(), unique_api);
- pass_method!(pending_unstake(staker: Option<CrossAccountId>) -> String => |v| v.to_string(), unique_api);
+ .collect::<Vec<_>>(), app_promotion_api);
+ pass_method!(total_staking_locked(staker: CrossAccountId) -> String => |v| v.to_string(), app_promotion_api);
+ pass_method!(pending_unstake(staker: Option<CrossAccountId>) -> String => |v| v.to_string(), app_promotion_api);
pass_method!(pending_unstake_per_block(staker: CrossAccountId) -> Vec<(BlockNumber, String)> =>
|v| v
.into_iter()
.map(|(b, a)| (b, a.to_string()))
- .collect::<Vec<_>>(), unique_api);
+ .collect::<Vec<_>>(), app_promotion_api);
}
#[allow(deprecated)]
node/rpc/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use 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};4546// RMRK47use up_data_structs::{48 RmrkCollectionInfo, RmrkInstanceInfo, RmrkResourceInfo, RmrkPropertyInfo, RmrkBaseInfo,49 RmrkPartType, RmrkTheme,50};5152/// Extra dependencies for GRANDPA53pub struct GrandpaDeps<B> {54 /// Voting round info.55 pub shared_voter_state: SharedVoterState,56 /// Authority set info.57 pub shared_authority_set: SharedAuthoritySet<Hash, BlockNumber>,58 /// Receives notifications about justification events from Grandpa.59 pub justification_stream: GrandpaJustificationStream<Block>,60 /// Executor to drive the subscription manager in the Grandpa RPC handler.61 pub subscription_executor: SubscriptionTaskExecutor,62 /// Finality proof provider.63 pub finality_provider: Arc<FinalityProofProvider<B, Block>>,64}6566/// Full client dependencies.67pub struct FullDeps<C, P, SC, CA: ChainApi> {68 /// The client instance to use.69 pub client: Arc<C>,70 /// Transaction pool instance.71 pub pool: Arc<P>,72 /// Graph pool instance.73 pub graph: Arc<Pool<CA>>,74 /// The SelectChain Strategy75 pub select_chain: SC,76 /// The Node authority flag77 pub is_authority: bool,78 /// Whether to enable dev signer79 pub enable_dev_signer: bool,80 /// Network service81 pub network: Arc<NetworkService<Block, Hash>>,82 /// Whether to deny unsafe calls83 pub deny_unsafe: DenyUnsafe,84 /// EthFilterApi pool.85 pub filter_pool: Option<FilterPool>,86 /// Backend.87 pub backend: Arc<fc_db::Backend<Block>>,88 /// Maximum number of logs in a query.89 pub max_past_logs: u32,90 /// Maximum fee history cache size.91 pub fee_history_limit: u64,92 /// Fee history cache.93 pub fee_history_cache: FeeHistoryCache,94 /// Cache for Ethereum block data.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}132133/// Instantiate all Full RPC extensions.134pub 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 // C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber, Hash>,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 // use pallet_contracts_rpc::{Contracts, ContractsApi};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 // io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));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 // #[cfg(not(feature = "unique-runtime"))]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, // max stored filters248 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 // Whether to format the `peer_count` response as Hex (default) or not.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}tests/src/interfaces/augment-api-query.tsdiffbeforeafterboth--- a/tests/src/interfaces/augment-api-query.ts
+++ b/tests/src/interfaces/augment-api-query.ts
@@ -6,7 +6,7 @@
import '@polkadot/api-base/types/storage';
import type { ApiTypes, AugmentedQuery, QueryableStorageEntry } from '@polkadot/api-base/types';
-import type { BTreeMap, Bytes, Option, U256, U8aFixed, Vec, bool, u128, u16, u32, u64 } from '@polkadot/types-codec';
+import type { BTreeMap, Bytes, Option, U256, U8aFixed, Vec, bool, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
import type { AnyNumber, ITuple } from '@polkadot/types-codec/types';
import type { AccountId32, H160, H256 } from '@polkadot/types/interfaces/runtime';
import type { CumulusPalletDmpQueueConfigData, CumulusPalletDmpQueuePageIndexData, CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, CumulusPalletXcmpQueueInboundChannelDetails, CumulusPalletXcmpQueueOutboundChannelDetails, CumulusPalletXcmpQueueQueueConfigData, EthereumBlock, EthereumLog, EthereumReceiptReceiptV3, EthereumTransactionTransactionV2, FpRpcTransactionStatus, FrameSupportWeightsPerDispatchClassU64, FrameSystemAccountInfo, FrameSystemEventRecord, FrameSystemLastRuntimeUpgradeInfo, FrameSystemPhase, OrmlVestingVestingSchedule, PalletBalancesAccountData, PalletBalancesBalanceLock, PalletBalancesReleases, PalletBalancesReserveData, PalletEvmAccountBasicCrossAccountIdRepr, PalletEvmContractHelpersSponsoringModeT, PalletNonfungibleItemData, PalletRefungibleItemData, PalletTransactionPaymentReleases, PalletTreasuryProposal, PalletUniqueSchedulerScheduledV3, PhantomTypeUpDataStructs, PolkadotCorePrimitivesOutboundHrmpMessage, PolkadotPrimitivesV2AbridgedHostConfiguration, PolkadotPrimitivesV2PersistedValidationData, PolkadotPrimitivesV2UpgradeRestriction, SpRuntimeDigest, SpTrieStorageProof, UpDataStructsCollection, UpDataStructsCollectionStats, UpDataStructsProperties, UpDataStructsPropertiesMapPropertyPermission, UpDataStructsPropertyPermission, UpDataStructsPropertyScope, UpDataStructsSponsorshipStateBasicCrossAccountIdRepr, UpDataStructsTokenChild } from '@polkadot/types/lookup';
@@ -513,10 +513,10 @@
promotion: {
admin: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> & QueryableStorageEntry<ApiType, []>;
/**
- * Stores the address of the staker for which the last revenue recalculation was performed.
+ * Stores hash a record for which the last revenue recalculation was performed.
* If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers.
**/
- lastCalcucaltedStaker: AugmentedQuery<ApiType, () => Observable<Option<AccountId32>>, []> & QueryableStorageEntry<ApiType, []>;
+ nextCalculatedRecord: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[AccountId32, u32]>>>, []> & QueryableStorageEntry<ApiType, []>;
/**
* Next target block when interest is recalculated
**/
@@ -530,6 +530,10 @@
**/
staked: AugmentedQuery<ApiType, (arg1: AccountId32 | string | Uint8Array, arg2: u32 | AnyNumber | Uint8Array) => Observable<ITuple<[u128, u32]>>, [AccountId32, u32]> & QueryableStorageEntry<ApiType, [AccountId32, u32]>;
/**
+ * Amount of stakes for an Account
+ **/
+ stakesPerAccount: AugmentedQuery<ApiType, (arg: AccountId32 | string | Uint8Array) => Observable<u8>, [AccountId32]> & QueryableStorageEntry<ApiType, [AccountId32]>;
+ /**
* A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.
**/
startBlock: AugmentedQuery<ApiType, () => Observable<u32>, []> & QueryableStorageEntry<ApiType, []>;