From 4919114f363f3b874c0f969090105bef0955a92e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 27 Jul 2018 16:54:33 -0400 Subject: [PATCH] move blockchain connection code to its own module --- lib/core/engine.js | 10 ++-------- .../blockchain_connector}/fundAccount.js | 0 .../blockchain_connector/index.js} | 12 ++++++------ .../blockchain_connector}/provider.js | 2 +- lib/tests/test.js | 3 ++- 5 files changed, 11 insertions(+), 16 deletions(-) rename lib/{contracts => modules/blockchain_connector}/fundAccount.js (100%) rename lib/{contracts/blockchain.js => modules/blockchain_connector/index.js} (97%) rename lib/{contracts => modules/blockchain_connector}/provider.js (97%) diff --git a/lib/core/engine.js b/lib/core/engine.js index 6465411b3..f1b9b26e4 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -251,16 +251,10 @@ class Engine { isDev: this.isDev }); - const Blockchain = require('../contracts/blockchain.js'); - (new Blockchain({ - contractsConfig: this.config.contractsConfig, - blockchainConfig: this.config.blockchainConfig, - events: this.events, - logger: this.logger, + this.registerModule('blockchain_connector', { isDev: this.isDev, - locale: this.locale, web3: options.web3 - })); /*eslint no-new: "off"*/ + }); this.registerModule('whisper'); } diff --git a/lib/contracts/fundAccount.js b/lib/modules/blockchain_connector/fundAccount.js similarity index 100% rename from lib/contracts/fundAccount.js rename to lib/modules/blockchain_connector/fundAccount.js diff --git a/lib/contracts/blockchain.js b/lib/modules/blockchain_connector/index.js similarity index 97% rename from lib/contracts/blockchain.js rename to lib/modules/blockchain_connector/index.js index 347c5e5c9..5bc14da15 100644 --- a/lib/contracts/blockchain.js +++ b/lib/modules/blockchain_connector/index.js @@ -1,19 +1,19 @@ const Web3 = require('web3'); const async = require('async'); const Provider = require('./provider.js'); -const utils = require('../utils/utils'); +const utils = require('../../utils/utils'); const WEB3_READY = 'web3Ready'; // TODO: consider another name, this is the blockchain connector class BlockchainConnector { - constructor(options) { + constructor(embark, options) { const self = this; this.plugins = options.plugins; - this.logger = options.logger; - this.events = options.events; - this.contractsConfig = options.contractsConfig; - this.blockchainConfig = options.blockchainConfig; + this.logger = embark.logger; + this.events = embark.events; + this.contractsConfig = embark.config.contractsConfig; + this.blockchainConfig = embark.config.blockchainConfig; this.web3 = options.web3; this.isDev = options.isDev; this.web3Endpoint = ''; diff --git a/lib/contracts/provider.js b/lib/modules/blockchain_connector/provider.js similarity index 97% rename from lib/contracts/provider.js rename to lib/modules/blockchain_connector/provider.js index 9a2ae58dd..59b1bdb96 100644 --- a/lib/contracts/provider.js +++ b/lib/modules/blockchain_connector/provider.js @@ -1,5 +1,5 @@ const async = require('async'); -const AccountParser = require('../utils/accountParser'); +const AccountParser = require('../../utils/accountParser'); const fundAccount = require('./fundAccount'); class Provider { diff --git a/lib/tests/test.js b/lib/tests/test.js index 9b3315ff7..a23ec66d6 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -6,7 +6,8 @@ const constants = require('../constants'); const Events = require('../core/events'); const cloneDeep = require('clone-deep'); const AccountParser = require('../utils/accountParser'); -const Provider = require('../contracts/provider'); +// TODO: breaks module isolation; tests need to be refactored to use the engine and avoid this +const Provider = require('../modules/blockchain_connector/provider.js'); const utils = require('../utils/utils'); const EmbarkJS = require('embarkjs');