@breeztech/breez-sdk-spark 0.13.5 → 0.13.7-debug

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
@@ -449,7 +449,7 @@ export interface AesSuccessActionData {
449
449
 
450
450
  export type InputType = ({ type: "bitcoinAddress" } & BitcoinAddressDetails) | ({ type: "bolt11Invoice" } & Bolt11InvoiceDetails) | ({ type: "bolt12Invoice" } & Bolt12InvoiceDetails) | ({ type: "bolt12Offer" } & Bolt12OfferDetails) | ({ type: "lightningAddress" } & LightningAddressDetails) | ({ type: "lnurlPay" } & LnurlPayRequestDetails) | ({ type: "silentPaymentAddress" } & SilentPaymentAddressDetails) | ({ type: "lnurlAuth" } & LnurlAuthRequestDetails) | ({ type: "url" } & string) | ({ type: "bip21" } & Bip21Details) | ({ type: "bolt12InvoiceRequest" } & Bolt12InvoiceRequestDetails) | ({ type: "lnurlWithdraw" } & LnurlWithdrawRequestDetails) | ({ type: "sparkAddress" } & SparkAddressDetails) | ({ type: "sparkInvoice" } & SparkInvoiceDetails);
451
451
 
452
- export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats?: number };
452
+ export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats: number };
453
453
 
