From ff63158ec533181ebd0406a732db3e22c58d3da9 Mon Sep 17 00:00:00 2001 From: Hjort Date: Wed, 11 May 2022 13:12:47 +0200 Subject: [PATCH] Remove type guards for versions that are subsets of others --- README.md | 10 ++++------ src/blockSummaryHelpers.ts | 7 +------ src/rewardStatusHelpers.ts | 6 +----- yarn.lock | 5 +++++ 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b7c1e009a..26d9b93da 100644 --- a/README.md +++ b/README.md @@ -637,21 +637,19 @@ const passiveDelegationStatus = await client.getPoolStatus(blockHash); ## getRewardStatus Retrieves the current amount of funds in the system at a specific block, and the state of the special accounts. -Protocol version 4 expanded the amount of information in the response, so one should check the type to access that. -This information includes information about the payday and total amount of funds staked. ```js const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; const rewardStatus = await client.getRewardStatus(blockHash); +``` +Protocol version 4 expanded the amount of information in the response, so one should check the type to access that. +This information includes information about the payday and total amount of funds staked. +```js if (isRewardStatusV1(rewardStatus)) { const nextPaydayTime = rewardStatus.nextPaydayTime; ... -} else if (isRewardStatusV0(rewardStatus)) { - // This status is for a block from protocol version <= 3, so it will only have limited information - ... } -... ``` ## Check block for transfers with memo diff --git a/src/blockSummaryHelpers.ts b/src/blockSummaryHelpers.ts index d416f05bb..6577019a2 100644 --- a/src/blockSummaryHelpers.ts +++ b/src/blockSummaryHelpers.ts @@ -1,6 +1,5 @@ import { Authorizations, - AuthorizationsV0, AuthorizationsV1, BlockSummary, BlockSummaryV0, @@ -22,10 +21,6 @@ import { export const isAuthorizationsV1 = (a: Authorizations): a is AuthorizationsV1 => (a as AuthorizationsV1).timeParameters !== undefined; -export function isAuthorizationsV0(a: Authorizations): a is AuthorizationsV0 { - return (a as AuthorizationsV1).timeParameters === undefined; -} - export const isChainParametersV1 = ( cp: ChainParameters ): cp is ChainParametersV1 => @@ -40,7 +35,7 @@ export const isKeysV1 = (k: Keys): k is KeysV1 => isAuthorizationsV1(k.level2Keys); export const isKeysV0 = (k: Keys): k is KeysV0 => - isAuthorizationsV0(k.level2Keys); + !isAuthorizationsV1(k.level2Keys); export const isUpdateQueuesV1 = (uq: UpdateQueues): uq is UpdateQueuesV1 => (uq as UpdateQueuesV1).timeParameters !== undefined; diff --git a/src/rewardStatusHelpers.ts b/src/rewardStatusHelpers.ts index 8f41f7582..30697c623 100644 --- a/src/rewardStatusHelpers.ts +++ b/src/rewardStatusHelpers.ts @@ -1,9 +1,5 @@ -import { RewardStatus, RewardStatusV0, RewardStatusV1 } from './types'; +import { RewardStatus, RewardStatusV1 } from './types'; export function isRewardStatusV1(rs: RewardStatus): rs is RewardStatusV1 { return rs.protocolVersion !== undefined && rs.protocolVersion > 3n; } - -export function isRewardStatusV0(rs: RewardStatus): rs is RewardStatusV0 { - return rs.protocolVersion === undefined || rs.protocolVersion <= 3n; -} diff --git a/yarn.lock b/yarn.lock index 8e5d43db9..ff0f96876 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2120,6 +2120,11 @@ google-protobuf@3.15.8: resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.15.8.tgz#5f3948905e4951c867d6bc143f385a80e2a39efe" integrity sha512-2jtfdqTaSxk0cuBJBtTTWsot4WtR9RVr2rXg7x7OoqiuOKopPrwXpM1G4dXIkLcUNRh3RKzz76C8IOkksZSeOw== +google-protobuf@^3.20.1: + version "3.20.1" + resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.20.1.tgz#1b255c2b59bcda7c399df46c65206aa3c7a0ce8b" + integrity sha512-XMf1+O32FjYIV3CYu6Tuh5PNbfNEU5Xu22X+Xkdb/DUexFlCzhvv7d5Iirm4AOwn8lv4al1YvIhzGrg2j9Zfzw== + graceful-fs@^4.2.4: version "4.2.8" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"