@spirobel/monero-wallet-api 0.5.0 → 0.5.2

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.
Files changed (30) hide show
  1. package/dist/actionlog/actionLog.d.ts +4 -0
  2. package/dist/actionlog/actionLog.js +9 -0
  3. package/dist/actionlog/actionLogOpened.d.ts +1 -0
  4. package/dist/actionlog/actionLogOpened.js +1 -0
  5. package/dist/api.d.ts +3 -2
  6. package/dist/api.js +3 -2
  7. package/dist/scanning-syncing/backgroundWorker.js +1 -1
  8. package/dist/scanning-syncing/blocksbuffer/blocksBufferFetchLoop.js +29 -3
  9. package/dist/scanning-syncing/blocksbuffer/blocksbufferCoordination.js +6 -3
  10. package/dist/scanning-syncing/connectionStatus.d.ts +1 -4
  11. package/dist/scanning-syncing/connectionStatus.js +1 -31
  12. package/dist/scanning-syncing/connectionStatusOpened.d.ts +15 -0
  13. package/dist/scanning-syncing/connectionStatusOpened.js +51 -0
  14. package/dist/scanning-syncing/openWallet.js +1 -1
  15. package/dist/scanning-syncing/scanSettings.d.ts +13 -13
  16. package/dist/scanning-syncing/scanSettings.js +26 -26
  17. package/dist/scanning-syncing/scanresult/scanCacheOpened.d.ts +53 -7
  18. package/dist/scanning-syncing/scanresult/scanCacheOpened.js +185 -50
  19. package/dist/scanning-syncing/scanresult/scanCoordination.d.ts +1 -1
  20. package/dist/scanning-syncing/scanresult/scanCoordination.js +64 -2
  21. package/dist/scanning-syncing/scansettings/scanSettings.d.ts +165 -0
  22. package/dist/scanning-syncing/scansettings/scanSettings.js +338 -0
  23. package/dist/scanning-syncing/worker-entrypoints/worker.js +1 -1
  24. package/dist/scanning-syncing/worker-mains/worker.js +1 -2
  25. package/dist/scansettings/scanSettings.d.ts +165 -0
  26. package/dist/scansettings/scanSettings.js +338 -0
  27. package/dist/scansettings/scanSettingsOpened.d.ts +102 -0
  28. package/dist/scansettings/scanSettingsOpened.js +299 -0
  29. package/dist/viewpair/ViewPair.js +1 -1
  30. package/package.json +1 -1
@@ -0,0 +1,4 @@
1
+ export type ActionLog = {
2
+ action: string;
3
+ data: string;
4
+ };
@@ -0,0 +1,9 @@
1
+ // the actionlog datastructure records three types of actions:
2
+ // 1. actions that the user has performed (external choice)
3
+ // 2. actions as the result of business logic during the execution of a tool call
4
+ // 3. actions as the result of business logic during the execution of an automated agreement
5
+ //
6
+ // tool call: privacy preserving interface between wallet and
7
+ // services that manage interaction with other users / wallets,
8
+ // set in motion by a user action (external choice to the whole (distributed, concurrent) system)
9
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/dist/api.d.ts CHANGED
@@ -8,7 +8,6 @@ export * from "./node-interaction/jsonEndpoints";
8
8
  export * from "./io/readDir";
9
9
  export * from "./io/atomicWrite";
10
10
  export * from "./io/sleep";
11
- export { writeScanSettings, readScanSettings, } from "./scanning-syncing/scanSettings";
12
11
  export { signTransaction, parseAddress, type ParsedAddress, type ParseAddressError, } from "./send-functionality/transactionBuilding";
13
12
  export { computeKeyImage } from "./scanning-syncing/scanresult/computeKeyImage";
14
13
  export * from "./multisig/multisig";
@@ -21,7 +20,9 @@ export { openWallets, openWallet } from "./scanning-syncing/openWallet";
21
20
  export * from "./scanning-syncing/blocksbuffer/blocksBufferFetchLoop";
22
21
  export * from "./scanning-syncing/blocksbuffer/blocksbufferCoordination";
23
22
  export * from "./scanning-syncing/connectionStatus";
24
- export * from "./scanning-syncing/scanSettings";
23
+ export { ConnectionStatusOpened } from "./scanning-syncing/connectionStatusOpened";
24
+ export * from "./scansettings/scanSettings";
25
+ export { ScanSettingsOpened } from "./scansettings/scanSettingsOpened";
25
26
  export * from "./scanning-syncing/scanresult/scanResult";
