Skip to content

Commit

Permalink
Update IndexerProvider with changes from Blockcore DNS JS.
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Jul 23, 2022
1 parent 3518563 commit 4d7e8ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@
},
"dependencies": {
"@blockcore/coininfo": "^5.2.2",
"@blockcore/dns": "^0.0.7"
"@blockcore/dns": "^0.0.8"
}
}
41 changes: 6 additions & 35 deletions src/IndexerProvider.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,30 @@
import { Address, ChainListEntry, RichListEntry, Supply, WalletListEntry } from './types.js';
import { WebRequest, BlockcoreDns, DnsListEntry, ServiceListEntry } from '@blockcore/dns';
import { WebRequest, BlockcoreDns, ServiceListEntry } from '@blockcore/dns';

export class IndexerProvider {
private dns: BlockcoreDns;
private nameservers: DnsListEntry[] = [];
private services: ServiceListEntry[] = [];
private currentServices: ServiceListEntry[] = [];
private network = 'STRAX'; // Should we default to BTC?
private currentServices: ServiceListEntry[] = [];

public constructor() {
this.dns = new BlockcoreDns('');
this.dns = new BlockcoreDns();
}

setNetwork(network: string) {
this.network = network;
this.filterServices();
}

filterServices() {
this.currentServices = this.services.filter((s) => s.symbol === this.network && s.online === true);
private filterServices() {
this.currentServices = this.dns.getOnlineServicesByNetwork(this.network);
}

/** Attempts to load the latest status of all services from all known nameservers. */
async load() {
this.nameservers = await BlockcoreDns.getDnsServers();

const servicesMap = new Map();

for (let i = 0; i < this.nameservers.length; i++) {
const nameserver = this.nameservers[i];

if (!nameserver) {
continue;
}

this.dns.setActiveServer(nameserver.url);

const services = await this.dns.getServicesByType('Indexer');

services.forEach((item) => servicesMap.set(item.domain, { ...servicesMap.get(item.domain), ...item }));
}

this.services = Array.from(servicesMap.values());

await this.dns.load();
this.filterServices();
}

getNameServers() {
return this.nameservers;
}

async getIndexersByNetwork(network: string) {
return this.dns.getServicesByTypeAndNetwork('Indexer', network);
}

on(event: string, callback: unknown) {
console.log(event, callback);
// "accountsChanged"
Expand Down

0 comments on commit 4d7e8ee

Please sign in to comment.