Skip to content

Commit

Permalink
feat(connector-fabric): endorsing peers request arg hyperledger#1122
Browse files Browse the repository at this point in the history
Makes it possible to set the endorsing peers on a transaction
when submitted through the Fabric connector.

For example these values can be passed in to the new parameter
and it will set the endorsers up accordingly prior to submitting
the transaction to the ledger:
- org1.example.com
- Org1MSP
- org2.example.com
- Org2MSP

(You only need either the org domain or the msp ID, no need
to specify both of them for it to work).

For a working example, see this test case:
packages/cactus-plugin-ledger-connector-fabric/src/test/typescript/
integration/fabric-v2-2-x/run-transaction-endpoint-v1.test.ts

Depends on hyperledger#1123
Depends on hyperledger#1130

Fixes hyperledger#1122

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Jul 22, 2021
1 parent 82c4d83 commit 2b97679
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"escc",
"execa",
"faio",
"fidm",
"fsouza",
"GETHKEYCHAINPASSWORD",
"ghcr",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,16 @@
"params"
],
"properties": {
"endorsingPeers": {
"description": "An array of MSP IDs to set as the list of endorsing peers for the transaction.",
"type": "array",
"items": {
"type": "string",
"minLength": 1,
"maxLength": 4096,
"nullable": false
}
},
"transientData": {
"type": "object",
"nullable": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ export interface InlineResponse501 {
* @interface RunTransactionRequest
*/
export interface RunTransactionRequest {
/**
* An array of MSP IDs to set as the list of endorsing peers for the transaction.
* @type {Array<string>}
* @memberof RunTransactionRequest
*/
endorsingPeers?: Array<string>;
/**
*
* @type {object}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "path";
import { Server } from "http";
import { Server as SecureServer } from "https";

import { Certificate } from "@fidm/x509";
import { Express } from "express";
import "multer";
import temp from "temp";
Expand Down Expand Up @@ -88,6 +89,7 @@ import {
import { sourceLangToRuntimeLang } from "./peer/source-lang-to-runtime-lang";
import FabricCAServices from "fabric-ca-client";
import { createGateway } from "./common/create-gateway";
import { Endorser } from "fabric-common";

/**
* Constant value holding the default $GOPATH in the Fabric CLI container as
Expand Down Expand Up @@ -916,7 +918,37 @@ export class PluginLedgerConnectorFabric
break;
}
case FabricContractInvocationType.Send: {
out = await contract.submitTransaction(fnName, ...params);
const tx = contract.createTransaction(fnName);
if (req.endorsingPeers) {
const { endorsingPeers } = req;
const channel = network.getChannel();

const allChannelEndorsers = (channel.getEndorsers() as unknown) as Array<
Endorser & { options: { pem: string } }
>;

const endorsers = allChannelEndorsers
.map((endorser) => {
const certificate = Certificate.fromPEM(
(endorser.options.pem as unknown) as Buffer,
);
return { certificate, endorser };
})
.filter(
({ endorser, certificate }) =>
endorsingPeers.includes(endorser.mspid) ||
endorsingPeers.includes(certificate.issuer.organizationName),
)
.map((it) => it.endorser);

this.log.debug(
"%o endorsers: %o",
endorsers.length,
endorsers.map((it) => `${it.mspid}:${it.name}`),
);
tx.setEndorsingPeers(endorsers);
}
out = await tx.submit(...params);
success = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,29 @@ test(testCase, async (t: Test) => {
);
}

{
const req: RunTransactionRequest = {
signingCredential,
gatewayOptions: {
identity: keychainEntryKey,
wallet: {
json: keychainEntryValue,
},
},
channelName,
invocationType: FabricContractInvocationType.Send,
contractName,
methodName: "CreateAsset",
params: ["asset388", "green", "111", assetOwner, "299"],
endorsingPeers: ["org1.example.com", "Org2MSP"],
};

const res = await apiClient.runTransactionV1(req);
t.ok(res, "Create green asset response truthy OK");
t.ok(res.data, "Create green asset response.data truthy OK");
t.equal(res.status, 200, "Create green asset response.status=200 OK");
}

{
const res = await apiClient.runTransactionV1({
gatewayOptions: {
Expand Down

0 comments on commit 2b97679

Please sign in to comment.