26
27
  export * from "./scanning-syncing/scanresult/scanStats";
27
28
  export * from "./scanning-syncing/scanresult/scanCache";
package/dist/api.js CHANGED
@@ -7,7 +7,6 @@ export * from "./node-interaction/jsonEndpoints";
7
7
  export * from "./io/readDir";
8
8
  export * from "./io/atomicWrite";
9
9
  export * from "./io/sleep";
10
- export { writeScanSettings, readScanSettings, } from "./scanning-syncing/scanSettings";
11
10
  export { signTransaction, parseAddress, } from "./send-functionality/transactionBuilding";
12
11
  export { computeKeyImage } from "./scanning-syncing/scanresult/computeKeyImage";
13
12
  export * from "./multisig/multisig";
@@ -20,7 +19,9 @@ export { openWallets, openWallet } from "./scanning-syncing/openWallet";
20
19
  export * from "./scanning-syncing/blocksbuffer/blocksBufferFetchLoop";
21
20
  export * from "./scanning-syncing/blocksbuffer/blocksbufferCoordination";
22
21
  export * from "./scanning-syncing/connectionStatus";
23
- export * from "./scanning-syncing/scanSettings";
22
+ export { ConnectionStatusOpened } from "./scanning-syncing/connectionStatusOpened";
23
+ export * from "./scansettings/scanSettings";
24
+ export { ScanSettingsOpened } from "./scansettings/scanSettingsOpened";
24
25
  export * from "./scanning-syncing/scanresult/scanResult";
25
26
  export * from "./scanning-syncing/scanresult/scanStats";
26
27
  export * from "./scanning-syncing/scanresult/scanCache";
@@ -1,6 +1,6 @@
1
1
  import { LOCAL_NODE_DEFAULT_URL } from "../node-interaction/nodeUrl";
2
2
  import {} from "./scanresult/scanCache";
3
- import { openScanSettingsFile, SCAN_SETTINGS_STORE_NAME_DEFAULT, } from "./scanSettings";
3
+ import { openScanSettingsFile, SCAN_SETTINGS_STORE_NAME_DEFAULT } from "../api";
4
4
  import { log, setupLoggingPath } from "../io/logging";
5
5
  import { workerMainCode } from "./worker-entrypoints/worker";
6
6
  export const CPU_POOL_SIZE = 4;
@@ -9,7 +9,12 @@ connection_status, // we make a local copy of this and pass last_packet and sync
9
9
  max_blocks_buffer_size = MAX_BLOCKS_BUFFER_SIZE, anchor_range, stopSync) {
10
10
  connection_status = structuredClone(connection_status);
11
11
  const nodeUrl = await NodeUrl.create(node_url);
12
- log("blocksBufferFetchLoop", ["NodeUrl:", nodeUrl.node_url, "start:", start_height]);
12
+ log("blocksBufferFetchLoop", [
13
+ "NodeUrl:",
14
+ nodeUrl.node_url,
15
+ "start:",
16
+ start_height,
17
+ ]);
13
18
  start_height = await reduceStartHeightToTip(start_height, nodeUrl.node_url);
14
19
  // initialise ranges on first call
15
20
  let { current_range, scanned_ranges } = await initScannedRanges(nodeUrl.node_url, start_height, anchor_range ? [anchor_range] : []);
@@ -39,15 +44,36 @@ max_blocks_buffer_size = MAX_BLOCKS_BUFFER_SIZE, anchor_range, stopSync) {
39
44
  await sleep(5000);
40
45
  continue;
41
46
  }
42
- log("blocksBufferFetchLoop", ["fetching", nodeUrl.node_url, current_range.start, "->", current_range.end]);
43
- const get_blocks_bin = await doRPCrequest(nodeUrl, current_range, stopSync);
47
+ log("blocksBufferFetchLoop", [
48
+ "fetching",
49
+ nodeUrl.node_url,
50
+ current_range.start,
51
+ "->",
52
+ current_range.end,
53
+ ]);
54
+ let get_blocks_bin;
55
+ try {
56
+ get_blocks_bin = await doRPCrequest(nodeUrl, current_range, stopSync);
57
+ }
58
+ catch (error) {
59
+ connection_status.last_packet = {
60
+ status: "connection_failed",
61
+ bytes_read: 0,
62
+ node_url,
63
+ timestamp: new Date().toISOString(),
64
+ };
65
+ yield connection_status.last_packet;
66
+ throw error;
67
+ }
44
68
  const result_meta = await nodeUrl.loadGetBlocksBinResponse(get_blocks_bin);
