Skip to content

Commit

Permalink
[FABN-845] JSDoc update for SideDB.js
Browse files Browse the repository at this point in the history
Add typeDef of collecionConfig
add 'greater' checking between requiredPeerCount and maximumPeerCount

Change-Id: I7a5b633c3b0fca65678a15cf3eabfd6575fcbae9
Signed-off-by: davidliu <[email protected]>
  • Loading branch information
davidkhala committed Jul 30, 2018
1 parent 0170563 commit 43afb5a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
10 changes: 3 additions & 7 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2091,10 +2091,10 @@ const Channel = class {
* args[2] is the ChaincodeDeploymentSpec
*
* the following optional arguments here (they can each be nil and may or may not be present)
* args[3] is a marshalled SignaturePolicyEnvelope representing the endorsement policy
* args[3] is a marshaled SignaturePolicyEnvelope representing the endorsement policy
* args[4] is the name of escc
* args[5] is the name of vscc
* args[6] is a marshalled CollectionConfigPackage struct
* args[6] is a marshaled CollectionConfigPackage struct
*/
const lcccSpec_args = [
Buffer.from(command),
Expand All @@ -2108,7 +2108,7 @@ const Channel = class {
lcccSpec_args[3] = this._buildEndorsementPolicy(request['endorsement-policy']);
}
if (request['collections-config']) {
const collectionConfigPackage = this._buildCollectionsConfigPackage(request['collections-config']);
const collectionConfigPackage = CollectionConfig.buildCollectionConfigPackage(request['collections-config']);
lcccSpec_args[6] = collectionConfigPackage.toBuffer();
}

Expand Down Expand Up @@ -2772,10 +2772,6 @@ const Channel = class {
return Policy.buildPolicy(this.getMSPManager().getMSPs(), policy);
}

_buildCollectionsConfigPackage(collectionsConfig) {
return CollectionConfig.buildCollectionConfigPackage(collectionsConfig);
}

/**
* return a printable representation of this channel object
*/
Expand Down
49 changes: 36 additions & 13 deletions fabric-client/lib/SideDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,31 @@ const logger = utils.getLogger('SideDB.js');
const { format } = require('util');

class CollectionConfig {
static buildCollectionConfigPackage(collectionsConfig) {
/**
* collectionsConfig can be either:
* - A string represents the collections-config.json file path
* - An array of collectionConfig
*/

/**
* @typedef {Object} collectionConfig
* @property {string} name
* @property policy
* @property {number} maxPeerCount integer
* @property {number} requiredPeerCount integer
* @property {!Long|number|string|!{low: number, high: number, unsigned: boolean}} blockToLive param will be converted to unsigned int64 as Long
*/

/**
*
* @param {string|collectionConfig[]} collectionsConfigs can be either:
* A string represents the collections-config.json file path;
* An array of collectionConfig;
*/
static buildCollectionConfigPackage(collectionsConfigs) {
try {
let content = collectionsConfig;
if (typeof collectionsConfig === 'string') {
logger.debug('Read CollectionsConfig From %s', collectionsConfig);
content = fs.readFileSync(collectionsConfig, 'utf8');
let content = collectionsConfigs;
if (typeof collectionsConfigs === 'string') {
logger.debug('Read CollectionsConfig From %s', collectionsConfigs);
content = fs.readFileSync(collectionsConfigs, 'utf8');
content = JSON.parse(content);
}
if (!Array.isArray(content) || content.length == 0) {
if (!Array.isArray(content) || content.length === 0) {
logger.error('Expect collections config of type Array, found %s', typeof content);
throw new Error('Expect collections config of type Array');
}
Expand All @@ -47,6 +58,11 @@ class CollectionConfig {
}
}

/**
*
* @param {collectionConfig} collectionConfig
* @returns {collectionConfig}
*/
static checkCollectionConfig(collectionConfig) {
let {
name,
Expand All @@ -69,6 +85,10 @@ class CollectionConfig {
throw new Error(format('CollectionConfig Requires Param "requiredPeerCount" of type number, found %j(type: %s)', requiredPeerCount, typeof requiredPeerCount));
}

if(maxPeerCount<requiredPeerCount){
throw new Error(`CollectionConfig Requires Param "maxPeerCount" bigger than "requiredPeerCount", found maxPeerCount==${maxPeerCount}, requiredPeerCount==${requiredPeerCount}`);
}

if(blockToLive === null || typeof blockToLive === 'undefined') {
blockToLive = 0; //default is never purge
} else if (Number.isNaN(Number.parseInt(blockToLive)) ||
Expand All @@ -92,6 +112,9 @@ class CollectionConfig {
};
}

/**
* @param {collectionConfig} collectionConfig
*/
static buildCollectionConfig(collectionConfig) {
try {
const {
Expand All @@ -116,9 +139,9 @@ class CollectionConfig {
principals.push(newPrincipal);
});

let signaturePolicy = Policy.buildSignaturePolicy(policy.policy);
const signaturePolicy = Policy.buildSignaturePolicy(policy.policy);

let signaturePolicyEnvelope = {
const signaturePolicyEnvelope = {
version: 0,
rule: signaturePolicy,
identities: principals
Expand Down

0 comments on commit 43afb5a

Please sign in to comment.