diff --git a/lib/contracts/blockchain.js b/lib/contracts/blockchain.js index 1d0f0c958..e2403c0c3 100644 --- a/lib/contracts/blockchain.js +++ b/lib/contracts/blockchain.js @@ -54,26 +54,34 @@ class Blockchain { }; provider = new Provider(providerOptions); - provider.startWeb3Provider(() => { - self.assertNodeConnection(true, (err) => { - if (err && self.web3StartedInProcess) { - // Already started blockchain in another node, we really have a node problem - self.logger.error(__('Unable to start the blockchain process. Is Geth installed?').red); - return cb(err); - } - if (!err) { - self.isWeb3Ready = true; - self.events.emit(WEB3_READY); - return cb(); - } - self.web3StartedInProcess = true; - self.startBlockchainNode(() => { - // Need to re-initialize web3 to connect to the new blockchain node - provider.stop(); - self.initWeb3(cb); + async.waterfall([ + function startProvider(next) { + provider.startWeb3Provider(next); + }, + function checkNode(next) { + self.assertNodeConnection(true, (err) => { + if (err && self.web3StartedInProcess) { + // Already started blockchain in another node, we really have a node problem + self.logger.error(__('Unable to start the blockchain process. Is Geth installed?').red); + return next(err); + } + if (!err) { + self.isWeb3Ready = true; + self.events.emit(WEB3_READY); + return next(); + } + self.web3StartedInProcess = true; + self.startBlockchainNode(() => { + // Need to re-initialize web3 to connect to the new blockchain node + provider.stop(); + self.initWeb3(cb); + }); }); - }); - }); + }, + function fundAccountsIfNeeded(next) { + provider.fundAccounts(next); + } + ], cb); } else { throw new Error("contracts config error: unknown deployment type " + this.contractsConfig.deployment.type); } diff --git a/lib/contracts/provider.js b/lib/contracts/provider.js index 2614e3845..f93379627 100644 --- a/lib/contracts/provider.js +++ b/lib/contracts/provider.js @@ -35,18 +35,10 @@ class Provider { self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger); self.addresses = []; async.waterfall([ - function fundAccounts(next) { + function populateWeb3Wallet(next) { if (!self.accounts.length) { return next(NO_ACCOUNTS); } - if (!self.isDev) { - return next(); - } - async.each(self.accounts, (account, eachCb) => { - fundAccount(self.web3, account.address, eachCb); - }, next); - }, - function populateWeb3Wallet(next) { self.accounts.forEach(account => { self.addresses.push(account.address); self.web3.eth.accounts.wallet.add(account); @@ -64,6 +56,19 @@ class Provider { }); } + fundAccounts(callback) { + const self = this; + if (!self.accounts.length) { + return callback(); + } + if (!self.isDev) { + return callback(); + } + async.each(self.accounts, (account, eachCb) => { + fundAccount(self.web3, account.address, eachCb); + }, callback); + } + stop() { this.engine.stop(); }