From a5275737967e6f68253d5b7ea584a00f9fbeae4d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 4 Mar 2017 20:14:47 -0500 Subject: [PATCH] separate the different functions in deployContracts --- lib/contracts/deploy_manager.js | 37 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index 75eff869e..f913ba83a 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -38,11 +38,7 @@ DeployManager.prototype.deployContracts = function(done) { }); contractsManager.build(callback); }, - function deployContracts2(contractsManager, callback) { - - //TODO: figure out where to put this since the web3 can be passed along if needed - // perhaps it should go into the deploy object itself - // TODO: should come from the config object + function connectWithWeb3(contractsManager, callback) { var web3; if (self.web3) { web3 = self.web3; @@ -50,32 +46,35 @@ DeployManager.prototype.deployContracts = function(done) { web3 = new Web3(); var web3Endpoint = 'http://' + self.config.blockchainConfig.rpcHost + ':' + self.config.blockchainConfig.rpcPort; web3.setProvider(new web3.providers.HttpProvider(web3Endpoint)); - if (!web3.isConnected()) { self.logger.error(("Couldn't connect to " + web3Endpoint.underline + " are you sure it's on?").red); self.logger.info("make sure you have an ethereum node or simulator running. e.g 'embark blockchain'".magenta); return callback(Error("error connecting to blockchain node")); } } - + callback(null, contractsManager, web3); + }, + function setDefaultAccount(contractsManager, web3, callback) { web3.eth.getAccounts(function(err, accounts) { if (err) { return callback(new Error(err)); } var selectedAccount = self.config.blockchainConfig.account.address; web3.eth.defaultAccount = (selectedAccount || accounts[0]); - - var deploy = new Deploy({ - web3: web3, - contractsManager: contractsManager, - logger: self.logger, - chainConfig: self.chainConfig, - env: self.config.env - }); - deploy.deployAll(function() { - self.events.emit('contractsDeployed', contractsManager); - callback(null, contractsManager); - }); + callback(null, contractsManager, web3); + }); + }, + function deployAllContracts(contractsManager, web3, callback) { + var deploy = new Deploy({ + web3: web3, + contractsManager: contractsManager, + logger: self.logger, + chainConfig: self.chainConfig, + env: self.config.env + }); + deploy.deployAll(function() { + self.events.emit('contractsDeployed', contractsManager); + callback(null, contractsManager); }); } ], function(err, result) {