Skip to content

Commit 4d7e8ee

Browse files
committed
Update IndexerProvider with changes from Blockcore DNS JS.
1 parent 3518563 commit 4d7e8ee

File tree

2 files changed

+7
-36
lines changed

2 files changed

+7
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@
6060
},
6161
"dependencies": {
6262
"@blockcore/coininfo": "^5.2.2",
63-
"@blockcore/dns": "^0.0.7"
63+
"@blockcore/dns": "^0.0.8"
6464
}
6565
}

src/IndexerProvider.ts

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,30 @@
11
import { Address, ChainListEntry, RichListEntry, Supply, WalletListEntry } from './types.js';
2-
import { WebRequest, BlockcoreDns, DnsListEntry, ServiceListEntry } from '@blockcore/dns';
2+
import { WebRequest, BlockcoreDns, ServiceListEntry } from '@blockcore/dns';
33

44
export class IndexerProvider {
55
private dns: BlockcoreDns;
6-
private nameservers: DnsListEntry[] = [];
7-
private services: ServiceListEntry[] = [];
8-
private currentServices: ServiceListEntry[] = [];
96
private network = 'STRAX'; // Should we default to BTC?
7+
private currentServices: ServiceListEntry[] = [];
108

119
public constructor() {
12-
this.dns = new BlockcoreDns('');
10+
this.dns = new BlockcoreDns();
1311
}
1412

1513
setNetwork(network: string) {
1614
this.network = network;
1715
this.filterServices();
1816
}
1917

20-
filterServices() {
21-
this.currentServices = this.services.filter((s) => s.symbol === this.network && s.online === true);
18+
private filterServices() {
19+
this.currentServices = this.dns.getOnlineServicesByNetwork(this.network);
2220
}
2321

2422
/** Attempts to load the latest status of all services from all known nameservers. */
2523
async load() {
26-
this.nameservers = await BlockcoreDns.getDnsServers();
27-
28-
const servicesMap = new Map();
29-
30-
for (let i = 0; i < this.nameservers.length; i++) {
31-
const nameserver = this.nameservers[i];
32-
33-
if (!nameserver) {
34-
continue;
35-
}
36-
37-
this.dns.setActiveServer(nameserver.url);
38-
39-
const services = await this.dns.getServicesByType('Indexer');
40-
41-
services.forEach((item) => servicesMap.set(item.domain, { ...servicesMap.get(item.domain), ...item }));
42-
}
43-
44-
this.services = Array.from(servicesMap.values());
45-
24+
await this.dns.load();
4625
this.filterServices();
4726
}
4827

49-
getNameServers() {
50-
return this.nameservers;
51-
}
52-
53-
async getIndexersByNetwork(network: string) {
54-
return this.dns.getServicesByTypeAndNetwork('Indexer', network);
55-
}
56-
5728
on(event: string, callback: unknown) {
5829
console.log(event, callback);
5930
// "accountsChanged"

0 commit comments

Comments
 (0)