From fe30f4b040b040f0e4d90a48cbbcbf6652fb7ec1 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 2 Mar 2017 08:15:35 -0500 Subject: [PATCH] make cmd call async --- lib/cmds/blockchain/blockchain.js | 6 +- lib/cmds/blockchain/geth_commands.js | 107 +++++++++++++++++---------- 2 files changed, 70 insertions(+), 43 deletions(-) diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 8fcc95887..e83167bc0 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -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() { diff --git a/lib/cmds/blockchain/geth_commands.js b/lib/cmds/blockchain/geth_commands.js index 4f2964c75..df4f75e82 100644 --- a/lib/cmds/blockchain/geth_commands.js +++ b/lib/cmds/blockchain/geth_commands.js @@ -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;