get blockchain object from event bus

This commit is contained in:
Iuri Matias 2018-07-27 16:03:15 -04:00
parent 62fad583da
commit 567b0c75b8
4 changed files with 21 additions and 5 deletions

View File

@ -24,6 +24,10 @@ class BlockchainConnector {
cb(self.isWeb3Ready); cb(self.isWeb3Ready);
}); });
self.events.setCommandHandler("blockchain:object", (cb) => {
cb(self);
});
if (!this.web3) { if (!this.web3) {
this.initWeb3(); this.initWeb3();
} else { } else {

View File

@ -206,7 +206,7 @@ class Engine {
events: this.events 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) { this.events.on('file-event', function (fileType) {
clearTimeout(self.fileTimeout); clearTimeout(self.fileTimeout);
@ -252,7 +252,7 @@ class Engine {
}); });
const Blockchain = require('../contracts/blockchain.js'); const Blockchain = require('../contracts/blockchain.js');
this.blockchain = new Blockchain({ (new Blockchain({
contractsConfig: this.config.contractsConfig, contractsConfig: this.config.contractsConfig,
blockchainConfig: this.config.blockchainConfig, blockchainConfig: this.config.blockchainConfig,
events: this.events, events: this.events,
@ -260,7 +260,7 @@ class Engine {
isDev: this.isDev, isDev: this.isDev,
locale: this.locale, locale: this.locale,
web3: options.web3 web3: options.web3
}); })); /*eslint no-new: "off"*/
this.registerModule('whisper'); this.registerModule('whisper');
} }

View File

@ -6,7 +6,6 @@ class ContractDeployer {
constructor(options) { constructor(options) {
const self = this; const self = this;
this.blockchain = options.blockchain;
this.logger = options.logger; this.logger = options.logger;
this.events = options.events; this.events = options.events;
this.plugins = options.plugins; this.plugins = options.plugins;
@ -71,6 +70,13 @@ class ContractDeployer {
} }
async.waterfall([ async.waterfall([
function requestBlockchainConnector(callback) {
self.events.request("blockchain:object", (blockchain) => {
self.blockchain = blockchain;
callback();
});
},
function _determineArguments(next) { function _determineArguments(next) {
self.determineArguments(params || contract.args, contract, (err, realArgs) => { self.determineArguments(params || contract.args, contract, (err, realArgs) => {
if (err) { if (err) {

View File

@ -20,7 +20,6 @@ class DeployManager {
this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false; this.onlyCompile = options.onlyCompile !== undefined ? options.onlyCompile : false;
this.contractDeployer = new ContractDeployer({ this.contractDeployer = new ContractDeployer({
blockchain: this.blockchain,
logger: this.logger, logger: this.logger,
events: this.events, events: this.events,
plugins: this.plugins plugins: this.plugins
@ -89,6 +88,13 @@ class DeployManager {
} }
async.waterfall([ async.waterfall([
function requestBlockchainConnector(callback) {
self.events.request("blockchain:object", (blockchain) => {
self.blockchain = blockchain;
callback();
});
},
function buildContracts(callback) { function buildContracts(callback) {
self.events.request("contracts:build", self.deployOnlyOnConfig, (err) => { self.events.request("contracts:build", self.deployOnlyOnConfig, (err) => {
callback(err); callback(err);