From 567b0c75b853ab45df2c45b6ba213a671597dc42 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 27 Jul 2018 16:03:15 -0400 Subject: [PATCH] get blockchain object from event bus --- lib/contracts/blockchain.js | 4 ++++ lib/core/engine.js | 6 +++--- lib/modules/deployment/contract_deployer.js | 8 +++++++- lib/modules/deployment/index.js | 8 +++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/contracts/blockchain.js b/lib/contracts/blockchain.js index ae6567fa..347c5e5c 100644 --- a/lib/contracts/blockchain.js +++ b/lib/contracts/blockchain.js @@ -24,6 +24,10 @@ class BlockchainConnector { cb(self.isWeb3Ready); }); + self.events.setCommandHandler("blockchain:object", (cb) => { + cb(self); + }); + if (!this.web3) { this.initWeb3(); } else { diff --git a/lib/core/engine.js b/lib/core/engine.js index a073373f..6465411b 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -206,7 +206,7 @@ class Engine { events: this.events }); - this.registerModule('deployment', {blockchain: this.blockchain, plugins: this.plugins, onlyCompile: options.onlyCompile}); + this.registerModule('deployment', {plugins: this.plugins, onlyCompile: options.onlyCompile}); this.events.on('file-event', function (fileType) { clearTimeout(self.fileTimeout); @@ -252,7 +252,7 @@ class Engine { }); const Blockchain = require('../contracts/blockchain.js'); - this.blockchain = new Blockchain({ + (new Blockchain({ contractsConfig: this.config.contractsConfig, blockchainConfig: this.config.blockchainConfig, events: this.events, @@ -260,7 +260,7 @@ class Engine { isDev: this.isDev, locale: this.locale, web3: options.web3 - }); + })); /*eslint no-new: "off"*/ this.registerModule('whisper'); } diff --git a/lib/modules/deployment/contract_deployer.js b/lib/modules/deployment/contract_deployer.js index cb150d7c..a0582974 100644 --- a/lib/modules/deployment/contract_deployer.js +++ b/lib/modules/deployment/contract_deployer.js @@ -6,7 +6,6 @@ class ContractDeployer { constructor(options) { const self = this; - this.blockchain = options.blockchain; this.logger = options.logger; this.events = options.events; this.plugins = options.plugins; @@ -71,6 +70,13 @@ class ContractDeployer { } async.waterfall([ + function requestBlockchainConnector(callback) { + self.events.request("blockchain:object", (blockchain) => { + self.blockchain = blockchain; + callback(); + }); + }, + function _determineArguments(next) { self.determineArguments(params || contract.args, contract, (err, realArgs) => { if (err) { diff --git a/lib/modules/deployment/index.js b/lib/modules/deployment/index.js index ce303bc8..c32ca242 100644 --- a/lib/modules/deployment/index.js +++ b/lib/modules/deployment/index.js @@ -20,7 +20,6 @@ class DeployManager { this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false; this.contractDeployer = new ContractDeployer({ - blockchain: this.blockchain, logger: this.logger, events: this.events, plugins: this.plugins @@ -89,6 +88,13 @@ class DeployManager { } async.waterfall([ + function requestBlockchainConnector(callback) { + self.events.request("blockchain:object", (blockchain) => { + self.blockchain = blockchain; + callback(); + }); + }, + function buildContracts(callback) { self.events.request("contracts:build", self.deployOnlyOnConfig, (err) => { callback(err);