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