Skip to content

Commit

Permalink
feat(fabric-connector): add private data support
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Belchior <rafael.belchior@tecnico.ulisboa.pt>
  • Loading branch information
RafaelAPB authored and petermetz committed May 25, 2021
1 parent 26b4261 commit 3f503f9
Show file tree
Hide file tree
Showing 11 changed files with 1,566 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@
"type": "string",
"enum": [
"FabricContractInvocationType.SEND",
"FabricContractInvocationType.CALL"
"FabricContractInvocationType.CALL",
"FabricContractInvocationType.SENDPRIVATE"
]
},
"SSHExecCommandResponse": {
Expand Down Expand Up @@ -288,6 +289,10 @@
"params"
],
"properties": {
"transientData": {
"type": "object",
"nullable": true
},
"signingCredential": {
"$ref": "#/components/schemas/FabricSigningCredential",
"nullable": false
Expand Down Expand Up @@ -323,6 +328,16 @@
"type": "string",
"nullable": true
}
},

"endorsingParties": {
"type": "array",
"nullable": false,
"default": [],
"items": {
"type": "string",
"nullable": true
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ export interface DeploymentTargetOrganization {
*/
export enum FabricContractInvocationType {
SEND = 'FabricContractInvocationType.SEND',
CALL = 'FabricContractInvocationType.CALL'
CALL = 'FabricContractInvocationType.CALL',
SENDPRIVATE = 'FabricContractInvocationType.SENDPRIVATE'
}

/**
Expand Down Expand Up @@ -615,6 +616,12 @@ export interface InlineResponse501 {
* @interface RunTransactionRequest
*/
export interface RunTransactionRequest {
/**
*
* @type {object}
* @memberof RunTransactionRequest
*/
transientData?: object | null;
/**
*
* @type {FabricSigningCredential}
Expand Down Expand Up @@ -651,6 +658,12 @@ export interface RunTransactionRequest {
* @memberof RunTransactionRequest
*/
params: Array<string>;
/**
*
* @type {Array<string>}
* @memberof RunTransactionRequest
*/
endorsingParties?: Array<string>;
}
/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Identity,
InMemoryWallet,
X509WalletMixin,
TransientMap,
} from "fabric-network";

import { Optional } from "typescript-optional";
Expand Down Expand Up @@ -232,8 +233,9 @@ export class PluginLedgerConnectorFabric

const ssh = new NodeSSH();
await ssh.connect(opts.sshConfig);
log.debug(`SSH connection OK`);

if (req.collectionsConfigFile) {
log.debug(`Has private data collection definition`);
}
try {
const {
sourceFiles,
Expand Down Expand Up @@ -809,6 +811,8 @@ export class PluginLedgerConnectorFabric
invocationType,
methodName: fnName,
params,
transientData,
endorsingParties,
} = req;

const gateway = new Gateway();
Expand Down Expand Up @@ -873,6 +877,41 @@ export class PluginLedgerConnectorFabric
success = true;
break;
}
case FabricContractInvocationType.SENDPRIVATE: {
if (!transientData) {
const message =
"Set transaction to send Transient Data but it was not provided";
throw new Error(`${fnTag} ${message}`);
}

const transientMap: TransientMap = transientData as TransientMap;

try {
//Obtains and parses each component of transient data
for (const key in transientMap) {
transientMap[key] = Buffer.from(
JSON.stringify(transientMap[key]),
);
}
} catch (ex) {
this.log.error(`Building transient map crashed: `, ex);
throw new Error(
`${fnTag} Unable to build the transient map: ${ex.message}`,
);
}

const transactionProposal = await contract.createTransaction(fnName);

if (endorsingParties) {
endorsingParties.forEach((org) => {
transactionProposal.setEndorsingOrganizations(org);
});
}

out = await transactionProposal.setTransient(transientMap).submit();
success = true;
break;
}
default: {
const message = `FabricContractInvocationType: ${invocationType}`;
throw new Error(`${fnTag} unknown ${message}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"index": {
"fields": [
"objectType",
"owner"
]
},
"ddoc": "indexOwnerDoc",
"name": "indexOwner",
"type": "json"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Using Private Data tutorial](https://hyperledger-fabric.readthedocs.io/en/latest/private_data_tutorial.html)
Loading

0 comments on commit 3f503f9

Please sign in to comment.