Skip to content

Commit

Permalink
feat(connector-fabric): endorsing peers request arg #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 #1123
Depends on #1130

Fixes #1122

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Jul 23, 2021
1 parent 250197f commit c6057a7
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 2 deletions.
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 @@ -72,6 +72,7 @@
},
"homepage": "https://github.com/hyperledger/cactus#readme",
"dependencies": {
"@fidm/x509": "1.2.1",
"@hyperledger/cactus-common": "0.6.0",
"@hyperledger/cactus-core": "0.6.0",
"@hyperledger/cactus-core-api": "0.6.0",
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
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,19 @@
"@ethersproject/properties" "^5.4.0"
"@ethersproject/strings" "^5.4.0"

"@fidm/asn1@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@fidm/asn1/-/asn1-1.0.4.tgz#afbf9f10a0cb83aca2114c6f59a97dd48eb7dd84"
integrity sha512-esd1jyNvRb2HVaQGq2Gg8Z0kbQPXzV9Tq5Z14KNIov6KfFD6PTaRIO8UpcsYiTNzOqJpmyzWgVTrUwFV3UF4TQ==

"@fidm/x509@1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@fidm/x509/-/x509-1.2.1.tgz#ae546a661005d776cc4dca674b399c1132c1e0e4"
integrity sha512-nwc2iesjyc9hkuzcrMCBXQRn653XuAUKorfWM8PZyJawiy1QzLj4vahwzaI25+pfpwOLvMzbJ0uKpWLDNmo16w==
dependencies:
"@fidm/asn1" "^1.0.4"
tweetnacl "^1.0.1"

"@grpc/grpc-js@^1.3.4":
version "1.3.6"
resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.3.6.tgz#6e2d17610c2c8df0f6ceab0e1968f563df74b173"
Expand Down Expand Up @@ -19424,7 +19437,7 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
resolved "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz"
integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=

tweetnacl@^1.0.3:
tweetnacl@^1.0.1, tweetnacl@^1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz"
integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==
Expand Down

0 comments on commit c6057a7

Please sign in to comment.