From 8baa53e0909b6cee7763c54572671b53897dcfe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Mart=C3=ADn=20Garc=C3=ADa=20Del=20Angel?= Date: Wed, 1 Nov 2017 16:45:12 -0600 Subject: [PATCH] Release Candidate 2 This version adds the following changes : + Added ORA Spinners for long processes (adds information about which part of the process is in as well) + Finished implementing the schedule validator + Fixed some menu bugs and usability issues + Fixed some grammar + Finished the CLI and Command Line --- blockchainManager.js | 105 ++++++++++++++++---- composer-logs/trace_20171102-162000-963.log | 4 + dist/lyra-cli.bna | Bin 9752 -> 9752 bytes index.js | 102 +++++++++++++++---- mongoManager.js | 2 +- 5 files changed, 176 insertions(+), 37 deletions(-) create mode 100644 composer-logs/trace_20171102-162000-963.log diff --git a/blockchainManager.js b/blockchainManager.js index 7a47234..c919f68 100644 --- a/blockchainManager.js +++ b/blockchainManager.js @@ -18,7 +18,7 @@ var chalk = require('chalk'); var figlet = require('figlet'); var md5 = require('md5') var now = require('performance-now'); - +const ora = require('ora'); // ------- Basic Libraries for this package ------- const mongo = require('./mongoManager'); @@ -47,7 +47,6 @@ class BlockchainManager { init() { return this.businessNetworkConnection.connect(this.connectionProfile, this.businessNetworkIdentifier, participantId, participantPwd) .then((result) => { - console.log(chalk.green('Connected to Hyperledger!')); this.businessNetworkDefinition = result; }) .catch(function (error) { @@ -413,7 +412,7 @@ class BlockchainManager { console.log(assets); }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + console.log('An error occured: ', error); process.exit(1); }); } @@ -426,6 +425,7 @@ class BlockchainManager { static registeredParticipants() { let bm = new BlockchainManager(); + return bm.init() .then(() => { return bm.checkRegisteredParticipants(); @@ -434,7 +434,7 @@ class BlockchainManager { console.log(participants); }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + console.log('An error occured: ', error); process.exit(1); }); } @@ -450,16 +450,25 @@ class BlockchainManager { */ static initializeLedger(clientSeed, walletSeed, bottom, top) { + /**Start the spinner */ + const spinner = new ora({ + text: 'Connecting to Hyperledger...', + spinner: process.argv[2], + color: 'blue' + }); let bm = new BlockchainManager(); + spinner.start(); return bm.init() .then(() => { + spinner.text = 'Creating wallets and accounts...'; + spinner.color = 'magenta'; return bm.initializatorDaemon(clientSeed, walletSeed, bottom, top); }) .then(() => { - console.log('Accounts created successfully!'); + spinner.succeed('Accounts created successfully!'); }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + spinner.fail('An error occured: ', error); process.exit(1); }); } @@ -480,7 +489,7 @@ class BlockchainManager { console.log(assets); }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + console.log('An error occured: ', error); process.exit(1); }); } @@ -501,7 +510,7 @@ class BlockchainManager { console.log(participants); }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + console.log('An error occured: ', error); process.exit(1); }); } @@ -516,16 +525,25 @@ class BlockchainManager { */ static transfer(fromID, toID, funds) { + /**Start the spinner */ + const spinner = new ora({ + text: 'Connecting to Hyperledger...', + spinner: process.argv[2], + color: 'blue' + }); let bm = new BlockchainManager(); + spinner.start(); return bm.init() .then(() => { + spinner.text = 'Making transaction...'; + spinner.color = 'magenta'; return bm.makeTransaction(fromID, toID, funds); }) .then(() => { - console.log('Success!'); + spinner.succeed('Transaction made successfully!'); }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + spinner.fail('An error occured: ', error); process.exit(1); }); } @@ -541,13 +559,23 @@ class BlockchainManager { */ static batchAccount(amount, bottom, top) { + /**Start the spinner */ + const spinner = new ora({ + text: 'Connecting to Hyperledger...', + spinner: process.argv[2], + color: 'blue' + }); let bm = new BlockchainManager(); //**Set up the time start */ let timeStart; let timeEnd; //**Set up the time end */ + spinner.start(); return bm.init() .then(() => { + spinner.text = 'Creating accounts...'; + spinner.color = 'magenta'; + /**Spinner business */ let all_promise = []; for (let i = 0; i < amount; i++) { all_promise.push(bm.initializatorDaemon(i, (i + amount), bottom, top)); @@ -558,10 +586,10 @@ class BlockchainManager { .then((arr) => { timeEnd = now().toFixed(0); bm.profilingTime(timeStart, timeEnd, amount, 'acc'); - console.log('Accounts created successfully!'); + spinner.succeed('Accounts created successfully!'); }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + spinner.fail('An error occured:', error); process.exit(1); }) } @@ -574,16 +602,28 @@ class BlockchainManager { */ static getTransactionSchedule(simTrax) { + /**Start the spinner */ + const spinner = new ora({ + text: 'Connecting to Hyperledger...', + spinner: process.argv[2], + color: 'blue' + }); + /**Get the Blockchain Manager */ let bm = new BlockchainManager(); + /**Start the Spinner */ + spinner.start(); return bm.init() .then(() => { + spinner.text = 'Getting the schedule...'; + spinner.color = 'green'; return bm.transactionSchedule(simTrax); }) .then((result) => { + spinner.succeed('Schedule created successfully!'); return result; }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + spinner.fail('An error occured: ', error); process.exit(1); }); } @@ -595,17 +635,28 @@ class BlockchainManager { */ static transactionCannon(simTrax) { + /**Start the spinner */ + const spinner = new ora({ + text: 'Connecting to Hyperledger...', + spinner: process.argv[2], + color: 'blue' + }); let bm = new BlockchainManager(); //**Set up the time start */ let timeStart; let timeEnd; let schedule; //**Set up the time end */ + spinner.start(); return bm.init() .then(() => { + spinner.text = 'Getting the cannon balls...'; + spinner.color = 'magenta'; return bm.transactionSchedule(simTrax); }) .then((result) => { + spinner.text = 'Breaking into the chain...'; + spinner.color = 'green'; let cannonBalls = []; schedule = result; for (let i = 0; i < result.length; i++) { @@ -617,13 +668,14 @@ class BlockchainManager { .then(() => { timeEnd = now().toFixed(0); bm.profilingTime(timeStart, timeEnd, simTrax, 'tx'); - console.log('Transaction Cannon Finished'); + console.log('\n'); + spinner.succeed('Transaction Cannon Finished!'); }) .then(() => { return schedule; }) .catch(function (error) { - console.log('An error occured: ', chalk.bold.red(error)); + spinner.fail('An error occured: ', error); process.exit(1); }); } @@ -636,11 +688,20 @@ class BlockchainManager { */ static isLedgerStateCorrect(schedule) { + /**Start the spinner */ + const spinner = new ora({ + text: 'Connecting to Hyperledger...', + spinner: process.argv[2], + color: 'blue' + }); let bm = new BlockchainManager(); let modState; /** Get the state of the database */ + spinner.start(); return mongo.getAllAst() .then((result) => { + spinner.text = 'Replicating transactions on memory...'; + spinner.color = 'magenta'; modState = result; for (let i = 0; i < schedule.length; i++) { for (let x = 0; x < modState.length; x++) { @@ -655,9 +716,13 @@ class BlockchainManager { return bm.init(); }) .then(() => { + spinner.text = 'Retrieving assets from Hyperledger...'; + spinner.color = 'yellow'; return bm.rawAssetsOnLedger(); }) .then((rawLedger) => { + spinner.text = 'Comparing in memory results with the ledger...'; + spinner.color = 'magenta'; let state = true; let unsynced = []; for (let i = 0; i < rawLedger.length; i++) { @@ -668,17 +733,21 @@ class BlockchainManager { } } } - if(!state){ + if (!state) { + spinner.fail('Ledger is not synced'); + console.log('\n'); console.log('=============== UNSYNCED ==============='); - for(let i=0;i"}$ +2017-11-01T22:20:02.475Z ERROR HLFConnection :ping() {"message":"Error trying to ping. Error: Error trying to query business network. Error: chaincode error (status: 500, message: Error: The current identity must be activated (ACTIVATION_REQUIRED))","stack":"Error: Error trying to ping. Error: Error trying to query business network. Error: chaincode error (status: 500, message: Error: The current identity must be activated (ACTIVATION_REQUIRED))\n at _checkRuntimeVersions.then.catch (/usr/local/lib/node_modules/composer-cli/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:663:34)\n at "}$ diff --git a/dist/lyra-cli.bna b/dist/lyra-cli.bna index 9d14c9051b1ef813e80dc784e0fd42f744bd7439..1e710c97626b6e752349ddfbad4172a540567615 100644 GIT binary patch delta 116 zcmbQ?GsA}`z?+$civa}kH*MtUWns$Sw0Sm*vlxheAl1zbq$lUfDTBC^ad#;w qfVg)Q7J+3OR4l-vDyAUnqlz_%(o;1CQOTI4ACxGmuT diff --git a/index.js b/index.js index 7bc841b..187fd34 100755 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ var chalk = require('chalk'); var clear = require('clear'); var figlet = require('figlet'); var inquirer = require('inquirer'); +var Table = require('cli-table'); //Hyperledger Fabric Code And Connectors var hyper = require('./blockchainManager'); @@ -178,7 +179,17 @@ switch (yargs._[0]) { console.log(chalk.bold.cyan('Lyra CLI App'), chalk.bold.green('Made by Aabo Technologies © 2017')); hyper.getTransactionSchedule(yargs.transactions) .then((result) => { - console.log(result); + let table = new Table({ + head: ['From', 'To', 'Funds'] + }); + for (const key of Object.keys(result)) { + let tableLine = []; + tableLine.push(result[key].from); + tableLine.push(result[key].to); + tableLine.push(result[key].funds); + table.push(tableLine); + } + console.log(table.toString()); process.exit(0); }) .catch(function (error) { @@ -194,11 +205,6 @@ switch (yargs._[0]) { return hyper.isLedgerStateCorrect(result); }) .then((result) => { - if (result) { - console.log(chalk.bold.green('The ledger is indeed synced')); - } else { - console.log(chalk.bold.red('The ledger is not synced')); - } process.exit(0); }) .catch(function (error) { @@ -214,11 +220,6 @@ switch (yargs._[0]) { return hyper.isLedgerStateCorrect(schedule); }) .then((result) => { - if (result) { - console.log(chalk.green('Success!')); - } else { - console.log(chalk.red('Not Success')); - } process.exit(0); }) .catch(function (error) { @@ -327,10 +328,10 @@ function debugMenu() { "Shows the project's authors", "Lists all registered assets in the Blockchain", "Lists all registered participants on the Blockchain", - "Initializes the Participants and Wallets on the network", + "Create a schedule for the transactions", "Lists all current wallets on the Ledger", "Lists all current participants on the Ledger", - "Makes a single transaction over the network", + "Make a single transaction over the network", new inquirer.Separator(), "Go back to the main menu" ] @@ -338,6 +339,9 @@ function debugMenu() { inquirer.prompt(questions).then(function (answers) { switch (answers.initial) { + case "Create a schedule for the transactions": + makeSchedule(); + break; case "Shows the project's authors": author(); console.log('\n'); @@ -363,9 +367,6 @@ function debugMenu() { process.exit(1); }); break; - case "Initializes the Participants and Wallets on the network": - batchCreation('debug'); - break; case "Lists all current wallets on the Ledger": hyper.assetsOnLedger() .then(() => { @@ -386,6 +387,32 @@ function debugMenu() { process.exit(1); }); break; + case "Make a single transaction over the network": + var questions = [{ + type: "input", + name: "from", + message: "Input the wallet address to send balance from" + },{ + type: "input", + name: 'to', + message: "Input the wallet address to receive balance" + },{ + type: 'input', + name: 'money', + message: 'Input the amount of money to send' + }]; + + inquirer.prompt(questions).then(function (answers) { + hyper.transfer(answers.from,answers.to,answers.money) + .then(()=>{ + debugMenu(); + }) + .catch(function(error){ + console.log('An error occured: ', chalk.bold.red(error)); + process.exit(1); + }); + }); + break; case "Go back to the main menu": clear(); mainMenu(); @@ -439,6 +466,42 @@ function testingMenu() { } }); } +/** + * @description Makes a Sample schedule for testing purposes + * @returns {Table} table including the transactions made by the schedule + */ + +function makeSchedule() { + var questions = [{ + type: 'input', + name: 'transactions', + message: 'Amount of transactions to create the sample schedule', + default: 1, + }]; + inquirer.prompt(questions).then(function (answers) { + hyper.getTransactionSchedule(answers.transactions) + .then((result) => { + let table = new Table({ + head: ['From', 'To', 'Funds'] + }); + for (const key of Object.keys(result)) { + let tableLine = []; + tableLine.push(result[key].from); + tableLine.push(result[key].to); + tableLine.push(result[key].funds); + table.push(tableLine); + } + console.log(table.toString()); + }) + .then(() => { + debugMenu(); + }) + .catch(function (error) { + console.log('An error occured: ', chalk.bold.red(error)); + process.exit(1); + }); + }); +} /**@description Starts the Transaction Cannon execution * @returns {Nothing} @@ -453,8 +516,11 @@ function startTheCannon() { }]; inquirer.prompt(questions).then(function (answers) { hyper.transactionCannon(answers.transactions) + .then((schedule) => { + return hyper.isLedgerStateCorrect(schedule); + }) .then(() => { - testingMenu(); + debugMenu(); }) .catch(function (error) { console.log('An error occured: ', chalk.bold.red(error)); @@ -528,7 +594,7 @@ function makeTransaction() { inquirer.prompt(questions).then(function (answers) { hyper.transfer(answers.from, answers.to, answers.funds) .then(() => { - mainMenu(); + debugMenu(); }) .catch(function (error) { console.log('An error occured: ', chalk.bold.red(error)); diff --git a/mongoManager.js b/mongoManager.js index a5f72a3..64dab87 100644 --- a/mongoManager.js +++ b/mongoManager.js @@ -310,7 +310,7 @@ class MongoManager { /**@description Executes the All Asset's id command * @returns {Promise} whose fullfilment means either all assets were retrieved or none existed - * @deprecated Should be taken out by release 1.0 + * @deprecated Should be taken out by release 1.2 if not used */ static getAllAstID() {