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() { Blockchain.prototype.run = function() {
var self = this;
console.log("===============================================================================".magenta); console.log("===============================================================================".magenta);
console.log("===============================================================================".magenta); console.log("===============================================================================".magenta);
console.log(("Embark Blockchain Using: " + this.client.name.underline).magenta); console.log(("Embark Blockchain Using: " + this.client.name.underline).magenta);
console.log("===============================================================================".magenta); console.log("===============================================================================".magenta);
console.log("===============================================================================".magenta); console.log("===============================================================================".magenta);
var address = this.initChainAndGetAddress(); var address = this.initChainAndGetAddress();
var mainCommand = this.client.mainCommand(address); this.client.mainCommand(address, function(cmd) {
this.runCommand(mainCommand); self.runCommand(cmd);
});
}; };
Blockchain.prototype.initChainAndGetAddress = function() { Blockchain.prototype.initChainAndGetAddress = function() {

View File

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