Skip to content

Commit f502650

Browse files
committed
fix: only show account warning when Geth will actually start
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.
1 parent 63831f6 commit f502650

File tree

2 files changed

+23
-27
lines changed

2 files changed

+23
-27
lines changed

packages/core/core/src/config.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ export class Config {
7979

8080
locale: string;
8181

82-
shownNoAccountConfigMsg = false; // flag to ensure "no account config" message is only displayed once to the user
83-
8482
corsParts: string[] = [];
8583

8684
providerUrl = '';
@@ -420,31 +418,6 @@ export class Config {
420418
this.blockchainConfig.isAutoEndpoint = true;
421419
}
422420

423-
if (
424-
!this.shownNoAccountConfigMsg &&
425-
(/rinkeby|testnet|livenet/).test(this.blockchainConfig.networkType) &&
426-
!(this.blockchainConfig.accounts && this.blockchainConfig.accounts.find(acc => acc.password)) &&
427-
!this.blockchainConfig.isDev &&
428-
this.env !== 'development' && this.env !== 'test') {
429-
this.logger.warn((
430-
'\n=== ' + __('Cannot unlock account - account config missing').bold + ' ===\n' +
431-
__('Geth is configured to sync to a testnet/livenet and needs to unlock an account ' +
432-
'to allow your dApp to interact with geth, however, the address and password must ' +
433-
'be specified in your blockchain config. Please update your blockchain config with ' +
434-
'a valid address and password: \n') +
435-
` - config/blockchain.js > ${this.env} > account\n\n`.italic +
436-
__('Please also make sure the keystore file for the account is located at: ') +
437-
'\n - Mac: ' + `~/Library/Ethereum/${this.env}/keystore`.italic +
438-
'\n - Linux: ' + `~/.ethereum/${this.env}/keystore`.italic +
439-
'\n - Windows: ' + `%APPDATA%\\Ethereum\\${this.env}\\keystore`.italic) +
440-
__('\n\nAlternatively, you could change ' +
441-
`config/blockchain.js > ${this.env} > networkType`.italic +
442-
__(' to ') +
443-
'"custom"\n'.italic).yellow
444-
);
445-
this.shownNoAccountConfigMsg = true;
446-
}
447-
448421
const accountDocsMessage = __('For more info, check the docs: %s', 'https://framework.embarklabs.io/docs/blockchain_accounts_configuration.html'.underline);
449422
if (this.blockchainConfig.account) {
450423
this.logger.error(__('The `account` config for the blockchain was removed. Please use `accounts` instead.'));

packages/plugins/geth/src/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Geth {
1919
this.isDev = options.isDev;
2020
this.events = embark.events;
2121
this.plugins = options.plugins;
22+
this.shownNoAccountConfigMsg = false; // flag to ensure "no account config" message is only displayed once to the user
2223

2324
if (!this.shouldInit()) {
2425
return;
@@ -33,6 +34,28 @@ class Geth {
3334
launchFn: (readyCb) => {
3435
this.events.request('processes:register', 'blockchain', {
3536
launchFn: (cb) => {
37+
if (!this.shownNoAccountConfigMsg &&
38+
(/rinkeby|testnet|livenet/).test(this.blockchainConfig.networkType) &&
39+
!(this.blockchainConfig.accounts && this.blockchainConfig.accounts.find(acc => acc.password)) &&
40+
!this.blockchainConfig.isDev && this.embark.env !== 'development' && this.embark.env !== 'test') {
41+
this.logger.warn((
42+
'\n=== ' + __('Cannot unlock account - account config missing').bold + ' ===\n' +
43+
__('Geth is configured to sync to a testnet/livenet and needs to unlock an account ' +
44+
'to allow your dApp to interact with geth, however, the address and password must ' +
45+
'be specified in your blockchain config. Please update your blockchain config with ' +
46+
'a valid address and password: \n') +
47+
` - config/blockchain.js > ${this.embark.env} > account\n\n`.italic +
48+
__('Please also make sure the keystore file for the account is located at: ') +
49+
'\n - Mac: ' + `~/Library/Ethereum/${this.embark.env}/keystore`.italic +
50+
'\n - Linux: ' + `~/.ethereum/${this.embark.env}/keystore`.italic +
51+
'\n - Windows: ' + `%APPDATA%\\Ethereum\\${this.embark.env}\\keystore`.italic) +
52+
__('\n\nAlternatively, you could change ' +
53+
`config/blockchain.js > ${this.embark.env} > networkType`.italic +
54+
__(' to ') +
55+
'"custom"\n'.italic).yellow
56+
);
57+
this.shownNoAccountConfigMsg = true;
58+
}
3659
this.startBlockchainNode(cb);
3760
},
3861
stopFn: (cb) => {

0 commit comments

Comments
 (0)