From a3db59c1451d4ebe82eb7c94c9ddfa307a7ed8d8 Mon Sep 17 00:00:00 2001 From: fraVlaca Date: Mon, 6 Sep 2021 13:06:36 +0100 Subject: [PATCH] last fixes for chaincode-javascript of asset-transfer-basic Signed-off-by: fraVlaca --- .../chaincode-typescript/src/assetTransfer.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/asset-transfer-basic/chaincode-typescript/src/assetTransfer.ts b/asset-transfer-basic/chaincode-typescript/src/assetTransfer.ts index 475e2b68..ee58c172 100644 --- a/asset-transfer-basic/chaincode-typescript/src/assetTransfer.ts +++ b/asset-transfer-basic/chaincode-typescript/src/assetTransfer.ts @@ -1,9 +1,9 @@ /* * SPDX-License-Identifier: Apache-2.0 */ -//Deterministic JSON.stringify() -const stringify = require('json-stringify-deterministic') -const sortKeysRecursive = require('sort-keys-recursive') +// Deterministic JSON.stringify() +import * as stringify from 'json-stringify-deterministic'); +import * as sortKeysRecursive from 'sort-keys-recursive'; import {Context, Contract, Info, Returns, Transaction} from 'fabric-contract-api'; import {Asset} from './asset'; @@ -59,10 +59,10 @@ export class AssetTransferContract extends Contract { for (const asset of assets) { asset.docType = 'asset'; - //example of how to write to world state deterministically - //use convetion of alphabetic order - //we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive' - //when retrieving data, in any lang, the order of data will be the same and consequently also the corresonding hash + // example of how to write to world state deterministically + // use convetion of alphabetic order + // we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive' + // when retrieving data, in any lang, the order of data will be the same and consequently also the corresonding hash await ctx.stub.putState(asset.ID, Buffer.from(stringify(sortKeysRecursive(asset)))); console.info(`Asset ${asset.ID} initialized`); } @@ -83,7 +83,7 @@ export class AssetTransferContract extends Contract { Owner: owner, AppraisedValue: appraisedValue, }; - //we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive' + // we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive' await ctx.stub.putState(id, Buffer.from(stringify(sortKeysRecursive(asset)))); } @@ -113,7 +113,7 @@ export class AssetTransferContract extends Contract { Owner: owner, AppraisedValue: appraisedValue, }; - //we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive' + // we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive' return ctx.stub.putState(id, Buffer.from(stringify(sortKeysRecursive(updatedAsset)))); } @@ -141,7 +141,7 @@ export class AssetTransferContract extends Contract { const assetString = await this.ReadAsset(ctx, id); const asset = JSON.parse(assetString); asset.Owner = newOwner; - //we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive' + // we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive' await ctx.stub.putState(id, Buffer.from(stringify(sortKeysRecursive(asset)))); }