Skip to content

Commit ba903c4

Browse files
Merge branch 'feature/forwards-compatibility' into forward-comp/COR-1837-Reward-Status
2 parents ab2ea43 + a5ccd88 commit ba903c4

File tree

5 files changed

+85
-40
lines changed

5 files changed

+85
-40
lines changed

examples/wallet/src/util.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
AccountAddress,
33
AccountInfo,
4+
AccountInfoType,
45
AccountTransaction,
56
AccountTransactionHeader,
67
AccountTransactionType,
@@ -314,11 +315,15 @@ export async function getAccount(accountAddress: AccountAddress.Type): Promise<A
314315
await loop(intervalMs, async () => {
315316
try {
316317
const accountInfo = await client.getAccountInfo(accountAddress);
318+
if (accountInfo.type === AccountInfoType.Unknown) {
319+
reject(new Error('Account info unknown'));
320+
return false;
321+
}
317322
resolve(accountInfo);
318323
return false;
319324
} catch {
320325
if (escapeCounter > maxRetries) {
321-
reject();
326+
reject(new Error('Max retry counter reached'));
322327
return false;
323328
} else {
324329
escapeCounter += 1;

packages/sdk/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@
2525
- `NodeInfoConsensusStatus` and `NodeCatchupStatus` now have been wrapped in `Upward`.
2626
- `RejectReason` now has been wrapped in `Upward`
2727
- `RewardStatus` now has been wrapped in `Upward`
28+
- `Cooldown.status` now has the type `Upward<CooldownStatus>`. This affects all `AccountInfo` variants.
29+
- `BakerPoolInfo.openStatus` now has the type `Upward<OpenStatusText>`.
30+
- Affects the `AccountInfoBaker` variant of `AccountInfo`.
31+
- Affects `BakerPoolStatus`.
32+
- `BakerSetOpenStatusEvent.openStatus` now has the type `Upward<OpenStatusText>`.
33+
- `AccountInfo` has been extended with a new variant `AccountInfoUnknown`.
2834

2935
#### `ConcordiumGRPCClient`:
3036

3137
- `waitForTransactionFinalization` is affected by the changes to `BlockItemSummaryInBlock`
3238
- `getBlockTransactionEvents` now returns `AsyncIterable<Upward<BlockItemSummary>>`.
3339
- `getBlockSpecialEvents` now returns `AsyncIterable<Upward<BlockSpecialEvent>>`.
40+
- `getPoolInfo` is affected by the changes to `BakerPoolInfo`
3441

3542
## 10.0.1
3643

packages/sdk/src/grpc/translation.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,16 @@ function trAmountFraction(amount: GRPC.AmountFraction | undefined): number {
207207
return unwrap(amount?.partsPerHundredThousand) / 100000;
208208
}
209209

210-
function trOpenStatus(openStatus: GRPC.OpenStatus | undefined): SDK.OpenStatusText {
211-
switch (unwrap(openStatus)) {
210+
function trOpenStatus(openStatus: GRPC.OpenStatus | undefined): Upward<SDK.OpenStatusText> {
211+
switch (openStatus) {
212212
case GRPC.OpenStatus.OPEN_FOR_ALL:
213213
return SDK.OpenStatusText.OpenForAll;
214214
case GRPC.OpenStatus.CLOSED_FOR_NEW:
215215
return SDK.OpenStatusText.ClosedForNew;
216216
case GRPC.OpenStatus.CLOSED_FOR_ALL:
217217
return SDK.OpenStatusText.ClosedForAll;
218+
case undefined:
219+
return null;
218220
}
219221
}
220222

@@ -241,15 +243,10 @@ function trBaker(baker: GRPC.AccountStakingInfo_Baker): SDK.AccountBakerDetails
241243
return v0;
242244
}
243245

244-
const bakerPoolInfo: SDK.BakerPoolInfo = {
245-
openStatus: trOpenStatus(baker.poolInfo?.openStatus),
246-
metadataUrl: unwrap(baker.poolInfo?.url),
247-
commissionRates: trCommissionRates(baker.poolInfo?.commissionRates),
248-
};
249246
return {
250247
...v0,
251248
version: 1,
252-
bakerPoolInfo: bakerPoolInfo,
249+
bakerPoolInfo: transPoolInfo(baker.poolInfo),
253250
};
254251
}
255252

@@ -419,21 +416,26 @@ export function accountInfo(acc: GRPC.AccountInfo): SDK.AccountInfo {
419416
accountTokens: acc.tokens.map(trTokenAccountInfo),
420417
};
421418

422-
if (acc.stake?.stakingInfo.oneofKind === 'delegator') {
423-
return {
424-
...accInfoCommon,
425-
type: SDK.AccountInfoType.Delegator,
426-
accountDelegation: trDelegator(acc.stake.stakingInfo.delegator),
427-
};
428-
} else if (acc.stake?.stakingInfo.oneofKind === 'baker') {
429-
return {
430-
...accInfoCommon,
431-
type: SDK.AccountInfoType.Baker,
432-
accountBaker: trBaker(acc.stake.stakingInfo.baker),
433-
};
434-
} else {
419+
if (acc.stake === undefined) {
435420
return accInfoCommon;
436421
}
422+
423+
switch (acc.stake.stakingInfo.oneofKind) {
424+
case 'delegator':
425+
return {
426+
...accInfoCommon,
427+
type: SDK.AccountInfoType.Delegator,
428+
accountDelegation: trDelegator(acc.stake.stakingInfo.delegator),
429+
};
430+
case 'baker':
431+
return {
432+
...accInfoCommon,
433+
type: SDK.AccountInfoType.Baker,
434+
accountBaker: trBaker(acc.stake.stakingInfo.baker),
435+
};
436+
case undefined:
437+
return { ...accInfoCommon, type: SDK.AccountInfoType.Unknown, accountBaker: null };
438+
}
437439
}
438440

439441
export function nextAccountSequenceNumber(nasn: GRPC.NextAccountSequenceNumber): SDK.NextAccountNonce {

packages/sdk/src/types.ts

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
/**
22
* @module Common GRPC-Client
33
*/
4-
import type { Upward } from './grpc/upward.js';
5-
import { Cbor, TokenId } from './plt/index.js';
6-
import { TokenAccountInfo } from './plt/types.js';
7-
import * as AccountAddress from './types/AccountAddress.js';
4+
import type { Upward } from './grpc/index.js';
5+
import type { Cbor, TokenId } from './plt/index.js';
6+
import type { TokenAccountInfo } from './plt/types.js';
7+
import type * as AccountAddress from './types/AccountAddress.js';
88
import type * as BlockHash from './types/BlockHash.js';
99
import type * as CcdAmount from './types/CcdAmount.js';
10-
import * as ContractAddress from './types/ContractAddress.js';
10+
import type * as ContractAddress from './types/ContractAddress.js';
1111
import type * as ContractName from './types/ContractName.js';
12-
import * as CredentialRegistrationId from './types/CredentialRegistrationId.js';
13-
import { DataBlob } from './types/DataBlob.js';
14-
import * as Duration from './types/Duration.js';
15-
import * as Energy from './types/Energy.js';
12+
import type * as CredentialRegistrationId from './types/CredentialRegistrationId.js';
13+
import type { DataBlob } from './types/DataBlob.js';
14+
import type * as Duration from './types/Duration.js';
15+
import type * as Energy from './types/Energy.js';
1616
import type * as InitName from './types/InitName.js';
1717
import type * as ModuleReference from './types/ModuleReference.js';
18-
import * as Parameter from './types/Parameter.js';
18+
import type * as Parameter from './types/Parameter.js';
1919
import type * as ReceiveName from './types/ReceiveName.js';
2020
import type * as ReturnValue from './types/ReturnValue.js';
2121
import type * as SequenceNumber from './types/SequenceNumber.js';
22-
import * as Timestamp from './types/Timestamp.js';
22+
import type * as Timestamp from './types/Timestamp.js';
2323
import type * as TransactionExpiry from './types/TransactionExpiry.js';
2424
import type * as TransactionHash from './types/TransactionHash.js';
25-
import { RejectReason } from './types/rejectReason.js';
26-
import { ContractTraceEvent } from './types/transactionEvent.js';
25+
import type { RejectReason } from './types/rejectReason.js';
26+
import type { ContractTraceEvent } from './types/transactionEvent.js';
2727

2828
export * from './types/NodeInfo.js';
2929
export * from './types/PeerInfo.js';
@@ -886,7 +886,13 @@ export type BakerId = bigint;
886886
export type DelegatorId = bigint;
887887

888888
export interface BakerPoolInfo {
889-
openStatus: OpenStatusText;
889+
/**
890+
* The status of validator pool
891+
*
892+
* **Please note**, this can possibly be unknown if the SDK is not fully compatible with the Concordium
893+
* node queried, in which case `null` is returned.
894+
*/
895+
openStatus: Upward<OpenStatusText>;
890896
metadataUrl: UrlString;
891897
commissionRates: CommissionRates;
892898
}
@@ -1103,6 +1109,7 @@ export enum AccountInfoType {
11031109
Simple = 'simple',
11041110
Baker = 'baker',
11051111
Delegator = 'delegator',
1112+
Unknown = 'unknown',
11061113
}
11071114

11081115
interface AccountInfoCommon {
@@ -1171,7 +1178,20 @@ export interface AccountInfoDelegator extends AccountInfoCommon {
11711178
accountDelegation: AccountDelegationDetails;
11721179
}
11731180

1174-
export type AccountInfo = AccountInfoSimple | AccountInfoBaker | AccountInfoDelegator;
1181+
export interface AccountInfoUnknown extends AccountInfoCommon {
1182+
type: AccountInfoType.Unknown;
1183+
/**
1184+
* This will only ever be `null`, which represents a variant of staking info for the account which is
1185+
* unknown to the SDK, for known staking variants this is represented by either {@linkcode AccountInfoBaker}
1186+
* or {@linkcode AccountInfoDElegator}.
1187+
*
1188+
* **Note**: This field is named `accountBaker` to align with the JSON representation produced by the
1189+
* corresponding rust SDK.
1190+
*/
1191+
accountBaker: Upward<never>;
1192+
}
1193+
1194+
export type AccountInfo = AccountInfoSimple | AccountInfoBaker | AccountInfoDelegator | AccountInfoUnknown;
11751195

11761196
export interface Description {
11771197
name: string;
@@ -2021,6 +2041,11 @@ export type Cooldown = {
20212041
timestamp: Timestamp.Type;
20222042
/** The amount that is in cooldown and set to be released at the end of the cooldown period */
20232043
amount: CcdAmount.Type;
2024-
/** The status of the cooldown */
2025-
status: CooldownStatus;
2044+
/**
2045+
* The status of the cooldown
2046+
*
2047+
* **Please note**, this can possibly be unknown if the SDK is not fully compatible with the Concordium
2048+
* node queried, in which case `null` is returned.
2049+
*/
2050+
status: Upward<CooldownStatus>;
20262051
};

packages/sdk/src/types/transactionEvent.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,13 @@ export interface BakerSetOpenStatusEvent {
299299
tag: TransactionEventTag.BakerSetOpenStatus;
300300
bakerId: BakerId;
301301
account: AccountAddress.Type;
302-
openStatus: OpenStatusText;
302+
/**
303+
* The status of validator pool
304+
*
305+
* **Please note**, this can possibly be unknown if the SDK is not fully compatible with the Concordium
306+
* node queried, in which case `null` is returned.
307+
*/
308+
openStatus: Upward<OpenStatusText>;
303309
}
304310

305311
export interface BakerSetMetadataURLEvent {

0 commit comments

Comments
 (0)