@breeztech/breez-sdk-spark 0.13.4 → 0.13.6
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.
- package/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +2 -2
- package/bundler/breez_sdk_spark_wasm_bg.js +9 -9
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +1 -1
- package/deno/breez_sdk_spark_wasm.d.ts +2 -2
- package/deno/breez_sdk_spark_wasm.js +9 -9
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +1 -1
- package/nodejs/breez_sdk_spark_wasm.d.ts +2 -2
- package/nodejs/breez_sdk_spark_wasm.js +9 -9
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +1 -1
- package/nodejs/postgres-token-store/index.cjs +26 -0
- package/nodejs/postgres-tree-store/index.cjs +31 -9
- package/package.json +1 -1
- package/web/breez_sdk_spark_wasm.d.ts +3 -3
- package/web/breez_sdk_spark_wasm.js +9 -9
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +1 -1
package/breez-sdk-spark.tgz
CHANGED
|
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>;
|
|
@@ -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
|
|
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;
|
|
@@ -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.
|
|
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
|
|
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
|
|
2888
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
};
|
|
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
|
|
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>;
|
|
@@ -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
|
|
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;
|
|
@@ -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.
|
|
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
|
-
|
|
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
|
-
|
|
2643
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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>;
|
|
@@ -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
|
|
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;
|
|
@@ -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.
|
|
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.
|
|
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.
|
|
2892
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
133
|
+
export const closure665_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;
|
|
@@ -102,6 +108,13 @@ class PostgresTokenStore {
|
|
|
102
108
|
const refreshTimestamp = new Date(refreshStartedAtMs);
|
|
103
109
|
|
|
104
110
|
await this._withWriteTransaction(async (client) => {
|
|
111
|
+
// Drop expired reservations BEFORE evaluating has_active_swap, otherwise a stale
|
|
112
|
+
// Swap reservation (from a crashed client or a swap whose finalize/cancel never
|
|
113
|
+
// ran) keeps has_active_swap true forever, which makes setTokensOutputs
|
|
114
|
+
// early-return and never reach any subsequent reconciliation. The reservation
|
|
115
|
+
// pins itself in place and the local token-output set freezes.
|
|
116
|
+
await this._cleanupStaleReservations(client);
|
|
117
|
+
|
|
105
118
|
// Skip if swap is active or completed during this refresh
|
|
106
119
|
const swapCheckResult = await client.query(
|
|
107
120
|
`SELECT
|
|
@@ -725,6 +738,19 @@ class PostgresTokenStore {
|
|
|
725
738
|
});
|
|
726
739
|
}
|
|
727
740
|
|
|
741
|
+
/**
|
|
742
|
+
* Delete reservations that have exceeded the timeout.
|
|
743
|
+
* Called during setTokensOutputs to clean up stale reservations from crashed clients.
|
|
744
|
+
* The ON DELETE SET NULL foreign key constraint automatically releases the outputs.
|
|
745
|
+
*/
|
|
746
|
+
async _cleanupStaleReservations(client) {
|
|
747
|
+
await client.query(
|
|
748
|
+
`DELETE FROM token_reservations
|
|
749
|
+
WHERE created_at < NOW() - make_interval(secs => $1)`,
|
|
750
|
+
[RESERVATION_TIMEOUT_SECS]
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
|
|
728
754
|
/**
|
|
729
755
|
* Upsert token metadata.
|
|
730
756
|
*/
|
|
@@ -189,6 +189,12 @@ class PostgresTreeStore {
|
|
|
189
189
|
await this._withWriteTransaction(async (client) => {
|
|
190
190
|
const refreshTimestamp = new Date(refreshStartedAtMs);
|
|
191
191
|
|
|
192
|
+
// Drop expired reservations BEFORE evaluating has_active_swap, otherwise a stale
|
|
193
|
+
// Swap reservation (from a crashed client or a swap whose finalize/cancel never
|
|
194
|
+
// ran) keeps has_active_swap true forever, which makes set_leaves early-return
|
|
195
|
+
// and never reach the cleanup again. The reservation pins itself in place.
|
|
196
|
+
await this._cleanupStaleReservations(client);
|
|
197
|
+
|
|
192
198
|
// Check for active swap or swap completed during refresh
|
|
193
199
|
const swapCheckResult = await client.query(`
|
|
194
200
|
SELECT
|
|
@@ -211,15 +217,15 @@ class PostgresTreeStore {
|
|
|
211
217
|
);
|
|
212
218
|
const spentIds = new Set(spentResult.rows.map((r) => r.leaf_id));
|
|
213
219
|
|
|
214
|
-
// Delete non-reserved leaves added before refresh started
|
|
220
|
+
// Delete non-reserved leaves added before refresh started.
|
|
221
|
+
// Includes leaves released earlier in this transaction by _cleanupStaleReservations
|
|
222
|
+
// (FK ON DELETE SET NULL) — those rows kept their old added_at, so they are
|
|
223
|
+
// dropped here and re-fetched from the operator response in the upsert below.
|
|
215
224
|
await client.query(
|
|
216
225
|
"DELETE FROM tree_leaves WHERE reservation_id IS NULL AND added_at < $1",
|
|
217
226
|
[refreshTimestamp]
|
|
218
227
|
);
|
|
219
228
|
|
|
220
|
-
// Clean up stale reservations (after leaf delete)
|
|
221
|
-
await this._cleanupStaleReservations(client);
|
|
222
|
-
|
|
223
229
|
// Upsert all leaves (filtering spent)
|
|
224
230
|
await this._batchUpsertLeaves(client, leaves, false, spentIds);
|
|
225
231
|
await this._batchUpsertLeaves(client, missingLeaves, true, spentIds);
|
|
@@ -234,27 +240,43 @@ class PostgresTreeStore {
|
|
|
234
240
|
}
|
|
235
241
|
|
|
236
242
|
/**
|
|
237
|
-
* Cancel a reservation
|
|
243
|
+
* Cancel a reservation. All leaves currently attached to the reservation are
|
|
244
|
+
* deleted from the store. The reservation row is dropped. The supplied
|
|
245
|
+
* `leavesToKeep` are inserted into the available pool.
|
|
246
|
+
*
|
|
247
|
+
* Callers pass the original reservation leaves to preserve the legacy
|
|
248
|
+
* "release everything back to the pool" behavior. Callers that have
|
|
249
|
+
* verified leaf state with the operator pass only the leaves confirmed
|
|
250
|
+
* safe to make available (e.g. dropping operator-locked leaves).
|
|
251
|
+
*
|
|
238
252
|
* @param {string} id - Reservation ID
|
|
253
|
+
* @param {Array} leavesToKeep - Leaves to insert as available
|
|
239
254
|
*/
|
|
240
|
-
async cancelReservation(id) {
|
|
255
|
+
async cancelReservation(id, leavesToKeep) {
|
|
241
256
|
try {
|
|
242
257
|
await this._withWriteTransaction(async (client) => {
|
|
243
|
-
// Check if reservation exists
|
|
244
258
|
const res = await client.query(
|
|
245
259
|
"SELECT id FROM tree_reservations WHERE id = $1",
|
|
246
260
|
[id]
|
|
247
261
|
);
|
|
248
262
|
|
|
249
263
|
if (res.rows.length === 0) {
|
|
250
|
-
return;
|
|
264
|
+
return;
|
|
251
265
|
}
|
|
252
266
|
|
|
253
|
-
|
|
267
|
+
await client.query(
|
|
268
|
+
"DELETE FROM tree_leaves WHERE reservation_id = $1",
|
|
269
|
+
[id]
|
|
270
|
+
);
|
|
271
|
+
|
|
254
272
|
await client.query(
|
|
255
273
|
"DELETE FROM tree_reservations WHERE id = $1",
|
|
256
274
|
[id]
|
|
257
275
|
);
|
|
276
|
+
|
|
277
|
+
if (leavesToKeep && leavesToKeep.length > 0) {
|
|
278
|
+
await this._batchUpsertLeaves(client, leavesToKeep, false, null);
|
|
279
|
+
}
|
|
258
280
|
});
|
|
259
281
|
} catch (error) {
|
|
260
282
|
if (error instanceof TreeStoreError) throw error;
|
package/package.json
CHANGED
|
@@ -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>;
|
|
@@ -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
|
|
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;
|
|
@@ -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
|
|
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.
|
|
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.
|
|
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.
|
|
2684
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
133
|
+
export const closure665_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
134
134
|
export const __wbindgen_start: () => void;
|