@otoplo/wallet-common 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,275 +1,323 @@
1
- import type { RequestResponse } from "@otoplo/electrum-client";
2
- import { ConnectionStatus, ElectrumClient, TransportScheme } from "@otoplo/electrum-client";
3
- import type { BlockTip, IFirstUse, IListUnspentRecord, ITemplateScript, ITokensBalance, ITokenUtxo, ITransaction, ITXHistory, IUtxo, RostrumParams, ServerFeatures } from "../types/rostrum.types";
4
- import type { Balance } from "../types/wallet.types";
5
- import { isTestnet } from "../utils/common";
6
- import type { WalletDB } from "../persistence";
7
-
8
- type RPCParameter = object | string | number | boolean | null;
9
- type PagedResult = { cursor?: string | null; [key: string]: unknown };
10
-
11
- export type RostrumEvent =
12
- | { type: 'connected' }
13
- | { type: 'disconnected' };
14
-
15
- export type RostrumUpdateCallback = (event: RostrumEvent) => void;
16
-
17
- export class RostrumService {
18
-
19
- private readonly walletDb: WalletDB;
20
-
21
- private client?: ElectrumClient;
22
-
23
- private updateCallback?: RostrumUpdateCallback;
24
-
25
- public constructor(walletDb: WalletDB) {
26
- this.walletDb = walletDb;
27
- }
28
-
29
- public onUpdate(callback: RostrumUpdateCallback): void {
30
- this.updateCallback = callback;
31
- }
32
-
33
- private notify(event: RostrumEvent): void {
34
- this.updateCallback?.(event);
35
- }
36
-
37
- public isConnected(): boolean {
38
- return this.client?.status === ConnectionStatus.CONNECTED;
39
- }
40
-
41
- public getFeatures(): Promise<ServerFeatures> {
42
- return this.execute<ServerFeatures>('server.features');
43
- }
44
-
45
- public getBlockTip(): Promise<BlockTip> {
46
- return this.execute<BlockTip>('blockchain.headers.tip');
47
- }
48
-
49
- public async getBalance(address: string): Promise<Balance> {
50
- const balance = await this.execute<Balance>('blockchain.address.get_balance', address, 'exclude_tokens');
51
- return { confirmed: BigInt(balance.confirmed).toString(), unconfirmed: BigInt(balance.unconfirmed).toString() };
52
- }
53
-
54
- public getTransactionsHistory(address: string, fromHeight = 0): Promise<ITXHistory[]> {
55
- return this.paginate<ITXHistory>('blockchain.address.get_history', 'history', cursor =>
56
- [address, { from_height: fromHeight }, cursor]
57
- );
58
- }
59
-
60
- public listTemplateScripts(template: string, constraint: string | null = null): Promise<ITemplateScript[]> {
61
- return this.paginate<ITemplateScript>('blockchain.script.list_template', 'scripts', cursor =>
62
- [template, constraint, cursor]
63
- );
64
- }
65
-
66
- public getFirstUse(address: string): Promise<IFirstUse> {
67
- return this.execute<IFirstUse>('blockchain.address.get_first_use', address);
68
- }
69
-
70
- public async isAddressUsed(address: string): Promise<boolean> {
71
- try {
72
- const firstUse = await this.getFirstUse(address);
73
- return !!(firstUse.tx_hash && firstUse.tx_hash !== "");
74
- } catch (e) {
75
- if (e instanceof Error && e.message.includes("not found")) {
76
- return false;
77
- }
78
- throw e;
79
- }
80
- }
81
-
82
- public getTransaction(id: string, verbose = true): Promise<ITransaction> {
83
- return this.execute<ITransaction>('blockchain.transaction.get', id, verbose);
84
- }
85
-
86
- public getUtxo(outpoint: string): Promise<IUtxo> {
87
- return this.execute<IUtxo>('blockchain.utxo.get', outpoint);
88
- }
89
-
90
- public getNexaUtxos(address: string): Promise<IListUnspentRecord[]> {
91
- return this.paginate<IListUnspentRecord>('blockchain.address.listunspent', 'unspent', cursor =>
92
- [address, 'exclude_tokens', cursor]
93
- );
94
- }
95
-
96
- public getTokenUtxos(address: string, token: string): Promise<ITokenUtxo[]> {
97
- return this.paginate<ITokenUtxo>('token.address.listunspent', 'unspent', cursor =>
98
- [address, cursor, token]
99
- );
100
- }
101
-
102
- public async getTokensBalance(address: string): Promise<Record<string, Balance>> {
103
- const tokensBalance = await this.execute<ITokensBalance>('token.address.get_balance', address);
104
- const balance: Record<string, Balance> = {};
105
-
106
- for (const cToken in tokensBalance.confirmed) {
107
- if (tokensBalance.confirmed[cToken] != 0) {
108
- balance[cToken] = { confirmed: BigInt(tokensBalance.confirmed[cToken]).toString(), unconfirmed: "0" }
109
- }
110
- }
111
-
112
- for (const uToken in tokensBalance.unconfirmed) {
113
- if (tokensBalance.unconfirmed[uToken] != 0) {
114
- if (balance[uToken]) {
115
- balance[uToken].unconfirmed = BigInt(tokensBalance.unconfirmed[uToken]).toString();
116
- } else {
117
- balance[uToken] = { confirmed: "0", unconfirmed: BigInt(tokensBalance.unconfirmed[uToken]).toString() }
118
- }
119
- }
120
- }
121
-
122
- return balance;
123
- }
124
-
125
- public broadcast(txHex: string): Promise<string> {
126
- return this.execute<string>('blockchain.transaction.broadcast', txHex);
127
- }
128
-
129
- public subscribeHeaders(handler: (block: number) => void): Promise<RequestResponse> {
130
- return this.client!.subscribe(([header]) => {
131
- const height = (header as BlockTip | null)?.height;
132
- handler(typeof height === 'number' ? height : 0);
133
- }, 'blockchain.headers.subscribe');
134
- }
135
-
136
- public subscribeAddress(address: string, handler: (address: string, status: string | null) => void): Promise<RequestResponse> {
137
- return this.client!.subscribe(([addr, status]) => handler(addr as string, status as string | null), 'blockchain.address.subscribe', address);
138
- }
139
-
140
- public async getLatency(): Promise<number> {
141
- try {
142
- const start = Date.now();
143
- const res = await this.getBlockTip();
144
- if (res) {
145
- return Date.now() - start;
146
- }
147
- return 0;
148
- } catch {
149
- return 0;
150
- }
151
- }
152
-
153
- public async connect(params?: RostrumParams): Promise<void> {
154
- try {
155
- await this.disconnect();
156
-
157
- if (!params) {
158
- params = await this.getCurrentInstance();
159
- }
160
-
161
- this.client = new ElectrumClient({
162
- application: "com.otoplo.wallet",
163
- version: "1.4.3",
164
- host: params.host,
165
- port: params.port,
166
- scheme: params.scheme,
167
- });
168
- this.client.on('connected', () => this.notify({ type: 'connected' }));
169
- this.client.on('disconnected', () => this.notify({ type: 'disconnected' }));
170
- await this.client.connect();
171
- } catch (e) {
172
- if (e instanceof Error) {
173
- console.info(e.message);
174
- } else {
175
- console.error(e);
176
- }
177
- throw e;
178
- }
179
- }
180
-
181
- public async disconnect(): Promise<void> {
182
- await this.client?.disconnect();
183
- }
184
-
185
- /**
186
- * Walk a cursor-paginated rostrum query: start with "start" and follow the returned cursor until it is null.
187
- * If the cursor expires mid-walk (e.g. reorg / mempool change), the walk is restarted from the beginning.
188
- */
189
- private async paginate<T>(method: string, key: string, buildParams: (cursor: string) => RPCParameter[], maxRestarts = 3): Promise<T[]> {
190
- for (let attempt = 0; ; attempt++) {
191
- try {
192
- const results: T[] = [];
193
- let cursor: string | null = 'start';
194
- while (cursor) {
195
- const page: PagedResult = await this.execute<PagedResult>(method, ...buildParams(cursor));
196
- results.push(...((page[key] as T[] | undefined) ?? []));
197
- cursor = page.cursor ?? null;
198
- }
199
- return results;
200
- } catch (e) {
201
- if (attempt < maxRestarts && e instanceof Error && e.message.includes('cursor expired')) {
202
- continue;
203
- }
204
- throw e;
205
- }
206
- }
207
- }
208
-
209
- private async execute<T>(method: string, ...parameters: RPCParameter[]): Promise<T> {
210
- await this.waitForConnection();
211
- return this.client!.request<T>(method, ...parameters);
212
- }
213
-
214
- private waitForConnection(timeout = 5000): Promise<void> {
215
- const start = Date.now();
216
-
217
- return new Promise((resolve, reject) => {
218
- const check = (): void => {
219
- if (this.isConnected()) {
220
- return resolve();
221
- }
222
- if (Date.now() - start > timeout) {
223
- return reject(new Error("Rostrum Connection timeout"));
224
- }
225
- setTimeout(check, 250);
226
- };
227
-
228
- check();
229
- });
230
- }
231
-
232
- public setCurrentInstance(params: RostrumParams): Promise<void> {
233
- return this.walletDb.saveSetting("rostrum-params", JSON.stringify(params));
234
- }
235
-
236
- public resetCurrentInstance(): Promise<void> {
237
- return this.walletDb.removeSetting("rostrum-params");
238
- }
239
-
240
- public async getCurrentInstance(): Promise<RostrumParams> {
241
- const params = await this.walletDb.getSetting("rostrum-params");
242
- if (params) {
243
- return JSON.parse(params);
244
- }
245
- return RostrumService.getPredefinedInstances()[0];
246
- }
247
-
248
- public static getPredefinedInstances(): RostrumParams[] {
249
- if (isTestnet()) {
250
- return [
251
- {
252
- scheme: TransportScheme.WSS,
253
- host: 'testnet-electrum.nexa.org',
254
- port: 30004,
255
- label: 'NexaOrg'
256
- }
257
- ];
258
- } else {
259
- return [
260
- {
261
- scheme: TransportScheme.WSS,
262
- host: 'rostrum.otoplo.com',
263
- port: 443,
264
- label: 'Otoplo'
265
- },
266
- {
267
- scheme: TransportScheme.WSS,
268
- host: 'electrum.nexa.org',
269
- port: 20004,
270
- label: 'NexaOrg'
271
- }
272
- ];
273
- }
274
- }
1
+ import type { RequestResponse } from "@otoplo/electrum-client";
2
+ import { ConnectionStatus, ElectrumClient, TransportScheme } from "@otoplo/electrum-client";
3
+ import type { BlockTip, IFirstUse, IListUnspentRecord, ITemplateScript, ITokensBalance, ITokenUtxo, ITransaction, ITXHistory, IUtxo, RostrumInstanceCheck, RostrumParams, ServerFeatures } from "../types/rostrum.types";
4
+ import type { Balance } from "../types/wallet.types";
5
+ import { isGenesisHashValid, isTestnet } from "../utils/common";
6
+ import type { WalletDB } from "../persistence";
7
+
8
+ type RPCParameter = object | string | number | boolean | null;
9
+ type PagedResult = { cursor?: string | null; [key: string]: unknown };
10
+
11
+ export type RostrumEvent =
12
+ | { type: 'connected' }
13
+ | { type: 'disconnected' };
14
+
15
+ export type RostrumUpdateCallback = (event: RostrumEvent) => void;
16
+
17
+ export class RostrumService {
18
+
19
+ private readonly walletDb: WalletDB;
20
+
21
+ private client?: ElectrumClient;
22
+
23
+ /** The server `client` connects to. */
24
+ private params?: RostrumParams;
25
+
26
+ private updateCallback?: RostrumUpdateCallback;
27
+
28
+ public constructor(walletDb: WalletDB) {
29
+ this.walletDb = walletDb;
30
+ }
31
+
32
+ public onUpdate(callback: RostrumUpdateCallback): void {
33
+ this.updateCallback = callback;
34
+ }
35
+
36
+ private notify(event: RostrumEvent): void {
37
+ this.updateCallback?.(event);
38
+ }
39
+
40
+ public isConnected(): boolean {
41
+ return this.client?.status === ConnectionStatus.CONNECTED;
42
+ }
43
+
44
+ public getFeatures(): Promise<ServerFeatures> {
45
+ return this.execute<ServerFeatures>('server.features');
46
+ }
47
+
48
+ public getBlockTip(): Promise<BlockTip> {
49
+ return this.execute<BlockTip>('blockchain.headers.tip');
50
+ }
51
+
52
+ public async getBalance(address: string): Promise<Balance> {
53
+ const balance = await this.execute<Balance>('blockchain.address.get_balance', address, 'exclude_tokens');
54
+ return { confirmed: BigInt(balance.confirmed).toString(), unconfirmed: BigInt(balance.unconfirmed).toString() };
55
+ }
56
+
57
+ public getTransactionsHistory(address: string, fromHeight = 0): Promise<ITXHistory[]> {
58
+ return this.paginate<ITXHistory>('blockchain.address.get_history', 'history', cursor =>
59
+ [address, { from_height: fromHeight }, cursor]
60
+ );
61
+ }
62
+
63
+ public listTemplateScripts(template: string, constraint: string | null = null): Promise<ITemplateScript[]> {
64
+ return this.paginate<ITemplateScript>('blockchain.script.list_template', 'scripts', cursor =>
65
+ [template, constraint, cursor]
66
+ );
67
+ }
68
+
69
+ public getFirstUse(address: string): Promise<IFirstUse> {
70
+ return this.execute<IFirstUse>('blockchain.address.get_first_use', address);
71
+ }
72
+
73
+ public async isAddressUsed(address: string): Promise<boolean> {
74
+ try {
75
+ const firstUse = await this.getFirstUse(address);
76
+ return !!(firstUse.tx_hash && firstUse.tx_hash !== "");
77
+ } catch (e) {
78
+ if (e instanceof Error && e.message.includes("not found")) {
79
+ return false;
80
+ }
81
+ throw e;
82
+ }
83
+ }
84
+
85
+ public getTransaction(id: string, verbose = true): Promise<ITransaction> {
86
+ return this.execute<ITransaction>('blockchain.transaction.get', id, verbose);
87
+ }
88
+
89
+ public getUtxo(outpoint: string): Promise<IUtxo> {
90
+ return this.execute<IUtxo>('blockchain.utxo.get', outpoint);
91
+ }
92
+
93
+ public getNexaUtxos(address: string): Promise<IListUnspentRecord[]> {
94
+ return this.paginate<IListUnspentRecord>('blockchain.address.listunspent', 'unspent', cursor =>
95
+ [address, 'exclude_tokens', cursor]
96
+ );
97
+ }
98
+
99
+ public getTokenUtxos(address: string, token: string): Promise<ITokenUtxo[]> {
100
+ return this.paginate<ITokenUtxo>('token.address.listunspent', 'unspent', cursor =>
101
+ [address, cursor, token]
102
+ );
103
+ }
104
+
105
+ public async getTokensBalance(address: string): Promise<Record<string, Balance>> {
106
+ const tokensBalance = await this.execute<ITokensBalance>('token.address.get_balance', address);
107
+ const balance: Record<string, Balance> = {};
108
+
109
+ for (const cToken in tokensBalance.confirmed) {
110
+ if (tokensBalance.confirmed[cToken] != 0) {
111
+ balance[cToken] = { confirmed: BigInt(tokensBalance.confirmed[cToken]).toString(), unconfirmed: "0" }
112
+ }
113
+ }
114
+
115
+ for (const uToken in tokensBalance.unconfirmed) {
116
+ if (tokensBalance.unconfirmed[uToken] != 0) {
117
+ if (balance[uToken]) {
118
+ balance[uToken].unconfirmed = BigInt(tokensBalance.unconfirmed[uToken]).toString();
119
+ } else {
120
+ balance[uToken] = { confirmed: "0", unconfirmed: BigInt(tokensBalance.unconfirmed[uToken]).toString() }
121
+ }
122
+ }
123
+ }
124
+
125
+ return balance;
126
+ }
127
+
128
+ public broadcast(txHex: string): Promise<string> {
129
+ return this.execute<string>('blockchain.transaction.broadcast', txHex);
130
+ }
131
+
132
+ public subscribeHeaders(handler: (block: number) => void): Promise<RequestResponse> {
133
+ return this.client!.subscribe(([header]) => {
134
+ const height = (header as BlockTip | null)?.height;
135
+ handler(typeof height === 'number' ? height : 0);
136
+ }, 'blockchain.headers.subscribe');
137
+ }
138
+
139
+ public subscribeAddress(address: string, handler: (address: string, status: string | null) => void): Promise<RequestResponse> {
140
+ return this.client!.subscribe(([addr, status]) => handler(addr as string, status as string | null), 'blockchain.address.subscribe', address);
141
+ }
142
+
143
+ public async getLatency(): Promise<number> {
144
+ try {
145
+ const start = Date.now();
146
+ const res = await this.getBlockTip();
147
+ if (res) {
148
+ return Date.now() - start;
149
+ }
150
+ return 0;
151
+ } catch {
152
+ return 0;
153
+ }
154
+ }
155
+
156
+ public async connect(params?: RostrumParams): Promise<void> {
157
+ try {
158
+ await this.disconnect();
159
+
160
+ if (!params) {
161
+ params = await this.getCurrentInstance();
162
+ }
163
+ this.params = params;
164
+
165
+ this.client = new ElectrumClient({
166
+ application: "com.otoplo.wallet",
167
+ version: "1.4.3",
168
+ host: params.host,
169
+ port: params.port,
170
+ scheme: params.scheme,
171
+ });
172
+ this.client.on('connected', () => this.notify({ type: 'connected' }));
173
+ this.client.on('disconnected', () => this.notify({ type: 'disconnected' }));
174
+ await this.client.connect();
175
+ } catch (e) {
176
+ if (e instanceof Error) {
177
+ console.info(e.message);
178
+ } else {
179
+ console.error(e);
180
+ }
181
+ throw e;
182
+ }
183
+ }
184
+
185
+ public async disconnect(): Promise<void> {
186
+ await this.client?.disconnect();
187
+ }
188
+
189
+ /**
190
+ * Checks whether the wallet can use a server (e.g. before switching to it): that it's reachable, on the wallet's
191
+ * network and indexes scripts. Never throws.
192
+ *
193
+ * The server this service is connected to answers on its connection; any other one is checked on a temporary
194
+ * connection, closed after.
195
+ */
196
+ public async checkInstance(params: RostrumParams): Promise<RostrumInstanceCheck> {
197
+ if (this.isConnected() && this.params && RostrumService.isSameInstance(this.params, params)) {
198
+ return this.check();
199
+ }
200
+
201
+ const probe = new RostrumService(this.walletDb);
202
+ try {
203
+ await probe.connect(params);
204
+ return await probe.check();
205
+ } catch {
206
+ return { status: 'offline' };
207
+ } finally {
208
+ await probe.disconnect();
209
+ }
210
+ }
211
+
212
+ private async check(): Promise<RostrumInstanceCheck> {
213
+ try {
214
+ const features = await this.getFeatures();
215
+ if (!isGenesisHashValid(features.genesis_hash)) {
216
+ return { status: 'wrong_network' };
217
+ }
218
+ if (!features.script_index) {
219
+ return { status: 'unsupported' };
220
+ }
221
+ const latency = await this.getLatency();
222
+ return latency ? { status: 'online', latency } : { status: 'offline' };
223
+ } catch {
224
+ return { status: 'offline' };
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Walk a cursor-paginated rostrum query: start with "start" and follow the returned cursor until it is null.
230
+ * If the cursor expires mid-walk (e.g. reorg / mempool change), the walk is restarted from the beginning.
231
+ */
232
+ private async paginate<T>(method: string, key: string, buildParams: (cursor: string) => RPCParameter[], maxRestarts = 3): Promise<T[]> {
233
+ for (let attempt = 0; ; attempt++) {
234
+ try {
235
+ const results: T[] = [];
236
+ let cursor: string | null = 'start';
237
+ while (cursor) {
238
+ const page: PagedResult = await this.execute<PagedResult>(method, ...buildParams(cursor));
239
+ results.push(...((page[key] as T[] | undefined) ?? []));
240
+ cursor = page.cursor ?? null;
241
+ }
242
+ return results;
243
+ } catch (e) {
244
+ if (attempt < maxRestarts && e instanceof Error && e.message.includes('cursor expired')) {
245
+ continue;
246
+ }
247
+ throw e;
248
+ }
249
+ }
250
+ }
251
+
252
+ private async execute<T>(method: string, ...parameters: RPCParameter[]): Promise<T> {
253
+ await this.waitForConnection();
254
+ return this.client!.request<T>(method, ...parameters);
255
+ }
256
+
257
+ private waitForConnection(timeout = 5000): Promise<void> {
258
+ const start = Date.now();
259
+
260
+ return new Promise((resolve, reject) => {
261
+ const check = (): void => {
262
+ if (this.isConnected()) {
263
+ return resolve();
264
+ }
265
+ if (Date.now() - start > timeout) {
266
+ return reject(new Error("Rostrum Connection timeout"));
267
+ }
268
+ setTimeout(check, 250);
269
+ };
270
+
271
+ check();
272
+ });
273
+ }
274
+
275
+ public setCurrentInstance(params: RostrumParams): Promise<void> {
276
+ return this.walletDb.saveSetting("rostrum-params", JSON.stringify(params));
277
+ }
278
+
279
+ public resetCurrentInstance(): Promise<void> {
280
+ return this.walletDb.removeSetting("rostrum-params");
281
+ }
282
+
283
+ public async getCurrentInstance(): Promise<RostrumParams> {
284
+ const params = await this.walletDb.getSetting("rostrum-params");
285
+ if (params) {
286
+ return JSON.parse(params);
287
+ }
288
+ return RostrumService.getPredefinedInstances()[0];
289
+ }
290
+
291
+ /** Whether both point to the same server (the label aside). */
292
+ public static isSameInstance(a: RostrumParams, b: RostrumParams): boolean {
293
+ return a.scheme === b.scheme && a.host.toLowerCase() === b.host.toLowerCase() && a.port === b.port;
294
+ }
295
+
296
+ public static getPredefinedInstances(): RostrumParams[] {
297
+ if (isTestnet()) {
298
+ return [
299
+ {
300
+ scheme: TransportScheme.WSS,
301
+ host: 'testnet-electrum.nexa.org',
302
+ port: 30004,
303
+ label: 'NexaOrg'
304
+ }
305
+ ];
306
+ } else {
307
+ return [
308
+ {
309
+ scheme: TransportScheme.WSS,
310
+ host: 'rostrum.otoplo.com',
311
+ port: 443,
312
+ label: 'Otoplo'
313
+ },
314
+ {
315
+ scheme: TransportScheme.WSS,
316
+ host: 'electrum.nexa.org',
317
+ port: 20004,
318
+ label: 'NexaOrg'
319
+ }
320
+ ];
321
+ }
322
+ }
275
323
  }
@@ -3,7 +3,7 @@ import { Address, AddressType, Transaction, TransactionBuilder, UnitUtils } from
3
3
  import type { KeyManager } from "./key";
4
4
  import type { RostrumService } from "./rostrum";
5
5
  import type { AssetMovement, TransactionDTO, TransactionType } from "../types/db.types";
6
- import { currentTimestamp, isNullOrEmpty, isValidNexaAddress, MAX_INT64, tokenAmountToAssetAmount, tokenIdToHex } from "../utils/common";
6
+ import { balanceTotal, currentTimestamp, isNullOrEmpty, isValidNexaAddress, MAX_INT64, tokenAmountToAssetAmount, tokenIdToHex } from "../utils/common";
7
7
  import { VAULT_FIRST_BLOCK } from "../utils/vault";
8
8
  import type { WalletDB } from "../persistence/wallet-db";
9
9
  import type { ITXHistory } from "../types/rostrum.types";
@@ -226,7 +226,7 @@ export class TransactionService {
226
226
  }
227
227
 
228
228
  private async populateNexaInputsAndChange(txBuilder: TransactionBuilder, from: AddressKey[], toChange: string, options: TxOptions): Promise<Map<string, PrivateKey>> {
229
- const allKeys = from.filter(k => BigInt(k.balance.confirmed) + BigInt(k.balance.unconfirmed) > 0n);
229
+ const allKeys = from.filter(k => balanceTotal(k.balance) > 0n);
230
230
  if (isNullOrEmpty(allKeys)) {
231
231
  throw new Error("Not enough Nexa balance.");
232
232
  }
@@ -144,14 +144,18 @@ export class WalletManager {
144
144
  }));
145
145
  }
146
146
 
147
+ /**
148
+ * Switches to another server (or reconnects to the current one without `params`): saves it, disconnects, then
149
+ * connects with `connect()`, retrying until it does. Check the server first with `RostrumService.checkInstance()`.
150
+ *
151
+ * @returns resolves like `connect()`: once connected and synced, or when stopped by `disconnectRostrum()`.
152
+ */
147
153
  public async reloadRostrum(params?: RostrumParams): Promise<void> {
148
154
  if (params) {
149
155
  await this.rostrumService.setCurrentInstance(params);
150
156
  }
151
157
  await this.disconnectRostrum();
152
- await this.initRostrum();
153
- this.startUpdates();
154
- await this.subscribeAllAddresses();
158
+ return this.connect();
155
159
  }
156
160
 
157
161
  public async initRostrum(): Promise<void> {