From 46e1ccd81bb53aafe7c20d8f4f54dde5cae58a4f Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 8 May 2018 16:25:48 -0400 Subject: [PATCH 1/5] use --dev when in development --- lib/cmds/blockchain/blockchain.js | 12 ++++++++++-- lib/cmds/blockchain/geth_commands.js | 11 +++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index e7314fc9..0a1e43cb 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -55,7 +55,12 @@ var Blockchain = function(options) { Blockchain.prototype.runCommand = function(cmd, options) { console.log(("running: " + cmd.underline).green); - return shelljs.exec(cmd, options); + return shelljs.exec(cmd, options, (err, stdout, _stderr) => { + if (err && this.env === 'development' && stdout.indexOf('Failed to unlock developer account') > 0) { + console.warn('\nDevelopment blockchain changed to use the --dev option.'.yellow); + console.warn('You will need to change your data directory in blockchain.json (datadir)'.yellow); + } + }); }; Blockchain.prototype.run = function() { @@ -69,7 +74,10 @@ Blockchain.prototype.run = function() { console.log(("could not find " + this.config.geth_bin + " command; is " + this.client.name + " installed or in the PATH?").green); return; } - var address = this.initChainAndGetAddress(); + let address = ''; + if (self.env !== "development") { + address = this.initChainAndGetAddress(); + } this.client.mainCommand(address, function(cmd) { self.runCommand(cmd, {async: true}); }); diff --git a/lib/cmds/blockchain/geth_commands.js b/lib/cmds/blockchain/geth_commands.js index 151b3267..c7e7dd2c 100644 --- a/lib/cmds/blockchain/geth_commands.js +++ b/lib/cmds/blockchain/geth_commands.js @@ -123,6 +123,7 @@ class GethCommands { let config = this.config; let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']); let ws_api = (this.config.wsApi || ['eth', 'web3', 'net']); + const isDev = self.env === 'development'; async.series([ function commonOptions(callback) { @@ -188,7 +189,7 @@ class GethCommands { } else { accountAddress = address; } - if (accountAddress) { + if (accountAddress && !isDev) { return callback(null, "--unlock=" + accountAddress); } callback(null, ""); @@ -200,10 +201,16 @@ class GethCommands { callback(null, ""); }, function mineWhenNeeded(callback) { - if (config.mineWhenNeeded) { + if (config.mineWhenNeeded && !isDev) { return callback(null, "js .embark/" + self.env + "/js/mine.js"); } callback(null, ""); + }, + function isDev(callback) { + if (isDev) { + return callback(null, '--dev'); + } + callback(null, ''); } ], function (err, results) { if (err) { From 92c8d70dd5696a9f6c08dc79b92d02daea43710e Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 9 May 2018 08:26:51 -0400 Subject: [PATCH 2/5] change warning to tell about --reset --- lib/cmds/blockchain/blockchain.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 0a1e43cb..8c50c753 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -57,8 +57,9 @@ Blockchain.prototype.runCommand = function(cmd, options) { console.log(("running: " + cmd.underline).green); return shelljs.exec(cmd, options, (err, stdout, _stderr) => { if (err && this.env === 'development' && stdout.indexOf('Failed to unlock developer account') > 0) { - console.warn('\nDevelopment blockchain changed to use the --dev option.'.yellow); - console.warn('You will need to change your data directory in blockchain.json (datadir)'.yellow); + console.warn('\nDevelopment blockchain has changed to use the --dev option.'.yellow); + console.warn('You can reset your workspace to fix the problem with'.yellow + ' embark --reset'.cyan); + console.warn('Otherwise, you can change your data directory in blockchain.json (datadir)'.yellow); } }); }; From 2913617a81aa851bad6bde6084f852b5c8e126fc Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 9 May 2018 08:29:17 -0400 Subject: [PATCH 3/5] fix command (reset) --- lib/cmds/blockchain/blockchain.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 8c50c753..9ee2533f 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -58,7 +58,7 @@ Blockchain.prototype.runCommand = function(cmd, options) { return shelljs.exec(cmd, options, (err, stdout, _stderr) => { if (err && this.env === 'development' && stdout.indexOf('Failed to unlock developer account') > 0) { console.warn('\nDevelopment blockchain has changed to use the --dev option.'.yellow); - console.warn('You can reset your workspace to fix the problem with'.yellow + ' embark --reset'.cyan); + console.warn('You can reset your workspace to fix the problem with'.yellow + ' embark reset'.cyan); console.warn('Otherwise, you can change your data directory in blockchain.json (datadir)'.yellow); } }); From 8cc485ac943823ce19626a354b28514bb4866b52 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 9 May 2018 09:17:48 -0400 Subject: [PATCH 4/5] add isDev blockchain option --- lib/cmds/blockchain/blockchain.js | 12 ++++++++++-- lib/cmds/blockchain/geth_commands.js | 8 ++++---- templates/boilerplate/config/blockchain.json | 1 + templates/demo/config/blockchain.json | 1 + test/test1/config/blockchain.json | 1 + test_apps/contracts_app/blockchain.json | 1 + test_apps/test_app/config/blockchain.json | 1 + 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 9ee2533f..d0fa2137 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -50,7 +50,15 @@ var Blockchain = function(options) { this.config.datadir = fs.embarkPath(".embark/development/datadir"); } - this.client = new options.client({config: this.config, env: this.env}); + if (this.blockchainConfig.isDev) { + this.isDev = true; + } else if (this.blockchainConfig.isDev === false) { + this.isDev = false; + } else { + this.isDev = this.env === 'development'; + } + + this.client = new options.client({config: this.config, env: this.env, isDev: this.isDev}); }; Blockchain.prototype.runCommand = function(cmd, options) { @@ -76,7 +84,7 @@ Blockchain.prototype.run = function() { return; } let address = ''; - if (self.env !== "development") { + if (!this.isDev) { address = this.initChainAndGetAddress(); } this.client.mainCommand(address, function(cmd) { diff --git a/lib/cmds/blockchain/geth_commands.js b/lib/cmds/blockchain/geth_commands.js index c7e7dd2c..84d28dcf 100644 --- a/lib/cmds/blockchain/geth_commands.js +++ b/lib/cmds/blockchain/geth_commands.js @@ -5,6 +5,7 @@ class GethCommands { constructor(options) { this.config = options && options.hasOwnProperty('config') ? options.config : {}; this.env = options && options.hasOwnProperty('env') ? options.env : 'development'; + this.isDev = options && options.hasOwnProperty('isDev') ? options.isDev : (this.env === 'development'); this.name = "Go-Ethereum (https://github.com/ethereum/go-ethereum)"; this.geth_bin = this.config.geth_bin || "geth"; } @@ -123,7 +124,6 @@ class GethCommands { let config = this.config; let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']); let ws_api = (this.config.wsApi || ['eth', 'web3', 'net']); - const isDev = self.env === 'development'; async.series([ function commonOptions(callback) { @@ -189,7 +189,7 @@ class GethCommands { } else { accountAddress = address; } - if (accountAddress && !isDev) { + if (accountAddress && !self.isDev) { return callback(null, "--unlock=" + accountAddress); } callback(null, ""); @@ -201,13 +201,13 @@ class GethCommands { callback(null, ""); }, function mineWhenNeeded(callback) { - if (config.mineWhenNeeded && !isDev) { + if (config.mineWhenNeeded && !self.isDev) { return callback(null, "js .embark/" + self.env + "/js/mine.js"); } callback(null, ""); }, function isDev(callback) { - if (isDev) { + if (self.isDev) { return callback(null, '--dev'); } callback(null, ''); diff --git a/templates/boilerplate/config/blockchain.json b/templates/boilerplate/config/blockchain.json index afff2072..a7f31878 100644 --- a/templates/boilerplate/config/blockchain.json +++ b/templates/boilerplate/config/blockchain.json @@ -4,6 +4,7 @@ "networkType": "custom", "genesisBlock": "config/development/genesis.json", "datadir": ".embark/development/datadir", + "isDev": true, "mineWhenNeeded": true, "nodiscover": true, "maxpeers": 0, diff --git a/templates/demo/config/blockchain.json b/templates/demo/config/blockchain.json index 638c8167..5743c38d 100644 --- a/templates/demo/config/blockchain.json +++ b/templates/demo/config/blockchain.json @@ -4,6 +4,7 @@ "networkType": "custom", "genesisBlock": "config/development/genesis.json", "datadir": ".embark/development/datadir", + "isDev": true, "mineWhenNeeded": true, "nodiscover": true, "maxpeers": 0, diff --git a/test/test1/config/blockchain.json b/test/test1/config/blockchain.json index 090f4078..fc0ba5e1 100644 --- a/test/test1/config/blockchain.json +++ b/test/test1/config/blockchain.json @@ -3,6 +3,7 @@ "networkType": "custom", "genesisBlock": "config/development/genesis.json", "datadir": ".embark/development/datadir", + "isDev": true, "mineWhenNeeded": true, "nodiscover": true, "rpcHost": "localhost", diff --git a/test_apps/contracts_app/blockchain.json b/test_apps/contracts_app/blockchain.json index 35edfb43..a574d400 100644 --- a/test_apps/contracts_app/blockchain.json +++ b/test_apps/contracts_app/blockchain.json @@ -4,6 +4,7 @@ "networkType": "custom", "genesisBlock": "development/genesis.json", "datadir": ".embark/development/datadir", + "isDev": true, "mineWhenNeeded": true, "nodiscover": true, "maxpeers": 0, diff --git a/test_apps/test_app/config/blockchain.json b/test_apps/test_app/config/blockchain.json index 6acbdfd5..2b9baa50 100644 --- a/test_apps/test_app/config/blockchain.json +++ b/test_apps/test_app/config/blockchain.json @@ -4,6 +4,7 @@ "networkType": "custom", "genesisBlock": "config/development/genesis.json", "datadir": ".embark/development/datadir", + "isDev": true, "mineWhenNeeded": true, "nodiscover": true, "maxpeers": 0, From cc9366719819c3b4da91150aa149f47345708495 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 9 May 2018 09:29:27 -0400 Subject: [PATCH 5/5] fix test --- test/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/config.js b/test/config.js index 27423873..50875a0a 100644 --- a/test/config.js +++ b/test/config.js @@ -22,6 +22,7 @@ describe('embark.Config', function () { "networkType": "custom", "genesisBlock": "config/development/genesis.json", "datadir": ".embark/development/datadir", + "isDev": true, "mineWhenNeeded": true, "nodiscover": true, "rpcHost": "localhost",