Skip to content

Commit

Permalink
feat(cactus-connector-fabric): add get transaction receipt by tx id
Browse files Browse the repository at this point in the history
Authored-by: Eduardo Vasques [email protected]
Co-authored-by: Rafael Belchior [email protected]
Signed-off-by: Rafael Belchior [email protected]
  • Loading branch information
RafaelAPB committed Nov 15, 2024
1 parent 4424bf9 commit 0172390
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 RunTxReqWithTxId {
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
Expand Down Expand Up @@ -225,6 +233,7 @@ export class PluginLedgerConnectorFabric
private readonly certStore: CertDatastore;
private readonly sshDebugOn: boolean;
private runningWatchBlocksMonitors = new Set<WatchBlocksV1Endpoint>();
private txSubject: ReplaySubject<RunTxReqWithTxId> = new ReplaySubject();

public get className(): string {
return PluginLedgerConnectorFabric.CLASS_NAME;
Expand Down Expand Up @@ -312,6 +321,10 @@ export class PluginLedgerConnectorFabric
return `@hyperledger/cactus-plugin-ledger-connector-fabric`;
}

public getTxSubjectObservable(): Observable<RunTxReqWithTxId> {
return this.txSubject.asObservable();
}

public async onPluginInit(): Promise<unknown> {
return;
}
Expand Down Expand Up @@ -1149,6 +1162,7 @@ export class PluginLedgerConnectorFabric
): Promise<RunTransactionResponse> {
const fnTag = `${this.className}#transact()`;
this.log.debug("%s ENTER", fnTag);

const {
channelName,
contractName,
Expand Down Expand Up @@ -1218,6 +1232,7 @@ export class PluginLedgerConnectorFabric
const transactionProposal = await contract.createTransaction(fnName);
transactionProposal.setEndorsingPeers(endorsingTargets);
out = await transactionProposal.setTransient(transientMap).submit();
transactionId = transactionProposal.getTransactionId();
break;
}
default: {
Expand All @@ -1226,6 +1241,17 @@ export class PluginLedgerConnectorFabric
}
}

// create RunTxReqWithTxId for transaction monitoring
const receiptData: RunTxReqWithTxId = {
request: req,
transactionId: transactionId == "" ? uuidv4() : transactionId,
timestamp: new Date(),
};
this.log.debug(
`RunTxReqWithTxId created with ID: ${receiptData.transactionId}`,
);
this.txSubject.next(receiptData);

const res: RunTransactionResponse = {
functionOutput: this.convertToTransactionResponseType(
out,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {
PluginLedgerConnectorFabric,
IPluginLedgerConnectorFabricOptions,
SignPayloadCallback,
RunTxReqWithTxId,
} from "./plugin-ledger-connector-fabric";

import { IPluginFactoryOptions } from "@hyperledger/cactus-core-api";
Expand Down

0 comments on commit 0172390

Please sign in to comment.