Skip to content

Commit

Permalink
fix: only show account warning when Geth will actually start
Browse files Browse the repository at this point in the history
Before, we checked if the network was a testnet or mainnet and
warned if there were no account sconfigured to sync. However, that
didn't take into account that we could connect to an external node,
hence not starting Geth at all.
So to fix that, I moved the condition and message to the Geth module
and only log when we start the node and the condition is met.
  • Loading branch information
jrainville committed Feb 4, 2020
1 parent 63831f6 commit f502650
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
27 changes: 0 additions & 27 deletions packages/core/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ export class Config {

locale: string;

shownNoAccountConfigMsg = false; // flag to ensure "no account config" message is only displayed once to the user

corsParts: string[] = [];

providerUrl = '';
Expand Down Expand Up @@ -420,31 +418,6 @@ export class Config {
this.blockchainConfig.isAutoEndpoint = true;
}

if (
!this.shownNoAccountConfigMsg &&
(/rinkeby|testnet|livenet/).test(this.blockchainConfig.networkType) &&
!(this.blockchainConfig.accounts && this.blockchainConfig.accounts.find(acc => acc.password)) &&
!this.blockchainConfig.isDev &&
this.env !== 'development' && this.env !== 'test') {
this.logger.warn((
'\n=== ' + __('Cannot unlock account - account config missing').bold + ' ===\n' +
__('Geth is configured to sync to a testnet/livenet and needs to unlock an account ' +
'to allow your dApp to interact with geth, however, the address and password must ' +
'be specified in your blockchain config. Please update your blockchain config with ' +
'a valid address and password: \n') +
` - config/blockchain.js > ${this.env} > account\n\n`.italic +
__('Please also make sure the keystore file for the account is located at: ') +
'\n - Mac: ' + `~/Library/Ethereum/${this.env}/keystore`.italic +
'\n - Linux: ' + `~/.ethereum/${this.env}/keystore`.italic +
'\n - Windows: ' + `%APPDATA%\\Ethereum\\${this.env}\\keystore`.italic) +
__('\n\nAlternatively, you could change ' +
`config/blockchain.js > ${this.env} > networkType`.italic +
__(' to ') +
'"custom"\n'.italic).yellow
);
this.shownNoAccountConfigMsg = true;
}

const accountDocsMessage = __('For more info, check the docs: %s', 'https://framework.embarklabs.io/docs/blockchain_accounts_configuration.html'.underline);
if (this.blockchainConfig.account) {
this.logger.error(__('The `account` config for the blockchain was removed. Please use `accounts` instead.'));
Expand Down
23 changes: 23 additions & 0 deletions packages/plugins/geth/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Geth {
this.isDev = options.isDev;
this.events = embark.events;
this.plugins = options.plugins;
this.shownNoAccountConfigMsg = false; // flag to ensure "no account config" message is only displayed once to the user

if (!this.shouldInit()) {
return;
Expand All @@ -33,6 +34,28 @@ class Geth {
launchFn: (readyCb) => {
this.events.request('processes:register', 'blockchain', {
launchFn: (cb) => {
if (!this.shownNoAccountConfigMsg &&
(/rinkeby|testnet|livenet/).test(this.blockchainConfig.networkType) &&
!(this.blockchainConfig.accounts && this.blockchainConfig.accounts.find(acc => acc.password)) &&
!this.blockchainConfig.isDev && this.embark.env !== 'development' && this.embark.env !== 'test') {
this.logger.warn((
'\n=== ' + __('Cannot unlock account - account config missing').bold + ' ===\n' +
__('Geth is configured to sync to a testnet/livenet and needs to unlock an account ' +
'to allow your dApp to interact with geth, however, the address and password must ' +
'be specified in your blockchain config. Please update your blockchain config with ' +
'a valid address and password: \n') +
` - config/blockchain.js > ${this.embark.env} > account\n\n`.italic +
__('Please also make sure the keystore file for the account is located at: ') +
'\n - Mac: ' + `~/Library/Ethereum/${this.embark.env}/keystore`.italic +
'\n - Linux: ' + `~/.ethereum/${this.embark.env}/keystore`.italic +
'\n - Windows: ' + `%APPDATA%\\Ethereum\\${this.embark.env}\\keystore`.italic) +
__('\n\nAlternatively, you could change ' +
`config/blockchain.js > ${this.embark.env} > networkType`.italic +
__(' to ') +
'"custom"\n'.italic).yellow
);
this.shownNoAccountConfigMsg = true;
}
this.startBlockchainNode(cb);
},
stopFn: (cb) => {
Expand Down

0 comments on commit f502650

Please sign in to comment.