From 1a698ccb852e38d784c140fc78fc38334be34a0e 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 12:30:29 -0600 Subject: [PATCH] Finished functions isLedgerSynced Moving into bug fixes, ora spinners and first stable release --- ...ockchainManager.js => blockchainManager.js | 24 ++++++++++++------- composer-logs/trace_20171102-122014-555.log | 4 ++++ composer-logs/trace_20171102-122615-117.log | 4 ++++ index.js | 10 +++++++- lib/mongoManager.js => mongoManager.js | 17 +++---------- 5 files changed, 36 insertions(+), 23 deletions(-) rename lib/blockchainManager.js => blockchainManager.js (97%) create mode 100644 composer-logs/trace_20171102-122014-555.log create mode 100644 composer-logs/trace_20171102-122615-117.log rename lib/mongoManager.js => mongoManager.js (96%) diff --git a/lib/blockchainManager.js b/blockchainManager.js similarity index 97% rename from lib/blockchainManager.js rename to blockchainManager.js index f92eece..450ae7d 100644 --- a/lib/blockchainManager.js +++ b/blockchainManager.js @@ -599,6 +599,7 @@ class BlockchainManager { //**Set up the time start */ let timeStart; let timeEnd; + let schedule; //**Set up the time end */ return bm.init() .then(() => { @@ -606,6 +607,7 @@ class BlockchainManager { }) .then((result) => { let cannonBalls = []; + schedule = result; for (let i = 0; i < result.length; i++) { cannonBalls.push(bm.makeTransaction(result[i].from, result[i].to, result[i].funds)); } @@ -617,6 +619,9 @@ class BlockchainManager { bm.profilingTime(timeStart, timeEnd, simTrax, 'tx'); console.log('Transaction Cannon Finished'); }) + .then(() => { + return schedule; + }) .catch(function (error) { console.log('An error occured: ', chalk.bold.red(error)); process.exit(1); @@ -634,20 +639,23 @@ class BlockchainManager { let bm = new BlockchainManager(); let modState; /** Get the state of the database */ - console.log(schedule); - return mdb.getAllAst() + return mongo.getAllAst() .then((result) => { + let arr = result; for (let i = 0; i < schedule.length; i++) { - for (let x = 0; x < result.length; x++) { - if (result[x].id == schedule[i].from) { - result[x].balance -= schedule[i].funds; + for (let x = 0; x < arr.length; x++) { + if (arr[x].id == schedule[i].from) { + arr[x].balance = arr[x].balance - schedule[i].funds; } - if (result[x].id == schedule[i].to) { - result[x].balance += schedule[i].funds; + if (arr[x].id == schedule[i].to) { + arr[x].balance = arr[x].balance + schedule[i].funds; } } } - modState = result; + modState = arr; + return bm.init(); + }) + .then(() => { return bm.rawAssetsOnLedger(); }) .then((rawLedger) => { diff --git a/composer-logs/trace_20171102-122014-555.log b/composer-logs/trace_20171102-122014-555.log new file mode 100644 index 0000000..859174b --- /dev/null +++ b/composer-logs/trace_20171102-122014-555.log @@ -0,0 +1,4 @@ +2017-11-01T18:20:16.049Z ERROR HLFConnectionManager :fabric-client() [client-utils.js]: sendPeersProposal - Promise is rejected: Error: chaincode error (status: 500, message: Error: The current identity must be activated (ACTIVATION_REQUIRED)) + at /Users/a01334390/Documents/Git Projects/Lyra/node_modules/fabric-client/node_modules/grpc/src/node/src/client.js:434:17 {}$ +2017-11-01T18:20:16.050Z ERROR HLFConnection :queryChainCode() {"message":"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 query business network. Error: chaincode error (status: 500, message: Error: The current identity must be activated (ACTIVATION_REQUIRED))\n at channel.queryByChaincode.then.catch (/Users/a01334390/Documents/Git Projects/Lyra/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:749:34)\n at "}$ +2017-11-01T18:20:16.050Z 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 (/Users/a01334390/Documents/Git Projects/Lyra/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:663:34)\n at "}$ diff --git a/composer-logs/trace_20171102-122615-117.log b/composer-logs/trace_20171102-122615-117.log new file mode 100644 index 0000000..449da19 --- /dev/null +++ b/composer-logs/trace_20171102-122615-117.log @@ -0,0 +1,4 @@ +2017-11-01T18:26:16.584Z ERROR HLFConnectionManager :fabric-client() [client-utils.js]: sendPeersProposal - Promise is rejected: Error: chaincode error (status: 500, message: Error: The current identity must be activated (ACTIVATION_REQUIRED)) + at /Users/a01334390/Documents/Git Projects/Lyra/node_modules/fabric-client/node_modules/grpc/src/node/src/client.js:434:17 {}$ +2017-11-01T18:26:16.585Z ERROR HLFConnection :queryChainCode() {"message":"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 query business network. Error: chaincode error (status: 500, message: Error: The current identity must be activated (ACTIVATION_REQUIRED))\n at channel.queryByChaincode.then.catch (/Users/a01334390/Documents/Git Projects/Lyra/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:749:34)\n at "}$ +2017-11-01T18:26:16.585Z 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 (/Users/a01334390/Documents/Git Projects/Lyra/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:663:34)\n at "}$ diff --git a/index.js b/index.js index 0fb62b1..f307f43 100755 --- a/index.js +++ b/index.js @@ -190,7 +190,15 @@ switch (yargs._[0]) { case 'cannon': console.log(chalk.bold.cyan('Lyra CLI App'), chalk.bold.green('Made by Aabo Technologies © 2017')); hyper.transactionCannon(yargs.transactions) - .then(() => { + .then((result) => { + 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) { diff --git a/lib/mongoManager.js b/mongoManager.js similarity index 96% rename from lib/mongoManager.js rename to mongoManager.js index 241da97..a5f72a3 100644 --- a/lib/mongoManager.js +++ b/mongoManager.js @@ -25,13 +25,13 @@ let connectionURI = config.get('mongoURI'); /** Get the Schemas */ var { Participant -} = require('../Schemas/participant'); +} = require('./Schemas/participant'); var { Transaction -} = require('../Schemas/transaction'); +} = require('./Schemas/transaction'); var { Wallet -} = require('../Schemas/wallet'); +} = require('./Schemas/wallet'); //Start the connection to Mongoose mongoose.Promise = global.Promise; @@ -40,17 +40,6 @@ mongoose.connect(connectionURI, { }); class MongoManager { - constructor() { - mongoose.connect(connectionURI, { - useMongoClient: true - }) - .then((result)=>{ - console.log('Connected to MongoDB'); - }) - .catch(function(error){ - console.log('an error ocurred'); - }); - } /**@description Persists a transaction into MongoDB * @param {JSON} a JSON Document with transaction information