fix conflict in engine

This commit is contained in:
Jonathan Rainville 2018-05-10 14:52:30 -04:00
parent a03757a5e6
commit a32c04c751
3 changed files with 41 additions and 2 deletions

View File

@ -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);
}

37
lib/core/provider.js Normal file
View File

@ -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;

View File

@ -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"
},