change init to async

This commit is contained in:
Richard Ramos 2020-02-15 09:22:22 -04:00
parent 0bfaf32228
commit f9c18af546
2 changed files with 44 additions and 32 deletions

View File

@ -39,8 +39,7 @@ export default class Subspace {
this.isWebsocketProvider = options.disableSubscriptions ? false : !!provider.on;
}
init() {
return new Promise(async resolve => {
async init() {
if (this.options.disableDatabase === true) {
this._db = new NullDatabase("", this.events);
} else {
@ -49,9 +48,7 @@ export default class Subspace {
this.eventSyncer = new EventSyncer(this.web3, this.events, this._db, this.isWebsocketProvider);
this.logSyncer = new LogSyncer(this.web3, this.events, this._db);
this.web3.net.getId().then(netId => {
this.networkId = netId;
});
this.networkId = await this.web3.net.getId();
const block = await this.web3.getBlock("latest");
@ -75,9 +72,6 @@ export default class Subspace {
this.options.callInterval = this.options.callInterval || 1000;
this._initCallInterval();
}
resolve();
});
}
contract(contractInstance) {

View File

@ -1,4 +1,5 @@
import createKeccakHash from "keccak";
import {map} from "rxjs/operators";
export function isAddress(address) {
return /^(0x)?[0-9a-fA-F]{40}$/i.test(address);
@ -24,3 +25,20 @@ export function toChecksumAddress(address) {
}
return ret;
}
export function mapFunc(observable) {
return prop => observable.pipe(
map(x => {
if (typeof prop === "string") {
return x[prop];
}
if (Array.isArray(prop)) {
let newValues = {};
prop.forEach(p => {
newValues[p] = x[p];
});
return newValues;
}
})
);
}