From 26a99b9945be722a56f12a5d55ccd70b83cc3637 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Fri, 12 Jul 2024 09:32:28 -0700 Subject: [PATCH] fix(connector-fabric): decode blocks in getTransactionReceiptByTxID() Since commit 8c030ae9e739a28ff0900f7af27ec0fbbb4b7ff9 we have to manually decode the protocol buffer block data because the querySystemChainCode() does not do it for us by default anymore. This was causing some type-checks to fail in getTransactionReceiptByTxID() which were explicitly guarding against receiving `Buffer`s as responses but now the only thing we receive from the query system chain code method is exactly `Buffer` type objects. Signed-off-by: Peter Somogyvari --- .../common/get-transaction-receipt-by-tx-id.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/common/get-transaction-receipt-by-tx-id.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/common/get-transaction-receipt-by-tx-id.ts index 54dd871931..b874bc0e77 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/common/get-transaction-receipt-by-tx-id.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/common/get-transaction-receipt-by-tx-id.ts @@ -1,12 +1,16 @@ import { LoggerProvider, LogLevelDesc } from "@hyperledger/cactus-common"; import { Gateway } from "fabric-network"; +import { common } from "fabric-protos"; +// BlockDecoder is not exported in ts definition so we need to use legacy import. +const { BlockDecoder } = require("fabric-common"); + import { GetTransactionReceiptResponse, TransactReceiptTransactionEndorsement, TransactReceiptTransactionCreator, TransactReceiptBlockMetaData, } from "../generated/openapi/typescript-axios"; -import { common } from "fabric-protos"; + import { querySystemChainCode } from "./query-system-chain-code"; export interface IGetTransactionReceiptByTxIDOptions { @@ -38,18 +42,17 @@ export async function getTransactionReceiptByTxID( gateway, connectionChannelName: req.channelName, }; - const block: common.Block = await querySystemChainCode( + const blockBuffer = await querySystemChainCode( queryConfig, "GetBlockByTxID", paramChannelName, reqTxID, ); - if (block instanceof Buffer) { - throw new Error( - "Unexpected encoded response from querySystemChainCode::GetBlockByTxID()", - ); - } + // Since commit 8c030ae9e739a28ff0900f7af27ec0fbbb4b7ff9 we have to manually + // decode the protocol buffer block data because the querySystemChainCode() + // does not do it for us by default anymore. + const block: common.Block = BlockDecoder.decode(blockBuffer); const blockJson = JSON.parse(JSON.stringify(block));