@spirobel/monero-wallet-api 0.3.3 → 0.3.5

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,7 +1,12 @@
1
1
  import { sleep } from "../../io/sleep";
2
2
  import { scanWallets } from "../backgroundWorker";
3
3
  while (true) {
4
- await scanWallets((x) => self.postMessage({ type: "RESULT", payload: x }), undefined, scan_settings_path, pathPrefix);
5
- console.log("no wallets found to scan in wallet settings, trying again in 1 second");
6
- await sleep(1000);
4
+ try {
5
+ await scanWallets((x) => self.postMessage({ type: "RESULT", payload: x }), undefined, scan_settings_path, pathPrefix);
6
+ console.log("no wallets found to scan in wallet settings, trying again in 1 second");
7
+ await sleep(1000);
8
+ }
9
+ catch (error) {
10
+ self.postMessage({ type: "ERROR", payload: error });
11
+ }
7
12
  }
@@ -127,51 +127,51 @@ export class ViewPair extends WasmProcessor {
127
127
  * scan
128
128
  */
129
129
  async scan(cacheChanged = (params) => console.log(params), stopSync, scan_settings_path, pathPrefix) {
130
- const processor = this;
131
- const nonHaltedWallets = await openNonHaltedWallets(scan_settings_path);
132
- const masterWalletSettings = nonHaltedWallets[0];
133
- if (masterWalletSettings.primary_address !== this.primary_address)
134
- throw new Error("master wallet should be the first of the non halted wallets");
135
- let masterStartHeight = await cullTooLargeScanHeight(processor.node_url, scan_settings_path);
136
- let current_range = await initScanCache(processor, masterStartHeight, scan_settings_path, pathPrefix);
137
- const blockGenerator = (async function* () {
138
- while (true) {
139
- if (stopSync?.aborted)
140
- return;
141
- const firstResponse = await processor.getBlocksBinExecuteRequest({ block_ids: current_range.block_hashes.map((b) => b.block_hash) }, stopSync);
142
- await readWriteConnectionStatusFile((cs) => {
143
- if (cs?.last_packet.status === "catastrophic_reorg")
130
+ try {
131
+ const processor = this;
132
+ const nonHaltedWallets = await openNonHaltedWallets(scan_settings_path);
133
+ const masterWalletSettings = nonHaltedWallets[0];
134
+ if (masterWalletSettings.primary_address !== this.primary_address)
135
+ throw new Error("master wallet should be the first of the non halted wallets");
136
+ let masterStartHeight = await cullTooLargeScanHeight(processor.node_url, scan_settings_path);
137
+ let current_range = await initScanCache(processor, masterStartHeight, scan_settings_path, pathPrefix);
138
+ const blockGenerator = (async function* () {
139
+ while (true) {
140
+ if (stopSync?.aborted)
144
141
  return;
145
- const connectionStatus = {
146
- last_packet: {
147
- status: "OK",
148
- bytes_read: firstResponse.length,
149
- node_url: processor.node_url,
150
- timestamp: new Date().toISOString(),
151
- },
152
- };
153
- return connectionStatus;
154
- });
155
- yield firstResponse;
156
- }
157
- })();
158
- const masterWithKeys = await walletSettingsPlusKeys(masterWalletSettings);
159
- const slaveViewPairs = [];
160
- if (nonHaltedWallets.length > 1) {
161
- for (const slaveWallet of nonHaltedWallets.slice(1)) {
162
- const slaveWithKeys = await walletSettingsPlusKeys(slaveWallet);
163
- const viewpair = await ViewPair.create(slaveWallet.primary_address, slaveWithKeys.secret_view_key, slaveWallet.subaddress_index, masterWalletSettings.node_url);
164
- slaveViewPairs.push({
165
- viewpair,
166
- current_range: await initScanCache(viewpair, masterStartHeight, scan_settings_path, pathPrefix),
167
- secret_spend_key: slaveWithKeys.secret_spend_key,
168
- });
142
+ const firstResponse = await processor.getBlocksBinExecuteRequest({ block_ids: current_range.block_hashes.map((b) => b.block_hash) }, stopSync);
143
+ await readWriteConnectionStatusFile((cs) => {
144
+ if (cs?.last_packet.status === "catastrophic_reorg")
145
+ return;
146
+ const connectionStatus = {
147
+ last_packet: {
148
+ status: "OK",
149
+ bytes_read: firstResponse.length,
150
+ node_url: processor.node_url,
151
+ timestamp: new Date().toISOString(),
152
+ },
153
+ };
154
+ return connectionStatus;
155
+ });
156
+ yield firstResponse;
157
+ }
158
+ })();
159
+ const masterWithKeys = await walletSettingsPlusKeys(masterWalletSettings);
160
+ const slaveViewPairs = [];
161
+ if (nonHaltedWallets.length > 1) {
162
+ for (const slaveWallet of nonHaltedWallets.slice(1)) {
163
+ const slaveWithKeys = await walletSettingsPlusKeys(slaveWallet);
164
+ const viewpair = await ViewPair.create(slaveWallet.primary_address, slaveWithKeys.secret_view_key, slaveWallet.subaddress_index, masterWalletSettings.node_url);
165
+ slaveViewPairs.push({
166
+ viewpair,
167
+ current_range: await initScanCache(viewpair, masterStartHeight, scan_settings_path, pathPrefix),
168
+ secret_spend_key: slaveWithKeys.secret_spend_key,
169
+ });
170
+ }
169
171
  }
170
- }
171
- const catastrophic_reorg_cb = async () => {
172
- writeConnectionStatusFile("catastrophic_reorg", processor.node_url, undefined, scan_settings_path);
173
- };
174
- try {
172
+ const catastrophic_reorg_cb = async () => {
173
+ writeConnectionStatusFile("catastrophic_reorg", processor.node_url, undefined, scan_settings_path);
174
+ };
175
175
  for await (const firstResponse of blockGenerator) {
176
176
  if (!firstResponse)
177
177
  continue;
@@ -227,6 +227,7 @@ export class ViewPair extends WasmProcessor {
227
227
  }
228
228
  catch (error) {
229
229
  handleScanError(error);
230
+ const processor = this;
230
231
  const cache = await readCacheFileDefaultLocation(processor.primary_address, pathPrefix);
231
232
  if (!cache)
232
233
  throw new Error(`${error} in scan() + cache not found for primary address: ${processor.primary_address} and path prefix: ${pathPrefix}`);
@@ -234,6 +235,7 @@ export class ViewPair extends WasmProcessor {
234
235
  newCache: cache,
235
236
  changed_outputs: [],
236
237
  });
238
+ throw error;
237
239
  }
238
240
  }
239
241
  /**
package/package.json CHANGED
@@ -40,7 +40,7 @@
40
40
  "clean": "rm -rf ./dist"
41
41
  },
42
42
  "files": ["dist"],
43
- "version": "0.3.3",
43
+ "version": "0.3.5",
44
44
  "devDependencies": {
45
45
  "@types/bun": "latest"
46
46
  },