Skip to content

Commit 7811211

Browse files
jrainvilleiurimatias
authored andcommitted
fix(blockchain/geth): create geth dev account before other accounts
1 parent 6c7782c commit 7811211

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

Diff for: src/lib/modules/blockchain_process/gethClient.js

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const async = require('async');
2+
const {spawn, exec} = require('child_process');
23
const GethMiner = require('./miner');
34
const semver = require('semver');
45
const constants = require('../../constants');
@@ -140,7 +141,7 @@ class GethClient {
140141

141142
newAccountCommand() {
142143
if (!(this.config.account && this.config.account.password)) {
143-
console.warn(__('Your blockchain is missing a password and creating an account may fail. Please consider updating ').yellow + __('config/blockchain > account > password').cyan + __(' then re-run the command').yellow);
144+
console.warn(__('Your blockchain config is missing a password and creating an account may fail. Please consider updating ').yellow + __('config/blockchain > accounts').cyan + __(' then re-run the command').yellow);
144145
}
145146
return this.bin + " " + this.commonOptions().join(' ') + " account new ";
146147
}
@@ -220,8 +221,34 @@ class GethClient {
220221
}
221222

222223
initDevChain(datadir, callback) {
223-
// No specific configuration needed for the dev chain
224-
return callback();
224+
exec(this.listAccountsCommand(), {}, (err, stdout, _stderr) => {
225+
if (err || stdout === undefined || stdout.indexOf("Fatal") >= 0) {
226+
return callback(err || stdout);
227+
}
228+
this.config.unlockAddressList = this.parseListAccountsCommandResultToAddressList(stdout);
229+
if (this.config.unlockAddressList.length) {
230+
return callback();
231+
}
232+
233+
// No accounts. We need to run the geth --dev command for it to create the dev account
234+
const args = this.commonOptions();
235+
args.push('--dev');
236+
console.log(__('Creating Geth dev account. Please wait...'));
237+
this.child = spawn(this.bin, args, {cwd: process.cwd()});
238+
239+
this.child.stderr.on('data', async (data) => {
240+
data = data.toString();
241+
if (data.indexOf('Using developer account') > -1) {
242+
this.child.kill();
243+
callback();
244+
}
245+
});
246+
247+
setTimeout(() => {
248+
this.child.kill();
249+
return callback(__('Geth dev command never returned a developer account'));
250+
}, 10 * 1000);
251+
});
225252
}
226253

227254
mainCommand(address, done) {

0 commit comments

Comments
 (0)