Skip to content

Commit 2fa7b5a

Browse files
Merge pull request #503 from Concordium/forward-comp/COR-1837-Reward-Status
Wrap Upward around RewardStatus
2 parents a5ccd88 + ba903c4 commit 2fa7b5a

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

examples/nodejs/client/getTokenomicsInfo.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BlockHash } from '@concordium/web-sdk';
1+
import { BlockHash, isKnown } from '@concordium/web-sdk';
22
import { ConcordiumGRPCNodeClient } from '@concordium/web-sdk/nodejs';
33
import { credentials } from '@grpc/grpc-js';
44
import meow from 'meow';
@@ -55,6 +55,11 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
5555

5656
// Protocol version 4 expanded the amount of information in the response, so one should check the type to access that.
5757
// This information includes information about the payday and total amount of funds staked.
58+
if (!isKnown(tokenomics)) {
59+
console.warn('Unknown tokenomics version found');
60+
return;
61+
}
62+
5863
if (tokenomics.version === 1) {
5964
console.log('Next payday time:', tokenomics.nextPaydayTime);
6065
console.log('Total staked amount by bakers and delegators', tokenomics.totalStakedCapital);

packages/sdk/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- `PassiveCommitteeInfo` now has been wrapped in `Upward`.
2525
- `NodeInfoConsensusStatus` and `NodeCatchupStatus` now have been wrapped in `Upward`.
2626
- `RejectReason` now has been wrapped in `Upward`
27+
- `RewardStatus` now has been wrapped in `Upward`
2728
- `Cooldown.status` now has the type `Upward<CooldownStatus>`. This affects all `AccountInfo` variants.
2829
- `BakerPoolInfo.openStatus` now has the type `Upward<OpenStatusText>`.
2930
- Affects the `AccountInfoBaker` variant of `AccountInfo`.

packages/sdk/src/grpc/GRPCClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ export class ConcordiumGRPCClient {
504504
* @param blockHash optional block hash to get the reward status at, otherwise retrieves from last finalized block
505505
* @returns the reward status at the given block, or undefined it the block does not exist.
506506
*/
507-
async getTokenomicsInfo(blockHash?: BlockHash.Type): Promise<SDK.TokenomicsInfo> {
507+
async getTokenomicsInfo(blockHash?: BlockHash.Type): Promise<Upward<SDK.TokenomicsInfo>> {
508508
const blockHashInput = getBlockHashInput(blockHash);
509509

510510
const response = await this.client.getTokenomicsInfo(blockHashInput).response;

packages/sdk/src/grpc/translation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ function translateProtocolVersion(pv: GRPC.ProtocolVersion): bigint {
635635
return BigInt(pv + 1); // Protocol version enum indexes from 0, i.e. pv.PROTOCOL_VERSION_1 = 0.
636636
}
637637

638-
export function tokenomicsInfo(info: GRPC.TokenomicsInfo): SDK.RewardStatus {
638+
export function tokenomicsInfo(info: GRPC.TokenomicsInfo): Upward<SDK.RewardStatus> {
639639
switch (info.tokenomics.oneofKind) {
640640
case 'v0': {
641641
const v0 = info.tokenomics.v0;
@@ -666,7 +666,7 @@ export function tokenomicsInfo(info: GRPC.TokenomicsInfo): SDK.RewardStatus {
666666
};
667667
}
668668
case undefined:
669-
throw new Error('Missing tokenomics info');
669+
return null;
670670
}
671671
}
672672

0 commit comments

Comments
 (0)