git.delta.rocks / unique-network / refs/commits / 0525582f3c41

difftreelog

fix some rpc fixes

Trubnikov Sergey2022-09-02parent: #d647f79.patch.diff
in: master

3 files changed

modifiedclient/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)]
modifiednode/rpc/src/lib.rsdiffbeforeafterboth
38use sp_block_builder::BlockBuilder;38use sp_block_builder::BlockBuilder;
39use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};39use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
40use sc_service::TransactionPool;40use sc_service::TransactionPool;
41use uc_rpc::AppPromotion;
42use std::{collections::BTreeMap, sync::Arc};41use std::{collections::BTreeMap, sync::Arc};
4342
44use up_common::types::opaque::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance};43use up_common::types::opaque::{Hash, AccountId, RuntimeInstance, Index, Block, BlockNumber, Balance};
232231
233 io.merge(Unique::new(client.clone()).into_rpc())?;232 io.merge(Unique::new(client.clone()).into_rpc())?;
234233
235 // #[cfg(not(feature = "unique-runtime"))]234 #[cfg(not(any(feature = "unique-runtime", feature = "quartz-runtime")))]
236 io.merge(AppPromotion::new(client.clone()).into_rpc())?;235 io.merge(AppPromotion::new(client.clone()).into_rpc())?;
237236
238 #[cfg(not(feature = "unique-runtime"))]237 #[cfg(not(feature = "unique-runtime"))]
modifiedtests/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, []>;