fabric-samples/auction-simple/application-javascript/queryBid.js
ali 05c06f4931
Fixed comment consistency problem (#844)
* fixed comment consistency problem with erc20 chaincode

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

* added more comment consistancy fix

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

* added more comment consistancy fix

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

* added more comment consistancy fix

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

* added more comment consistancy fix

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>
Co-authored-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>
2022-12-14 09:18:21 +01:00

73 lines
2.2 KiB
JavaScript

/*
* Copyright IBM Corp. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
'use strict';
const { Gateway, Wallets } = require('fabric-network');
const path = require('path');
const { buildCCPOrg1, buildCCPOrg2, buildWallet, prettyJSONString} = require('../../test-application/javascript/AppUtil.js');
const myChannel = 'mychannel';
const myChaincodeName = 'auction';
async function queryBid(ccp,wallet,user,auctionID,bidID) {
try {
const gateway = new Gateway();
// Connect using Discovery enabled
await gateway.connect(ccp,
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
const network = await gateway.getNetwork(myChannel);
const contract = network.getContract(myChaincodeName);
console.log('\n--> Evaluate Transaction: read bid from private data store');
let result = await contract.evaluateTransaction('QueryBid',auctionID,bidID);
console.log('*** Result: Bid: ' + prettyJSONString(result.toString()));
gateway.disconnect();
} catch (error) {
console.error(`******** FAILED to submit bid: ${error}`);
}
}
async function main() {
try {
if (process.argv[2] === undefined || process.argv[3] === undefined ||
process.argv[4] === undefined || process.argv[5] === undefined) {
console.log('Usage: node bid.js org userID auctionID bidID');
process.exit(1);
}
const org = process.argv[2];
const user = process.argv[3];
const auctionID = process.argv[4];
const bidID = process.argv[5];
if (org === 'Org1' || org === 'org1') {
const ccp = buildCCPOrg1();
const walletPath = path.join(__dirname, 'wallet/org1');
const wallet = await buildWallet(Wallets, walletPath);
await queryBid(ccp,wallet,user,auctionID,bidID);
}
else if (org === 'Org2' || org === 'org2') {
const ccp = buildCCPOrg2();
const walletPath = path.join(__dirname, 'wallet/org2');
const wallet = await buildWallet(Wallets, walletPath);
await queryBid(ccp,wallet,user,auctionID,bidID);
} else {
console.log('Usage: node bid.js org userID auctionID bidID');
console.log('Org must be Org1 or Org2');
}
} catch (error) {
console.error(`******** FAILED to run the application: ${error}`);
}
}
main();