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.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);
}

View File

@ -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();
}