45
69
  log("blocksBufferFetchLoop", "response: " + result_meta.block_infos.length + " blocks");
70
+ connection_status.sync.daemon_height = result_meta.daemon_height;
46
71
  connection_status.last_packet = {
47
72
  status: "OK",
48
73
  bytes_read: get_blocks_bin.length,
49
74
  node_url: node_url,
50
75
  timestamp: new Date().toISOString(),
76
+ daemon_height: result_meta.daemon_height,
51
77
  };
52
78
  yield connection_status.last_packet;
53
79
  // no new blocks: at tip, sleep and retry
@@ -19,10 +19,13 @@ export async function handleConnectionStatusChanges(event, scanSettingsPath) {
19
19
  }
20
20
  }
21
21
  if ("scanned_ranges" in event) {
22
- //TODO: only write this to disk after blocks_buffer_changed has been handled by wallets.
23
- //look for same comment in blocksBufferFetchLoop.ts
24
22
  await readWriteConnectionStatusFile((cs2) => {
25
- cs2.sync = event;
23
+ cs2.sync = {
24
+ ...event,
25
+ // preserve eta and current_scan_height from file
26
+ eta: cs2.sync.eta || event.eta,
27
+ current_scan_height: cs2.sync.current_scan_height || event.current_scan_height,
28
+ };
26
29
  }, scanSettingsPath);
27
30
  }
28
31
  }
@@ -5,6 +5,7 @@ export type ConnectionSatusLastPacket = {
5
5
  bytes_read: number;
6
6
  node_url: string;
7
7
  timestamp: string;
8
+ daemon_height?: number;
8
9
  };
