diff --git a/examples/nodejs/client/getBlockItemStatus.ts b/examples/nodejs/client/getBlockItemStatus.ts index fc03652ea..fbf6d8454 100644 --- a/examples/nodejs/client/getBlockItemStatus.ts +++ b/examples/nodejs/client/getBlockItemStatus.ts @@ -94,7 +94,7 @@ const client = new ConcordiumGRPCNodeClient( const { failedTransactionType, rejectReason } = summary; console.log( 'Transaction of type "' + failedTransactionType + '" failed because:', - rejectReason.tag + rejectReason?.tag ?? 'unknown' ); break; default: diff --git a/examples/nodejs/plt/modify-list.ts b/examples/nodejs/plt/modify-list.ts index 45a1ccc1a..ce3055a20 100644 --- a/examples/nodejs/plt/modify-list.ts +++ b/examples/nodejs/plt/modify-list.ts @@ -156,8 +156,8 @@ 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?.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); diff --git a/examples/nodejs/plt/pause.ts b/examples/nodejs/plt/pause.ts index bd38ab6fb..81171e02a 100644 --- a/examples/nodejs/plt/pause.ts +++ b/examples/nodejs/plt/pause.ts @@ -121,8 +121,8 @@ 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?.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); diff --git a/examples/nodejs/plt/transfer.ts b/examples/nodejs/plt/transfer.ts index c9949c73f..8339a8e58 100644 --- a/examples/nodejs/plt/transfer.ts +++ b/examples/nodejs/plt/transfer.ts @@ -129,8 +129,8 @@ 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?.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); diff --git a/examples/nodejs/plt/update-supply.ts b/examples/nodejs/plt/update-supply.ts index 1f94e1000..4dad692e3 100644 --- a/examples/nodejs/plt/update-supply.ts +++ b/examples/nodejs/plt/update-supply.ts @@ -123,8 +123,8 @@ 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?.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); diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index 100ee877a..c74b33e15 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -20,6 +20,7 @@ - `PendingUpdate.effect` now has the type `Upward`. - `PassiveCommitteeInfo` now has been wrapped in `Upward`. - `NodeInfoConsensusStatus` and `NodeCatchupStatus` now have been wrapped in `Upward`. +- `RejectReason` now has been wrapped in `Upward` #### `ConcordiumGRPCClient`: diff --git a/packages/sdk/src/grpc/translation.ts b/packages/sdk/src/grpc/translation.ts index 7f4209835..9b0abedc4 100644 --- a/packages/sdk/src/grpc/translation.ts +++ b/packages/sdk/src/grpc/translation.ts @@ -1010,7 +1010,7 @@ function trDelegationEvent( } } -function trRejectReason(rejectReason: GRPC.RejectReason | undefined): SDK.RejectReason { +function trRejectReason(rejectReason: GRPC.RejectReason | undefined): Upward { function simpleReason(tag: SDK.SimpleRejectReasonTag): SDK.RejectReason { return { tag: SDK.RejectReasonTag[tag], @@ -1209,7 +1209,7 @@ function trRejectReason(rejectReason: GRPC.RejectReason | undefined): SDK.Reject }, }; case undefined: - throw Error('Failed translating RejectReason, encountered undefined value'); + return null; } } diff --git a/packages/sdk/src/types.ts b/packages/sdk/src/types.ts index 45f58b6d8..e515f069d 100644 --- a/packages/sdk/src/types.ts +++ b/packages/sdk/src/types.ts @@ -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'; @@ -1590,7 +1591,13 @@ export interface InvokeContractSuccessResult { export interface InvokeContractFailedResult { tag: 'failure'; usedEnergy: Energy.Type; - reason: RejectReason; + /** + * The reject reason for the failed contract invocation. + * + * **Please note**, this can possibly be unknown if the SDK is not fully compatible with the Concordium + * node queried, in which case `null` is returned. + */ + reason: Upward; /** * Return value from smart contract call, used to provide error messages. * Is only defined when smart contract instance is a V1 smart contract and diff --git a/packages/sdk/src/types/blockItemSummary.ts b/packages/sdk/src/types/blockItemSummary.ts index 396c8825f..eb4d4a9fc 100644 --- a/packages/sdk/src/types/blockItemSummary.ts +++ b/packages/sdk/src/types/blockItemSummary.ts @@ -210,7 +210,13 @@ export interface UpdateCredentialsSummary { export interface FailedTransactionSummary { transactionType: TransactionKindString.Failed; failedTransactionType?: TransactionKindString; - rejectReason: RejectReason; + /** + * The reject reason for the failed transaction + * + * **Please note**, this can possibly be unknown if the SDK is not fully compatible with the Concordium + * node queried, in which case `null` is returned. + */ + rejectReason: Upward; } /** @@ -389,15 +395,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(summary: T): RejectReason; +export function getTransactionRejectReason(summary: T): Upward; export function getTransactionRejectReason(summary: AccountCreationSummary | UpdateSummary): undefined; export function getTransactionRejectReason( summary: Exclude ): undefined; -export function getTransactionRejectReason(summary: BlockItemSummary): RejectReason | undefined; -export function getTransactionRejectReason(summary: BlockItemSummary): RejectReason | undefined { +export function getTransactionRejectReason(summary: BlockItemSummary): Upward | undefined; +export function getTransactionRejectReason(summary: BlockItemSummary): Upward | undefined { if (!isRejectTransaction(summary)) { return undefined; } diff --git a/packages/sdk/test/client/clientV2.test.ts b/packages/sdk/test/client/clientV2.test.ts index ce97a9792..2522c49ca 100644 --- a/packages/sdk/test/client/clientV2.test.ts +++ b/packages/sdk/test/client/clientV2.test.ts @@ -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) => {