|
1 | 1 | const async = require('async');
|
| 2 | +const {spawn, exec} = require('child_process'); |
2 | 3 | const GethMiner = require('./miner');
|
3 | 4 | const semver = require('semver');
|
4 | 5 | const constants = require('../../constants');
|
@@ -140,7 +141,7 @@ class GethClient {
|
140 | 141 |
|
141 | 142 | newAccountCommand() {
|
142 | 143 | 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); |
144 | 145 | }
|
145 | 146 | return this.bin + " " + this.commonOptions().join(' ') + " account new ";
|
146 | 147 | }
|
@@ -220,8 +221,34 @@ class GethClient {
|
220 | 221 | }
|
221 | 222 |
|
222 | 223 | 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 | + }); |
225 | 252 | }
|
226 | 253 |
|
227 | 254 | mainCommand(address, done) {
|
|
0 commit comments