454
454
  export interface SetLnurlMetadataItem {
455
455
  paymentHash: string;
@@ -334,7 +334,7 @@ export function task_worker_entry_point(ptr) {
334
334
  }
335
335
 
336
336
  function __wbg_adapter_64(arg0, arg1, arg2) {
337
- wasm.closure385_externref_shim(arg0, arg1, arg2);
337
+ wasm.closure386_externref_shim(arg0, arg1, arg2);
338
338
  }
339
339
 
340
340
  function __wbg_adapter_69(arg0, arg1) {
@@ -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.closure665_externref_shim(arg0, arg1, arg2, arg3);
345
+ wasm.closure666_externref_shim(arg0, arg1, arg2, arg3);
346
346
  }
347
347
 
348
348
  const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
@@ -2884,28 +2884,28 @@ export function __wbindgen_cb_drop(arg0) {
2884
2884
  return ret;
2885
2885
  };
2886
2886
 
2887
- export function __wbindgen_closure_wrapper13493(arg0, arg1, arg2) {
2888
- const ret = makeMutClosure(arg0, arg1, 869, __wbg_adapter_69);
2887
+ export function __wbindgen_closure_wrapper13509(arg0, arg1, arg2) {
2888
+ const ret = makeMutClosure(arg0, arg1, 870, __wbg_adapter_69);
2889
2889
  return ret;
2890
2890
  };
2891
2891
 
2892
- export function __wbindgen_closure_wrapper15518(arg0, arg1, arg2) {
2893
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2892
+ export function __wbindgen_closure_wrapper15533(arg0, arg1, arg2) {
2893
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2894
2894
  return ret;
2895
2895
  };
2896
2896
 
2897
- export function __wbindgen_closure_wrapper5986(arg0, arg1, arg2) {
2898
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2897
+ export function __wbindgen_closure_wrapper6003(arg0, arg1, arg2) {
2898
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2899
2899
  return ret;
2900
2900
  };
2901
2901
 
2902
- export function __wbindgen_closure_wrapper5993(arg0, arg1, arg2) {
2903
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2902
+ export function __wbindgen_closure_wrapper6010(arg0, arg1, arg2) {
2903
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2904
2904
  return ret;
2905
2905
  };
2906
2906
 
2907
- export function __wbindgen_closure_wrapper7609(arg0, arg1, arg2) {
2908
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2907
+ export function __wbindgen_closure_wrapper7625(arg0, arg1, arg2) {
2908
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_69);
2909
2909
  return ret;
2910
2910
  };
2911
2911
 
@@ -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 closure385_externref_shim: (a: number, b: number, c: any) => void;
131
+ export const closure386_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 closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
133
+ export const closure666_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;
@@ -449,7 +449,7 @@ export interface AesSuccessActionData {
449
449
 
450
450
  export type InputType = ({ type: "bitcoinAddress" } & BitcoinAddressDetails) | ({ type: "bolt11Invoice" } & Bolt11InvoiceDetails) | ({ type: "bolt12Invoice" } & Bolt12InvoiceDetails) | ({ type: "bolt12Offer" } & Bolt12OfferDetails) | ({ type: "lightningAddress" } & LightningAddressDetails) | ({ type: "lnurlPay" } & LnurlPayRequestDetails) | ({ type: "silentPaymentAddress" } & SilentPaymentAddressDetails) | ({ type: "lnurlAuth" } & LnurlAuthRequestDetails) | ({ type: "url" } & string) | ({ type: "bip21" } & Bip21Details) | ({ type: "bolt12InvoiceRequest" } & Bolt12InvoiceRequestDetails) | ({ type: "lnurlWithdraw" } & LnurlWithdrawRequestDetails) | ({ type: "sparkAddress" } & SparkAddressDetails) | ({ type: "sparkInvoice" } & SparkInvoiceDetails);
451
451
 
452
- export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats?: number };
452
+ export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats: number };
453
453
 
454
454
  export interface SetLnurlMetadataItem {
455
455
  paymentHash: string;
@@ -317,7 +317,7 @@ export function task_worker_entry_point(ptr) {
317
317
  }
318
318
 
319
319
  function __wbg_adapter_64(arg0, arg1, arg2) {
320
- wasm.closure385_externref_shim(arg0, arg1, arg2);
320
+ wasm.closure386_externref_shim(arg0, arg1, arg2);
321
321
  }
322
322
 
323
323
  function __wbg_adapter_69(arg0, arg1) {
@@ -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.closure665_externref_shim(arg0, arg1, arg2, arg3);
328
+ wasm.closure666_externref_shim(arg0, arg1, arg2, arg3);
329
329
  }
330
330
 
331
331
  const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
@@ -2639,24 +2639,24 @@ const imports = {
2639
2639
  const ret = false;
2640
2640
  return ret;
2641
2641
  },
2642
- __wbindgen_closure_wrapper13493: function(arg0, arg1, arg2) {
2643
- const ret = makeMutClosure(arg0, arg1, 869, __wbg_adapter_69);
2642
+ __wbindgen_closure_wrapper13509: function(arg0, arg1, arg2) {
2643
+ const ret = makeMutClosure(arg0, arg1, 870, __wbg_adapter_69);
2644
2644
  return ret;
2645
2645
  },
2646
- __wbindgen_closure_wrapper15518: function(arg0, arg1, arg2) {
2647
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2646
+ __wbindgen_closure_wrapper15533: function(arg0, arg1, arg2) {
2647
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2648
2648
  return ret;
2649
2649
  },
2650
- __wbindgen_closure_wrapper5986: function(arg0, arg1, arg2) {
2651
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2650
+ __wbindgen_closure_wrapper6003: function(arg0, arg1, arg2) {
2651
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2652
2652
  return ret;
2653
2653
  },
2654
- __wbindgen_closure_wrapper5993: function(arg0, arg1, arg2) {
2655
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2654
+ __wbindgen_closure_wrapper6010: function(arg0, arg1, arg2) {
2655
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2656
2656
  return ret;
2657
2657
  },
2658
- __wbindgen_closure_wrapper7609: function(arg0, arg1, arg2) {
2659
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2658
+ __wbindgen_closure_wrapper7625: function(arg0, arg1, arg2) {
2659
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_69);
2660
2660
  return ret;
2661
2661
  },
2662
2662
  __wbindgen_debug_string: function(arg0, arg1) {
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 closure385_externref_shim: (a: number, b: number, c: any) => void;
131
+ export const closure386_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 closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
133
+ export const closure666_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;
@@ -449,7 +449,7 @@ export interface AesSuccessActionData {
449
449
 
450
450
  export type InputType = ({ type: "bitcoinAddress" } & BitcoinAddressDetails) | ({ type: "bolt11Invoice" } & Bolt11InvoiceDetails) | ({ type: "bolt12Invoice" } & Bolt12InvoiceDetails) | ({ type: "bolt12Offer" } & Bolt12OfferDetails) | ({ type: "lightningAddress" } & LightningAddressDetails) | ({ type: "lnurlPay" } & LnurlPayRequestDetails) | ({ type: "silentPaymentAddress" } & SilentPaymentAddressDetails) | ({ type: "lnurlAuth" } & LnurlAuthRequestDetails) | ({ type: "url" } & string) | ({ type: "bip21" } & Bip21Details) | ({ type: "bolt12InvoiceRequest" } & Bolt12InvoiceRequestDetails) | ({ type: "lnurlWithdraw" } & LnurlWithdrawRequestDetails) | ({ type: "sparkAddress" } & SparkAddressDetails) | ({ type: "sparkInvoice" } & SparkInvoiceDetails);
451
451
 
452
- export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats?: number };
452
+ export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats: number };
453
453
 
454
454
  export interface SetLnurlMetadataItem {
455
455
  paymentHash: string;
@@ -330,7 +330,7 @@ module.exports.task_worker_entry_point = function(ptr) {
330
330
  };
331
331
 
332
332
  function __wbg_adapter_64(arg0, arg1, arg2) {
333
- wasm.closure385_externref_shim(arg0, arg1, arg2);
333
+ wasm.closure386_externref_shim(arg0, arg1, arg2);
334
334
  }
335
335
 
336
336
  function __wbg_adapter_69(arg0, arg1) {
@@ -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.closure665_externref_shim(arg0, arg1, arg2, arg3);
341
+ wasm.closure666_externref_shim(arg0, arg1, arg2, arg3);
342
342
  }
343
343
 
344
344
  const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
@@ -2888,28 +2888,28 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
2888
2888
  return ret;
2889
2889
  };
2890
2890
 
2891
- module.exports.__wbindgen_closure_wrapper13493 = function(arg0, arg1, arg2) {
2892
- const ret = makeMutClosure(arg0, arg1, 869, __wbg_adapter_69);
2891
+ module.exports.__wbindgen_closure_wrapper13509 = function(arg0, arg1, arg2) {
2892
+ const ret = makeMutClosure(arg0, arg1, 870, __wbg_adapter_69);
2893
2893
  return ret;
2894
2894
  };
2895
2895
 
2896
- module.exports.__wbindgen_closure_wrapper15518 = function(arg0, arg1, arg2) {
2897
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2896
+ module.exports.__wbindgen_closure_wrapper15533 = function(arg0, arg1, arg2) {
2897
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2898
2898
  return ret;
2899
2899
  };
2900
2900
 
2901
- module.exports.__wbindgen_closure_wrapper5986 = function(arg0, arg1, arg2) {
2902
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2901
+ module.exports.__wbindgen_closure_wrapper6003 = function(arg0, arg1, arg2) {
2902
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2903
2903
  return ret;
2904
2904
  };
2905
2905
 
2906
- module.exports.__wbindgen_closure_wrapper5993 = function(arg0, arg1, arg2) {
2907
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2906
+ module.exports.__wbindgen_closure_wrapper6010 = function(arg0, arg1, arg2) {
2907
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2908
2908
  return ret;
2909
2909
  };
2910
2910
 
2911
- module.exports.__wbindgen_closure_wrapper7609 = function(arg0, arg1, arg2) {
2912
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2911
+ module.exports.__wbindgen_closure_wrapper7625 = function(arg0, arg1, arg2) {
2912
+ const ret = makeMutClosure(arg0, arg1, 387, __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 closure385_externref_shim: (a: number, b: number, c: any) => void;
131
+ export const closure386_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 closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
133
+ export const closure666_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;
@@ -36,6 +36,12 @@ const TOKEN_STORE_WRITE_LOCK_KEY = "8390042714201347154"; // 0x746F6B656E535452
36
36
  */
37
37
  const SPENT_MARKER_CLEANUP_THRESHOLD_MS = 5 * 60 * 1000; // 5 minutes
38
38
 
39
+ /**
40
+ * Reservations whose created_at is older than this are considered stale and are
41
+ * dropped at the start of setTokensOutputs. Matches the tree store's timeout.
42
+ */
43
+ const RESERVATION_TIMEOUT_SECS = 300; // 5 minutes
44
+
39
45
  class PostgresTokenStore {
40
46
  constructor(pool, logger = null) {
41
47
  this.pool = pool;
@@ -69,7 +75,9 @@ class PostgresTokenStore {
69
75
  }
70
76
 
71
77
  /**
72
- * Run a function inside a transaction with the advisory lock.
78
+ * Run a function inside a transaction with the advisory lock. Reserved for
79
+ * operations whose correctness depends on serializing the available-output
80
+ * set (`reserveTokenOutputs`, `setTokensOutputs`).
73
81
  * @param {function(import('pg').PoolClient): Promise<T>} fn
74
82
  * @returns {Promise<T>}
75
83
  * @template T
@@ -90,6 +98,30 @@ class PostgresTokenStore {
90
98
  }
91
99
  }
92
100
 
101
+ /**
102
+ * Run a function inside a transaction without the advisory lock. Used by
103
+ * operations scoped to a single reservation_id (`cancelReservation`,
104
+ * `finalizeReservation`) where MVCC + row-level locks suffice and the global
105
+ * lock would only add contention.
106
+ * @param {function(import('pg').PoolClient): Promise<T>} fn
107
+ * @returns {Promise<T>}
108
+ * @template T
109
+ */
110
+ async _withTransaction(fn) {
111
+ const client = await this.pool.connect();
112
+ try {
113
+ await client.query("BEGIN");
114
+ const result = await fn(client);
115
+ await client.query("COMMIT");
116
+ return result;
117
+ } catch (error) {
118
+ await client.query("ROLLBACK").catch(() => {});
119
+ throw error;
120
+ } finally {
121
+ client.release();
122
+ }
123
+ }
124
+
93
125
  // ===== TokenOutputStore Methods =====
94
126
 
95
127
  /**
@@ -102,6 +134,13 @@ class PostgresTokenStore {
102
134
  const refreshTimestamp = new Date(refreshStartedAtMs);
103
135
 
104
136
  await this._withWriteTransaction(async (client) => {
137
+ // Drop expired reservations BEFORE evaluating has_active_swap, otherwise a stale
138
+ // Swap reservation (from a crashed client or a swap whose finalize/cancel never
139
+ // ran) keeps has_active_swap true forever, which makes setTokensOutputs
140
+ // early-return and never reach any subsequent reconciliation. The reservation
141
+ // pins itself in place and the local token-output set freezes.
142
+ await this._cleanupStaleReservations(client);
143
+
105
144
  // Skip if swap is active or completed during this refresh
106
145
  const swapCheckResult = await client.query(
107
146
  `SELECT
@@ -601,7 +640,7 @@ class PostgresTokenStore {
601
640
  */
602
641
  async cancelReservation(id) {
603
642
  try {
604
- await this._withWriteTransaction(async (client) => {
643
+ await this._withTransaction(async (client) => {
605
644
  // Clear reservation_id from outputs
606
645
  await client.query(
607
646
  "UPDATE token_outputs SET reservation_id = NULL WHERE reservation_id = $1",
@@ -629,7 +668,7 @@ class PostgresTokenStore {
629
668
  */
630
669
  async finalizeReservation(id) {
631
670
  try {
632
- await this._withWriteTransaction(async (client) => {
671
+ await this._withTransaction(async (client) => {
633
672
  // Get reservation purpose
634
673
  const reservationResult = await client.query(
635
674
  "SELECT purpose FROM token_reservations WHERE id = $1",
@@ -725,6 +764,19 @@ class PostgresTokenStore {
725
764
  });
726
765
  }
727
766
 
767
+ /**
768
+ * Delete reservations that have exceeded the timeout.
769
+ * Called during setTokensOutputs to clean up stale reservations from crashed clients.
770
+ * The ON DELETE SET NULL foreign key constraint automatically releases the outputs.
771
+ */
772
+ async _cleanupStaleReservations(client) {
773
+ await client.query(
774
+ `DELETE FROM token_reservations
775
+ WHERE created_at < NOW() - make_interval(secs => $1)`,
776
+ [RESERVATION_TIMEOUT_SECS]
777
+ );
778
+ }
779
+
728
780
  /**
729
781
  * Upsert token metadata.
730
782
  */
@@ -73,7 +73,9 @@ class PostgresTreeStore {
73
73
  }
74
74
 
75
75
  /**
76
- * Run a function inside a transaction with the advisory lock.
76
+ * Run a function inside a transaction with the advisory lock. Reserved for
77
+ * operations whose correctness depends on serializing the available-leaf set
78
+ * (`tryReserveLeaves`, `setLeaves`).
77
79
  * @param {function(import('pg').PoolClient): Promise<T>} fn
78
80
  * @returns {Promise<T>}
79
81
  * @template T
@@ -94,6 +96,31 @@ class PostgresTreeStore {
94
96
  }
95
97
  }
96
98
 
99
+ /**
100
+ * Run a function inside a transaction without the advisory lock. Used by
101
+ * operations scoped to a single reservation_id (`addLeaves`,
102
+ * `cancelReservation`, `finalizeReservation`, `updateReservation`) where
103
+ * MVCC + row-level locks suffice and the global lock would only add
104
+ * contention.
105
+ * @param {function(import('pg').PoolClient): Promise<T>} fn
106
+ * @returns {Promise<T>}
107
+ * @template T
108
+ */
109
+ async _withTransaction(fn) {
110
+ const client = await this.pool.connect();
111
+ try {
112
+ await client.query("BEGIN");
113
+ const result = await fn(client);
114
+ await client.query("COMMIT");
115
+ return result;
116
+ } catch (error) {
117
+ await client.query("ROLLBACK").catch(() => {});
118
+ throw error;
119
+ } finally {
120
+ client.release();
121
+ }
122
+ }
123
+
97
124
  // ===== TreeStore Methods =====
98
125
 
99
126
  /**
@@ -106,7 +133,7 @@ class PostgresTreeStore {
106
133
  return;
107
134
  }
108
135
 
109
- await this._withWriteTransaction(async (client) => {
136
+ await this._withTransaction(async (client) => {
110
137
  // Remove these leaves from spent_leaves table
111
138
  const leafIds = leaves.map((l) => l.id);
112
139
  await this._batchRemoveSpentLeaves(client, leafIds);
@@ -189,6 +216,12 @@ class PostgresTreeStore {
189
216
  await this._withWriteTransaction(async (client) => {
190
217
  const refreshTimestamp = new Date(refreshStartedAtMs);
191
218
 
219
+ // Drop expired reservations BEFORE evaluating has_active_swap, otherwise a stale
220
+ // Swap reservation (from a crashed client or a swap whose finalize/cancel never
221
+ // ran) keeps has_active_swap true forever, which makes set_leaves early-return
222
+ // and never reach the cleanup again. The reservation pins itself in place.
223
+ await this._cleanupStaleReservations(client);
224
+
192
225
  // Check for active swap or swap completed during refresh
193
226
  const swapCheckResult = await client.query(`
194
227
  SELECT
@@ -211,15 +244,15 @@ class PostgresTreeStore {
211
244
  );
212
245
  const spentIds = new Set(spentResult.rows.map((r) => r.leaf_id));
213
246
 
214
- // Delete non-reserved leaves added before refresh started
247
+ // Delete non-reserved leaves added before refresh started.
248
+ // Includes leaves released earlier in this transaction by _cleanupStaleReservations
249
+ // (FK ON DELETE SET NULL) — those rows kept their old added_at, so they are
250
+ // dropped here and re-fetched from the operator response in the upsert below.
215
251
  await client.query(
216
252
  "DELETE FROM tree_leaves WHERE reservation_id IS NULL AND added_at < $1",
217
253
  [refreshTimestamp]
218
254
  );
219
255
 
220
- // Clean up stale reservations (after leaf delete)
221
- await this._cleanupStaleReservations(client);
222
-
223
256
  // Upsert all leaves (filtering spent)
224
257
  await this._batchUpsertLeaves(client, leaves, false, spentIds);
225
258
  await this._batchUpsertLeaves(client, missingLeaves, true, spentIds);
@@ -248,7 +281,7 @@ class PostgresTreeStore {
248
281
  */
249
282
  async cancelReservation(id, leavesToKeep) {
250
283
  try {
251
- await this._withWriteTransaction(async (client) => {
284
+ await this._withTransaction(async (client) => {
252
285
  const res = await client.query(
253
286
  "SELECT id FROM tree_reservations WHERE id = $1",
254
287
  [id]
@@ -288,7 +321,7 @@ class PostgresTreeStore {
288
321
  */
289
322
  async finalizeReservation(id, newLeaves) {
290
323
  try {
291
- await this._withWriteTransaction(async (client) => {
324
+ await this._withTransaction(async (client) => {
292
325
  // Check if reservation exists and get purpose
293
326
  const res = await client.query(
294
327
  "SELECT id, purpose FROM tree_reservations WHERE id = $1",
@@ -451,7 +484,7 @@ class PostgresTreeStore {
451
484
  */
452
485
  async updateReservation(reservationId, reservedLeaves, changeLeaves) {
453
486
  try {
454
- return await this._withWriteTransaction(async (client) => {
487
+ return await this._withTransaction(async (client) => {
455
488
  // Check if reservation exists
456
489
  const res = await client.query(
457
490
  "SELECT id FROM tree_reservations WHERE id = $1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@breeztech/breez-sdk-spark",
3
- "version": "0.13.5",
3
+ "version": "0.13.7-debug",
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)",
@@ -449,7 +449,7 @@ export interface AesSuccessActionData {
449
449
 
450
450
  export type InputType = ({ type: "bitcoinAddress" } & BitcoinAddressDetails) | ({ type: "bolt11Invoice" } & Bolt11InvoiceDetails) | ({ type: "bolt12Invoice" } & Bolt12InvoiceDetails) | ({ type: "bolt12Offer" } & Bolt12OfferDetails) | ({ type: "lightningAddress" } & LightningAddressDetails) | ({ type: "lnurlPay" } & LnurlPayRequestDetails) | ({ type: "silentPaymentAddress" } & SilentPaymentAddressDetails) | ({ type: "lnurlAuth" } & LnurlAuthRequestDetails) | ({ type: "url" } & string) | ({ type: "bip21" } & Bip21Details) | ({ type: "bolt12InvoiceRequest" } & Bolt12InvoiceRequestDetails) | ({ type: "lnurlWithdraw" } & LnurlWithdrawRequestDetails) | ({ type: "sparkAddress" } & SparkAddressDetails) | ({ type: "sparkInvoice" } & SparkInvoiceDetails);
451
451
 
452
- export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats?: number };
452
+ export type BuyBitcoinRequest = { type: "moonpay"; lockedAmountSat?: number; redirectUrl?: string } | { type: "cashApp"; amountSats: number };
453
453
 
454
454
  export interface SetLnurlMetadataItem {
455
455
  paymentHash: string;
@@ -1669,9 +1669,9 @@ export interface InitOutput {
1669
1669
  readonly __externref_drop_slice: (a: number, b: number) => void;
1670
1670
  readonly __wbindgen_export_7: WebAssembly.Table;
1671
1671
  readonly __externref_table_dealloc: (a: number) => void;
1672
- readonly closure385_externref_shim: (a: number, b: number, c: any) => void;
1672
+ readonly closure386_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 closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
1674
+ readonly closure666_externref_shim: (a: number, b: number, c: any, d: any) => void;
1675
1675
  readonly __wbindgen_start: () => void;
1676
1676
  }
1677
1677
 
@@ -326,7 +326,7 @@ export function task_worker_entry_point(ptr) {
326
326
  }
327
327
 
328
328
  function __wbg_adapter_64(arg0, arg1, arg2) {
329
- wasm.closure385_externref_shim(arg0, arg1, arg2);
329
+ wasm.closure386_externref_shim(arg0, arg1, arg2);
330
330
  }
331
331
 
332
332
  function __wbg_adapter_69(arg0, arg1) {
@@ -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.closure665_externref_shim(arg0, arg1, arg2, arg3);
337
+ wasm.closure666_externref_shim(arg0, arg1, arg2, arg3);
338
338
  }
339
339
 
340
340
  const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
@@ -2680,24 +2680,24 @@ function __wbg_get_imports() {
2680
2680
  const ret = false;
2681
2681
  return ret;
2682
2682
  };
2683
- imports.wbg.__wbindgen_closure_wrapper13493 = function(arg0, arg1, arg2) {
2684
- const ret = makeMutClosure(arg0, arg1, 869, __wbg_adapter_69);
2683
+ imports.wbg.__wbindgen_closure_wrapper13509 = function(arg0, arg1, arg2) {
2684
+ const ret = makeMutClosure(arg0, arg1, 870, __wbg_adapter_69);
2685
2685
  return ret;
2686
2686
  };
2687
- imports.wbg.__wbindgen_closure_wrapper15518 = function(arg0, arg1, arg2) {
2688
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2687
+ imports.wbg.__wbindgen_closure_wrapper15533 = function(arg0, arg1, arg2) {
2688
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2689
2689
  return ret;
2690
2690
  };
2691
- imports.wbg.__wbindgen_closure_wrapper5986 = function(arg0, arg1, arg2) {
2692
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2691
+ imports.wbg.__wbindgen_closure_wrapper6003 = function(arg0, arg1, arg2) {
2692
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2693
2693
  return ret;
2694
2694
  };
2695
- imports.wbg.__wbindgen_closure_wrapper5993 = function(arg0, arg1, arg2) {
2696
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_64);
2695
+ imports.wbg.__wbindgen_closure_wrapper6010 = function(arg0, arg1, arg2) {
2696
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_64);
2697
2697
  return ret;
2698
2698
  };
2699
- imports.wbg.__wbindgen_closure_wrapper7609 = function(arg0, arg1, arg2) {
2700
- const ret = makeMutClosure(arg0, arg1, 386, __wbg_adapter_69);
2699
+ imports.wbg.__wbindgen_closure_wrapper7625 = function(arg0, arg1, arg2) {
2700
+ const ret = makeMutClosure(arg0, arg1, 387, __wbg_adapter_69);
2701
2701
  return ret;
2702
2702
  };
2703
2703
  imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
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 closure385_externref_shim: (a: number, b: number, c: any) => void;
131
+ export const closure386_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 closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
133
+ export const closure666_externref_shim: (a: number, b: number, c: any, d: any) => void;
134
134
  export const __wbindgen_start: () => void;