From 0aa7b526666a2ee50a47e1ea4dc1ddcc2a17b72d Mon Sep 17 00:00:00 2001 From: "abdou.chakhkhar" Date: Fri, 26 Aug 2022 21:27:35 +0100 Subject: [PATCH] eslint change Signed-off-by: abdou.chakhkhar --- .../chaincode-javascript/.eslintrc.js | 6 ----- .../lib/PrivateAssetTransfer.js | 25 +++++++++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/asset-transfer-private-data/chaincode-javascript/.eslintrc.js b/asset-transfer-private-data/chaincode-javascript/.eslintrc.js index 555c0cf5..02c824f8 100644 --- a/asset-transfer-private-data/chaincode-javascript/.eslintrc.js +++ b/asset-transfer-private-data/chaincode-javascript/.eslintrc.js @@ -12,22 +12,16 @@ module.exports = { ecmaVersion: 8, sourceType: 'script' }, - extends: "eslint:recommended", rules: { indent: ['error', 4], 'linebreak-style': ['error', 'unix'], - quotes: ['error', 'single'], - semi: ['error', 'always'], 'no-unused-vars': ['error', { args: 'none' }], 'no-console': 'off', curly: 'error', - eqeqeq: 'error', 'no-throw-literal': 'error', strict: 'error', 'no-var': 'error', 'dot-notation': 'error', - 'no-tabs': 'error', - 'no-trailing-spaces': 'error', 'no-use-before-define': 'error', 'no-useless-call': 'error', 'no-with': 'error', diff --git a/asset-transfer-private-data/chaincode-javascript/lib/PrivateAssetTransfer.js b/asset-transfer-private-data/chaincode-javascript/lib/PrivateAssetTransfer.js index b2649ce3..9cc44635 100644 --- a/asset-transfer-private-data/chaincode-javascript/lib/PrivateAssetTransfer.js +++ b/asset-transfer-private-data/chaincode-javascript/lib/PrivateAssetTransfer.js @@ -102,11 +102,26 @@ class PrivateAssetTransfer extends Contract { const promiseOfIterator = response.iterator.response.results; const allResults = []; - for await (const res of promiseOfIterator) { - allResults.push(res.resultBytes.toString()); + let result = await promiseOfIterator.next(); + while (!result.done) { + const strValue = Buffer.from(result.value.value.toString()).toString('utf8'); + let record; + try { + record = JSON.parse(strValue); + } catch (err) { + console.log(err); + record = strValue; + } + allResults.push(record); + result = await promiseOfIterator.next(); } - return allResults; + // for await(const res of promiseOfIterator) { + // allResults.push(res.resultBytes.toString()); + // } + + + return JSON.stringify(allResults); } // ReadAssetPrivateDetails reads the asset private details in organization specific collection @@ -223,7 +238,7 @@ class PrivateAssetTransfer extends Contract { let valueJSON = JSON.parse(transientAssetJSON); // Do some error checking since we get the chance - if (!valueJSON.assetID && valueJSON.assetID === "") { + if (!valueJSON.assetID && valueJSON.assetID === '') { throw new Error(`assetID field must be a non-empty string`); } @@ -412,7 +427,7 @@ class PrivateAssetTransfer extends Contract { // Get hash of owners agreed to value const ownerAppraisedValueHash = await ctx.stub.getPrivateDataHash(collectionOwner, assetID); - + if (!ownerAppraisedValueHash) { throw Error(`Hash of appraised value for ${assetID} does not exist in collection ${collectionOwner}.`) }