Skip to content

Commit af35d63

Browse files
authored
Merge branch 'feature/forwards-compatibility' into forward-comp/account-info
2 parents d4e9ed4 + 383ad91 commit af35d63

File tree

10 files changed

+31
-18
lines changed

10 files changed

+31
-18
lines changed

examples/nodejs/client/getBlockItemStatus.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const client = new ConcordiumGRPCNodeClient(
9494
const { failedTransactionType, rejectReason } = summary;
9595
console.log(
9696
'Transaction of type "' + failedTransactionType + '" failed because:',
97-
rejectReason.tag
97+
rejectReason?.tag ?? 'unknown'
9898
);
9999
break;
100100
default:

examples/nodejs/plt/modify-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ const client = new ConcordiumGRPCNodeClient(
156156
});
157157
break;
158158
case TransactionKindString.Failed:
159-
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
160-
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
159+
if (result.summary.rejectReason?.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
160+
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
161161
}
162162
const details = Cbor.decode(result.summary.rejectReason.contents.details);
163163
console.error(result.summary.rejectReason.contents, details);

examples/nodejs/plt/pause.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ const client = new ConcordiumGRPCNodeClient(
121121
});
122122
break;
123123
case TransactionKindString.Failed:
124-
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
125-
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
124+
if (result.summary.rejectReason?.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
125+
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
126126
}
127127
const details = Cbor.decode(result.summary.rejectReason.contents.details);
128128
console.error(result.summary.rejectReason.contents, details);

examples/nodejs/plt/transfer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ const client = new ConcordiumGRPCNodeClient(
129129
result.summary.events.forEach((e) => console.log(e));
130130
break;
131131
case TransactionKindString.Failed:
132-
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
133-
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
132+
if (result.summary.rejectReason?.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
133+
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
134134
}
135135
const details = Cbor.decode(result.summary.rejectReason.contents.details);
136136
console.error(result.summary.rejectReason.contents, details);

examples/nodejs/plt/update-supply.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ const client = new ConcordiumGRPCNodeClient(addr, Number(port), credentials.crea
123123
result.summary.events.forEach((e) => console.log(e));
124124
break;
125125
case TransactionKindString.Failed:
126-
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
127-
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
126+
if (result.summary.rejectReason?.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
127+
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
128128
}
129129
const details = Cbor.decode(result.summary.rejectReason.contents.details);
130130
console.error(result.summary.rejectReason.contents, details);

packages/sdk/CHANGELOG.md

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

packages/sdk/src/grpc/translation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ function trDelegationEvent(
10121012
}
10131013
}
10141014

1015-
function trRejectReason(rejectReason: GRPC.RejectReason | undefined): SDK.RejectReason {
1015+
function trRejectReason(rejectReason: GRPC.RejectReason | undefined): Upward<SDK.RejectReason> {
10161016
function simpleReason(tag: SDK.SimpleRejectReasonTag): SDK.RejectReason {
10171017
return {
10181018
tag: SDK.RejectReasonTag[tag],
@@ -1211,7 +1211,7 @@ function trRejectReason(rejectReason: GRPC.RejectReason | undefined): SDK.Reject
12111211
},
12121212
};
12131213
case undefined:
1214-
throw Error('Failed translating RejectReason, encountered undefined value');
1214+
return null;
12151215
}
12161216
}
12171217

packages/sdk/src/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,13 @@ export interface InvokeContractSuccessResult {
16111611
export interface InvokeContractFailedResult {
16121612
tag: 'failure';
16131613
usedEnergy: Energy.Type;
1614-
reason: RejectReason;
1614+
/**
1615+
* The reject reason for the failed contract invocation.
1616+
*
1617+
* **Please note**, this can possibly be unknown if the SDK is not fully compatible with the Concordium
1618+
* node queried, in which case `null` is returned.
1619+
*/
1620+
reason: Upward<RejectReason>;
16151621
/**
16161622
* Return value from smart contract call, used to provide error messages.
16171623
* Is only defined when smart contract instance is a V1 smart contract and

packages/sdk/src/types/blockItemSummary.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ export interface UpdateCredentialsSummary {
210210
export interface FailedTransactionSummary {
211211
transactionType: TransactionKindString.Failed;
212212
failedTransactionType?: TransactionKindString;
213-
rejectReason: RejectReason;
213+
/**
214+
* The reject reason for the failed transaction
215+
*
216+
* **Please note**, this can possibly be unknown if the SDK is not fully compatible with the Concordium
217+
* node queried, in which case `null` is returned.
218+
*/
219+
rejectReason: Upward<RejectReason>;
214220
}
215221

216222
/**
@@ -389,15 +395,15 @@ export const isSuccessTransaction = (
389395
*
390396
* @param {BlockItemSummary} summary - The block item summary to check.
391397
*
392-
* @returns {RejectReason | undfined} Reject reason if `summary` is a rejected transaction. Otherwise returns undefined.
398+
* @returns {RejectReason | undefined} Reject reason if `summary` is a rejected transaction. Otherwise returns undefined.
393399
*/
394-
export function getTransactionRejectReason<T extends FailedTransactionSummary>(summary: T): RejectReason;
400+
export function getTransactionRejectReason<T extends FailedTransactionSummary>(summary: T): Upward<RejectReason>;
395401
export function getTransactionRejectReason(summary: AccountCreationSummary | UpdateSummary): undefined;
396402
export function getTransactionRejectReason(
397403
summary: Exclude<AccountTransactionSummary, FailedTransactionSummary>
398404
): undefined;
399-
export function getTransactionRejectReason(summary: BlockItemSummary): RejectReason | undefined;
400-
export function getTransactionRejectReason(summary: BlockItemSummary): RejectReason | undefined {
405+
export function getTransactionRejectReason(summary: BlockItemSummary): Upward<RejectReason> | undefined;
406+
export function getTransactionRejectReason(summary: BlockItemSummary): Upward<RejectReason> | undefined {
401407
if (!isRejectTransaction(summary)) {
402408
return undefined;
403409
}

packages/sdk/test/client/clientV2.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ test.each(clients)('Failed invoke contract', async (client) => {
187187
}
188188

189189
expect(result.usedEnergy.value).toBe(340n);
190-
expect(result.reason.tag).toBe(v1.RejectReasonTag.RejectedReceive);
190+
expect(result.reason?.tag).toBe(v1.RejectReasonTag.RejectedReceive);
191191
});
192192

193193
test.each(clients)('Invoke contract on v0 contract', async (client) => {

0 commit comments

Comments
 (0)