Merge pull request #495 from embark-framework/bug_fix/accounts-with-no-node

change account funding order to enable starting a node before
This commit is contained in:
Iuri Matias 2018-06-07 14:30:11 -04:00 committed by GitHub
commit 48c99b4075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 28 deletions

View File

@ -54,26 +54,34 @@ class Blockchain {
}; };
provider = new Provider(providerOptions); provider = new Provider(providerOptions);
provider.startWeb3Provider(() => { async.waterfall([
self.assertNodeConnection(true, (err) => { function startProvider(next) {
if (err && self.web3StartedInProcess) { provider.startWeb3Provider(next);
// 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); function checkNode(next) {
return cb(err); self.assertNodeConnection(true, (err) => {
} if (err && self.web3StartedInProcess) {
if (!err) { // Already started blockchain in another node, we really have a node problem
self.isWeb3Ready = true; self.logger.error(__('Unable to start the blockchain process. Is Geth installed?').red);
self.events.emit(WEB3_READY); return next(err);
return cb(); }
} if (!err) {
self.web3StartedInProcess = true; self.isWeb3Ready = true;
self.startBlockchainNode(() => { self.events.emit(WEB3_READY);
// Need to re-initialize web3 to connect to the new blockchain node return next();
provider.stop(); }
self.initWeb3(cb); 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 { } 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();
} }