mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
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>
This commit is contained in:
parent
37513c3c2b
commit
9b071d0463
12 changed files with 541 additions and 500 deletions
5
auction/application-javascript/.eslintignore
Normal file
5
auction/application-javascript/.eslintignore
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
coverage
|
||||
36
auction/application-javascript/.eslintrc.js
Normal file
36
auction/application-javascript/.eslintrc.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
node: true,
|
||||
mocha: true
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 8,
|
||||
sourceType: 'script'
|
||||
},
|
||||
extends: 'eslint:recommended',
|
||||
rules: {
|
||||
indent: ['error', 'tab'],
|
||||
'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-trailing-spaces': 'error',
|
||||
'no-use-before-define': 'error',
|
||||
'no-useless-call': 'error',
|
||||
'no-with': 'error',
|
||||
'operator-linebreak': 'error',
|
||||
yoda: 'error',
|
||||
'quote-props': ['error', 'as-needed']
|
||||
}
|
||||
};
|
||||
|
|
@ -14,45 +14,45 @@ const myChannel = 'mychannel';
|
|||
const myChaincodeName = 'auction';
|
||||
|
||||
async function bid(ccp,wallet,user,orgMSP,auctionID,price) {
|
||||
try {
|
||||
try {
|
||||
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
|
||||
console.log('\n--> Evaluate Transaction: get your client ID');
|
||||
let bidder = await contract.evaluateTransaction('GetSubmittingClientIdentity');
|
||||
console.log('*** Result: Bidder ID is ' + bidder.toString());
|
||||
console.log('\n--> Evaluate Transaction: get your client ID');
|
||||
let bidder = await contract.evaluateTransaction('GetSubmittingClientIdentity');
|
||||
console.log('*** Result: Bidder ID is ' + bidder.toString());
|
||||
|
||||
let bidData = { objectType: 'bid', price: parseInt(price), org: orgMSP, bidder: bidder.toString()};
|
||||
let bidData = { objectType: 'bid', price: parseInt(price), org: orgMSP, bidder: bidder.toString()};
|
||||
|
||||
let statefulTxn = contract.createTransaction('Bid');
|
||||
statefulTxn.setEndorsingOrganizations(orgMSP);
|
||||
let tmapData = Buffer.from(JSON.stringify(bidData));
|
||||
statefulTxn.setTransient({
|
||||
bid: tmapData
|
||||
});
|
||||
let statefulTxn = contract.createTransaction('Bid');
|
||||
statefulTxn.setEndorsingOrganizations(orgMSP);
|
||||
let tmapData = Buffer.from(JSON.stringify(bidData));
|
||||
statefulTxn.setTransient({
|
||||
bid: tmapData
|
||||
});
|
||||
|
||||
let bidID = statefulTxn.getTransactionId();
|
||||
let bidID = statefulTxn.getTransactionId();
|
||||
|
||||
console.log('\n--> Submit Transaction: Create the bid that is stored in your organization\'s private data collection');
|
||||
await statefulTxn.submit(auctionID);
|
||||
console.log('*** Result: committed');
|
||||
console.log('*** Result ***SAVE THIS VALUE*** BidID: ' + bidID.toString());
|
||||
console.log('\n--> Submit Transaction: Create the bid that is stored in your organization\'s private data collection');
|
||||
await statefulTxn.submit(auctionID);
|
||||
console.log('*** Result: committed');
|
||||
console.log('*** Result ***SAVE THIS VALUE*** BidID: ' + bidID.toString());
|
||||
|
||||
console.log('\n--> Evaluate Transaction: read the bid that was just created');
|
||||
let result = await contract.evaluateTransaction('QueryBid',auctionID,bidID);
|
||||
console.log('*** Result: Bid: ' + prettyJSONString(result.toString()));
|
||||
console.log('\n--> Evaluate Transaction: read the bid that was just created');
|
||||
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}`);
|
||||
if (error.stack) {
|
||||
gateway.disconnect();
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to submit bid: ${error}`);
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
|
|
@ -60,42 +60,42 @@ async function bid(ccp,wallet,user,orgMSP,auctionID,price) {
|
|||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
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 price");
|
||||
process.exit(1);
|
||||
}
|
||||
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 price');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
const price = process.argv[5];
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
const price = process.argv[5];
|
||||
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
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 bid(ccp,wallet,user,orgMSP,auctionID,price);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
const orgMSP = 'Org1MSP';
|
||||
const ccp = buildCCPOrg1();
|
||||
const walletPath = path.join(__dirname, 'wallet/org1');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await bid(ccp,wallet,user,orgMSP,auctionID,price);
|
||||
}
|
||||
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 bid(ccp,wallet,user,orgMSP,auctionID,price);
|
||||
} else {
|
||||
console.log("Usage: node bid.js org userID auctionID price");
|
||||
console.log("Org must be Org1 or Org2");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to run the application: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const orgMSP = 'Org2MSP';
|
||||
const ccp = buildCCPOrg2();
|
||||
const walletPath = path.join(__dirname, 'wallet/org2');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await bid(ccp,wallet,user,orgMSP,auctionID,price);
|
||||
} else {
|
||||
console.log('Usage: node bid.js org userID auctionID price');
|
||||
console.log('Org must be Org1 or Org2');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to run the application: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -14,83 +14,83 @@ const myChannel = 'mychannel';
|
|||
const myChaincodeName = 'auction';
|
||||
|
||||
async function closeAuction(ccp,wallet,user,auctionID) {
|
||||
try {
|
||||
try {
|
||||
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
|
||||
// Query the auction to get the list of endorsing orgs.
|
||||
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
var auctionJSON = JSON.parse(auctionString);
|
||||
// Query the auction to get the list of endorsing orgs.
|
||||
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
let auctionJSON = JSON.parse(auctionString);
|
||||
|
||||
let statefulTxn = contract.createTransaction('CloseAuction');
|
||||
let statefulTxn = contract.createTransaction('CloseAuction');
|
||||
|
||||
if (auctionJSON.organizations.length == 2) {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0],auctionJSON.organizations[1]);
|
||||
} else {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0]);
|
||||
}
|
||||
if (auctionJSON.organizations.length == 2) {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0],auctionJSON.organizations[1]);
|
||||
} else {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0]);
|
||||
}
|
||||
|
||||
console.log('\n--> Submit Transaction: close auction');
|
||||
await statefulTxn.submit(auctionID);
|
||||
console.log('*** Result: committed');
|
||||
console.log('\n--> Submit Transaction: close auction');
|
||||
await statefulTxn.submit(auctionID);
|
||||
console.log('*** Result: committed');
|
||||
|
||||
console.log('\n--> Evaluate Transaction: query the updated auction');
|
||||
let result = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
console.log('*** Result: Auction: ' + prettyJSONString(result.toString()));
|
||||
console.log('\n--> Evaluate Transaction: query the updated 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}`);
|
||||
process.exit(1);
|
||||
gateway.disconnect();
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to submit bid: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
try {
|
||||
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined
|
||||
|| process.argv[4] == undefined) {
|
||||
console.log("Usage: node closeAuction.js org userID auctionID");
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined ||
|
||||
process.argv[4] == undefined) {
|
||||
console.log('Usage: node closeAuction.js org userID auctionID');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
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 closeAuction(ccp,wallet,user,auctionID);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
const orgMSP = 'Org1MSP';
|
||||
const ccp = buildCCPOrg1();
|
||||
const walletPath = path.join(__dirname, 'wallet/org1');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await closeAuction(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 closeAuction(ccp,wallet,user,auctionID);
|
||||
} else {
|
||||
console.log("Usage: node closeAuction.js org userID auctionID ");
|
||||
console.log("Org must be Org1 or Org2");
|
||||
}
|
||||
} catch (error) {
|
||||
const orgMSP = 'Org2MSP';
|
||||
const ccp = buildCCPOrg2();
|
||||
const walletPath = path.join(__dirname, 'wallet/org2');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await closeAuction(ccp,wallet,user,auctionID);
|
||||
} else {
|
||||
console.log('Usage: node closeAuction.js org userID auctionID ');
|
||||
console.log('Org must be Org1 or Org2');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to run the application: ${error}`);
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,69 +14,69 @@ const myChannel = 'mychannel';
|
|||
const myChaincodeName = 'auction';
|
||||
|
||||
async function createAuction(ccp,wallet,user,auctionID,item) {
|
||||
try {
|
||||
try {
|
||||
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
|
||||
let statefulTxn = contract.createTransaction('CreateAuction');
|
||||
let statefulTxn = contract.createTransaction('CreateAuction');
|
||||
|
||||
console.log('\n--> Submit Transaction: Propose a new auction');
|
||||
await statefulTxn.submit(auctionID,item);
|
||||
console.log('*** Result: committed');
|
||||
console.log('\n--> Submit Transaction: Propose a new auction');
|
||||
await statefulTxn.submit(auctionID,item);
|
||||
console.log('*** Result: committed');
|
||||
|
||||
console.log('\n--> Evaluate Transaction: query the auction that was just created');
|
||||
let result = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
console.log('*** Result: Auction: ' + prettyJSONString(result.toString()));
|
||||
console.log('\n--> Evaluate Transaction: query the auction that was just created');
|
||||
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}`);
|
||||
gateway.disconnect();
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to submit bid: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
try {
|
||||
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined
|
||||
|| process.argv[4] == undefined || process.argv[5] == undefined) {
|
||||
console.log("Usage: node createAuction.js org userID auctionID item");
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined ||
|
||||
process.argv[4] == undefined || process.argv[5] == undefined) {
|
||||
console.log('Usage: node createAuction.js org userID auctionID item');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
const item = process.argv[5];
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
const item = process.argv[5];
|
||||
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
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 createAuction(ccp,wallet,user,auctionID,item);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
const orgMSP = 'Org1MSP';
|
||||
const ccp = buildCCPOrg1();
|
||||
const walletPath = path.join(__dirname, 'wallet/org1');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await createAuction(ccp,wallet,user,auctionID,item);
|
||||
}
|
||||
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 createAuction(ccp,wallet,user,auctionID,item);
|
||||
} else {
|
||||
console.log("Usage: node createAuction.js org userID auctionID item");
|
||||
console.log("Org must be Org1 or Org2");
|
||||
}
|
||||
} catch (error) {
|
||||
const orgMSP = 'Org2MSP';
|
||||
const ccp = buildCCPOrg2();
|
||||
const walletPath = path.join(__dirname, 'wallet/org2');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await createAuction(ccp,wallet,user,auctionID,item);
|
||||
} else {
|
||||
console.log('Usage: node createAuction.js org userID auctionID item');
|
||||
console.log('Org must be Org1 or Org2');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to run the application: ${error}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,83 +14,83 @@ const myChannel = 'mychannel';
|
|||
const myChaincodeName = 'auction';
|
||||
|
||||
async function endAuction(ccp,wallet,user,auctionID) {
|
||||
try {
|
||||
try {
|
||||
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
|
||||
// Query the auction to get the list of endorsing orgs.
|
||||
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
var auctionJSON = JSON.parse(auctionString);
|
||||
// Query the auction to get the list of endorsing orgs.
|
||||
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
let auctionJSON = JSON.parse(auctionString);
|
||||
|
||||
let statefulTxn = contract.createTransaction('EndAuction');
|
||||
let statefulTxn = contract.createTransaction('EndAuction');
|
||||
|
||||
if (auctionJSON.organizations.length == 2) {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0],auctionJSON.organizations[1]);
|
||||
} else {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0]);
|
||||
}
|
||||
if (auctionJSON.organizations.length == 2) {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0],auctionJSON.organizations[1]);
|
||||
} else {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0]);
|
||||
}
|
||||
|
||||
console.log('\n--> Submit the transaction to end the auction');
|
||||
await statefulTxn.submit(auctionID);
|
||||
console.log('*** Result: committed');
|
||||
console.log('\n--> Submit the transaction to end the auction');
|
||||
await statefulTxn.submit(auctionID);
|
||||
console.log('*** Result: committed');
|
||||
|
||||
console.log('\n--> Evaluate Transaction: query the updated auction');
|
||||
let result = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
console.log('*** Result: Auction: ' + prettyJSONString(result.toString()));
|
||||
console.log('\n--> Evaluate Transaction: query the updated 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}`);
|
||||
process.exit(1);
|
||||
gateway.disconnect();
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to submit bid: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
try {
|
||||
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined
|
||||
|| process.argv[4] == undefined) {
|
||||
console.log("Usage: node endAuction.js org userID auctionID");
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined ||
|
||||
process.argv[4] == undefined) {
|
||||
console.log('Usage: node endAuction.js org userID auctionID');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
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 endAuction(ccp,wallet,user,auctionID);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
const orgMSP = 'Org1MSP';
|
||||
const ccp = buildCCPOrg1();
|
||||
const walletPath = path.join(__dirname, 'wallet/org1');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await endAuction(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 endAuction(ccp,wallet,user,auctionID);
|
||||
} else {
|
||||
console.log("Usage: node endAuction.js org userID auctionID");
|
||||
console.log("Org must be Org1 or Org2");
|
||||
}
|
||||
} catch (error) {
|
||||
const orgMSP = 'Org2MSP';
|
||||
const ccp = buildCCPOrg2();
|
||||
const walletPath = path.join(__dirname, 'wallet/org2');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await endAuction(ccp,wallet,user,auctionID);
|
||||
} else {
|
||||
console.log('Usage: node endAuction.js org userID auctionID');
|
||||
console.log('Org must be Org1 or Org2');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to run the application: ${error}`);
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,52 +16,52 @@ const mspOrg1 = 'Org1MSP';
|
|||
const mspOrg2 = 'Org2MSP';
|
||||
|
||||
async function connectToOrg1CA() {
|
||||
console.log('\n--> Enrolling the Org1 CA admin');
|
||||
const ccpOrg1 = buildCCPOrg1();
|
||||
const caOrg1Client = buildCAClient(FabricCAServices, ccpOrg1, 'ca.org1.example.com');
|
||||
console.log('\n--> Enrolling the Org1 CA admin');
|
||||
const ccpOrg1 = buildCCPOrg1();
|
||||
const caOrg1Client = buildCAClient(FabricCAServices, ccpOrg1, 'ca.org1.example.com');
|
||||
|
||||
const walletPathOrg1 = path.join(__dirname, 'wallet/org1');
|
||||
const walletOrg1 = await buildWallet(Wallets, walletPathOrg1);
|
||||
const walletPathOrg1 = path.join(__dirname, 'wallet/org1');
|
||||
const walletOrg1 = await buildWallet(Wallets, walletPathOrg1);
|
||||
|
||||
await enrollAdmin(caOrg1Client, walletOrg1, mspOrg1);
|
||||
await enrollAdmin(caOrg1Client, walletOrg1, mspOrg1);
|
||||
|
||||
}
|
||||
|
||||
async function connectToOrg2CA() {
|
||||
console.log('\n--> Enrolling the Org2 CA admin');
|
||||
const ccpOrg2 = buildCCPOrg2();
|
||||
const caOrg2Client = buildCAClient(FabricCAServices, ccpOrg2, 'ca.org2.example.com');
|
||||
console.log('\n--> Enrolling the Org2 CA admin');
|
||||
const ccpOrg2 = buildCCPOrg2();
|
||||
const caOrg2Client = buildCAClient(FabricCAServices, ccpOrg2, 'ca.org2.example.com');
|
||||
|
||||
const walletPathOrg2 = path.join(__dirname, 'wallet/org2');
|
||||
const walletOrg2 = await buildWallet(Wallets, walletPathOrg2);
|
||||
const walletPathOrg2 = path.join(__dirname, 'wallet/org2');
|
||||
const walletOrg2 = await buildWallet(Wallets, walletPathOrg2);
|
||||
|
||||
await enrollAdmin(caOrg2Client, walletOrg2, mspOrg2);
|
||||
await enrollAdmin(caOrg2Client, walletOrg2, mspOrg2);
|
||||
|
||||
}
|
||||
async function main() {
|
||||
|
||||
if (process.argv[2] == undefined) {
|
||||
console.log("Usage: node enrollAdmin.js Org");
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.argv[2] == undefined) {
|
||||
console.log('Usage: node enrollAdmin.js Org');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const org = process.argv[2];
|
||||
const org = process.argv[2];
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
await connectToOrg1CA();
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
await connectToOrg2CA();
|
||||
} else {
|
||||
console.log("Usage: node registerUser.js org userID");
|
||||
console.log("Org must be Org1 or Org2");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in enrolling admin: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
await connectToOrg1CA();
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
await connectToOrg2CA();
|
||||
} else {
|
||||
console.log('Usage: node registerUser.js org userID');
|
||||
console.log('Org must be Org1 or Org2');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in enrolling admin: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -14,62 +14,62 @@ const myChannel = 'mychannel';
|
|||
const myChaincodeName = 'auction';
|
||||
|
||||
async function queryAuction(ccp,wallet,user,auctionID) {
|
||||
try {
|
||||
try {
|
||||
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
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()));
|
||||
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}`);
|
||||
gateway.disconnect();
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to submit bid: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
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];
|
||||
const org = process.argv[2];
|
||||
const user = process.argv[3];
|
||||
const auctionID = process.argv[4];
|
||||
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
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 = '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) {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,63 +14,63 @@ const myChannel = 'mychannel';
|
|||
const myChaincodeName = 'auction';
|
||||
|
||||
async function queryBid(ccp,wallet,user,auctionID,bidID) {
|
||||
try {
|
||||
try {
|
||||
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
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()));
|
||||
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}`);
|
||||
gateway.disconnect();
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to submit bid: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
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];
|
||||
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') {
|
||||
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 queryBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
const orgMSP = 'Org1MSP';
|
||||
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 orgMSP = 'Org2MSP';
|
||||
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}`);
|
||||
}
|
||||
const orgMSP = 'Org2MSP';
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,53 +16,53 @@ const mspOrg1 = 'Org1MSP';
|
|||
const mspOrg2 = 'Org2MSP';
|
||||
|
||||
async function connectToOrg1CA(UserID) {
|
||||
console.log('\n--> Register and enrolling new user');
|
||||
const ccpOrg1 = buildCCPOrg1();
|
||||
const caOrg1Client = buildCAClient(FabricCAServices, ccpOrg1, 'ca.org1.example.com');
|
||||
console.log('\n--> Register and enrolling new user');
|
||||
const ccpOrg1 = buildCCPOrg1();
|
||||
const caOrg1Client = buildCAClient(FabricCAServices, ccpOrg1, 'ca.org1.example.com');
|
||||
|
||||
const walletPathOrg1 = path.join(__dirname, 'wallet/org1');
|
||||
const walletOrg1 = await buildWallet(Wallets, walletPathOrg1);
|
||||
const walletPathOrg1 = path.join(__dirname, 'wallet/org1');
|
||||
const walletOrg1 = await buildWallet(Wallets, walletPathOrg1);
|
||||
|
||||
await registerAndEnrollUser(caOrg1Client, walletOrg1, mspOrg1, UserID, 'org1.department1');
|
||||
await registerAndEnrollUser(caOrg1Client, walletOrg1, mspOrg1, UserID, 'org1.department1');
|
||||
|
||||
}
|
||||
|
||||
async function connectToOrg2CA(UserID) {
|
||||
console.log('\n--> Register and enrolling new user');
|
||||
const ccpOrg2 = buildCCPOrg2();
|
||||
const caOrg2Client = buildCAClient(FabricCAServices, ccpOrg2, 'ca.org2.example.com');
|
||||
console.log('\n--> Register and enrolling new user');
|
||||
const ccpOrg2 = buildCCPOrg2();
|
||||
const caOrg2Client = buildCAClient(FabricCAServices, ccpOrg2, 'ca.org2.example.com');
|
||||
|
||||
const walletPathOrg2 = path.join(__dirname, 'wallet/org2');
|
||||
const walletOrg2 = await buildWallet(Wallets, walletPathOrg2);
|
||||
const walletPathOrg2 = path.join(__dirname, 'wallet/org2');
|
||||
const walletOrg2 = await buildWallet(Wallets, walletPathOrg2);
|
||||
|
||||
await registerAndEnrollUser(caOrg2Client, walletOrg2, mspOrg2, UserID, 'org2.department1');
|
||||
await registerAndEnrollUser(caOrg2Client, walletOrg2, mspOrg2, UserID, 'org2.department1');
|
||||
|
||||
}
|
||||
async function main() {
|
||||
|
||||
if (process.argv[2] == undefined && process.argv[3] == undefined) {
|
||||
console.log("Usage: node registerEnrollUser.js org userID");
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.argv[2] == undefined && process.argv[3] == undefined) {
|
||||
console.log('Usage: node registerEnrollUser.js org userID');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const org = process.argv[2];
|
||||
const userId = process.argv[3];
|
||||
const org = process.argv[2];
|
||||
const userId = process.argv[3];
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
await connectToOrg1CA(userId);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
await connectToOrg2CA(userId);
|
||||
} else {
|
||||
console.log("Usage: node registerEnrollUser.js org userID");
|
||||
console.log("Org must be Org1 or Org2");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in enrolling admin: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (org == 'Org1' || org == 'org1') {
|
||||
await connectToOrg1CA(userId);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
await connectToOrg2CA(userId);
|
||||
} else {
|
||||
console.log('Usage: node registerEnrollUser.js org userID');
|
||||
console.log('Org must be Org1 or Org2');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error in enrolling admin: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -14,95 +14,95 @@ const myChannel = 'mychannel';
|
|||
const myChaincodeName = 'auction';
|
||||
|
||||
async function addBid(ccp,wallet,user,auctionID,bidID) {
|
||||
try {
|
||||
try {
|
||||
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
|
||||
console.log('\n--> Evaluate Transaction: read your bid');
|
||||
let bidString = await contract.evaluateTransaction('QueryBid',auctionID,bidID);
|
||||
var bidJSON = JSON.parse(bidString);
|
||||
console.log('\n--> Evaluate Transaction: read your bid');
|
||||
let bidString = await contract.evaluateTransaction('QueryBid',auctionID,bidID);
|
||||
let bidJSON = JSON.parse(bidString);
|
||||
|
||||
//console.log('\n--> Evaluate Transaction: query the auction you want to join');
|
||||
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
// console.log('*** Result: Bid: ' + prettyJSONString(auctionString.toString()));
|
||||
var auctionJSON = JSON.parse(auctionString);
|
||||
//console.log('\n--> Evaluate Transaction: query the auction you want to join');
|
||||
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
// console.log('*** Result: Bid: ' + prettyJSONString(auctionString.toString()));
|
||||
let auctionJSON = JSON.parse(auctionString);
|
||||
|
||||
let bidData = { objectType: 'bid', price: parseInt(bidJSON.price), org: bidJSON.org, bidder: bidJSON.bidder};
|
||||
console.log('*** Result: Bid: ' + JSON.stringify(bidData,null,2));
|
||||
let bidData = { objectType: 'bid', price: parseInt(bidJSON.price), org: bidJSON.org, bidder: bidJSON.bidder};
|
||||
console.log('*** Result: Bid: ' + JSON.stringify(bidData,null,2));
|
||||
|
||||
let statefulTxn = contract.createTransaction('RevealBid');
|
||||
let tmapData = Buffer.from(JSON.stringify(bidData));
|
||||
statefulTxn.setTransient({
|
||||
bid: tmapData
|
||||
});
|
||||
let statefulTxn = contract.createTransaction('RevealBid');
|
||||
let tmapData = Buffer.from(JSON.stringify(bidData));
|
||||
statefulTxn.setTransient({
|
||||
bid: tmapData
|
||||
});
|
||||
|
||||
if (auctionJSON.organizations.length == 2) {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0],auctionJSON.organizations[1]);
|
||||
} else {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0]);
|
||||
}
|
||||
if (auctionJSON.organizations.length == 2) {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0],auctionJSON.organizations[1]);
|
||||
} else {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0]);
|
||||
}
|
||||
|
||||
await statefulTxn.submit(auctionID,bidID);
|
||||
await statefulTxn.submit(auctionID,bidID);
|
||||
|
||||
console.log('\n--> Evaluate Transaction: query the auction to see that our bid was added');
|
||||
let result = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
console.log('*** Result: Auction: ' + prettyJSONString(result.toString()));
|
||||
console.log('\n--> Evaluate Transaction: query the auction to see that our bid was added');
|
||||
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}`);
|
||||
gateway.disconnect();
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to submit bid: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
try {
|
||||
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined
|
||||
|| process.argv[4] == undefined || process.argv[5] == undefined) {
|
||||
console.log("Usage: node revealBid.js org userID auctionID bidID");
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined ||
|
||||
process.argv[4] == undefined || process.argv[5] == undefined) {
|
||||
console.log('Usage: node revealBid.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];
|
||||
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') {
|
||||
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 addBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
const orgMSP = 'Org1MSP';
|
||||
const ccp = buildCCPOrg1();
|
||||
const walletPath = path.join(__dirname, 'wallet/org1');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await addBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
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 addBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
else {
|
||||
console.log("Usage: node revealBid.js org userID auctionID bidID");
|
||||
console.log("Org must be Org1 or Org2");
|
||||
}
|
||||
} catch (error) {
|
||||
const orgMSP = 'Org2MSP';
|
||||
const ccp = buildCCPOrg2();
|
||||
const walletPath = path.join(__dirname, 'wallet/org2');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await addBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
else {
|
||||
console.log('Usage: node revealBid.js org userID auctionID bidID');
|
||||
console.log('Org must be Org1 or Org2');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to run the application: ${error}`);
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,93 +15,93 @@ const myChaincodeName = 'auction';
|
|||
|
||||
|
||||
function prettyJSONString(inputString) {
|
||||
if (inputString) {
|
||||
return JSON.stringify(JSON.parse(inputString), null, 2);
|
||||
}
|
||||
else {
|
||||
return inputString;
|
||||
}
|
||||
if (inputString) {
|
||||
return JSON.stringify(JSON.parse(inputString), null, 2);
|
||||
}
|
||||
else {
|
||||
return inputString;
|
||||
}
|
||||
}
|
||||
|
||||
async function submitBid(ccp,wallet,user,auctionID,bidID) {
|
||||
try {
|
||||
try {
|
||||
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
const gateway = new Gateway();
|
||||
//connect using Discovery enabled
|
||||
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
await gateway.connect(ccp,
|
||||
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });
|
||||
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
const network = await gateway.getNetwork(myChannel);
|
||||
const contract = network.getContract(myChaincodeName);
|
||||
|
||||
console.log('\n--> Evaluate Transaction: query the auction you want to join');
|
||||
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
var auctionJSON = JSON.parse(auctionString);
|
||||
console.log('\n--> Evaluate Transaction: query the auction you want to join');
|
||||
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
let auctionJSON = JSON.parse(auctionString);
|
||||
|
||||
let statefulTxn = contract.createTransaction('SubmitBid');
|
||||
let statefulTxn = contract.createTransaction('SubmitBid');
|
||||
|
||||
if (auctionJSON.organizations.length == 2) {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0],auctionJSON.organizations[1]);
|
||||
} else {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0]);
|
||||
}
|
||||
if (auctionJSON.organizations.length == 2) {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0],auctionJSON.organizations[1]);
|
||||
} else {
|
||||
statefulTxn.setEndorsingOrganizations(auctionJSON.organizations[0]);
|
||||
}
|
||||
|
||||
console.log('\n--> Submit Transaction: add bid to the auction');
|
||||
await statefulTxn.submit(auctionID,bidID);
|
||||
console.log('\n--> Submit Transaction: add bid to the auction');
|
||||
await statefulTxn.submit(auctionID,bidID);
|
||||
|
||||
console.log('\n--> Evaluate Transaction: query the auction to see that our bid was added');
|
||||
let result = await contract.evaluateTransaction('QueryAuction',auctionID);
|
||||
console.log('*** Result: Auction: ' + prettyJSONString(result.toString()));
|
||||
console.log('\n--> Evaluate Transaction: query the auction to see that our bid was added');
|
||||
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}`);
|
||||
gateway.disconnect();
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to submit bid: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
try {
|
||||
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined
|
||||
|| process.argv[4] == undefined || process.argv[5] == undefined) {
|
||||
console.log("Usage: node submitBid.js org userID auctionID bidID");
|
||||
process.exit(1);
|
||||
}
|
||||
if (process.argv[2] == undefined || process.argv[3] == undefined ||
|
||||
process.argv[4] == undefined || process.argv[5] == undefined) {
|
||||
console.log('Usage: node submitBid.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];
|
||||
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') {
|
||||
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 submitBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
else if (org == 'Org2' || org == 'org2') {
|
||||
const orgMSP = 'Org1MSP';
|
||||
const ccp = buildCCPOrg1();
|
||||
const walletPath = path.join(__dirname, 'wallet/org1');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await submitBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
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 submitBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
else {
|
||||
console.log("Usage: node submitBid.js org userID auctionID bidID");
|
||||
console.log("Org must be Org1 or Org2");
|
||||
}
|
||||
} catch (error) {
|
||||
const orgMSP = 'Org2MSP';
|
||||
const ccp = buildCCPOrg2();
|
||||
const walletPath = path.join(__dirname, 'wallet/org2');
|
||||
const wallet = await buildWallet(Wallets, walletPath);
|
||||
await submitBid(ccp,wallet,user,auctionID,bidID);
|
||||
}
|
||||
else {
|
||||
console.log('Usage: node submitBid.js org userID auctionID bidID');
|
||||
console.log('Org must be Org1 or Org2');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to run the application: ${error}`);
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
if (error.stack) {
|
||||
console.error(error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue