fabric-samples/auction/application-javascript/queryAuction.js
Brett Logan 9b071d0463 Add ESLinte to Auction Example
The auction example had no ESLint configuration.
This change adds a .eslintrc.js file that matches
the rest of the projects.

This change also fixes all the linting issue in
the auction example.

Signed-off-by: Brett Logan <lindluni@github.com>
2021-02-11 18:11:17 -05:00

76 lines
2.1 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 queryAuction(ccp,wallet,user,auctionID) {
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: query the auction');
let result = await contract.evaluateTransaction('QueryAuction',auctionID);
console.log('*** Result: Auction: ' + 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) {
console.log('Usage: node queryAuction.js org userID auctionID');
process.exit(1);
}
const org = process.argv[2];
const user = process.argv[3];
const auctionID = process.argv[4];
if (org == 'Org1' || org == 'org1') {
const orgMSP = 'Org1MSP';
const ccp = buildCCPOrg1();
const walletPath = path.join(__dirname, 'wallet/org1');
const wallet = await buildWallet(Wallets, walletPath);
await queryAuction(ccp,wallet,user,auctionID);
}
else if (org == 'Org2' || org == 'org2') {
const orgMSP = 'Org2MSP';
const ccp = buildCCPOrg2();
const walletPath = path.join(__dirname, 'wallet/org2');
const wallet = await buildWallet(Wallets, walletPath);
await queryAuction(ccp,wallet,user,auctionID);
} else {
console.log('Usage: node queryAuction.js org userID auctionID');
console.log('Org must be Org1 or Org2');
}
} catch (error) {
console.error(`******** FAILED to run the application: ${error}`);
}
}
main();