9
10
  export type ConnectionStatusSync = {
10
11
  reorg_info?: ReorgInfo;
@@ -21,10 +22,6 @@ export type ConnectionStatus = {
21
22
  export declare const DEFAULT_CONNECTION_STATUS_PREFIX = "ConnectionStatus-";
22
23
  export declare function msToHHMM(ms: number): string;
23
24
  export declare function emptyConnectionStatus(overrides?: Partial<ConnectionStatus>): ConnectionStatus;
24
- export declare function updateSyncETA(daemon_height: number, current_scan_height: number, last_height: number | null, last_timestamp: number | null, scan_settings_path?: string): Promise<{
25
- last_height: number;
26
- last_timestamp: number;
27
- }>;
28
25
  export declare function connectionStatusFilePath(scan_settings_path?: string): string;
29
26
  export declare function readConnectionStatusDefaultLocation(scan_settings_path?: string): Promise<ConnectionStatus | undefined>;
30
27
  export declare function readConnectionStatusFile(connectionStatusFilePath: string): Promise<ConnectionStatus | undefined>;
@@ -1,5 +1,5 @@
1
1
  import { atomicWrite, } from "../api";
2
- import { SCAN_SETTINGS_STORE_NAME_DEFAULT } from "./scanSettings";
2
+ import { SCAN_SETTINGS_STORE_NAME_DEFAULT } from "../api";
3
3
  export const DEFAULT_CONNECTION_STATUS_PREFIX = "ConnectionStatus-";
4
4
  export function msToHHMM(ms) {
5
5
  const totalSeconds = Math.floor(ms / 1000);
@@ -31,36 +31,6 @@ export function emptyConnectionStatus(overrides) {
31
31
  };
32
32
  return overrides ? { ...defaultStatus, ...overrides } : defaultStatus;
33
33
  }
34
- export async function updateSyncETA(daemon_height, current_scan_height, last_height, last_timestamp, scan_settings_path) {
35
- const blocks_till_tip = daemon_height - current_scan_height;
36
- let blocks_since_last_update = null;
37
- let duration = null;
38
- if (typeof last_height === "number") {
39
- blocks_since_last_update = current_scan_height - last_height;
40
- }
41
- if (typeof last_timestamp === "number") {
42
- duration = Date.now() - last_timestamp;
43
- }
44
- let eta = "00:00";
45
- if (blocks_since_last_update !== null &&
46
- duration !== null &&
47
- duration > 0 &&
48
- blocks_till_tip > 0) {
49
- const blocks_per_ms = blocks_since_last_update / duration;
50
- const eta_ms = blocks_till_tip / blocks_per_ms;
51
- eta = msToHHMM(eta_ms);
52
- }
53
- await readWriteConnectionStatusFile((cs) => {
54
- cs.sync = {
55
- ...cs.sync,
56
- daemon_height,
57
- current_scan_height,
58
- eta,
59
- timestamp: new Date().toISOString(),
60
- };
61
- }, scan_settings_path);
62
- return { last_height: current_scan_height, last_timestamp: Date.now() };
63
- }
64
34
  export function connectionStatusFilePath(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
65
35
  const parts = scan_settings_path.split("/");
66
36
  const basename = parts.pop();
@@ -0,0 +1,15 @@
1
+ import { type ConnectionStatus } from "../api";
2
+ export declare class ConnectionStatusOpened {
3
+ private _onChange?;
4
+ private _timer;
5
+ private _cached;
6
+ private _prevConnected;
7
+ private _path;
8
+ constructor(scan_settings_path: string, _onChange?: ((status: ConnectionStatus | null) => void) | null | undefined);
9
+ watch(intervalMs?: number): void;
10
+ unwatch(): void;
11
+ get connectionStatus(): ConnectionStatus | null;
12
+ get isConnected(): boolean;
13
+ get daemonHeight(): number | undefined;
14
+ private _poll;
15
+ }
@@ -0,0 +1,51 @@
1
+ import { readConnectionStatusFile, connectionStatusFilePath, } from "../api";
2
+ export class ConnectionStatusOpened {
3
+ _onChange;
4
+ _timer;
5
+ _cached = null;
6
+ _prevConnected = false;
7
+ _path;
8
+ constructor(scan_settings_path, _onChange) {
9
+ this._onChange = _onChange;
10
+ this._path = connectionStatusFilePath(scan_settings_path);
11
+ }
12
+ watch(intervalMs = 2500) {
13
+ if (this._timer)
14
+ return;
15
+ this._poll();
16
+ this._timer = setInterval(() => this._poll(), intervalMs);
17
+ }
18
+ unwatch() {
19
+ if (this._timer) {
20
+ clearInterval(this._timer);
21
+ this._timer = undefined;
22
+ }
23
+ }
24
+ get connectionStatus() {
25
+ return this._cached;
26
+ }
27
+ get isConnected() {
28
+ const cs = this._cached;
29
+ if (!cs?.last_packet)
30
+ return false;
31
+ const { status, timestamp } = cs.last_packet;
32
+ if (status !== "OK" && status !== "blocks_buffer_full")
33
+ return false;
34
+ if (!timestamp)
35
+ return false;
36
+ const age = Date.now() - new Date(timestamp).getTime();
37
+ return age >= 0 && age <= 10_000;
38
+ }
39
+ get daemonHeight() {
40
+ return this._cached?.last_packet?.daemon_height;
41
+ }
42
+ async _poll() {
43
+ this._cached =
44
+ (await readConnectionStatusFile(this._path).catch(() => null)) || null;
45
+ const now = this.isConnected;
46
+ if (now !== this._prevConnected) {
47
+ this._prevConnected = now;
48
+ this._onChange?.(this._cached);
49
+ }
50
+ }
51
+ }
@@ -1,5 +1,5 @@
1
1
  import { ManyScanCachesOpened, ScanCacheOpened, } from "./scanresult/scanCacheOpened";
2
- import { openScanSettingsFile, writeWalletToScanSettings, } from "./scanSettings";
2
+ import { openScanSettingsFile, writeWalletToScanSettings } from "../api";
3
3
  /**
4
4
  * Opens all **non halted wallets listed in ScanSettings.json** for scanning.
5
5
  *
@@ -71,21 +71,21 @@ export type ScanSettingsOpened = {
71
71
  * ```
72
72
  *
73
73
  * @param scan_settings - The complete {@link ScanSettings} configuration to persist.
74
- * @param settingsStorePath - Optional path for the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
74
+ * @param scan_settings_path - Optional path for the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
75
75
  * @returns A promise that resolves when the file is successfully written.
76
76
  * @throws Will throw if file writing fails (e.g., permissions, disk space).
77
77
  */
78
- export declare function writeScanSettings(scan_settings: ScanSettings, settingsStorePath?: string): Promise<number>;
78
+ export declare function writeScanSettings(scan_settings: ScanSettings, scan_settings_path?: string): Promise<number>;
79
79
  export type WriteScanSettingsFileParams = {
80
- settingsStorePath?: string;
80
+ scan_settings_path?: string;
81
81
  writeCallback: (settings: ScanSettings) => void | Promise<void>;
82
82
  };
83
83
  export declare function writeScanSettingsFileDefaultLocation(params: WriteScanSettingsFileParams): Promise<void>;
84
- export declare function writeStartHeightToScanSettings(start_height: number | null, settingsStorePath?: string): Promise<number>;
85
- export declare function writeDaemonHeightAsStartHeightToScanSettings(node_url: string, settingsStorePath?: string): Promise<number>;
86
- export declare function cullTooLargeScanHeight(node_url: string, settingsStorePath?: string): Promise<number>;
87
- export declare function writeNodeUrlToScanSettings(node_url: string, settingsStorePath?: string): Promise<number>;
88
- export declare function readNodeUrlFromScanSettings(settingsStorePath?: string): Promise<string | undefined>;
84
+ export declare function writeStartHeightToScanSettings(start_height: number | null, scan_settings_path?: string): Promise<number>;
85
+ export declare function writeDaemonHeightAsStartHeightToScanSettings(node_url: string, scan_settings_path?: string): Promise<number>;
86
+ export declare function cullTooLargeScanHeight(node_url: string, scan_settings_path?: string): Promise<number>;
87
+ export declare function writeNodeUrlToScanSettings(node_url: string, scan_settings_path?: string): Promise<number>;
88
+ export declare function readNodeUrlFromScanSettings(scan_settings_path?: string): Promise<string | undefined>;
89
89
  /**
90
90
  * Writes the merchant confirmation threshold to scan settings.
91
91
  *
@@ -97,11 +97,11 @@ export declare function readNodeUrlFromScanSettings(settingsStorePath?: string):
97
97
  *
98
98
  * @param merchant_confirmations - Number of confirmations required before
99
99
  * accepting a payment, or `null` to leave it unset.
100
- * @param settingsStorePath - Optional path for the settings file.
100
+ * @param scan_settings_path - Optional path for the settings file.
101
101
  * Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
102
102
  * @returns A promise that resolves when the file is successfully written.
103
103
  */
104
- export declare function writeMerchantConfirmationsToScanSettings(merchant_confirmations: number | null, settingsStorePath?: string): Promise<number>;
104
+ export declare function writeMerchantConfirmationsToScanSettings(merchant_confirmations: number | null, scan_settings_path?: string): Promise<number>;
105
105
  /**
106
106
  * Reads the merchant confirmation threshold from scan settings.
107
107
  *
@@ -112,12 +112,12 @@ export declare function writeMerchantConfirmationsToScanSettings(merchant_confir
112
112
  * for a payment. The actual enforcement of this policy is left to the
113
113
  * custom payment-system code that consumes this library.
114
114
  *
115
- * @param settingsStorePath - Optional path for the settings file.
115
+ * @param scan_settings_path - Optional path for the settings file.
116
116
  * Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
117
117
  * @returns The configured number of confirmations, null, or `undefined`
118
118
  * if the setting has not been persisted yet.
119
119
  */
120
- export declare function readMerchantConfirmationsFromScanSettings(settingsStorePath?: string): Promise<number | null | undefined>;
120
+ export declare function readMerchantConfirmationsFromScanSettings(scan_settings_path?: string): Promise<number | null | undefined>;
121
121
  /**
122
122
  * Reads scan settings from the default or specified storage file.
123
123
  * secret_view_key and spend_private_key are read from environment variables
@@ -130,7 +130,7 @@ export declare function readMerchantConfirmationsFromScanSettings(settingsStoreP
130
130
  * }
131
131
  * ```
132
132
  *
133
- * @param settingsStorePath - Path to the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
133
+ * @param scan_settings_path - Path to the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
134
134
  * @returns The parsed {@link ScanSettings} object if file exists and is valid JSON, otherwise `undefined`.
135
135
  */
136
136
  export declare function readScanSettings(scan_settings_path?: string): Promise<ScanSettingsOpened | undefined>;
@@ -23,15 +23,15 @@ export const SUB_ADDRESS_INDEX_DEFAULT_VALUE = 1;
23
23
  * ```
24
24
  *
25
25
  * @param scan_settings - The complete {@link ScanSettings} configuration to persist.
26
- * @param settingsStorePath - Optional path for the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
26
+ * @param scan_settings_path - Optional path for the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
27
27
  * @returns A promise that resolves when the file is successfully written.
28
28
  * @throws Will throw if file writing fails (e.g., permissions, disk space).
29
29
  */
30
- export async function writeScanSettings(scan_settings, settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
31
- return await atomicWrite(settingsStorePath, JSON.stringify(scan_settings, null, 2));
30
+ export async function writeScanSettings(scan_settings, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
31
+ return await atomicWrite(scan_settings_path, JSON.stringify(scan_settings, null, 2));
32
32
  }
33
33
  export async function writeScanSettingsFileDefaultLocation(params) {
34
- let settings = await openScanSettingsFile(params.settingsStorePath);
34
+ let settings = await openScanSettingsFile(params.scan_settings_path);
35
35
  if (!settings) {
36
36
  // Create empty ScanSettings object with default values
37
37
  settings = {
@@ -42,10 +42,10 @@ export async function writeScanSettingsFileDefaultLocation(params) {
42
42
  }
43
43
  await params.writeCallback(settings);
44
44
  // write to settings file
45
- await writeScanSettings(settings, params.settingsStorePath);
45
+ await writeScanSettings(settings, params.scan_settings_path);
46
46
  }
47
- export async function writeStartHeightToScanSettings(start_height, settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
48
- const scanSettings = (await openScanSettingsFile(settingsStorePath)) || {
47
+ export async function writeStartHeightToScanSettings(start_height, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
48
+ const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
49
49
  node_url: LOCAL_NODE_DEFAULT_URL,
50
50
  wallets: [],
51
51
  start_height: null,
@@ -53,20 +53,20 @@ export async function writeStartHeightToScanSettings(start_height, settingsStore
53
53
  scanSettings.start_height = start_height;
54
54
  return await atomicWrite(SCAN_SETTINGS_STORE_NAME_DEFAULT, JSON.stringify(scanSettings, null, 2));
55
55
  }
56
- export async function writeDaemonHeightAsStartHeightToScanSettings(node_url, settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
56
+ export async function writeDaemonHeightAsStartHeightToScanSettings(node_url, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
57
57
  const getInfo = await get_info(node_url);
58
- const scanSettings = (await openScanSettingsFile(settingsStorePath)) || {
58
+ const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
59
59
  node_url: LOCAL_NODE_DEFAULT_URL,
60
60
  wallets: [],
61
61
  start_height: null,
62
62
  };
63
63
  scanSettings.start_height = getInfo.height - 1;
64
- await atomicWrite(settingsStorePath, JSON.stringify(scanSettings, null, 2));
64
+ await atomicWrite(scan_settings_path, JSON.stringify(scanSettings, null, 2));
65
65
  return getInfo.height;
66
66
  }
67
- export async function cullTooLargeScanHeight(node_url, settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
67
+ export async function cullTooLargeScanHeight(node_url, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
68
68
  const getInfo = await get_info(node_url);
69
- const scanSettings = (await openScanSettingsFile(settingsStorePath)) || {
69
+ const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
70
70
  node_url: LOCAL_NODE_DEFAULT_URL,
71
71
  wallets: [],
72
72
  start_height: null,
@@ -74,21 +74,21 @@ export async function cullTooLargeScanHeight(node_url, settingsStorePath = SCAN_
74
74
  if (scanSettings.start_height === null ||
75
75
  scanSettings.start_height > getInfo.height - 1) {
76
76
  scanSettings.start_height = getInfo.height - 1;
77
- await atomicWrite(settingsStorePath, JSON.stringify(scanSettings, null, 2));
77
+ await atomicWrite(scan_settings_path, JSON.stringify(scanSettings, null, 2));
78
78
  }
79
79
  return scanSettings.start_height;
80
80
  }
81
- export async function writeNodeUrlToScanSettings(node_url, settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
82
- const scanSettings = (await openScanSettingsFile(settingsStorePath)) || {
81
+ export async function writeNodeUrlToScanSettings(node_url, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
82
+ const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
83
83
  node_url: LOCAL_NODE_DEFAULT_URL,
84
84
  wallets: [],
85
85
  start_height: null,
86
86
  };
87
87
  scanSettings.node_url = node_url;
88
- return await atomicWrite(settingsStorePath, JSON.stringify(scanSettings, null, 2));
88
+ return await atomicWrite(scan_settings_path, JSON.stringify(scanSettings, null, 2));
89
89
  }
90
- export async function readNodeUrlFromScanSettings(settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
91
- const scanSettings = await openScanSettingsFile(settingsStorePath);
90
+ export async function readNodeUrlFromScanSettings(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
91
+ const scanSettings = await openScanSettingsFile(scan_settings_path);
92
92
  return scanSettings?.node_url;
93
93
  }
94
94
  /**
@@ -102,18 +102,18 @@ export async function readNodeUrlFromScanSettings(settingsStorePath = SCAN_SETTI
102
102
  *
103
103
  * @param merchant_confirmations - Number of confirmations required before
104
104
  * accepting a payment, or `null` to leave it unset.
105
- * @param settingsStorePath - Optional path for the settings file.
105
+ * @param scan_settings_path - Optional path for the settings file.
106
106
  * Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
107
107
  * @returns A promise that resolves when the file is successfully written.
108
108
  */
109
- export async function writeMerchantConfirmationsToScanSettings(merchant_confirmations, settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
110
- const scanSettings = (await openScanSettingsFile(settingsStorePath)) || {
109
+ export async function writeMerchantConfirmationsToScanSettings(merchant_confirmations, scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
110
+ const scanSettings = (await openScanSettingsFile(scan_settings_path)) || {
111
111
  node_url: LOCAL_NODE_DEFAULT_URL,
112
112
  wallets: [],
113
113
  start_height: null,
114
114
  };
115
115
  scanSettings.merchant_confirmations = merchant_confirmations;
116
- return await atomicWrite(settingsStorePath, JSON.stringify(scanSettings, null, 2));
116
+ return await atomicWrite(scan_settings_path, JSON.stringify(scanSettings, null, 2));
117
117
  }
118
118
  /**
119
119
  * Reads the merchant confirmation threshold from scan settings.
@@ -125,13 +125,13 @@ export async function writeMerchantConfirmationsToScanSettings(merchant_confirma
125
125
  * for a payment. The actual enforcement of this policy is left to the
126
126
  * custom payment-system code that consumes this library.
127
127
  *
128
- * @param settingsStorePath - Optional path for the settings file.
128
+ * @param scan_settings_path - Optional path for the settings file.
129
129
  * Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
130
130
  * @returns The configured number of confirmations, null, or `undefined`
131
131
  * if the setting has not been persisted yet.
132
132
  */
133
- export async function readMerchantConfirmationsFromScanSettings(settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
134
- const scanSettings = await openScanSettingsFile(settingsStorePath);
133
+ export async function readMerchantConfirmationsFromScanSettings(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
134
+ const scanSettings = await openScanSettingsFile(scan_settings_path);
135
135
  return scanSettings?.merchant_confirmations;
136
136
  }
137
137
  /**
@@ -146,7 +146,7 @@ export async function readMerchantConfirmationsFromScanSettings(settingsStorePat
146
146
  * }
147
147
  * ```
148
148
  *
149
- * @param settingsStorePath - Path to the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
149
+ * @param scan_settings_path - Path to the settings file. Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
150
150
  * @returns The parsed {@link ScanSettings} object if file exists and is valid JSON, otherwise `undefined`.
151
151
  */
152
152
  export async function readScanSettings(scan_settings_path = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
@@ -1,7 +1,10 @@
1
1
  import { ViewPair, type FeeEstimateResponse, type Output, type SendRawTransactionResult } from "../../api";
2
2
  import { type Payment } from "../../send-functionality/inputSelection";
3
+ import { ConnectionStatusOpened } from "../connectionStatusOpened";
4
+ import type { LogSetting, PossibleLogs } from "../../io/logging";
3
5
  import { type CacheChangedCallback, type CacheChangedCallbackParameters, type ScanCache, type Subaddress, type TxLog } from "./scanCache";
4
6
  import { type FoundTransaction, type PrePendingTx } from "./scanStats";
7
+ import { type ConnectionStatus } from "../connectionStatus";
5
8
  export type SlaveScanCache = boolean;
6
9
  export type ScanCacheOpenedCreateParams = {
7
10
  primary_address: string;
@@ -18,6 +21,7 @@ export type CreateTransactionParams = {
18
21
  no_fee_circuit_breaker?: boolean;
19
22
  };
20
23
  export declare class ScanCacheOpened {
24
+ private _scanSettings;
21
25
  readonly view_pair: ViewPair;
22
26
  readonly wallet_route: string | undefined;
23
27
  readonly wallet_name: string | undefined;
@@ -56,8 +60,16 @@ export declare class ScanCacheOpened {
56
60
  get primary_address(): string;
57
61
  get node_url(): string;
58
62
  private set node_url(value);
63
+ get merchant_confirmations(): number | null | undefined;
64
+ get cpu_worker_count(): number | undefined;
65
+ get logs(): LogSetting | undefined;
66
+ get logs_include(): PossibleLogs[] | undefined;
67
+ get logs_exclude(): PossibleLogs[] | undefined;
59
68
  changeNodeUrlAndStartHeight(node_url?: string, start_height?: number | null): Promise<void>;
60
69
  changeNodeUrl(node_url: string): Promise<void>;
70
+ setMerchantConfirmations(merchant_confirmations: number | null): Promise<void>;
71
+ setCpuWorkerCount(cpu_worker_count: number | undefined): Promise<void>;
72
+ setLogSettings(logs?: LogSetting | null, logs_include?: PossibleLogs[] | null, logs_exclude?: PossibleLogs[] | null): Promise<void>;
61
73
  retry(): Promise<boolean>;
62
74
  sendTransaction(signedTx: string): Promise<SendRawTransactionResult>;
63
75
  signTransaction(unsignedTx: string): Promise<string>;
@@ -115,9 +127,9 @@ export declare class ScanCacheOpened {
115
127
  notify(callback: CacheChangedCallback): {
116
128
  remove: () => null;
117
129
  };
118
- pause(): Promise<number>;
130
+ pause(): Promise<void>;
119
131
  stopWorker(): void;
120
- unpause(): Promise<number>;
132
+ unpause(): Promise<void>;
121
133
  /**
122
134
  * selectInputs returns array of inputs, whose sum is larger than amount
123
135
  * adds approximate fee for 10kb transaction to amount if feePerByte is supplied
@@ -160,9 +172,15 @@ export type ManyScanCachesOpenedCreateOptions = {
160
172
  notifyMasterChanged?: CacheChangedCallback;
161
173
  no_stats?: boolean;
162
174
  workerError?: (error: unknown) => void;
175
+ autoRetry?: boolean;
176
+ retryDelayMs?: number;
177
+ connectionStatusIntervalMs?: number;
178
+ onConnectionStatusChange?: ((status: ConnectionStatus | null) => void) | null;
163
179
  };
164
180
  export declare class ManyScanCachesOpened {
165
- readonly wallets: ScanCacheOpened[];
181
+ readonly connectionStatusOpened: ConnectionStatusOpened;
182
+ private _scanSettings;
183
+ private _options;
166
184
  get start_height(): number | null;
167
185
  get current_height(): number | null;
168
186
  get node_url(): string;
@@ -170,11 +188,39 @@ export declare class ManyScanCachesOpened {
170
188
  retry(): Promise<boolean>;
171
189
  stopWorker(): void;
172
190
  changeNodeUrl(node_url: string): Promise<void>;
191
+ get merchant_confirmations(): number | null | undefined;
192
+ get cpu_worker_count(): number | undefined;
193
+ get logs(): LogSetting | undefined;
194
+ get logs_include(): PossibleLogs[] | undefined;
195
+ get logs_exclude(): PossibleLogs[] | undefined;
196
+ get connectionStatus(): ConnectionStatus | null;
197
+ get daemonHeight(): number | undefined;
198
+ watchConnectionStatus(intervalMs?: number): void;
199
+ unwatchConnectionStatus(): void;
200
+ setMerchantConfirmations(merchant_confirmations: number | null): Promise<void>;
201
+ setCpuWorkerCount(cpu_worker_count: number | undefined): Promise<void>;
202
+ setLogSettings(logs?: LogSetting | null, logs_include?: PossibleLogs[] | null, logs_exclude?: PossibleLogs[] | null): Promise<void>;
173
203
  changeStartHeight(start_height: number | null): Promise<void>;
174
- static create({ scan_settings_path, pathPrefix, no_worker, notifyMasterChanged, no_stats, workerError, }: ManyScanCachesOpenedCreateOptions): Promise<ManyScanCachesOpened | undefined>;
175
- /**
176
- * feed the master wallet and therefore all wallets
177
- */
204
+ private static _buildWallets;
205
+ static create(options: ManyScanCachesOpenedCreateOptions): Promise<ManyScanCachesOpened | undefined>;
206
+ buildWallets(): Promise<void>;
207
+ addViewWallet(primary_address: string, view_key: string, fields?: {
208
+ wallet_name?: string;
209
+ wallet_slot?: number;
210
+ wallet_route?: string;
211
+ subaddress_index?: number;
212
+ halted?: boolean;
213
+ }): Promise<void>;
214
+ addSpendWallet(wallet_secret: Uint8Array, fields?: {
215
+ wallet_name?: string;
216
+ wallet_slot?: number;
217
+ wallet_route?: string;
218
+ subaddress_index?: number;
219
+ halted?: boolean;
220
+ }): Promise<void>;
221
+ removeWallet(primary_address: string): Promise<void>;
178
222
  feed(params: CacheChangedCallbackParameters): Promise<void>;
223
+ private _wallets;
224
+ get wallets(): ScanCacheOpened[];
179
225
  private constructor();
180
226
  }