fix webserver errors

This commit is contained in:
Jonathan Rainville 2018-07-06 14:43:01 -04:00 committed by Iuri Matias
parent 5bfd9d2dae
commit 2cd0c5518a

View File

@ -28,6 +28,7 @@ class Provider {
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, self.logger);
self.addresses = [];
if (!self.accounts.length) {
return callback();
}
@ -35,32 +36,35 @@ class Provider {
self.addresses.push(account.address);
self.web3.eth.accounts.wallet.add(account);
});
self.web3.eth.defaultAccount = self.addresses[0];
const realAccountFunction = self.web3.eth.getAccounts;
self.web3.eth.getAccounts = function (cb) {
cb = cb || function () {};
return new Promise((resolve, reject) => {
realAccountFunction((err, accounts) => {
const realSend = self.provider.send.bind(self.provider);
self.provider.send = function (payload, cb) {
if (payload.method === 'eth_accounts') {
return realSend(payload, function (err, result) {
if (err) {
cb(err);
return reject(err);
return cb(err);
}
// console.log('ACOUNTS', accounts);
// console.log('My addresses', self.addresses);
// accounts = self.addresses;
accounts = [accounts[0]].concat(self.addresses);
// accounts = accounts.concat(self.addresses);
// accounts = self.addresses.concat(accounts);
cb(null, accounts);
resolve(accounts);
result.result = result.result.concat(self.addresses);
cb(null, result);
});
});
}
realSend(payload, cb);
};
callback();
}
stop() {
if (this.provider && this.provider.removeAllListeners) {
this.provider.removeAllListeners('connect');
this.provider.removeAllListeners('error');
this.provider.removeAllListeners('end');
this.provider.removeAllListeners('data');
this.provider.responseCallbacks = {};
this.provider = null;
}
}
fundAccounts(callback) {
const self = this;
if (!self.accounts.length) {