From 0525582f3c4188f6f944fe6c56d4002562953dae Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Fri, 02 Sep 2022 11:59:42 +0000 Subject: [PATCH] fix: some rpc fixes --- --- a/client/rpc/src/lib.rs +++ b/client/rpc/src/lib.rs @@ -412,47 +412,27 @@ } } -pub struct Unique { - client: Arc, - _marker: std::marker::PhantomData

, -} - -impl Unique { - pub fn new(client: Arc) -> Self { - Self { - client, - _marker: Default::default(), +macro_rules! define_struct_for_server_api { + ($name:ident) => { + pub struct $name { + client: Arc, + _marker: std::marker::PhantomData

, } - } -} - -pub struct AppPromotion { - client: Arc, - _marker: std::marker::PhantomData

, -} - -impl AppPromotion { - pub fn new(client: Arc) -> Self { - Self { - client, - _marker: Default::default(), + + impl $name { + pub fn new(client: Arc) -> Self { + Self { + client, + _marker: Default::default(), + } + } } - } -} - -pub struct Rmrk { - client: Arc, - _marker: std::marker::PhantomData

, + }; } -impl Rmrk { - pub fn new(client: Arc) -> 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::>(), unique_api); - pass_method!(total_staking_locked(staker: CrossAccountId) -> String => |v| v.to_string(), unique_api); - pass_method!(pending_unstake(staker: Option) -> String => |v| v.to_string(), unique_api); + .collect::>(), app_promotion_api); + pass_method!(total_staking_locked(staker: CrossAccountId) -> String => |v| v.to_string(), app_promotion_api); + pass_method!(pending_unstake(staker: Option) -> 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::>(), unique_api); + .collect::>(), app_promotion_api); } #[allow(deprecated)] --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -38,7 +38,6 @@ use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; use sc_service::TransactionPool; -use uc_rpc::AppPromotion; use std::{collections::BTreeMap, sync::Arc}; use up_common::types::opaque::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance}; @@ -232,7 +231,7 @@ io.merge(Unique::new(client.clone()).into_rpc())?; - // #[cfg(not(feature = "unique-runtime"))] + #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))] io.merge(AppPromotion::new(client.clone()).into_rpc())?; #[cfg(not(feature = "unique-runtime"))] --- 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 Observable>, []> & QueryableStorageEntry; /** - * 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 Observable>, []> & QueryableStorageEntry; + nextCalculatedRecord: AugmentedQuery Observable>>, []> & QueryableStorageEntry; /** * Next target block when interest is recalculated **/ @@ -530,6 +530,10 @@ **/ staked: AugmentedQuery Observable>, [AccountId32, u32]> & QueryableStorageEntry; /** + * Amount of stakes for an Account + **/ + stakesPerAccount: AugmentedQuery Observable, [AccountId32]> & QueryableStorageEntry; + /** * A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`. **/ startBlock: AugmentedQuery Observable, []> & QueryableStorageEntry; -- gitstuff