Skip to content

Commit

Permalink
Release Candidate 3
Browse files Browse the repository at this point in the history
Most of the changes from the previous version but now: 
+ You can choose between persisting transactions or not into MongoDB
+ Some documentation has been cleansed
  • Loading branch information
martin-headspace committed Nov 1, 2017
1 parent 8baa53e commit 4d728ae
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 11 deletions.
76 changes: 69 additions & 7 deletions blockchainManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,64 @@ class BlockchainManager {
"owner": "resource:org.aabo.Client#" + to.owner.getIdentifier()
}
});
// mongo.saveTx(resource);
return this.businessNetworkConnection.submitTransaction(resource);;
})
.catch(function (error) {
console.log('An error occured: ', chalk.bold.red(error));
});
}

/**
* @name makeReplicatedTransaction
* @author Aabo Technologies © 2017 - Server's team
* @description This method makes a single transaction over the ledger
* @param {String} fromID is the md5 related to a Client's wallet on the ledger who's sending money
* @param {String} toID is the md5 related to a Client's wallet on the ledger who's receiving money
* @param {Number} funds is an amount of money to be sent from one wallet to the other
* @returns {Promise} whose fullfiment means a transaction was made succesfully
*/

makeReplicatedTransaction(fromID,toID,funds){
const METHOD = 'makeReplicatedTransaction';
let from;
let walletRegistry;
let to;
let resource;

return this.businessNetworkConnection.getAssetRegistry('org.aabo.Wallet')
.then((registry) => {
walletRegistry = registry;
return walletRegistry.get(fromID);
})
.then((fromm) => {
from = fromm;
return walletRegistry.get(toID);
})
.then((too) => {
to = too;
})
.then(() => {
//return mongo.saveTx(resource);
let serializer = this.businessNetworkDefinition.getSerializer();
resource = serializer.fromJSON({
"$class": "org.aabo.Transfer",
"amount": funds,
"from": {
"$class": "org.aabo.Wallet",
"id": from.getIdentifier(),
"balance": from.balance,
"owner": "resource:org.aabo.Client#" + from.owner.getIdentifier()
},
"to": {
"$class": "org.aabo.Wallet",
"id": to.getIdentifier(),
"balance": to.balance,
"owner": "resource:org.aabo.Client#" + to.owner.getIdentifier()
}
});
return this.businessNetworkConnection.submitTransaction(resource);;
})
.then(() => {
return mongo.saveTx(resource);
})
.catch(function (error) {
console.log('An error occured: ', chalk.bold.red(error));
Expand Down Expand Up @@ -631,10 +684,11 @@ class BlockchainManager {
* @author Aabo Technologies © 2017 - Server's team
* @description This is it. This launches as many transactions as possible, it doesn't care about your feelings
* @param {Number} amount of transactions to make
* @param {String} replica if the transaction information will be replicated
* @returns {Promise} that it will try it's best, don't sweat it
*/

static transactionCannon(simTrax) {
static transactionCannon(simTrax,replica) {
/**Start the spinner */
const spinner = new ora({
text: 'Connecting to Hyperledger...',
Expand All @@ -655,12 +709,20 @@ class BlockchainManager {
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++) {
cannonBalls.push(bm.makeTransaction(result[i].from, result[i].to, result[i].funds));
if(replica.toLowerCase() == 'n'){
for (let i = 0; i < result.length; i++) {
spinner.text = 'Breaking into the chain...';
spinner.color = 'green';
cannonBalls.push(bm.makeTransaction(result[i].from, result[i].to, result[i].funds));
}
}else{
for (let i = 0; i < result.length; i++) {
spinner.text = 'Merely tapping into the chain...';
spinner.color = 'red';
cannonBalls.push(bm.makeReplicatedTransaction(result[i].from, result[i].to, result[i].funds));
}
}
timeStart = now().toFixed(0);
return Promise.all(cannonBalls);
Expand Down
23 changes: 20 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ var yargs = require('yargs')
description: 'Amount of transactions to launch into the ledger',
require: true,
alias: 't'
},
replication: {
description : 'Replication of transactions into MongoDB',
require: false,
default : 'n',
alias :'r'
}
})
.command('ledger', 'Checks if ledger is synced', {
Expand Down Expand Up @@ -200,7 +206,7 @@ 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)
hyper.transactionCannon(yargs.transactions,yargs.replication)
.then((result) => {
return hyper.isLedgerStateCorrect(result);
})
Expand Down Expand Up @@ -513,14 +519,25 @@ function startTheCannon() {
name: 'transactions',
message: 'Amount of transactions to launch into the ledger',
default: 1,
},{
type: 'confirm',
name: 'replica',
message: 'Do you want the transactions to be replicated?',
default : false
}];
inquirer.prompt(questions).then(function (answers) {
hyper.transactionCannon(answers.transactions)
let rep;
if(answers.replica){
rep = 'y';
} else{
rep = 'n';
}
hyper.transactionCannon(answers.transactions,rep)
.then((schedule) => {
return hyper.isLedgerStateCorrect(schedule);
})
.then(() => {
debugMenu();
testingMenu();
})
.catch(function (error) {
console.log('An error occured: ', chalk.bold.red(error));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lyra-cli",
"version": "0.8.8",
"version": "1.0.0",
"description": "Hyperledger Composer Super Fast Network",
"author": "Aabo Technologies© 2017 - Server's Team",
"main": "index.js",
Expand Down

0 comments on commit 4d728ae

Please sign in to comment.