Skip to content

Commit

Permalink
feat(cactus-connector-fabric): add get tx receipt by tx id
Browse files Browse the repository at this point in the history
Authored-by: Eduardo Vasques <[email protected]>
Signed-off-by: Rafael Belchior <[email protected]>
  • Loading branch information
RafaelAPB authored and raynatopedrajeta committed Jan 6, 2025
1 parent 8ee9c62 commit c8d5405
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/.dast-nuclei-cmd-api-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ jobs:

# Delete the first and the second items in the array (remove keychain and manual consortium plugins)
- run: jq 'del(.plugins[0,1])' .config.json > .config2.json && mv .config2.json .config.json

- name: Install Keychain manual plugin into the API server
run: jq '.plugins += [{ "packageName":"@hyperledger/cactus-plugin-keychain-memory","type":"org.hyperledger.cactus.plugin_import_type.LOCAL","action":"org.hyperledger.cactus.plugin_import_action.INSTALL","options":{"packageSrc":"/home/runner/work/cacti/cacti/packages/cactus-plugin-keychain-memory/","instanceId":"0daacd05-d1cd-4eab-9332-4ad1aff4b909","keychainId":"d29d728e-eaa0-4e2d-b187-d132242b0d9a"}}]' .config.json > .config2.json && mv .config2.json .config.json

- name: Install Fabric connector into the API server
run: jq '.plugins += [{ "packageName":"@hyperledger/cactus-plugin-ledger-connector-fabric", "type":"org.hyperledger.cactus.plugin_import_type.LOCAL", "action":"org.hyperledger.cactus.plugin_import_action.INSTALL", "options":{ "packageSrc":"/home/runner/work/cacti/cacti/packages/cactus-plugin-ledger-connector-fabric/", "instanceId":"some-unique-fabric-connector-instance-id", "peerBinary":"/fabric-samples/bin/peer", "connectionProfile":"{}", "dockerBinary":"usr/local/bin/docker","cliContainerEnv":{"CORE_PEER_LOCALMSPID":"Org1MSP","CORE_PEER_ADDRESS":"peer0.org1.example.com:7051","CORE_PEER_MSPCONFIGPATH":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp","CORE_PEER_TLS_ROOTCERT_FILE":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt","ORDERER_TLS_ROOTCERT_FILE":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"},"discoveryOptions":{"enabled":true,"asLocalhost":true}}}] ' .config.json > .config2.json && mv .config2.json .config.json
run: jq '.plugins += [{ "packageName":"@hyperledger/cactus-plugin-ledger-connector-fabric", "type":"org.hyperledger.cactus.plugin_import_type.LOCAL", "action":"org.hyperledger.cactus.plugin_import_action.INSTALL", "options":{ "packageSrc":"/home/runner/work/cacti/cacti/packages/cactus-plugin-ledger-connector-fabric/", "instanceId":"some-unique-fabric-connector-instance-id", "peerBinary":"/fabric-samples/bin/peer", "connectionProfile":"{}", "connectionProfile":"{}", "dockerBinary":"usr/local/bin/docker","cliContainerEnv":{"CORE_PEER_LOCALMSPID":"Org1MSP","CORE_PEER_ADDRESS":"peer0.org1.example.com:7051","CORE_PEER_MSPCONFIGPATH":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp","CORE_PEER_TLS_ROOTCERT_FILE":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt","ORDERER_TLS_ROOTCERT_FILE":"/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"},"discoveryOptions":{"enabled":true,"asLocalhost":true}}}] ' .config.json > .config2.json && mv .config2.json .config.json

- name: Install Besu connector into the API server
run: jq '.plugins += [{"packageName":"@hyperledger/cactus-plugin-ledger-connector-besu","type":"org.hyperledger.cactus.plugin_import_type.LOCAL","action":"org.hyperledger.cactus.plugin_import_action.INSTALL","options":{"packageSrc":"/home/runner/work/cacti/cacti/packages/cactus-plugin-ledger-connector-besu/", "rpcApiHttpHost":"http://127.0.0.1:8545", "rpcApiWsHost":"ws://127.0.0.1:8546", "instanceId":"some-unique-besu-connector-instance-id"}}]' .config.json > .config2.json && mv .config2.json .config.json
Expand Down
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 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
Expand Down Expand Up @@ -229,6 +237,7 @@ export class PluginLedgerConnectorFabric
private readonly certStore: CertDatastore;
private readonly sshDebugOn: boolean;
private runningWatchBlocksMonitors = new Set<WatchBlocksV1Endpoint>();
private txSubject: ReplaySubject<IRunTxReqWithTxId> = new ReplaySubject();

public get className(): string {
return PluginLedgerConnectorFabric.CLASS_NAME;
Expand Down Expand Up @@ -295,18 +304,26 @@ export class PluginLedgerConnectorFabric
);
}


this.sshDebugOn = opts.sshDebugOn === true;
if (this.opts.sshConfig) {
this.sshConfig = this.opts.sshConfig;

if (this.sshDebugOn) {
this.sshConfig = this.enableSshDebugLogs(this.sshConfig);
}
} else if (this.opts.sshConfigB64) {
const sshConfigBuffer = Buffer.from(this.opts.sshConfigB64, "base64");
const sshConfigString = sshConfigBuffer.toString("utf-8");
this.sshConfig = JSON.parse(sshConfigString);

if (this.sshDebugOn) {
this.sshConfig = this.enableSshDebugLogs(this.sshConfig);
}
} else {
throw new Error("Cannot instantiate Fabric connector without SSH config");
}
if (this.sshDebugOn) {
this.sshConfig = this.enableSshDebugLogs(this.sshConfig);
// throw new Error("Cannot instantiate Fabric connector without SSH config");
this.sshConfig = {}
console.log("temp removed")
}

this.signCallback = opts.signCallback;
Expand Down Expand Up @@ -339,6 +356,10 @@ export class PluginLedgerConnectorFabric
return `@hyperledger/cactus-plugin-ledger-connector-fabric`;
}

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

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

const {
channelName,
contractName,
Expand Down Expand Up @@ -1247,6 +1269,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 @@ -1255,6 +1278,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {
PluginLedgerConnectorFabric,
IPluginLedgerConnectorFabricOptions,
SignPayloadCallback,
IRunTxReqWithTxId,
} from "./plugin-ledger-connector-fabric";

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

0 comments on commit c8d5405

Please sign in to comment.