@spirobel/monero-wallet-api 0.6.2 → 0.6.4
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.
|
@@ -245,8 +245,13 @@ export class ActionLogOpened {
|
|
|
245
245
|
}
|
|
246
246
|
case "worker.changeNodeUrlAndStartHeight": {
|
|
247
247
|
const p = env.payload;
|
|
248
|
-
|
|
249
|
-
|
|
248
|
+
try {
|
|
249
|
+
await this.mco?.changeNodeUrlAndStartHeight(p?.node_url, p?.start_height);
|
|
250
|
+
return {};
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
return { error: err instanceof Error ? err.message : String(err) };
|
|
254
|
+
}
|
|
250
255
|
}
|
|
251
256
|
case "worker.buildWallets":
|
|
252
257
|
await this.mco?.buildWallets();
|
|
@@ -173,14 +173,19 @@ export class ScanCacheOpened {
|
|
|
173
173
|
return this._scanSettings.logs_exclude;
|
|
174
174
|
}
|
|
175
175
|
async changeNodeUrlAndStartHeight(node_url, start_height) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
await this.
|
|
179
|
-
this.node_url = node_url;
|
|
176
|
+
// stop first so a live worker cannot write the old file over the new url.
|
|
177
|
+
try {
|
|
178
|
+
await this.stopWorker();
|
|
180
179
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
catch {
|
|
181
|
+
// stop can fail. still write the new url.
|
|
182
|
+
}
|
|
183
|
+
if (node_url !== undefined || start_height !== undefined) {
|
|
184
|
+
await this._scanSettings.setNodeUrlAndStartHeight(node_url, start_height);
|
|
185
|
+
if (node_url !== undefined)
|
|
186
|
+
this.node_url = node_url;
|
|
187
|
+
if (start_height !== undefined)
|
|
188
|
+
this._start_height = start_height;
|
|
184
189
|
}
|
|
185
190
|
await this.unpause();
|
|
186
191
|
}
|
|
@@ -751,7 +756,11 @@ export class ScanCacheOpened {
|
|
|
751
756
|
delete this.worker;
|
|
752
757
|
// drain coordinator first, then hard kill workers
|
|
753
758
|
try {
|
|
754
|
-
|
|
759
|
+
// shutdown already races 5s. this race still returns if that promise never settles.
|
|
760
|
+
await Promise.race([
|
|
761
|
+
worker.shutdown(),
|
|
762
|
+
new Promise((resolve) => setTimeout(resolve, 5000)),
|
|
763
|
+
]);
|
|
755
764
|
}
|
|
756
765
|
catch {
|
|
757
766
|
// still terminate below
|
|
@@ -925,17 +934,25 @@ export class ManyScanCachesOpened {
|
|
|
925
934
|
}
|
|
926
935
|
async changeNodeUrlAndStartHeight(node_url, start_height) {
|
|
927
936
|
if (this.actionLogOpened.extensionMessageBus === "ui") {
|
|
928
|
-
|
|
937
|
+
// the background owns the worker. it stops, then writes. do not write here first.
|
|
938
|
+
const result = await sendToBackground("worker.changeNodeUrlAndStartHeight", {
|
|
929
939
|
node_url,
|
|
930
940
|
start_height,
|
|
931
|
-
})
|
|
941
|
+
});
|
|
942
|
+
if (result &&
|
|
943
|
+
typeof result === "object" &&
|
|
944
|
+
"error" in result &&
|
|
945
|
+
result.error) {
|
|
946
|
+
throw new Error(String(result.error));
|
|
947
|
+
}
|
|
948
|
+
if (result == null)
|
|
949
|
+
throw new Error("background did not save the node url");
|
|
932
950
|
return;
|
|
933
951
|
}
|
|
934
952
|
if (this.wallets.length === 0) {
|
|
935
|
-
if (node_url !== undefined)
|
|
936
|
-
await this._scanSettings.
|
|
937
|
-
|
|
938
|
-
await this._scanSettings.setStartHeight(start_height);
|
|
953
|
+
if (node_url !== undefined || start_height !== undefined) {
|
|
954
|
+
await this._scanSettings.setNodeUrlAndStartHeight(node_url, start_height);
|
|
955
|
+
}
|
|
939
956
|
return;
|
|
940
957
|
}
|
|
941
958
|
await this.wallets[0].changeNodeUrlAndStartHeight(node_url, start_height);
|
|
@@ -20,6 +20,7 @@ export declare class ScanSettingsOpened {
|
|
|
20
20
|
get pathPrefix(): string;
|
|
21
21
|
setNodeUrl(node_url: string): Promise<void>;
|
|
22
22
|
setStartHeight(start_height: number | null): Promise<void>;
|
|
23
|
+
setNodeUrlAndStartHeight(node_url?: string, start_height?: number | null): Promise<void>;
|
|
23
24
|
setMerchantConfirmations(merchant_confirmations: number | undefined | null): Promise<void>;
|
|
24
25
|
setCpuWorkerCount(cpu_worker_count: number | undefined | null): Promise<void>;
|
|
25
26
|
setLogSettings(logs?: LogSetting | null, logs_include?: PossibleLogs[] | null, logs_exclude?: PossibleLogs[] | null): Promise<void>;
|
|
@@ -54,14 +54,21 @@ export class ScanSettingsOpened {
|
|
|
54
54
|
return this._pathPrefix;
|
|
55
55
|
}
|
|
56
56
|
async setNodeUrl(node_url) {
|
|
57
|
-
await this.
|
|
58
|
-
this._settings.node_url = ScanSettingsOpened._validateNodeUrl(node_url);
|
|
59
|
-
await this._persist();
|
|
57
|
+
await this.setNodeUrlAndStartHeight(node_url, undefined);
|
|
60
58
|
}
|
|
61
59
|
async setStartHeight(start_height) {
|
|
60
|
+
await this.setNodeUrlAndStartHeight(undefined, start_height);
|
|
61
|
+
}
|
|
62
|
+
// one read and one write. a second reload must not put the old url back.
|
|
63
|
+
async setNodeUrlAndStartHeight(node_url, start_height) {
|
|
62
64
|
await this.reload();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
if (node_url !== undefined) {
|
|
66
|
+
this._settings.node_url = ScanSettingsOpened._validateNodeUrl(node_url);
|
|
67
|
+
}
|
|
68
|
+
if (start_height !== undefined) {
|
|
69
|
+
ScanSettingsOpened._validateStartHeight(start_height);
|
|
70
|
+
this._settings.start_height = start_height;
|
|
71
|
+
}
|
|
65
72
|
await this._persist();
|
|
66
73
|
}
|
|
67
74
|
async setMerchantConfirmations(merchant_confirmations) {
|