make cmd call async
This commit is contained in:
parent
7597480bc4
commit
fe30f4b040
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
||||
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) {
|
||||
cmd += "--nodiscover ";
|
||||
return callback(null, "--nodiscover");
|
||||
}
|
||||
|
||||
callback(null, "");
|
||||
},
|
||||
function vmDebug(callback) {
|
||||
if (config.vmdebug) {
|
||||
cmd += "--vmdebug ";
|
||||
return callback(null, "--vmdebug");
|
||||
}
|
||||
|
||||
cmd += "--maxpeers " + config.maxpeers + " ";
|
||||
|
||||
callback(null, "");
|
||||
},
|
||||
function maxPeers(callback) {
|
||||
var cmd = "--maxpeers " + config.maxpeers;
|
||||
callback(null, cmd);
|
||||
},
|
||||
function mining(callback) {
|
||||
if (config.mineWhenNeeded || config.mine) {
|
||||
cmd += "--mine ";
|
||||
return callback(null, "--mine ");
|
||||
}
|
||||
|
||||
callback("");
|
||||
},
|
||||
function bootnodes(callback) {
|
||||
if (config.bootnodes && config.bootnodes !== "" && config.bootnodes !== []) {
|
||||
cmd += "--bootnodes " + config.bootnodes;
|
||||
return callback(null, "--bootnodes " + config.bootnodes);
|
||||
}
|
||||
|
||||
callback("");
|
||||
},
|
||||
function whisper(callback) {
|
||||
if (config.whisper) {
|
||||
cmd += "--shh ";
|
||||
rpc_api.push('shh');
|
||||
return callback(null, "--shh ");
|
||||
}
|
||||
|
||||
cmd += '--rpcapi "' + rpc_api.join(',') + '" ';
|
||||
|
||||
callback("");
|
||||
},
|
||||
function rpcApi(callback) {
|
||||
callback(null, '--rpcapi "' + rpc_api.join(',') + '"');
|
||||
},
|
||||
function accountToUnlock(callback) {
|
||||
var accountAddress = config.account.address || address;
|
||||
if (accountAddress) {
|
||||
cmd += "--unlock=" + accountAddress + " ";
|
||||
return callback(null, "--unlock=" + accountAddress);
|
||||
}
|
||||
|
||||
callback(null, "");
|
||||
},
|
||||
function mineWhenNeeded(callback) {
|
||||
if (config.mineWhenNeeded) {
|
||||
cmd += "js .embark/" + this.env + "/js/mine.js";
|
||||
return callback(null, "js .embark/" + self.env + "/js/mine.js");
|
||||
}
|
||||
|
||||
return cmd;
|
||||
callback(null, "");
|
||||
}
|
||||
], function(err, results) {
|
||||
done(self.geth_bin + " " + results.join(" "));
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = GethCommands;
|
||||
|
|
Loading…
Reference in New Issue