|
1 | 1 | 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'; |
3 | 3 |
|
4 | 4 | export class IndexerProvider { |
5 | 5 | private dns: BlockcoreDns; |
6 | | - private nameservers: DnsListEntry[] = []; |
7 | | - private services: ServiceListEntry[] = []; |
8 | | - private currentServices: ServiceListEntry[] = []; |
9 | 6 | private network = 'STRAX'; // Should we default to BTC? |
| 7 | + private currentServices: ServiceListEntry[] = []; |
10 | 8 |
|
11 | 9 | public constructor() { |
12 | | - this.dns = new BlockcoreDns(''); |
| 10 | + this.dns = new BlockcoreDns(); |
13 | 11 | } |
14 | 12 |
|
15 | 13 | setNetwork(network: string) { |
16 | 14 | this.network = network; |
17 | 15 | this.filterServices(); |
18 | 16 | } |
19 | 17 |
|
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); |
22 | 20 | } |
23 | 21 |
|
24 | 22 | /** Attempts to load the latest status of all services from all known nameservers. */ |
25 | 23 | 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(); |
46 | 25 | this.filterServices(); |
47 | 26 | } |
48 | 27 |
|
49 | | - getNameServers() { |
50 | | - return this.nameservers; |
51 | | - } |
52 | | - |
53 | | - async getIndexersByNetwork(network: string) { |
54 | | - return this.dns.getServicesByTypeAndNetwork('Indexer', network); |
55 | | - } |
56 | | - |
57 | 28 | on(event: string, callback: unknown) { |
58 | 29 | console.log(event, callback); |
59 | 30 | // "accountsChanged" |
|
0 commit comments