@breeztech/breez-sdk-spark 0.13.4 → 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.
Binary file
@@ -66,7 +66,7 @@ export interface TreeStore {
66
66
  addLeaves: (leaves: TreeNode[]) => Promise<void>;
67
67
  getLeaves: () => Promise<Leaves>;
68
68
  setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
69
- cancelReservation: (id: string) => Promise<void>;
69
+ cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
70
70
  finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
71
71
  tryReserveLeaves: (targetAmounts: TargetAmounts | null, exactOnly: boolean, purpose: string) => Promise<ReserveResult>;
72
72
  now: () => Promise<number>;
@@ -342,7 +342,7 @@ function __wbg_adapter_69(arg0, arg1) {
342
342
  }
343
343
 
344
344
  function __wbg_adapter_433(arg0, arg1, arg2, arg3) {
345
- wasm.closure663_externref_shim(arg0, arg1, arg2, arg3);
345
+ wasm.closure665_externref_shim(arg0, arg1, arg2, arg3);
346
346
  }
347
347
 
348
348
  const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
@@ -1499,13 +1499,13 @@ export function __wbg_call_7cccdd69e0791ae2() { return handleError(function (arg
1499
1499
  return ret;
1500
1500
  }, arguments) };
1501
1501
 
1502
- export function __wbg_cancelReservation_d85a13db3e8e3c7b() { return handleError(function (arg0, arg1, arg2) {
1502
+ export function __wbg_cancelReservation_038a18dbc15a13b5() { return handleError(function (arg0, arg1, arg2, arg3) {
1503
1503
  let deferred0_0;
1504
1504
  let deferred0_1;
1505
1505
  try {
1506
1506
  deferred0_0 = arg1;
1507
1507
  deferred0_1 = arg2;
1508
- const ret = arg0.cancelReservation(getStringFromWasm0(arg1, arg2));
1508
+ const ret = arg0.cancelReservation(getStringFromWasm0(arg1, arg2), arg3);
1509
1509
  return ret;
1510
1510
  } finally {
1511
1511
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
@@ -2884,27 +2884,27 @@ export function __wbindgen_cb_drop(arg0) {
2884
2884
  return ret;
2885
2885
  };
2886
2886
 
2887
- export function __wbindgen_closure_wrapper13486(arg0, arg1, arg2) {
2888
- const ret = makeMutClosure(arg0, arg1, 867, __wbg_adapter_69);
2887
+ export function __wbindgen_closure_wrapper13493(arg0, arg1, arg2) {
2888
+ const ret = makeMutClosure(arg0, arg1, 869, __wbg_adapter_69);
2889
2889
  return ret;
2890
2890
  };
2891
2891
 
2892
- export function __wbindgen_closure_wrapper15492(arg0, arg1, arg2) {
2892
+ export function __wbindgen_closure_wrapper15518(arg0, arg1, arg2) {
2893
2893
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2894
2894
  return ret;
2895
2895
  };
2896
2896
 
2897
- export function __wbindgen_closure_wrapper5977(arg0, arg1, arg2) {
2897
+ export function __wbindgen_closure_wrapper5986(arg0, arg1, arg2) {
2898
2898
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2899
2899
  return ret;
2900
2900
  };
2901
2901
 
2902
- export function __wbindgen_closure_wrapper5984(arg0, arg1, arg2) {
2902
+ export function __wbindgen_closure_wrapper5993(arg0, arg1, arg2) {
2903
2903
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2904
2904
  return ret;
2905
2905
  };
2906
2906
 
2907
- export function __wbindgen_closure_wrapper7603(arg0, arg1, arg2) {
2907
+ export function __wbindgen_closure_wrapper7609(arg0, arg1, arg2) {
2908
2908
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2909
2909
  return ret;
2910
2910
  };
@@ -130,5 +130,5 @@ export const __wbindgen_export_7: WebAssembly.Table;
130
130
  export const __externref_table_dealloc: (a: number) => void;
131
131
  export const closure385_externref_shim: (a: number, b: number, c: any) => void;
132
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 closure663_externref_shim: (a: number, b: number, c: any, d: any) => void;
133
+ export const closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;
@@ -66,7 +66,7 @@ export interface TreeStore {
66
66
  addLeaves: (leaves: TreeNode[]) => Promise<void>;
67
67
  getLeaves: () => Promise<Leaves>;
68
68
  setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
69
- cancelReservation: (id: string) => Promise<void>;
69
+ cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
70
70
  finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
71
71
  tryReserveLeaves: (targetAmounts: TargetAmounts | null, exactOnly: boolean, purpose: string) => Promise<ReserveResult>;
72
72
  now: () => Promise<number>;
@@ -325,7 +325,7 @@ function __wbg_adapter_69(arg0, arg1) {
325
325
  }
326
326
 
327
327
  function __wbg_adapter_433(arg0, arg1, arg2, arg3) {
328
- wasm.closure663_externref_shim(arg0, arg1, arg2, arg3);
328
+ wasm.closure665_externref_shim(arg0, arg1, arg2, arg3);
329
329
  }
330
330
 
331
331
  const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
@@ -1465,13 +1465,13 @@ const imports = {
1465
1465
  const ret = arg0.call(arg1, arg2);
1466
1466
  return ret;
1467
1467
  }, arguments) },
1468
- __wbg_cancelReservation_d85a13db3e8e3c7b: function() { return handleError(function (arg0, arg1, arg2) {
1468
+ __wbg_cancelReservation_038a18dbc15a13b5: function() { return handleError(function (arg0, arg1, arg2, arg3) {
1469
1469
  let deferred0_0;
1470
1470
  let deferred0_1;
1471
1471
  try {
1472
1472
  deferred0_0 = arg1;
1473
1473
  deferred0_1 = arg2;
1474
- const ret = arg0.cancelReservation(getStringFromWasm0(arg1, arg2));
1474
+ const ret = arg0.cancelReservation(getStringFromWasm0(arg1, arg2), arg3);
1475
1475
  return ret;
1476
1476
  } finally {
1477
1477
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
@@ -2639,23 +2639,23 @@ const imports = {
2639
2639
  const ret = false;
2640
2640
  return ret;
2641
2641
  },
2642
- __wbindgen_closure_wrapper13486: function(arg0, arg1, arg2) {
2643
- const ret = makeMutClosure(arg0, arg1, 867, __wbg_adapter_69);
2642
+ __wbindgen_closure_wrapper13493: function(arg0, arg1, arg2) {
2643
+ const ret = makeMutClosure(arg0, arg1, 869, __wbg_adapter_69);
2644
2644
  return ret;
2645
2645
  },
2646
- __wbindgen_closure_wrapper15492: function(arg0, arg1, arg2) {
2646
+ __wbindgen_closure_wrapper15518: function(arg0, arg1, arg2) {
2647
2647
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2648
2648
  return ret;
2649
2649
  },
2650
- __wbindgen_closure_wrapper5977: function(arg0, arg1, arg2) {
2650
+ __wbindgen_closure_wrapper5986: function(arg0, arg1, arg2) {
2651
2651
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2652
2652
  return ret;
2653
2653
  },
2654
- __wbindgen_closure_wrapper5984: function(arg0, arg1, arg2) {
2654
+ __wbindgen_closure_wrapper5993: function(arg0, arg1, arg2) {
2655
2655
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2656
2656
  return ret;
2657
2657
  },
2658
- __wbindgen_closure_wrapper7603: function(arg0, arg1, arg2) {
2658
+ __wbindgen_closure_wrapper7609: function(arg0, arg1, arg2) {
2659
2659
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2660
2660
  return ret;
2661
2661
  },
Binary file
@@ -130,5 +130,5 @@ export const __wbindgen_export_7: WebAssembly.Table;
130
130
  export const __externref_table_dealloc: (a: number) => void;
131
131
  export const closure385_externref_shim: (a: number, b: number, c: any) => void;
132
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 closure663_externref_shim: (a: number, b: number, c: any, d: any) => void;
133
+ export const closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;
@@ -66,7 +66,7 @@ export interface TreeStore {
66
66
  addLeaves: (leaves: TreeNode[]) => Promise<void>;
67
67
  getLeaves: () => Promise<Leaves>;
68
68
  setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
69
- cancelReservation: (id: string) => Promise<void>;
69
+ cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
70
70
  finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
71
71
  tryReserveLeaves: (targetAmounts: TargetAmounts | null, exactOnly: boolean, purpose: string) => Promise<ReserveResult>;
72
72
  now: () => Promise<number>;
@@ -338,7 +338,7 @@ function __wbg_adapter_69(arg0, arg1) {
338
338
  }
339
339
 
340
340
  function __wbg_adapter_433(arg0, arg1, arg2, arg3) {
341
- wasm.closure663_externref_shim(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);
@@ -2888,27 +2888,27 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
2888
2888
  return ret;
2889
2889
  };
2890
2890
 
2891
- module.exports.__wbindgen_closure_wrapper13486 = function(arg0, arg1, arg2) {
2892
- const ret = makeMutClosure(arg0, arg1, 867, __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_wrapper15492 = function(arg0, arg1, arg2) {
2896
+ module.exports.__wbindgen_closure_wrapper15518 = function(arg0, arg1, arg2) {
2897
2897
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2898
2898
  return ret;
2899
2899
  };
2900
2900
 
2901
- module.exports.__wbindgen_closure_wrapper5977 = function(arg0, arg1, arg2) {
2901
+ module.exports.__wbindgen_closure_wrapper5986 = function(arg0, arg1, arg2) {
2902
2902
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2903
2903
  return ret;
2904
2904
  };
2905
2905
 
2906
- module.exports.__wbindgen_closure_wrapper5984 = function(arg0, arg1, arg2) {
2906
+ module.exports.__wbindgen_closure_wrapper5993 = function(arg0, arg1, arg2) {
2907
2907
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2908
2908
  return ret;
2909
2909
  };
2910
2910
 
2911
- module.exports.__wbindgen_closure_wrapper7603 = function(arg0, arg1, arg2) {
2911
+ module.exports.__wbindgen_closure_wrapper7609 = function(arg0, arg1, arg2) {
2912
2912
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2913
2913
  return ret;
2914
2914
  };
Binary file
@@ -130,5 +130,5 @@ export const __wbindgen_export_7: WebAssembly.Table;
130
130
  export const __externref_table_dealloc: (a: number) => void;
131
131
  export const closure385_externref_shim: (a: number, b: number, c: any) => void;
132
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 closure663_externref_shim: (a: number, b: number, c: any, d: any) => void;
133
+ export const closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;
@@ -234,27 +234,43 @@ class PostgresTreeStore {
234
234
  }
235
235
 
236
236
  /**
237
- * 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
+ *
238
246
  * @param {string} id - Reservation ID
247
+ * @param {Array} leavesToKeep - Leaves to insert as available
239
248
  */
240
- async cancelReservation(id) {
249
+ async cancelReservation(id, leavesToKeep) {
241
250
  try {
242
251
  await this._withWriteTransaction(async (client) => {
243
- // Check if reservation exists
244
252
  const res = await client.query(
245
253
  "SELECT id FROM tree_reservations WHERE id = $1",
246
254
  [id]
247
255
  );
248
256
 
249
257
  if (res.rows.length === 0) {
250
- return; // Already cancelled or finalized
258
+ return;
251
259
  }
252
260
 
253
- // 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
+
254
266
  await client.query(
255
267
  "DELETE FROM tree_reservations WHERE id = $1",
256
268
  [id]
257
269
  );
270
+
271
+ if (leavesToKeep && leavesToKeep.length > 0) {
272
+ await this._batchUpsertLeaves(client, leavesToKeep, false, null);
273
+ }
258
274
  });
259
275
  } catch (error) {
260
276
  if (error instanceof TreeStoreError) throw error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breeztech/breez-sdk-spark",
3
- "version": "0.13.4",
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)",
@@ -66,7 +66,7 @@ export interface TreeStore {
66
66
  addLeaves: (leaves: TreeNode[]) => Promise<void>;
67
67
  getLeaves: () => Promise<Leaves>;
68
68
  setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
69
- cancelReservation: (id: string) => Promise<void>;
69
+ cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
70
70
  finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
71
71
  tryReserveLeaves: (targetAmounts: TargetAmounts | null, exactOnly: boolean, purpose: string) => Promise<ReserveResult>;
72
72
  now: () => Promise<number>;
@@ -1671,7 +1671,7 @@ export interface InitOutput {
1671
1671
  readonly __externref_table_dealloc: (a: number) => void;
1672
1672
  readonly closure385_externref_shim: (a: number, b: number, c: any) => void;
1673
1673
  readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1015faeeadd5b26c: (a: number, b: number) => void;
1674
- readonly closure663_externref_shim: (a: number, b: number, c: any, d: any) => void;
1674
+ readonly closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
1675
1675
  readonly __wbindgen_start: () => void;
1676
1676
  }
1677
1677
 
@@ -334,7 +334,7 @@ function __wbg_adapter_69(arg0, arg1) {
334
334
  }
335
335
 
336
336
  function __wbg_adapter_433(arg0, arg1, arg2, arg3) {
337
- wasm.closure663_externref_shim(arg0, arg1, arg2, arg3);
337
+ wasm.closure665_externref_shim(arg0, arg1, arg2, arg3);
338
338
  }
339
339
 
340
340
  const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
@@ -1506,13 +1506,13 @@ function __wbg_get_imports() {
1506
1506
  const ret = arg0.call(arg1, arg2);
1507
1507
  return ret;
1508
1508
  }, arguments) };
1509
- imports.wbg.__wbg_cancelReservation_d85a13db3e8e3c7b = function() { return handleError(function (arg0, arg1, arg2) {
1509
+ imports.wbg.__wbg_cancelReservation_038a18dbc15a13b5 = function() { return handleError(function (arg0, arg1, arg2, arg3) {
1510
1510
  let deferred0_0;
1511
1511
  let deferred0_1;
1512
1512
  try {
1513
1513
  deferred0_0 = arg1;
1514
1514
  deferred0_1 = arg2;
1515
- const ret = arg0.cancelReservation(getStringFromWasm0(arg1, arg2));
1515
+ const ret = arg0.cancelReservation(getStringFromWasm0(arg1, arg2), arg3);
1516
1516
  return ret;
1517
1517
  } finally {
1518
1518
  wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
@@ -2680,23 +2680,23 @@ function __wbg_get_imports() {
2680
2680
  const ret = false;
2681
2681
  return ret;
2682
2682
  };
2683
- imports.wbg.__wbindgen_closure_wrapper13486 = function(arg0, arg1, arg2) {
2684
- const ret = makeMutClosure(arg0, arg1, 867, __wbg_adapter_69);
2683
+ imports.wbg.__wbindgen_closure_wrapper13493 = function(arg0, arg1, arg2) {
2684
+ const ret = makeMutClosure(arg0, arg1, 869, __wbg_adapter_69);
2685
2685
  return ret;
2686
2686
  };
2687
- imports.wbg.__wbindgen_closure_wrapper15492 = function(arg0, arg1, arg2) {
2687
+ imports.wbg.__wbindgen_closure_wrapper15518 = function(arg0, arg1, arg2) {
2688
2688
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2689
2689
  return ret;
2690
2690
  };
2691
- imports.wbg.__wbindgen_closure_wrapper5977 = function(arg0, arg1, arg2) {
2691
+ imports.wbg.__wbindgen_closure_wrapper5986 = function(arg0, arg1, arg2) {
2692
2692
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2693
2693
  return ret;
2694
2694
  };
2695
- imports.wbg.__wbindgen_closure_wrapper5984 = function(arg0, arg1, arg2) {
2695
+ imports.wbg.__wbindgen_closure_wrapper5993 = function(arg0, arg1, arg2) {
2696
2696
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2697
2697
  return ret;
2698
2698
  };
2699
- imports.wbg.__wbindgen_closure_wrapper7603 = function(arg0, arg1, arg2) {
2699
+ imports.wbg.__wbindgen_closure_wrapper7609 = function(arg0, arg1, arg2) {
2700
2700
  const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2701
2701
  return ret;
2702
2702
  };
Binary file
@@ -130,5 +130,5 @@ export const __wbindgen_export_7: WebAssembly.Table;
130
130
  export const __externref_table_dealloc: (a: number) => void;
131
131
  export const closure385_externref_shim: (a: number, b: number, c: any) => void;
132
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 closure663_externref_shim: (a: number, b: number, c: any, d: any) => void;
133
+ export const closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;