From a32c04c75188b53cfb9e2fc8923dd9bcfe6a477f Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 10 May 2018 14:52:30 -0400 Subject: [PATCH] fix conflict in engine --- lib/core/engine.js | 5 +++-- lib/core/provider.js | 37 +++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 lib/core/provider.js diff --git a/lib/core/engine.js b/lib/core/engine.js index 2254d1acf..35d8ed325 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -10,6 +10,7 @@ const Watch = require('../pipeline/watch.js'); const LibraryManager = require('../versions/library_manager.js'); const Pipeline = require('../pipeline/pipeline.js'); const async = require('async'); +const Provider = require('./provider'); class Engine { constructor(options) { @@ -271,8 +272,8 @@ class Engine { if (this.web3 === undefined) { this.web3 = new Web3(); if (this.config.contractsConfig.deployment.type === "rpc") { - let web3Endpoint = 'http://' + this.config.contractsConfig.deployment.host + ':' + this.config.contractsConfig.deployment.port; - this.web3.setProvider(new this.web3.providers.HttpProvider(web3Endpoint)); + const web3Endpoint = 'http://' + this.config.contractsConfig.deployment.host + ':' + this.config.contractsConfig.deployment.port; + this.web3.setProvider(new Provider(web3Endpoint)); } else { throw new Error("contracts config error: unknown deployment type " + this.config.contractsConfig.deployment.type); } diff --git a/lib/core/provider.js b/lib/core/provider.js new file mode 100644 index 000000000..66f92d3a0 --- /dev/null +++ b/lib/core/provider.js @@ -0,0 +1,37 @@ +const ProviderEngine = require('web3-provider-engine'); +// const ProviderSubprovider = require("web3-provider-engine/subproviders/provider.js"); +const RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js'); + +class Provider { + constructor(web3Endpoint) { + this.engine = new ProviderEngine(); + // this.web3 = new Web3(engine); + + this.engine.addProvider(new RpcSubprovider({ + rpcUrl: web3Endpoint + })); + + this.engine.on('block', function (block) { + console.log('================================'); + console.log('BLOCK CHANGED:', '#' + block.number.toString('hex'), '0x' + block.hash.toString('hex')); + console.log('================================'); + }); + + // network connectivity error + this.engine.on('error', function (err) { + // report connectivity errors + console.error(err.stack); + }); + this.engine.start(); + } + + sendAsync() { + this.engine.sendAsync.apply(this.engine, arguments); + } + + send() { + return this.engine.send.apply(this.engine, arguments); + } +} + +module.exports = Provider; diff --git a/package.json b/package.json index c2a357285..fc27e7f91 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "url-loader": "^0.6.2", "viz.js": "^1.8.1", "web3": "1.0.0-beta.34", + "web3-provider-engine": "^14.0.5", "webpack": "^3.10.0", "window-size": "^1.1.0" },