make cmd call async

This commit is contained in:
Iuri Matias 2017-03-02 08:15:35 -05:00
parent 7597480bc4
commit fe30f4b040
2 changed files with 70 additions and 43 deletions

View File

@ -41,14 +41,16 @@ Blockchain.prototype.runCommand = function(cmd) {
};
Blockchain.prototype.run = function() {
var self = this;
console.log("===============================================================================".magenta);
console.log("===============================================================================".magenta);
console.log(("Embark Blockchain Using: " + this.client.name.underline).magenta);
console.log("===============================================================================".magenta);
console.log("===============================================================================".magenta);
var address = this.initChainAndGetAddress();
var mainCommand = this.client.mainCommand(address);
this.runCommand(mainCommand);
this.client.mainCommand(address, function(cmd) {
self.runCommand(cmd);
});
};
Blockchain.prototype.initChainAndGetAddress = function() {

View File

@ -1,3 +1,4 @@
var async = require('async');
// TODO: make all of this async
var GethCommands = function(options) {
@ -86,50 +87,74 @@ GethCommands.prototype.determineRpcOptions = function(config) {
return cmd;
};
GethCommands.prototype.mainCommand = function(address) {
GethCommands.prototype.mainCommand = function(address, done) {
var self = this;
var config = this.config;
var cmd = this.geth_bin + " ";
var rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']);
cmd += this.commonOptions();
cmd += this.determineRpcOptions(this.config);
if (config.nodiscover) {
cmd += "--nodiscover ";
}
if (config.vmdebug) {
cmd += "--vmdebug ";
}
cmd += "--maxpeers " + config.maxpeers + " ";
if (config.mineWhenNeeded || config.mine) {
cmd += "--mine ";
}
if (config.bootnodes && config.bootnodes !== "" && config.bootnodes !== []) {
cmd += "--bootnodes " + config.bootnodes;
}
if (config.whisper) {
cmd += "--shh ";
rpc_api.push('shh');
}
cmd += '--rpcapi "' + rpc_api.join(',') + '" ';
var accountAddress = config.account.address || address;
if (accountAddress) {
cmd += "--unlock=" + accountAddress + " ";
}
if (config.mineWhenNeeded) {
cmd += "js .embark/" + this.env + "/js/mine.js";
}
return cmd;
async.series([
function commonOptions(callback) {
var cmd = self.commonOptions();
callback(null, cmd);
},
function rpcOptions(callback) {
var cmd = self.determineRpcOptions(self.config);
callback(null, cmd);
},
function dontGetPeers(callback) {
if (config.nodiscover) {
return callback(null, "--nodiscover");
}
callback(null, "");
},
function vmDebug(callback) {
if (config.vmdebug) {
return callback(null, "--vmdebug");
}
callback(null, "");
},
function maxPeers(callback) {
var cmd = "--maxpeers " + config.maxpeers;
callback(null, cmd);
},
function mining(callback) {
if (config.mineWhenNeeded || config.mine) {
return callback(null, "--mine ");
}
callback("");
},
function bootnodes(callback) {
if (config.bootnodes && config.bootnodes !== "" && config.bootnodes !== []) {
return callback(null, "--bootnodes " + config.bootnodes);
}
callback("");
},
function whisper(callback) {
if (config.whisper) {
rpc_api.push('shh');
return callback(null, "--shh ");
}
callback("");
},
function rpcApi(callback) {
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
},
function accountToUnlock(callback) {
var accountAddress = config.account.address || address;
if (accountAddress) {
return callback(null, "--unlock=" + accountAddress);
}
callback(null, "");
},
function mineWhenNeeded(callback) {
if (config.mineWhenNeeded) {
return callback(null, "js .embark/" + self.env + "/js/mine.js");
}
callback(null, "");
}
], function(err, results) {
done(self.geth_bin + " " + results.join(" "));
});
};
module.exports = GethCommands;