add wallet and clean up

This commit is contained in:
Jonathan Rainville 2018-05-14 12:08:03 -04:00
parent 39ede07cdb
commit 37ca90ad9b
2 changed files with 1222 additions and 144 deletions

View File

@ -11,6 +11,8 @@ class Provider {
this.accountsConfig = options.accountsConfig; this.accountsConfig = options.accountsConfig;
this.logger = options.logger; this.logger = options.logger;
this.engine = new ProviderEngine(); this.engine = new ProviderEngine();
this.asyncMethods = {};
this.syncMethods = {};
this.engine.addProvider(new RpcSubprovider({ this.engine.addProvider(new RpcSubprovider({
rpcUrl: options.web3Endpoint rpcUrl: options.web3Endpoint
@ -36,6 +38,9 @@ class Provider {
}); });
if (this.accounts.length) { if (this.accounts.length) {
this.accounts.forEach(account => {
this.web3.eth.accounts.wallet.add(account);
});
this.asyncMethods = { this.asyncMethods = {
eth_accounts: self.eth_accounts.bind(this) eth_accounts: self.eth_accounts.bind(this)
}; };
@ -45,16 +50,10 @@ class Provider {
} }
} }
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 // network connectivity error
this.engine.on('error', function (err) { this.engine.on('error', (err) => {
// report connectivity errors // report connectivity errors
console.error(err.stack); this.logger.error(err.stack);
}); });
this.engine.start(); this.engine.start();
} }
@ -72,7 +71,7 @@ class Provider {
const addressIndex = accountConfig.addressIndex || 0; const addressIndex = accountConfig.addressIndex || 0;
const numAddresses = accountConfig.numAddresses || 1; const numAddresses = accountConfig.numAddresses || 1;
const wallet_hdpath = "m/44'/60'/0'/0/"; // TODO check if this can change const wallet_hdpath = accountConfig.hdpath || "m/44'/60'/0'/0/";
const accounts = []; const accounts = [];
for (let i = addressIndex; i < addressIndex + numAddresses; i++) { for (let i = addressIndex; i < addressIndex + numAddresses; i++) {
@ -96,7 +95,6 @@ class Provider {
} }
sendAsync(payload, callback) { sendAsync(payload, callback) {
// this.engine.sendAsync.apply(this.engine, arguments);
let method = this.asyncMethods[payload.method]; let method = this.asyncMethods[payload.method];
if (method) { if (method) {
return method.call(method, payload, (err, result) => { return method.call(method, payload, (err, result) => {

1348
package-lock.json generated

File diff suppressed because it is too large Load Diff