Skip to content
2 changes: 1 addition & 1 deletion examples/nodejs/client/getBlockItemStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const client = new ConcordiumGRPCNodeClient(
const { failedTransactionType, rejectReason } = summary;
console.log(
'Transaction of type "' + failedTransactionType + '" failed because:',
rejectReason.tag
rejectReason?.tag ?? 'undefined'
);
break;
default:
Expand Down
7 changes: 5 additions & 2 deletions examples/nodejs/plt/modify-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ const client = new ConcordiumGRPCNodeClient(
});
break;
case TransactionKindString.Failed:
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
if (
!result.summary.rejectReason ||
result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed
) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
}
const details = Cbor.decode(result.summary.rejectReason.contents.details);
console.error(result.summary.rejectReason.contents, details);
Expand Down
7 changes: 5 additions & 2 deletions examples/nodejs/plt/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ const client = new ConcordiumGRPCNodeClient(
});
break;
case TransactionKindString.Failed:
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
if (
!result.summary.rejectReason ||
result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed
) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
}
const details = Cbor.decode(result.summary.rejectReason.contents.details);
console.error(result.summary.rejectReason.contents, details);
Expand Down
7 changes: 5 additions & 2 deletions examples/nodejs/plt/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ const client = new ConcordiumGRPCNodeClient(
result.summary.events.forEach((e) => console.log(e));
break;
case TransactionKindString.Failed:
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
if (
!result.summary.rejectReason ||
result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed
) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
}
const details = Cbor.decode(result.summary.rejectReason.contents.details);
console.error(result.summary.rejectReason.contents, details);
Expand Down
7 changes: 5 additions & 2 deletions examples/nodejs/plt/update-supply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ const client = new ConcordiumGRPCNodeClient(addr, Number(port), credentials.crea
result.summary.events.forEach((e) => console.log(e));
break;
case TransactionKindString.Failed:
if (result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason.tag);
if (
!result.summary.rejectReason ||
result.summary.rejectReason.tag !== RejectReasonTag.TokenUpdateTransactionFailed
) {
throw new Error('Unexpected reject reason tag: ' + result.summary.rejectReason?.tag);
}
const details = Cbor.decode(result.summary.rejectReason.contents.details);
console.error(result.summary.rejectReason.contents, details);
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- `PendingUpdate.effect` now has the type `Upward<PendingUpateEffect>`.
- `PassiveCommitteeInfo` now has been wrapped in `Upward`.
- `NodeInfoConsensusStatus` and `NodeCatchupStatus` now have been wrapped in `Upward`.
- `RejectReason` now has been wrapped in `Upward`

#### `ConcordiumGRPCClient`:

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/grpc/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ function trDelegationEvent(
}
}

function trRejectReason(rejectReason: GRPC.RejectReason | undefined): SDK.RejectReason {
function trRejectReason(rejectReason: GRPC.RejectReason | undefined): Upward<SDK.RejectReason> {
function simpleReason(tag: SDK.SimpleRejectReasonTag): SDK.RejectReason {
return {
tag: SDK.RejectReasonTag[tag],
Expand Down Expand Up @@ -1209,7 +1209,7 @@ function trRejectReason(rejectReason: GRPC.RejectReason | undefined): SDK.Reject
},
};
case undefined:
throw Error('Failed translating RejectReason, encountered undefined value');
return null;
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @module Common GRPC-Client
*/
import type { Upward } from './grpc/upward.js';
import { Cbor, TokenId } from './plt/index.js';
import { TokenAccountInfo } from './plt/types.js';
import * as AccountAddress from './types/AccountAddress.js';
Expand Down Expand Up @@ -1590,7 +1591,7 @@ export interface InvokeContractSuccessResult {
export interface InvokeContractFailedResult {
tag: 'failure';
usedEnergy: Energy.Type;
reason: RejectReason;
reason: Upward<RejectReason>;
/**
* Return value from smart contract call, used to provide error messages.
* Is only defined when smart contract instance is a V1 smart contract and
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/src/types/blockItemSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export interface UpdateCredentialsSummary {
export interface FailedTransactionSummary {
transactionType: TransactionKindString.Failed;
failedTransactionType?: TransactionKindString;
rejectReason: RejectReason;
rejectReason: Upward<RejectReason>;
}

/**
Expand Down Expand Up @@ -389,15 +389,15 @@ export const isSuccessTransaction = (
*
* @param {BlockItemSummary} summary - The block item summary to check.
*
* @returns {RejectReason | undfined} Reject reason if `summary` is a rejected transaction. Otherwise returns undefined.
* @returns {RejectReason | undefined} Reject reason if `summary` is a rejected transaction. Otherwise returns undefined.
*/
export function getTransactionRejectReason<T extends FailedTransactionSummary>(summary: T): RejectReason;
export function getTransactionRejectReason<T extends FailedTransactionSummary>(summary: T): Upward<RejectReason>;
export function getTransactionRejectReason(summary: AccountCreationSummary | UpdateSummary): undefined;
export function getTransactionRejectReason(
summary: Exclude<AccountTransactionSummary, FailedTransactionSummary>
): undefined;
export function getTransactionRejectReason(summary: BlockItemSummary): RejectReason | undefined;
export function getTransactionRejectReason(summary: BlockItemSummary): RejectReason | undefined {
export function getTransactionRejectReason(summary: BlockItemSummary): Upward<RejectReason> | undefined;
export function getTransactionRejectReason(summary: BlockItemSummary): Upward<RejectReason> | undefined {
if (!isRejectTransaction(summary)) {
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/client/clientV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ test.each(clients)('Failed invoke contract', async (client) => {
}

expect(result.usedEnergy.value).toBe(340n);
expect(result.reason.tag).toBe(v1.RejectReasonTag.RejectedReceive);
expect(result.reason?.tag).toBe(v1.RejectReasonTag.RejectedReceive);
});

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