From 1c1b7788e823f5daaa92b3aef9c1b97103e1ed7b Mon Sep 17 00:00:00 2001 From: Ali Shahverdi Date: Mon, 24 Oct 2022 15:37:54 +0330 Subject: [PATCH] added more comment consistancy fix Signed-off-by: Ali Shahverdi --- .../application-gateway-typescript/src/app.ts | 2 +- .../application-javascript/app.js | 14 +++++----- .../chaincode-go/chaincode/asset_queries.go | 2 +- .../chaincode/asset_queries_test.go | 8 +++--- .../chaincode-go/chaincode/asset_transfer.go | 2 +- .../chaincode/asset_transfer_test.go | 26 +++++++++---------- .../samples/privatedata/AssetTransfer.java | 14 +++++----- .../chaincode-typescript/src/assetContract.ts | 2 +- .../application-gateway-typescript/src/app.ts | 2 +- .../src/connect.ts | 2 +- 10 files changed, 37 insertions(+), 37 deletions(-) diff --git a/asset-transfer-private-data/application-gateway-typescript/src/app.ts b/asset-transfer-private-data/application-gateway-typescript/src/app.ts index 6a7e5729..0513807d 100644 --- a/asset-transfer-private-data/application-gateway-typescript/src/app.ts +++ b/asset-transfer-private-data/application-gateway-typescript/src/app.ts @@ -75,7 +75,7 @@ async function main(): Promise { await getAssetsByRange(contractOrg1); try{ - //Attempt to transfer asset without prior aprroval from Org2, transaction expected to fail. + // Attempt to transfer asset without prior aprroval from Org2, transaction expected to fail. console.log('\nAttempt TransferAsset without prior AgreeToTransfer'); await transferAsset(contractOrg1, assetID1); doFail('TransferAsset transaction succeeded when it was expected to fail'); diff --git a/asset-transfer-private-data/application-javascript/app.js b/asset-transfer-private-data/application-javascript/app.js index 77ac59fa..36c03f58 100644 --- a/asset-transfer-private-data/application-javascript/app.js +++ b/asset-transfer-private-data/application-javascript/app.js @@ -121,7 +121,7 @@ async function initContractFromOrg1Identity() { try { // Create a new gateway for connecting to Org's peer node. const gatewayOrg1 = new Gateway(); - //connect using Discovery enabled + // Connect using Discovery enabled await gatewayOrg1.connect(ccpOrg1, { wallet: walletOrg1, identity: Org1UserId, discovery: { enabled: true, asLocalhost: true } }); @@ -191,15 +191,15 @@ async function main() { console.log('\n**************** As Org1 Client ****************'); console.log('Adding Assets to work with:\n--> Submit Transaction: CreateAsset ' + assetID1); let statefulTxn = contractOrg1.createTransaction('CreateAsset'); - //if you need to customize endorsement to specific set of Orgs, use setEndorsingOrganizations - //statefulTxn.setEndorsingOrganizations(mspOrg1); + // if you need to customize endorsement to specific set of Orgs, use setEndorsingOrganizations + // statefulTxn.setEndorsingOrganizations(mspOrg1); let tmapData = Buffer.from(JSON.stringify(asset1Data)); statefulTxn.setTransient({ asset_properties: tmapData }); result = await statefulTxn.submit(); - //Add asset2 + // Add asset2 console.log('\n--> Submit Transaction: CreateAsset ' + assetID2); statefulTxn = contractOrg1.createTransaction('CreateAsset'); tmapData = Buffer.from(JSON.stringify(asset2Data)); @@ -285,13 +285,13 @@ async function main() { }); result = await statefulTxn.submit(); - //Again ReadAsset : results will show that the buyer identity now owns the asset: + // Again ReadAsset : results will show that the buyer identity now owns the asset: console.log('\n--> Evaluate Transaction: ReadAsset ' + assetID1); result = await contractOrg1.evaluateTransaction('ReadAsset', assetID1); console.log(`<-- result: ${prettyJSONString(result.toString())}`); verifyAssetData(mspOrg1, result, assetID1, 'green', 20, Org2UserId); - //Confirm that transfer removed the private details from the Org1 collection: + // Confirm that transfer removed the private details from the Org1 collection: console.log('\n--> Evaluate Transaction: ReadAssetPrivateDetails'); // ReadAssetPrivateDetails reads data from Org's private collection: Should return empty result = await contractOrg1.evaluateTransaction('ReadAssetPrivateDetails', org1PrivateCollectionName, assetID1); @@ -307,7 +307,7 @@ async function main() { console.log('\n********* Demo deleting asset **************'); let dataForDelete = { assetID: assetID2 }; try { - //Non-owner Org2 should not be able to DeleteAsset. Expect an error from DeleteAsset + // Non-owner Org2 should not be able to DeleteAsset. Expect an error from DeleteAsset console.log('--> Attempt Transaction: as Org2 DeleteAsset ' + assetID2); statefulTxn = contractOrg2.createTransaction('DeleteAsset'); tmapData = Buffer.from(JSON.stringify(dataForDelete)); diff --git a/asset-transfer-private-data/chaincode-go/chaincode/asset_queries.go b/asset-transfer-private-data/chaincode-go/chaincode/asset_queries.go index 8672e31d..490ee235 100644 --- a/asset-transfer-private-data/chaincode-go/chaincode/asset_queries.go +++ b/asset-transfer-private-data/chaincode-go/chaincode/asset_queries.go @@ -23,7 +23,7 @@ func (s *SmartContract) ReadAsset(ctx contractapi.TransactionContextInterface, a return nil, fmt.Errorf("failed to read asset: %v", err) } - //No Asset found, return empty response + // No Asset found, return empty response if assetJSON == nil { log.Printf("%v does not exist in collection %v", assetID, assetCollection) return nil, nil diff --git a/asset-transfer-private-data/chaincode-go/chaincode/asset_queries_test.go b/asset-transfer-private-data/chaincode-go/chaincode/asset_queries_test.go index 3663c87a..0d7ce89c 100644 --- a/asset-transfer-private-data/chaincode-go/chaincode/asset_queries_test.go +++ b/asset-transfer-private-data/chaincode-go/chaincode/asset_queries_test.go @@ -53,7 +53,7 @@ func TestReadAssetPrivateDetails(t *testing.T) { require.NoError(t, err) require.Nil(t, assetBytes) - //read from the collection with no access + // read from the collection with no access chaincodeStub.GetPrivateDataReturns(nil, fmt.Errorf("collection not found")) assetBytes, err = assetTransferCC.ReadAssetPrivateDetails(transactionContext, myOrg2PrivCollection, "id1") require.EqualError(t, err, "failed to read asset details: collection not found") @@ -72,7 +72,7 @@ func TestReadTransferAgreement(t *testing.T) { transactionContext, chaincodeStub := prepMocksAsOrg1() assetTransferCC := chaincode.SmartContract{} - //TransferAgreement does not exist + // TransferAgreement does not exist assetBytes, err := assetTransferCC.ReadTransferAgreement(transactionContext, "id1") require.NoError(t, err) require.Nil(t, assetBytes) @@ -115,7 +115,7 @@ func TestQueryAssetByOwner(t *testing.T) { func TestQueryAssets(t *testing.T) { transactionContext, chaincodeStub := prepMocksAsOrg1() - //Iterator with no records + // Iterator with no records iterator := &mocks.StateQueryIterator{} iterator.HasNextReturns(false) chaincodeStub.GetPrivateDataQueryResultReturns(iterator, nil) @@ -150,7 +150,7 @@ func TestQueryAssets(t *testing.T) { func TestGetAssetByRange(t *testing.T) { transactionContext, chaincodeStub := prepMocksAsOrg1() - //Iterator with no records + // Iterator with no records iterator := &mocks.StateQueryIterator{} iterator.HasNextReturns(false) chaincodeStub.GetPrivateDataByRangeReturns(iterator, nil) diff --git a/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer.go b/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer.go index 9e18d9d8..92c10424 100644 --- a/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer.go +++ b/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer.go @@ -59,7 +59,7 @@ func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface) // Asset properties are private, therefore they get passed in transient field, instead of func args transientAssetJSON, ok := transientMap["asset_properties"] if !ok { - //log error to stdout + // log error to stdout return fmt.Errorf("asset not found in the transient map input") } diff --git a/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer_test.go b/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer_test.go index c6ec5ac5..743a5a86 100644 --- a/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer_test.go +++ b/asset-transfer-private-data/chaincode-go/chaincode/asset_transfer_test.go @@ -127,7 +127,7 @@ func TestCreateAssetSuccessful(t *testing.T) { setReturnAssetPropsInTransientMap(t, chaincodeStub, testAsset) err := assetTransferCC.CreateAsset(transactionContext) require.NoError(t, err) - //Validate PutPrivateData calls + // Validate PutPrivateData calls calledCollection, calledId, _ := chaincodeStub.PutPrivateDataArgsForCall(0) require.Equal(t, assetCollectionName, calledCollection) require.Equal(t, "id1", calledId) @@ -149,7 +149,7 @@ func TestAgreeToTransferBadInput(t *testing.T) { assetPrivDetail := &chaincode.AssetPrivateDetails{ ID: "id1", - //no AppraisedValue + // no AppraisedValue } setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail) origAsset := chaincode.Asset{ @@ -165,7 +165,7 @@ func TestAgreeToTransferBadInput(t *testing.T) { require.EqualError(t, err, "appraisedValue field must be a positive integer") assetPrivDetail = &chaincode.AssetPrivateDetails{ - //no ID + // no ID AppraisedValue: 500, } setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail) @@ -177,7 +177,7 @@ func TestAgreeToTransferBadInput(t *testing.T) { AppraisedValue: 500, } setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail) - //asset does not exist + // asset does not exist setReturnPrivateDataInStub(t, chaincodeStub, nil) err = assetTransferCC.AgreeToTransfer(transactionContext) require.EqualError(t, err, "id1 does not exist") @@ -232,7 +232,7 @@ func TestTransferAssetBadInput(t *testing.T) { BuyerMSP: myOrg2Msp, } setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner) - //asset does not exist + // asset does not exist setReturnPrivateDataInStub(t, chaincodeStub, nil) err = assetTransferCC.TransferAsset(transactionContext) require.EqualError(t, err, "id1 does not exist") @@ -254,15 +254,15 @@ func TestTransferAssetSuccessful(t *testing.T) { Owner: myOrg1Clientid, } setReturnPrivateDataInStub(t, chaincodeStub, &origAsset) - //to ensure we pass data hash verification + // to ensure we pass data hash verification chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil) - //to ensure that ReadTransferAgreement call returns org2 client ID + // to ensure that ReadTransferAgreement call returns org2 client ID chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte(myOrg2Clientid), nil) chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil) err := assetTransferCC.TransferAsset(transactionContext) require.NoError(t, err) - //Validate PutPrivateData calls + // Validate PutPrivateData calls expectedNewAsset := origAsset expectedNewAsset.Owner = myOrg2Clientid expectedNewAssetBytes, err := json.Marshal(expectedNewAsset) @@ -289,7 +289,7 @@ func TestTransferAssetByNonOwner(t *testing.T) { BuyerMSP: myOrg1Msp, } setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner) - //Try to transfer asset owned by Org2 + // Try to transfer asset owned by Org2 org2Asset := chaincode.Asset{ ID: "id1", Type: "testfulasset", @@ -318,10 +318,10 @@ func TestTransferAssetWithoutAnAgreement(t *testing.T) { Owner: myOrg1Clientid, } setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset) - //to ensure we pass data hash verification + // to ensure we pass data hash verification chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil) chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil) - //ReadTransferAgreement call returns no buyer client ID + // ReadTransferAgreement call returns no buyer client ID chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte{}, nil) err := assetTransferCC.TransferAsset(transactionContext) @@ -346,7 +346,7 @@ func TestTransferAssetNonMatchingAppraisalValue(t *testing.T) { } setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset) chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil) - //data hash different in each collection + // data hash different in each collection chaincodeStub.GetPrivateDataHashReturnsOnCall(0, []byte("datahash1"), nil) chaincodeStub.GetPrivateDataHashReturnsOnCall(1, []byte("datahash2"), nil) @@ -369,7 +369,7 @@ func prepMocks(orgMSP, clientId string) (*mocks.TransactionContext, *mocks.Chain clientIdentity := &mocks.ClientIdentity{} clientIdentity.GetMSPIDReturns(orgMSP, nil) clientIdentity.GetIDReturns(clientId, nil) - //set matching msp ID using peer shim env variable + // set matching msp ID using peer shim env variable os.Setenv("CORE_PEER_LOCALMSPID", orgMSP) transactionContext.GetClientIdentityReturns(clientIdentity) return transactionContext, chaincodeStub diff --git a/asset-transfer-private-data/chaincode-java/src/main/java/org/hyperledger/fabric/samples/privatedata/AssetTransfer.java b/asset-transfer-private-data/chaincode-java/src/main/java/org/hyperledger/fabric/samples/privatedata/AssetTransfer.java index f95a234d..94a261c4 100644 --- a/asset-transfer-private-data/chaincode-java/src/main/java/org/hyperledger/fabric/samples/privatedata/AssetTransfer.java +++ b/asset-transfer-private-data/chaincode-java/src/main/java/org/hyperledger/fabric/samples/privatedata/AssetTransfer.java @@ -319,7 +319,7 @@ public final class AssetTransfer implements ContractInterface { // write private data from this peer. verifyClientOrgMatchesPeerOrg(ctx); - //Make submitting client the owner + // Make submitting client the owner asset.setOwner(clientID); System.out.printf("CreateAsset Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, assetID); System.out.printf("Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, new String(asset.serialize())); @@ -328,7 +328,7 @@ public final class AssetTransfer implements ContractInterface { // Get collection name for this organization. String orgCollectionName = getCollectionName(ctx); - //Save AssetPrivateDetails to org collection + // Save AssetPrivateDetails to org collection AssetPrivateDetails assetPriv = new AssetPrivateDetails(assetID, appraisedValue); System.out.printf("Put AssetPrivateDetails: collection %s, ID %s\n", orgCollectionName, assetID); stub.putPrivateData(orgCollectionName, assetID, assetPriv.serialize()); @@ -392,12 +392,12 @@ public final class AssetTransfer implements ContractInterface { verifyClientOrgMatchesPeerOrg(ctx); - //Save AssetPrivateDetails to org collection + // Save AssetPrivateDetails to org collection System.out.printf("Put AssetPrivateDetails: collection %s, ID %s\n", orgCollectionName, assetID); stub.putPrivateData(orgCollectionName, assetID, assetPriv.serialize()); String clientID = ctx.getClientIdentity().getId(); - //Write the AgreeToTransfer key in assetCollection + // Write the AgreeToTransfer key in assetCollection CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID); System.out.printf("AgreeToTransfer Put: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey); stub.putPrivateData(ASSET_COLLECTION_NAME, aggKey.toString(), clientID); @@ -470,15 +470,15 @@ public final class AssetTransfer implements ContractInterface { String newOwner = transferAgreement.getBuyerID(); thisAsset.setOwner(newOwner); - //Save updated Asset to collection + // Save updated Asset to collection System.out.printf("Transfer Asset: collection %s, ID %s to owner %s\n", ASSET_COLLECTION_NAME, assetID, newOwner); stub.putPrivateData(ASSET_COLLECTION_NAME, assetID, thisAsset.serialize()); - // delete the key from owners collection + // Delete the key from owners collection String ownersCollectionName = getCollectionName(ctx); stub.delPrivateData(ownersCollectionName, assetID); - //Delete the transfer agreement from the asset collection + // Delete the transfer agreement from the asset collection CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID); System.out.printf("AgreeToTransfer deleteKey: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey); stub.delPrivateData(ASSET_COLLECTION_NAME, aggKey.toString()); diff --git a/asset-transfer-sbe/chaincode-typescript/src/assetContract.ts b/asset-transfer-sbe/chaincode-typescript/src/assetContract.ts index 493f85cb..436c59f0 100644 --- a/asset-transfer-sbe/chaincode-typescript/src/assetContract.ts +++ b/asset-transfer-sbe/chaincode-typescript/src/assetContract.ts @@ -134,7 +134,7 @@ export class AssetContract extends Contract { sigsPolicies.push(signedBy); }); - // create the policy such that it requires any N signature's from all of the principals provided + // Create the policy such that it requires any N signature's from all of the principals provided const allOf = { n: nOrgs, rules: sigsPolicies diff --git a/asset-transfer-secured-agreement/application-gateway-typescript/src/app.ts b/asset-transfer-secured-agreement/application-gateway-typescript/src/app.ts index e2210d65..a9fd6365 100644 --- a/asset-transfer-secured-agreement/application-gateway-typescript/src/app.ts +++ b/asset-transfer-secured-agreement/application-gateway-typescript/src/app.ts @@ -13,7 +13,7 @@ import { RED, RESET } from './utils'; const channelName = 'mychannel'; const chaincodeName = 'secured'; -//Use a random key so that we can run multiple times +// Use a random key so that we can run multiple times const now = Date.now().toString(); let assetKey: string; diff --git a/asset-transfer-secured-agreement/application-gateway-typescript/src/connect.ts b/asset-transfer-secured-agreement/application-gateway-typescript/src/connect.ts index e10f8bd6..4b08b048 100644 --- a/asset-transfer-secured-agreement/application-gateway-typescript/src/connect.ts +++ b/asset-transfer-secured-agreement/application-gateway-typescript/src/connect.ts @@ -73,7 +73,7 @@ export const peerEndpointOrg2 = 'localhost:9051'; export const peerNameOrg1 = 'peer0.org1.example.com'; export const peerNameOrg2 = 'peer0.org2.example.com'; -//Collection Names +// Collection Names export const org1PrivateCollectionName = 'Org1MSPPrivateCollection'; export const org2PrivateCollectionName = 'Org2MSPPrivateCollection';