From ca32d7aac007806f449bb2a76c7b1b984ce1a251 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 31 Jul 2018 09:59:27 -0400 Subject: [PATCH] warn if mismatch on network id --- lib/constants.json | 8 +++++++- lib/modules/blockchain_connector/index.js | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/constants.json b/lib/constants.json index 31b77984..bedc38d2 100644 --- a/lib/constants.json +++ b/lib/constants.json @@ -38,7 +38,13 @@ "blockchainExit": "blockchainExit", "init": "init", "initiated": "initiated", - "servicePortOnProxy": 10 + "servicePortOnProxy": 10, + "networkIds": { + "mainnet": 1, + "testnet": 3, + "ropsten": 3, + "rinkeby": 4 + } }, "storage": { "init": "init", diff --git a/lib/modules/blockchain_connector/index.js b/lib/modules/blockchain_connector/index.js index 5bc14da1..25aa94a2 100644 --- a/lib/modules/blockchain_connector/index.js +++ b/lib/modules/blockchain_connector/index.js @@ -2,6 +2,7 @@ const Web3 = require('web3'); const async = require('async'); const Provider = require('./provider.js'); const utils = require('../../utils/utils'); +const constants = require('../../constants'); const WEB3_READY = 'web3Ready'; @@ -18,7 +19,6 @@ class BlockchainConnector { this.isDev = options.isDev; this.web3Endpoint = ''; this.isWeb3Ready = false; - this.web3StartedInProcess = false; self.events.setCommandHandler("blockchain:web3:isReady", (cb) => { cb(self.isWeb3Ready); @@ -74,6 +74,18 @@ class BlockchainConnector { self.events.request("processes:launch", "blockchain", () => { self.provider.startWeb3Provider(() => { + this.web3.eth.net.getId() + .then(id => { + let networkId = self.blockchainConfig.networkId; + if (!networkId && constants.blockchain.networkIds[self.blockchainConfig.networkType]) { + networkId = constants.blockchain.networkIds[self.blockchainConfig.networkType]; + } + if (id !== networkId) { + 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')); + } + }) + .catch(console.error); self.provider.fundAccounts(() => { self.isWeb3Ready = true; self.events.emit(WEB3_READY);