@spirobel/monero-wallet-api 0.3.15 → 0.3.18

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.
@@ -5,6 +5,11 @@ export async function atomicWrite(targetPath, data) {
5
5
  const { rename } = await import("node:fs/promises");
6
6
  const tempPath = targetPath + ".tmp";
7
7
  const bytesWritten = await Bun.write(tempPath, data);
8
- await rename(tempPath, targetPath);
8
+ try {
9
+ await rename(tempPath, targetPath);
10
+ }
11
+ catch (e) {
12
+ //eat rename failed
13
+ }
9
14
  return bytesWritten;
10
15
  }
@@ -34,11 +34,13 @@ export type ScanSettings = {
34
34
  wallets: ScanSetting[];
35
35
  node_url: string;
36
36
  start_height: number | null;
37
+ merchant_confirmations?: number | null;
37
38
  };
38
39
  export type ScanSettingsOpened = {
39
40
  wallets: (ScanSettingOpened | undefined)[];
40
41
  node_url: string;
41
42
  start_height: number | null;
43
+ merchant_confirmations?: number | null;
42
44
  };
43
45
  /**
44
46
  * Writes scan settings to the default or specified storage file in json.
@@ -71,6 +73,38 @@ export declare function writeDaemonHeightAsStartHeightToScanSettings(node_url: s
71
73
  export declare function cullTooLargeScanHeight(node_url: string, settingsStorePath?: string): Promise<number>;
72
74
  export declare function writeNodeUrlToScanSettings(node_url: string, settingsStorePath?: string): Promise<number>;
73
75
  export declare function readNodeUrlFromScanSettings(settingsStorePath?: string): Promise<string | undefined>;
76
+ /**
77
+ * Writes the merchant confirmation threshold to scan settings.
78
+ *
79
+ * This setting only has effect when the wallet is run as part of a checkout system,
80
+ * that accepts payments.
81
+ * It determines after how many confirmations a transaction is accepted
82
+ * for a payment. The actual enforcement of this policy is left to the
83
+ * custom payment-system code that consumes this library.
84
+ *
85
+ * @param merchant_confirmations - Number of confirmations required before
86
+ * accepting a payment, or `null` to leave it unset.
87
+ * @param settingsStorePath - Optional path for the settings file.
88
+ * Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
89
+ * @returns A promise that resolves when the file is successfully written.
90
+ */
91
+ export declare function writeMerchantConfirmationsToScanSettings(merchant_confirmations: number | null, settingsStorePath?: string): Promise<number>;
92
+ /**
93
+ * Reads the merchant confirmation threshold from scan settings.
94
+ *
95
+ * This setting only has effect when the wallet is run as part of a checkout system,
96
+ * that accepts payments.
97
+ *
98
+ * It determines after how many confirmations a transaction is accepted
99
+ * for a payment. The actual enforcement of this policy is left to the
100
+ * custom payment-system code that consumes this library.
101
+ *
102
+ * @param settingsStorePath - Optional path for the settings file.
103
+ * Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
104
+ * @returns The configured number of confirmations, null, or `undefined`
105
+ * if the setting has not been persisted yet.
106
+ */
107
+ export declare function readMerchantConfirmationsFromScanSettings(settingsStorePath?: string): Promise<number | null | undefined>;
74
108
  /**
75
109
  * Reads scan settings from the default or specified storage file.
76
110
  * secret_view_key and spend_private_key are read from environment variables
@@ -87,6 +87,49 @@ export async function readNodeUrlFromScanSettings(settingsStorePath = SCAN_SETTI
87
87
  const scanSettings = await openScanSettingsFile(settingsStorePath);
88
88
  return scanSettings?.node_url;
89
89
  }
90
+ /**
91
+ * Writes the merchant confirmation threshold to scan settings.
92
+ *
93
+ * This setting only has effect when the wallet is run as part of a checkout system,
94
+ * that accepts payments.
95
+ * It determines after how many confirmations a transaction is accepted
96
+ * for a payment. The actual enforcement of this policy is left to the
97
+ * custom payment-system code that consumes this library.
98
+ *
99
+ * @param merchant_confirmations - Number of confirmations required before
100
+ * accepting a payment, or `null` to leave it unset.
101
+ * @param settingsStorePath - Optional path for the settings file.
102
+ * Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
103
+ * @returns A promise that resolves when the file is successfully written.
104
+ */
105
+ export async function writeMerchantConfirmationsToScanSettings(merchant_confirmations, settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
106
+ const scanSettings = (await openScanSettingsFile(settingsStorePath)) || {
107
+ node_url: LOCAL_NODE_DEFAULT_URL,
108
+ wallets: [],
109
+ start_height: null,
110
+ };
111
+ scanSettings.merchant_confirmations = merchant_confirmations;
112
+ return await atomicWrite(settingsStorePath, JSON.stringify(scanSettings, null, 2));
113
+ }
114
+ /**
115
+ * Reads the merchant confirmation threshold from scan settings.
116
+ *
117
+ * This setting only has effect when the wallet is run as part of a checkout system,
118
+ * that accepts payments.
119
+ *
120
+ * It determines after how many confirmations a transaction is accepted
121
+ * for a payment. The actual enforcement of this policy is left to the
122
+ * custom payment-system code that consumes this library.
123
+ *
124
+ * @param settingsStorePath - Optional path for the settings file.
125
+ * Defaults to `SCAN_SETTINGS_STORE_NAME_DEFAULT`.
126
+ * @returns The configured number of confirmations, null, or `undefined`
127
+ * if the setting has not been persisted yet.
128
+ */
129
+ export async function readMerchantConfirmationsFromScanSettings(settingsStorePath = SCAN_SETTINGS_STORE_NAME_DEFAULT) {
130
+ const scanSettings = await openScanSettingsFile(settingsStorePath);
131
+ return scanSettings?.merchant_confirmations;
132
+ }
90
133
  /**
91
134
  * Reads scan settings from the default or specified storage file.
92
135
  * secret_view_key and spend_private_key are read from environment variables