conflict in provider

This commit is contained in:
Jonathan Rainville 2018-06-29 11:24:20 -04:00
parent dfff83d42d
commit 62c6b57f45
1 changed files with 10 additions and 15 deletions

View File

@ -4,11 +4,14 @@ const WsSubprovider = require('embark-web3-provider-engine/subproviders/websocke
const async = require('async'); const async = require('async');
const AccountParser = require('./accountParser'); const AccountParser = require('./accountParser');
const fundAccount = require('./fundAccount'); const fundAccount = require('./fundAccount');
const EventEmitter = require('events');
EventEmitter.prototype._maxListeners = 300;
const NO_ACCOUNTS = 'noAccounts'; const NO_ACCOUNTS = 'noAccounts';
class Provider { class Provider extends ProviderEngine {
constructor(options) { constructor(options) {
super();
this.web3 = options.web3; this.web3 = options.web3;
this.accountsConfig = options.accountsConfig; this.accountsConfig = options.accountsConfig;
this.blockchainConfig = options.blockchainConfig; this.blockchainConfig = options.blockchainConfig;
@ -16,19 +19,19 @@ class Provider {
this.web3Endpoint = options.web3Endpoint; this.web3Endpoint = options.web3Endpoint;
this.logger = options.logger; this.logger = options.logger;
this.isDev = options.isDev; this.isDev = options.isDev;
this.engine = new ProviderEngine();
this.asyncMethods = {}; this.asyncMethods = {};
this.setMaxListeners(300);
} }
startWeb3Provider(callback) { startWeb3Provider(callback) {
const self = this; const self = this;
if (this.type === 'rpc') { if (this.type === 'rpc') {
self.engine.addProvider(new RpcSubprovider({ self.addProvider(new RpcSubprovider({
rpcUrl: self.web3Endpoint rpcUrl: self.web3Endpoint
})); }));
} else if (this.type === 'ws') { } else if (this.type === 'ws') {
self.engine.addProvider(new WsSubprovider({ self.addProvider(new WsSubprovider({
rpcUrl: self.web3Endpoint, rpcUrl: self.web3Endpoint,
origin: this.blockchainConfig.wsOrigins.split(',')[0] origin: this.blockchainConfig.wsOrigins.split(',')[0]
})); }));
@ -38,7 +41,7 @@ class Provider {
// network connectivity error // network connectivity error
self.engine.on('error', (err) => { self.on('error', (err) => {
// report connectivity errors as trace due to polling // report connectivity errors as trace due to polling
self.logger.trace('web3 provider error: ', err); self.logger.trace('web3 provider error: ', err);
self.logger.trace('stopping web3 provider due to error'); self.logger.trace('stopping web3 provider due to error');
@ -47,8 +50,8 @@ class Provider {
self.engine.stop(); self.engine.stop();
}); });
self.engine.start();
self.web3.setProvider(self); self.web3.setProvider(self);
self.start();
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger); self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
self.addresses = []; self.addresses = [];
@ -87,10 +90,6 @@ class Provider {
}, callback); }, callback);
} }
stop() {
this.engine.stop();
}
eth_accounts(payload, cb) { eth_accounts(payload, cb) {
return cb(null, this.addresses); return cb(null, this.addresses);
} }
@ -106,11 +105,7 @@ class Provider {
callback(null, response); callback(null, response);
}); });
} }
this.engine.sendAsync.apply(this.engine, arguments); super.sendAsync(payload, callback);
}
send() {
return this.engine.send.apply(this.engine, arguments);
} }
} }