@breeztech/breez-sdk-spark 0.13.2-dev5 → 0.13.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.
@@ -234,17 +234,6 @@ module.exports.defaultPostgresStorageConfig = function(connection_string) {
234
234
  return ret;
235
235
  };
236
236
 
237
- /**
238
- * Creates a default external signer from a mnemonic phrase.
239
- *
240
- * This creates a signer that can be used with `connectWithSigner` or `SdkBuilder.newWithSigner`.
241
- * @returns {Promise<SparkStatus>}
242
- */
243
- module.exports.getSparkStatus = function() {
244
- const ret = wasm.getSparkStatus();
245
- return ret;
246
- };
247
-
248
237
  /**
249
238
  * @param {Network} network
250
239
  * @returns {Config}
@@ -254,18 +243,6 @@ module.exports.defaultConfig = function(network) {
254
243
  return ret;
255
244
  };
256
245
 
257
- /**
258
- * @param {Logger} logger
259
- * @param {string | null} [filter]
260
- * @returns {Promise<void>}
261
- */
262
- module.exports.initLogging = function(logger, filter) {
263
- var ptr0 = isLikeNone(filter) ? 0 : passStringToWasm0(filter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
264
- var len0 = WASM_VECTOR_LEN;
265
- const ret = wasm.initLogging(logger, ptr0, len0);
266
- return ret;
267
- };
268
-
269
246
  /**
270
247
  * @param {ConnectRequest} request
271
248
  * @returns {Promise<BreezSdk>}
@@ -275,19 +252,6 @@ module.exports.connect = function(request) {
275
252
  return ret;
276
253
  };
277
254
 
278
- /**
279
- * @param {Config} config
280
- * @param {ExternalSigner} signer
281
- * @param {string} storage_dir
282
- * @returns {Promise<BreezSdk>}
283
- */
284
- module.exports.connectWithSigner = function(config, signer, storage_dir) {
285
- const ptr0 = passStringToWasm0(storage_dir, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
286
- const len0 = WASM_VECTOR_LEN;
287
- const ret = wasm.connectWithSigner(config, signer, ptr0, len0);
288
- return ret;
289
- };
290
-
291
255
  function takeFromExternrefTable0(idx) {
292
256
  const value = wasm.__wbindgen_export_5.get(idx);
293
257
  wasm.__externref_table_dealloc(idx);
@@ -312,6 +276,42 @@ module.exports.defaultExternalSigner = function(mnemonic, passphrase, network, k
312
276
  return DefaultSigner.__wrap(ret[0]);
313
277
  };
314
278
 
279
+ /**
280
+ * @param {Logger} logger
281
+ * @param {string | null} [filter]
282
+ * @returns {Promise<void>}
283
+ */
284
+ module.exports.initLogging = function(logger, filter) {
285
+ var ptr0 = isLikeNone(filter) ? 0 : passStringToWasm0(filter, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
286
+ var len0 = WASM_VECTOR_LEN;
287
+ const ret = wasm.initLogging(logger, ptr0, len0);
288
+ return ret;
289
+ };
290
+
291
+ /**
292
+ * Creates a default external signer from a mnemonic phrase.
293
+ *
294
+ * This creates a signer that can be used with `connectWithSigner` or `SdkBuilder.newWithSigner`.
295
+ * @returns {Promise<SparkStatus>}
296
+ */
297
+ module.exports.getSparkStatus = function() {
298
+ const ret = wasm.getSparkStatus();
299
+ return ret;
300
+ };
301
+
302
+ /**
303
+ * @param {Config} config
304
+ * @param {ExternalSigner} signer
305
+ * @param {string} storage_dir
306
+ * @returns {Promise<BreezSdk>}
307
+ */
308
+ module.exports.connectWithSigner = function(config, signer, storage_dir) {
309
+ const ptr0 = passStringToWasm0(storage_dir, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
310
+ const len0 = WASM_VECTOR_LEN;
311
+ const ret = wasm.connectWithSigner(config, signer, ptr0, len0);
312
+ return ret;
313
+ };
314
+
315
315
  function passArray8ToWasm0(arg, malloc) {
316
316
  const ptr = malloc(arg.length * 1, 1) >>> 0;
317
317
  getUint8ArrayMemory0().set(arg, ptr / 1);
@@ -330,15 +330,15 @@ module.exports.task_worker_entry_point = function(ptr) {
330
330
  };
331
331
 
332
332
  function __wbg_adapter_64(arg0, arg1, arg2) {
333
- wasm.closure384_externref_shim(arg0, arg1, arg2);
333
+ wasm.closure385_externref_shim(arg0, arg1, arg2);
334
334
  }
335
335
 
336
336
  function __wbg_adapter_69(arg0, arg1) {
337
- wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h140914a8cfe47e73(arg0, arg1);
337
+ wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1015faeeadd5b26c(arg0, arg1);
338
338
  }
339
339
 
340
- function __wbg_adapter_423(arg0, arg1, arg2, arg3) {
341
- wasm.closure656_externref_shim(arg0, arg1, arg2, arg3);
340
+ function __wbg_adapter_433(arg0, arg1, arg2, arg3) {
341
+ wasm.closure665_externref_shim(arg0, arg1, arg2, arg3);
342
342
  }
343
343
 
344
344
  const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
@@ -1503,13 +1503,13 @@ module.exports.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(fun
1503
1503
  return ret;
1504
1504
  }, arguments) };
1505
1505
 
1506
- module.exports.__wbg_cancelReservation_d85a13db3e8e3c7b = function() { return handleError(function (arg0, arg1, arg2) {
1506
+ module.exports.__wbg_cancelReservation_038a18dbc15a13b5 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
1507
1507
  let deferred0_0;
1508
1508
  let deferred0_1;
1509
1509
  try {
1510
1510
  deferred0_0 = arg1;
1511
1511
  deferred0_1 = arg2;
1512
- const ret = arg0.cancelReservation(getStringFromWasm0(arg1, arg2));
1512
+ const ret = arg0.cancelReservation(getStringFromWasm0(arg1, arg2), arg3);
1513
1513
  return ret;
1514
1514
  } finally {
1515
1515
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
@@ -2235,7 +2235,7 @@ module.exports.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
2235
2235
  const a = state0.a;
2236
2236
  state0.a = 0;
2237
2237
  try {
2238
- return __wbg_adapter_423(a, state0.b, arg0, arg1);
2238
+ return __wbg_adapter_433(a, state0.b, arg0, arg1);
2239
2239
  } finally {
2240
2240
  state0.a = a;
2241
2241
  }
@@ -2888,28 +2888,28 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
2888
2888
  return ret;
2889
2889
  };
2890
2890
 
2891
- module.exports.__wbindgen_closure_wrapper10276 = function(arg0, arg1, arg2) {
2892
- const ret = makeMutClosure(arg0, arg1, 385, __wbg_adapter_69);
2891
+ module.exports.__wbindgen_closure_wrapper13493 = function(arg0, arg1, arg2) {
2892
+ const ret = makeMutClosure(arg0, arg1, 869, __wbg_adapter_69);
2893
2893
  return ret;
2894
2894
  };
2895
2895
 
2896
- module.exports.__wbindgen_closure_wrapper15432 = function(arg0, arg1, arg2) {
2897
- const ret = makeMutClosure(arg0, arg1, 385, __wbg_adapter_64);
2896
+ module.exports.__wbindgen_closure_wrapper15518 = function(arg0, arg1, arg2) {
2897
+ const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2898
2898
  return ret;
2899
2899
  };
2900
2900
 
2901
- module.exports.__wbindgen_closure_wrapper5935 = function(arg0, arg1, arg2) {
2902
- const ret = makeMutClosure(arg0, arg1, 385, __wbg_adapter_64);
2901
+ module.exports.__wbindgen_closure_wrapper5986 = function(arg0, arg1, arg2) {
2902
+ const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2903
2903
  return ret;
2904
2904
  };
2905
2905
 
2906
- module.exports.__wbindgen_closure_wrapper5941 = function(arg0, arg1, arg2) {
2907
- const ret = makeMutClosure(arg0, arg1, 385, __wbg_adapter_64);
2906
+ module.exports.__wbindgen_closure_wrapper5993 = function(arg0, arg1, arg2) {
2907
+ const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2908
2908
  return ret;
2909
2909
  };
2910
2910
 
2911
- module.exports.__wbindgen_closure_wrapper7576 = function(arg0, arg1, arg2) {
2912
- const ret = makeMutClosure(arg0, arg1, 865, __wbg_adapter_69);
2911
+ module.exports.__wbindgen_closure_wrapper7609 = function(arg0, arg1, arg2) {
2912
+ const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2913
2913
  return ret;
2914
2914
  };
2915
2915
 
Binary file
@@ -128,7 +128,7 @@ export const __wbindgen_export_5: WebAssembly.Table;
128
128
  export const __externref_drop_slice: (a: number, b: number) => void;
129
129
  export const __wbindgen_export_7: WebAssembly.Table;
130
130
  export const __externref_table_dealloc: (a: number) => void;
131
- export const closure384_externref_shim: (a: number, b: number, c: any) => void;
132
- export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h140914a8cfe47e73: (a: number, b: number) => void;
133
- export const closure656_externref_shim: (a: number, b: number, c: any, d: any) => void;
131
+ export const closure385_externref_shim: (a: number, b: number, c: any) => void;
132
+ export const _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1015faeeadd5b26c: (a: number, b: number) => void;
133
+ export const closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;
package/nodejs/index.mjs CHANGED
@@ -5,12 +5,12 @@ import pkg from './index.js';
5
5
 
6
6
  export const {
7
7
  defaultPostgresStorageConfig,
8
- getSparkStatus,
9
8
  defaultConfig,
10
- initLogging,
11
9
  connect,
12
- connectWithSigner,
13
10
  defaultExternalSigner,
11
+ initLogging,
12
+ getSparkStatus,
13
+ connectWithSigner,
14
14
  task_worker_entry_point,
15
15
  BreezSdk,
16
16
  DefaultSigner,
@@ -205,7 +205,6 @@ class PostgresTreeStore {
205
205
  // Clean up old spent markers
206
206
  await this._cleanupSpentMarkers(client, refreshTimestamp);
207
207
 
208
- // Get recent spent leaf IDs (spent_at >= refresh_timestamp)
209
208
  const spentResult = await client.query(
210
209
  "SELECT leaf_id FROM tree_spent_leaves WHERE spent_at >= $1",
211
210
  [refreshTimestamp]
@@ -235,27 +234,43 @@ class PostgresTreeStore {
235
234
  }
236
235
 
237
236
  /**
238
- * Cancel a reservation, releasing reserved leaves.
237
+ * Cancel a reservation. All leaves currently attached to the reservation are
238
+ * deleted from the store. The reservation row is dropped. The supplied
239
+ * `leavesToKeep` are inserted into the available pool.
240
+ *
241
+ * Callers pass the original reservation leaves to preserve the legacy
242
+ * "release everything back to the pool" behavior. Callers that have
243
+ * verified leaf state with the operator pass only the leaves confirmed
244
+ * safe to make available (e.g. dropping operator-locked leaves).
245
+ *
239
246
  * @param {string} id - Reservation ID
247
+ * @param {Array} leavesToKeep - Leaves to insert as available
240
248
  */
241
- async cancelReservation(id) {
249
+ async cancelReservation(id, leavesToKeep) {
242
250
  try {
243
251
  await this._withWriteTransaction(async (client) => {
244
- // Check if reservation exists
245
252
  const res = await client.query(
246
253
  "SELECT id FROM tree_reservations WHERE id = $1",
247
254
  [id]
248
255
  );
249
256
 
250
257
  if (res.rows.length === 0) {
251
- return; // Already cancelled or finalized
258
+ return;
252
259
  }
253
260
 
254
- // Delete reservation (ON DELETE SET NULL releases leaves)
261
+ await client.query(
262
+ "DELETE FROM tree_leaves WHERE reservation_id = $1",
263
+ [id]
264
+ );
265
+
255
266
  await client.query(
256
267
  "DELETE FROM tree_reservations WHERE id = $1",
257
268
  [id]
258
269
  );
270
+
271
+ if (leavesToKeep && leavesToKeep.length > 0) {
272
+ await this._batchUpsertLeaves(client, leavesToKeep, false, null);
273
+ }
259
274
  });
260
275
  } catch (error) {
261
276
  if (error instanceof TreeStoreError) throw error;
@@ -280,32 +295,26 @@ class PostgresTreeStore {
280
295
  [id]
281
296
  );
282
297
 
283
- if (res.rows.length === 0) {
284
- return; // Already finalized or cancelled
298
+ let isSwap = false;
299
+ let reservedLeafIds = [];
300
+ if (res.rows.length > 0) {
301
+ isSwap = res.rows[0].purpose === "Swap";
302
+ const leafResult = await client.query(
303
+ "SELECT id FROM tree_leaves WHERE reservation_id = $1",
304
+ [id]
305
+ );
306
+ reservedLeafIds = leafResult.rows.map((r) => r.id);
307
+ await this._batchInsertSpentLeaves(client, reservedLeafIds);
308
+ await client.query(
309
+ "DELETE FROM tree_leaves WHERE reservation_id = $1",
310
+ [id]
311
+ );
312
+ await client.query(
313
+ "DELETE FROM tree_reservations WHERE id = $1",
314
+ [id]
315
+ );
285
316
  }
286
317
 
287
- const isSwap = res.rows[0].purpose === "Swap";
288
-
289
- // Get reserved leaf IDs
290
- const leafResult = await client.query(
291
- "SELECT id FROM tree_leaves WHERE reservation_id = $1",
292
- [id]
293
- );
294
- const reservedLeafIds = leafResult.rows.map((r) => r.id);
295
-
296
- // Mark as spent
297
- await this._batchInsertSpentLeaves(client, reservedLeafIds);
298
-
299
- // Delete reserved leaves and reservation
300
- await client.query(
301
- "DELETE FROM tree_leaves WHERE reservation_id = $1",
302
- [id]
303
- );
304
- await client.query(
305
- "DELETE FROM tree_reservations WHERE id = $1",
306
- [id]
307
- );
308
-
309
318
  // Add new leaves if provided
310
319
  if (newLeaves && newLeaves.length > 0) {
311
320
  await this._batchUpsertLeaves(client, newLeaves, false, null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breeztech/breez-sdk-spark",
3
- "version": "0.13.2-dev5",
3
+ "version": "0.13.5",
4
4
  "description": "Breez Spark SDK",
5
5
  "repository": "https://github.com/breez/spark-sdk",
6
6
  "author": "Breez <contact@breez.technology> (https://github.com/breez)",
package/ssr/index.js CHANGED
@@ -28,24 +28,29 @@ export function defaultPostgresStorageConfig(...args) {
28
28
  return _module.defaultPostgresStorageConfig(...args);
29
29
  }
30
30
 
31
- export function getSparkStatus(...args) {
32
- if (!_module) _notInitialized('getSparkStatus');
33
- return _module.getSparkStatus(...args);
34
- }
35
-
36
31
  export function defaultConfig(...args) {
37
32
  if (!_module) _notInitialized('defaultConfig');
38
33
  return _module.defaultConfig(...args);
39
34
  }
40
35
 
36
+ export function connect(...args) {
37
+ if (!_module) _notInitialized('connect');
38
+ return _module.connect(...args);
39
+ }
40
+
41
+ export function defaultExternalSigner(...args) {
42
+ if (!_module) _notInitialized('defaultExternalSigner');
43
+ return _module.defaultExternalSigner(...args);
44
+ }
45
+
41
46
  export function initLogging(...args) {
42
47
  if (!_module) _notInitialized('initLogging');
43
48
  return _module.initLogging(...args);
44
49
  }
45
50
 
46
- export function connect(...args) {
47
- if (!_module) _notInitialized('connect');
48
- return _module.connect(...args);
51
+ export function getSparkStatus(...args) {
52
+ if (!_module) _notInitialized('getSparkStatus');
53
+ return _module.getSparkStatus(...args);
49
54
  }
50
55
 
51
56
  export function connectWithSigner(...args) {
@@ -53,11 +58,6 @@ export function connectWithSigner(...args) {
53
58
  return _module.connectWithSigner(...args);
54
59
  }
55
60
 
56
- export function defaultExternalSigner(...args) {
57
- if (!_module) _notInitialized('defaultExternalSigner');
58
- return _module.defaultExternalSigner(...args);
59
- }
60
-
61
61
  export function task_worker_entry_point(...args) {
62
62
  if (!_module) _notInitialized('task_worker_entry_point');
63
63
  return _module.task_worker_entry_point(...args);