From 73d64349cfd25b588ed909e5e8400bb46fb27246 Mon Sep 17 00:00:00 2001 From: Rafael Belchior Date: Fri, 15 Nov 2024 19:47:51 +0200 Subject: [PATCH] feat(cactus-connector-fabric): add get tx receipt by tx id Authored-by: Eduardo Vasques Signed-off-by: Rafael Belchior --- .../get-transaction-receipt-by-tx-id.ts | 2 +- .../plugin-ledger-connector-fabric.ts | 26 +++++++++++++++++++ .../src/main/typescript/public-api.ts | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) 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 b874bc0e77..887a8f4284 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 @@ -157,7 +157,7 @@ export async function getTransactionReceiptByTxID( if (!extensionNsRwset.rwset) continue; const rwset = extensionNsRwset.rwset; - if (!rwset.writes) continue; + if (!rwset.writes || rwset.writes.length === 0) continue; const rwsetWrite = rwset.writes; if (!rwsetWrite[0].key) continue; const rwsetKey = rwsetWrite[0].key; diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts index fa785261b8..89a0fa9e44 100644 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/plugin-ledger-connector-fabric.ts @@ -147,6 +147,7 @@ import { formatCactiFullBlockResponse, formatCactiTransactionsBlockResponse, } from "./get-block/cacti-block-formatters"; + import { GetBlockEndpointV1 } from "./get-block/get-block-endpoint-v1"; import { GetChainInfoEndpointV1 } from "./get-chain-info/get-chain-info-endpoint-v1"; import { querySystemChainCode } from "./common/query-system-chain-code"; @@ -158,10 +159,17 @@ import { } from "./common/utils"; import { findAndReplaceFabricLoggingSpec } from "./common/find-and-replace-fabric-logging-spec"; import { deployContractGoSourceImplFabricV256 } from "./deploy-contract-go-source/deploy-contract-go-source-impl-fabric-v2-5-6"; +import { Observable, ReplaySubject } from "rxjs"; const { loadFromConfig } = require("fabric-network/lib/impl/ccp/networkconfig"); assertFabricFunctionIsAvailable(loadFromConfig, "loadFromConfig"); +export interface IRunTxReqWithTxId { + request: RunTransactionRequest; + transactionId: string; + timestamp: Date; +} + /** * Constant value holding the default $GOPATH in the Fabric CLI container as * observed on fabric deployments that are produced by the official examples @@ -229,6 +237,7 @@ export class PluginLedgerConnectorFabric private readonly certStore: CertDatastore; private readonly sshDebugOn: boolean; private runningWatchBlocksMonitors = new Set(); + private txSubject: ReplaySubject = new ReplaySubject(); public get className(): string { return PluginLedgerConnectorFabric.CLASS_NAME; @@ -339,6 +348,10 @@ export class PluginLedgerConnectorFabric return `@hyperledger/cactus-plugin-ledger-connector-fabric`; } + public getTxSubjectObservable(): Observable { + return this.txSubject.asObservable(); + } + public async onPluginInit(): Promise { return; } @@ -1178,6 +1191,7 @@ export class PluginLedgerConnectorFabric ): Promise { const fnTag = `${this.className}#transact()`; this.log.debug("%s ENTER", fnTag); + const { channelName, contractName, @@ -1247,6 +1261,7 @@ export class PluginLedgerConnectorFabric const transactionProposal = await contract.createTransaction(fnName); transactionProposal.setEndorsingPeers(endorsingTargets); out = await transactionProposal.setTransient(transientMap).submit(); + transactionId = transactionProposal.getTransactionId(); break; } default: { @@ -1255,6 +1270,17 @@ export class PluginLedgerConnectorFabric } } + // create IRunTxReqWithTxId for transaction monitoring + const receiptData: IRunTxReqWithTxId = { + request: req, + transactionId: transactionId == "" ? uuidv4() : transactionId, + timestamp: new Date(), + }; + this.log.debug( + `IRunTxReqWithTxId created with ID: ${receiptData.transactionId}`, + ); + this.txSubject.next(receiptData); + const res: RunTransactionResponse = { functionOutput: this.convertToTransactionResponseType( out, diff --git a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/public-api.ts b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/public-api.ts index 50172d9cf8..d7d62d46a6 100755 --- a/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/public-api.ts +++ b/packages/cactus-plugin-ledger-connector-fabric/src/main/typescript/public-api.ts @@ -9,6 +9,7 @@ export { PluginLedgerConnectorFabric, IPluginLedgerConnectorFabricOptions, SignPayloadCallback, + IRunTxReqWithTxId, } from "./plugin-ledger-connector-fabric"; import { IPluginFactoryOptions } from "@hyperledger/cactus-core-api";