From 23d840bdb3a0e81503271941604c4800fcbfef08 Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Sun, 10 Mar 2024 02:19:36 +0800 Subject: [PATCH 1/2] Fix ChaincodeResponse definition and add new response types (#413) Signed-off-by: Jerrylum --- apis/fabric-shim-api/types/index.d.ts | 14 +++++++++++++- libraries/fabric-shim/types/index.d.ts | 12 ++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/apis/fabric-shim-api/types/index.d.ts b/apis/fabric-shim-api/types/index.d.ts index 98f176ea0..497c1dfba 100644 --- a/apis/fabric-shim-api/types/index.d.ts +++ b/apis/fabric-shim-api/types/index.d.ts @@ -14,9 +14,21 @@ declare module 'fabric-shim-api' { interface ChaincodeResponse { status: number; - message: string; + message?: string; + payload?: Uint8Array; + } + + interface SuccessResponse { + status: RESPONSE_CODE.OK; + message?: string; payload: Uint8Array; } + + interface ErrorResponse { + status: RESPONSE_CODE.ERROR; + message: string; + payload?: Uint8Array; + } interface ClientIdentity { assertAttributeValue(attrName: string, attrValue: string): boolean; diff --git a/libraries/fabric-shim/types/index.d.ts b/libraries/fabric-shim/types/index.d.ts index 2e948ceff..ba89f199d 100644 --- a/libraries/fabric-shim/types/index.d.ts +++ b/libraries/fabric-shim/types/index.d.ts @@ -12,6 +12,8 @@ declare module 'fabric-shim' { import { ChaincodeInterface, ChaincodeProposal, + ErrorResponse, + SuccessResponse, ChaincodeResponse, ChaincodeStub as IChaincodeStub, ClientIdentity as IClientIdentity, @@ -26,6 +28,8 @@ declare module 'fabric-shim' { export { ChaincodeInterface, ChaincodeProposal, + ErrorResponse, + SuccessResponse, ChaincodeResponse, Iterators, QueryResponseMetadata, @@ -35,16 +39,16 @@ declare module 'fabric-shim' { Timestamp } - export function error(msg: Uint8Array): ChaincodeResponse; + export function error(msg: Uint8Array): ErrorResponse; export function newLogger(name: string): Logger; export function start(chaincode: ChaincodeInterface): any; - export function success(payload?: Uint8Array): ChaincodeResponse; + export function success(payload?: Uint8Array): SuccessResponse; export class Shim { - static error(msg: Uint8Array): ChaincodeResponse; + static error(msg: Uint8Array): ErrorResponse; static newLogger(name: string): Logger; static start(chaincode: ChaincodeInterface): any; - static success(payload?: Uint8Array): ChaincodeResponse; + static success(payload?: Uint8Array): SuccessResponse; static server(chaincode: ChaincodeInterface, serverOpts: ChaincodeServerOpts): ChaincodeServer; } From bd0bdc57df38dca9f6eda594b8243269a7e5213a Mon Sep 17 00:00:00 2001 From: Jerrylum Date: Sun, 10 Mar 2024 02:54:32 +0800 Subject: [PATCH 2/2] Fix Shim.error type definition Signed-off-by: Jerrylum --- libraries/fabric-shim/types/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/fabric-shim/types/index.d.ts b/libraries/fabric-shim/types/index.d.ts index ba89f199d..259e543c5 100644 --- a/libraries/fabric-shim/types/index.d.ts +++ b/libraries/fabric-shim/types/index.d.ts @@ -39,13 +39,13 @@ declare module 'fabric-shim' { Timestamp } - export function error(msg: Uint8Array): ErrorResponse; + export function error(msg: string): ErrorResponse; export function newLogger(name: string): Logger; export function start(chaincode: ChaincodeInterface): any; export function success(payload?: Uint8Array): SuccessResponse; export class Shim { - static error(msg: Uint8Array): ErrorResponse; + static error(msg: string): ErrorResponse; static newLogger(name: string): Logger; static start(chaincode: ChaincodeInterface): any; static success(payload?: Uint8Array): SuccessResponse;