From 23f7ec396ac65ae5ebd621e44f129acb1d5f5fd5 Mon Sep 17 00:00:00 2001
From: Anthony Laibe <anthony@laibe.cc>
Date: Thu, 23 Aug 2018 15:29:39 +0100
Subject: [PATCH 1/2] Allow zero config in blockchain

---
 lib/core/config.js                           |  4 ++--
 lib/core/processes/processLauncher.js        | 15 ++++++++++++++-
 lib/modules/blockchain_connector/index.js    |  2 +-
 lib/modules/blockchain_process/blockchain.js |  2 +-
 lib/modules/ens/index.js                     |  8 ++------
 5 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/lib/core/config.js b/lib/core/config.js
index 3ca8fda6..13372037 100644
--- a/lib/core/config.js
+++ b/lib/core/config.js
@@ -123,11 +123,11 @@ Config.prototype._updateBlockchainCors = function(){
   }
 
   let cors = corsParts.join(',');
-  if(blockchainConfig.rpcCorsDomain === 'auto'){ 
+  if(blockchainConfig.rpcCorsDomain === 'auto'){
     if(cors.length) blockchainConfig.rpcCorsDomain = cors;
     else blockchainConfig.rpcCorsDomain = '';
   }
-  if(blockchainConfig.wsOrigins === 'auto'){ 
+  if(blockchainConfig.wsOrigins === 'auto'){
     if(cors.length) blockchainConfig.wsOrigins = cors;
     else blockchainConfig.wsOrigins = '';
   }
diff --git a/lib/core/processes/processLauncher.js b/lib/core/processes/processLauncher.js
index 1bbf9153..7ee80fc5 100644
--- a/lib/core/processes/processLauncher.js
+++ b/lib/core/processes/processLauncher.js
@@ -3,6 +3,7 @@ const constants = require('../../constants');
 const path = require('path');
 const utils = require('../../utils/utils');
 
+let processCount = 1;
 class ProcessLauncher {
 
   /**
@@ -15,7 +16,14 @@ class ProcessLauncher {
    */
   constructor(options) {
     this.name = path.basename(options.modulePath);
-    this.process = child_process.fork(options.modulePath);
+
+    if (this._isDebug()) {
+      const childOptions = {stdio: 'pipe', execArgv: ['--inspect-brk=' + (60000 + processCount)]};
+      processCount++;
+      this.process = child_process.fork(options.modulePath, [], childOptions);
+    } else {
+      this.process = child_process.fork(options.modulePath);
+    }
     this.logger = options.logger;
     this.events = options.events;
     this.silent = options.silent;
@@ -25,6 +33,11 @@ class ProcessLauncher {
     this._subscribeToMessages();
   }
 
+  _isDebug() {
+    const argvString= process.execArgv.join();
+    return argvString.includes('--debug') || argvString.includes('--inspect');
+  }
+
   // Subscribes to messages from the child process and delegates to the right methods
   _subscribeToMessages() {
     const self = this;
diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js
index 5142234e..6d812ef5 100644
--- a/lib/modules/blockchain_connector/index.js
+++ b/lib/modules/blockchain_connector/index.js
@@ -82,7 +82,7 @@ class BlockchainConnector {
             if (!networkId && constants.blockchain.networkIds[self.blockchainConfig.networkType]) {
               networkId = constants.blockchain.networkIds[self.blockchainConfig.networkType];
             }
-            if (id.toString() !== networkId.toString()) {
+            if (networkId && id.toString() !== networkId.toString()) {
               self.logger.warn(__('Connected to a blockchain node on network {{realId}} while your config specifies {{configId}}', {realId: id, configId: networkId}));
               self.logger.warn(__('Make sure you started the right blockchain node'));
             }
diff --git a/lib/modules/blockchain_process/blockchain.js b/lib/modules/blockchain_process/blockchain.js
index c50c237b..65bb92e4 100644
--- a/lib/modules/blockchain_process/blockchain.js
+++ b/lib/modules/blockchain_process/blockchain.js
@@ -155,7 +155,7 @@ Blockchain.prototype.run = function() {
     }
   ], function (err, cmd, args) {
     if (err) {
-      console.error(err);
+      console.error(err.message);
       return;
     }
     args = utils.compact(args);
diff --git a/lib/modules/ens/index.js b/lib/modules/ens/index.js
index 4d0bf70b..e93abb9e 100644
--- a/lib/modules/ens/index.js
+++ b/lib/modules/ens/index.js
@@ -217,11 +217,7 @@ class ENS {
           "ENS": {
             "deploy": false,
             "silent": true
-          }
-        }
-      },
-      "development": {
-        "contracts": {
+          },
           "ENSRegistry": {
             "deploy": true,
             "silent": true,
@@ -285,7 +281,7 @@ class ENS {
     if (this.registration && this.registration.rootDomain) {
       // Register root domain if it is defined
       const rootNode = namehash.hash(this.registration.rootDomain);
-      config.development.contracts['FIFSRegistrar'] = {
+      config.default.contracts['FIFSRegistrar'] = {
         "deploy": true,
         "silent": true,
         "args": ["$ENSRegistry", rootNode],

From fdd2d10d3802339abebf9b68e3adc401b059ef86 Mon Sep 17 00:00:00 2001
From: Anthony Laibe <anthony@laibe.cc>
Date: Tue, 28 Aug 2018 09:32:39 +0100
Subject: [PATCH 2/2] Add warning

---
 lib/core/config.js | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/core/config.js b/lib/core/config.js
index 13372037..6eafa54e 100644
--- a/lib/core/config.js
+++ b/lib/core/config.js
@@ -187,6 +187,12 @@ Config.prototype.loadBlockchainConfigFile = function() {
   if (!configFilePath) {
     this.blockchainConfig.default = true;
   }
+  if(!this.blockchainConfig.account && !this.blockchainConfig.isDev) {
+    this.logger.warn(
+      __('Account settings are needed for this chain.' +
+         ' Please put a valid address and possibly a password in your blockchain config or use a dev chain.')
+    );
+  }
 };
 
 Config.prototype.loadContractsConfigFile = function() {