change account funding order to enable starting a node before

This commit is contained in:
Jonathan Rainville 2018-06-07 12:55:07 -04:00
parent b5ac5626cb
commit bfc8663a61
2 changed files with 41 additions and 28 deletions

View File

@ -54,17 +54,21 @@ class Blockchain {
}; };
provider = new Provider(providerOptions); provider = new Provider(providerOptions);
provider.startWeb3Provider(() => { async.waterfall([
function startProvider(next) {
provider.startWeb3Provider(next);
},
function checkNode(next) {
self.assertNodeConnection(true, (err) => { self.assertNodeConnection(true, (err) => {
if (err && self.web3StartedInProcess) { if (err && self.web3StartedInProcess) {
// Already started blockchain in another node, we really have a node problem // 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); self.logger.error(__('Unable to start the blockchain process. Is Geth installed?').red);
return cb(err); return next(err);
} }
if (!err) { if (!err) {
self.isWeb3Ready = true; self.isWeb3Ready = true;
self.events.emit(WEB3_READY); self.events.emit(WEB3_READY);
return cb(); return next();
} }
self.web3StartedInProcess = true; self.web3StartedInProcess = true;
self.startBlockchainNode(() => { self.startBlockchainNode(() => {
@ -73,7 +77,11 @@ class Blockchain {
self.initWeb3(cb); self.initWeb3(cb);
}); });
}); });
}); },
function fundAccountsIfNeeded(next) {
provider.fundAccounts(next);
}
], cb);
} else { } else {
throw new Error("contracts config error: unknown deployment type " + this.contractsConfig.deployment.type); throw new Error("contracts config error: unknown deployment type " + this.contractsConfig.deployment.type);
} }

View File

@ -35,18 +35,10 @@ class Provider {
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger); self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
self.addresses = []; self.addresses = [];
async.waterfall([ async.waterfall([
function fundAccounts(next) { function populateWeb3Wallet(next) {
if (!self.accounts.length) { if (!self.accounts.length) {
return next(NO_ACCOUNTS); 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.accounts.forEach(account => {
self.addresses.push(account.address); self.addresses.push(account.address);
self.web3.eth.accounts.wallet.add(account); 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() { stop() {
this.engine.stop(); this.engine.stop();
} }