@breeztech/breez-sdk-spark 0.13.6 → 0.13.8-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.
- package/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +2 -0
- package/bundler/breez_sdk_spark_wasm_bg.js +49 -16
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +2 -2
- package/deno/breez_sdk_spark_wasm.d.ts +2 -0
- package/deno/breez_sdk_spark_wasm.js +43 -16
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +2 -2
- package/nodejs/breez_sdk_spark_wasm.d.ts +2 -0
- package/nodejs/breez_sdk_spark_wasm.js +49 -16
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +2 -2
- package/nodejs/postgres-token-store/index.cjs +81 -3
- package/nodejs/postgres-tree-store/index.cjs +138 -20
- package/package.json +1 -1
- package/web/breez_sdk_spark_wasm.d.ts +4 -2
- package/web/breez_sdk_spark_wasm.js +43 -16
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +2 -2
package/breez-sdk-spark.tgz
CHANGED
|
Binary file
|
|
@@ -65,6 +65,7 @@ type ReserveResult =
|
|
|
65
65
|
export interface TreeStore {
|
|
66
66
|
addLeaves: (leaves: TreeNode[]) => Promise<void>;
|
|
67
67
|
getLeaves: () => Promise<Leaves>;
|
|
68
|
+
getAvailableBalance: () => Promise<bigint | number>;
|
|
68
69
|
setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
|
|
69
70
|
cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
|
|
70
71
|
finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
|
|
@@ -152,6 +153,7 @@ type WasmReservationTarget =
|
|
|
152
153
|
export interface TokenStore {
|
|
153
154
|
setTokensOutputs: (tokenOutputs: WasmTokenOutputs[], refreshStartedAtMs: number) => Promise<void>;
|
|
154
155
|
listTokensOutputs: () => Promise<WasmTokenOutputsPerStatus[]>;
|
|
156
|
+
getTokenBalances: () => Promise<WasmTokenBalance[]>;
|
|
155
157
|
getTokenOutputs: (filter: WasmGetTokenOutputsFilter) => Promise<WasmTokenOutputsPerStatus>;
|
|
156
158
|
insertTokenOutputs: (tokenOutputs: WasmTokenOutputs) => Promise<void>;
|
|
157
159
|
reserveTokenOutputs: (
|
|
@@ -333,16 +333,16 @@ export function task_worker_entry_point(ptr) {
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
function
|
|
337
|
-
wasm.
|
|
336
|
+
function __wbg_adapter_68(arg0, arg1, arg2) {
|
|
337
|
+
wasm.closure388_externref_shim(arg0, arg1, arg2);
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
function
|
|
340
|
+
function __wbg_adapter_73(arg0, arg1) {
|
|
341
341
|
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1015faeeadd5b26c(arg0, arg1);
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
-
function
|
|
345
|
-
wasm.
|
|
344
|
+
function __wbg_adapter_445(arg0, arg1, arg2, arg3) {
|
|
345
|
+
wasm.closure668_externref_shim(arg0, arg1, arg2, arg3);
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
|
|
@@ -1386,6 +1386,11 @@ export class TokenIssuer {
|
|
|
1386
1386
|
}
|
|
1387
1387
|
}
|
|
1388
1388
|
|
|
1389
|
+
export function __wbg_BigInt_470dd987b8190f8e(arg0) {
|
|
1390
|
+
const ret = BigInt(arg0);
|
|
1391
|
+
return ret;
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1389
1394
|
export function __wbg_String_8f0eb39a4a4c2f66(arg0, arg1) {
|
|
1390
1395
|
const ret = String(arg1);
|
|
1391
1396
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -1817,6 +1822,11 @@ export function __wbg_getAddressUtxos_328ceb8b4a63a6da() { return handleError(fu
|
|
|
1817
1822
|
}
|
|
1818
1823
|
}, arguments) };
|
|
1819
1824
|
|
|
1825
|
+
export function __wbg_getAvailableBalance_c24d30be8dc60bd5() { return handleError(function (arg0) {
|
|
1826
|
+
const ret = arg0.getAvailableBalance();
|
|
1827
|
+
return ret;
|
|
1828
|
+
}, arguments) };
|
|
1829
|
+
|
|
1820
1830
|
export function __wbg_getCachedItem_de40d6348815c7b9() { return handleError(function (arg0, arg1, arg2) {
|
|
1821
1831
|
let deferred0_0;
|
|
1822
1832
|
let deferred0_1;
|
|
@@ -1932,6 +1942,11 @@ export function __wbg_getStaticDepositSecretSource_8e310c718339e400() { return h
|
|
|
1932
1942
|
return ret;
|
|
1933
1943
|
}, arguments) };
|
|
1934
1944
|
|
|
1945
|
+
export function __wbg_getTokenBalances_2e44f820b2d89c1e() { return handleError(function (arg0) {
|
|
1946
|
+
const ret = arg0.getTokenBalances();
|
|
1947
|
+
return ret;
|
|
1948
|
+
}, arguments) };
|
|
1949
|
+
|
|
1935
1950
|
export function __wbg_getTokenOutputs_f51d6f5d47330273() { return handleError(function (arg0, arg1) {
|
|
1936
1951
|
const ret = arg0.getTokenOutputs(arg1);
|
|
1937
1952
|
return ret;
|
|
@@ -2231,7 +2246,7 @@ export function __wbg_new_23a2665fac83c611(arg0, arg1) {
|
|
|
2231
2246
|
const a = state0.a;
|
|
2232
2247
|
state0.a = 0;
|
|
2233
2248
|
try {
|
|
2234
|
-
return
|
|
2249
|
+
return __wbg_adapter_445(a, state0.b, arg0, arg1);
|
|
2235
2250
|
} finally {
|
|
2236
2251
|
state0.a = a;
|
|
2237
2252
|
}
|
|
@@ -2752,6 +2767,14 @@ export function __wbg_then_48b406749878a531(arg0, arg1, arg2) {
|
|
|
2752
2767
|
return ret;
|
|
2753
2768
|
};
|
|
2754
2769
|
|
|
2770
|
+
export function __wbg_toString_2f76f493957b63da(arg0, arg1, arg2) {
|
|
2771
|
+
const ret = arg1.toString(arg2);
|
|
2772
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2773
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2774
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
2775
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
2776
|
+
};
|
|
2777
|
+
|
|
2755
2778
|
export function __wbg_toString_5285597960676b7b(arg0) {
|
|
2756
2779
|
const ret = arg0.toString();
|
|
2757
2780
|
return ret;
|
|
@@ -2884,28 +2907,28 @@ export function __wbindgen_cb_drop(arg0) {
|
|
|
2884
2907
|
return ret;
|
|
2885
2908
|
};
|
|
2886
2909
|
|
|
2887
|
-
export function
|
|
2888
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2910
|
+
export function __wbindgen_closure_wrapper13524(arg0, arg1, arg2) {
|
|
2911
|
+
const ret = makeMutClosure(arg0, arg1, 872, __wbg_adapter_73);
|
|
2889
2912
|
return ret;
|
|
2890
2913
|
};
|
|
2891
2914
|
|
|
2892
|
-
export function
|
|
2893
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2915
|
+
export function __wbindgen_closure_wrapper15546(arg0, arg1, arg2) {
|
|
2916
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2894
2917
|
return ret;
|
|
2895
2918
|
};
|
|
2896
2919
|
|
|
2897
|
-
export function
|
|
2898
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2920
|
+
export function __wbindgen_closure_wrapper6018(arg0, arg1, arg2) {
|
|
2921
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2899
2922
|
return ret;
|
|
2900
2923
|
};
|
|
2901
2924
|
|
|
2902
|
-
export function
|
|
2903
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2925
|
+
export function __wbindgen_closure_wrapper6025(arg0, arg1, arg2) {
|
|
2926
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2904
2927
|
return ret;
|
|
2905
2928
|
};
|
|
2906
2929
|
|
|
2907
|
-
export function
|
|
2908
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2930
|
+
export function __wbindgen_closure_wrapper7640(arg0, arg1, arg2) {
|
|
2931
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_73);
|
|
2909
2932
|
return ret;
|
|
2910
2933
|
};
|
|
2911
2934
|
|
|
@@ -2979,11 +3002,21 @@ export function __wbindgen_jsval_loose_eq(arg0, arg1) {
|
|
|
2979
3002
|
return ret;
|
|
2980
3003
|
};
|
|
2981
3004
|
|
|
3005
|
+
export function __wbindgen_lt(arg0, arg1) {
|
|
3006
|
+
const ret = arg0 < arg1;
|
|
3007
|
+
return ret;
|
|
3008
|
+
};
|
|
3009
|
+
|
|
2982
3010
|
export function __wbindgen_memory() {
|
|
2983
3011
|
const ret = wasm.memory;
|
|
2984
3012
|
return ret;
|
|
2985
3013
|
};
|
|
2986
3014
|
|
|
3015
|
+
export function __wbindgen_neg(arg0) {
|
|
3016
|
+
const ret = -arg0;
|
|
3017
|
+
return ret;
|
|
3018
|
+
};
|
|
3019
|
+
|
|
2987
3020
|
export function __wbindgen_number_get(arg0, arg1) {
|
|
2988
3021
|
const obj = arg1;
|
|
2989
3022
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
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
|
|
131
|
+
export const closure388_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 closure668_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
134
134
|
export const __wbindgen_start: () => void;
|
|
@@ -65,6 +65,7 @@ type ReserveResult =
|
|
|
65
65
|
export interface TreeStore {
|
|
66
66
|
addLeaves: (leaves: TreeNode[]) => Promise<void>;
|
|
67
67
|
getLeaves: () => Promise<Leaves>;
|
|
68
|
+
getAvailableBalance: () => Promise<bigint | number>;
|
|
68
69
|
setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
|
|
69
70
|
cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
|
|
70
71
|
finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
|
|
@@ -152,6 +153,7 @@ type WasmReservationTarget =
|
|
|
152
153
|
export interface TokenStore {
|
|
153
154
|
setTokensOutputs: (tokenOutputs: WasmTokenOutputs[], refreshStartedAtMs: number) => Promise<void>;
|
|
154
155
|
listTokensOutputs: () => Promise<WasmTokenOutputsPerStatus[]>;
|
|
156
|
+
getTokenBalances: () => Promise<WasmTokenBalance[]>;
|
|
155
157
|
getTokenOutputs: (filter: WasmGetTokenOutputsFilter) => Promise<WasmTokenOutputsPerStatus>;
|
|
156
158
|
insertTokenOutputs: (tokenOutputs: WasmTokenOutputs) => Promise<void>;
|
|
157
159
|
reserveTokenOutputs: (
|
|
@@ -316,16 +316,16 @@ export function task_worker_entry_point(ptr) {
|
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
-
function
|
|
320
|
-
wasm.
|
|
319
|
+
function __wbg_adapter_68(arg0, arg1, arg2) {
|
|
320
|
+
wasm.closure388_externref_shim(arg0, arg1, arg2);
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
-
function
|
|
323
|
+
function __wbg_adapter_73(arg0, arg1) {
|
|
324
324
|
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1015faeeadd5b26c(arg0, arg1);
|
|
325
325
|
}
|
|
326
326
|
|
|
327
|
-
function
|
|
328
|
-
wasm.
|
|
327
|
+
function __wbg_adapter_445(arg0, arg1, arg2, arg3) {
|
|
328
|
+
wasm.closure668_externref_shim(arg0, arg1, arg2, arg3);
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
|
|
@@ -1371,6 +1371,10 @@ export class TokenIssuer {
|
|
|
1371
1371
|
|
|
1372
1372
|
const imports = {
|
|
1373
1373
|
__wbindgen_placeholder__: {
|
|
1374
|
+
__wbg_BigInt_470dd987b8190f8e: function(arg0) {
|
|
1375
|
+
const ret = BigInt(arg0);
|
|
1376
|
+
return ret;
|
|
1377
|
+
},
|
|
1374
1378
|
__wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
|
|
1375
1379
|
const ret = String(arg1);
|
|
1376
1380
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -1741,6 +1745,10 @@ const imports = {
|
|
|
1741
1745
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
1742
1746
|
}
|
|
1743
1747
|
}, arguments) },
|
|
1748
|
+
__wbg_getAvailableBalance_c24d30be8dc60bd5: function() { return handleError(function (arg0) {
|
|
1749
|
+
const ret = arg0.getAvailableBalance();
|
|
1750
|
+
return ret;
|
|
1751
|
+
}, arguments) },
|
|
1744
1752
|
__wbg_getCachedItem_de40d6348815c7b9: function() { return handleError(function (arg0, arg1, arg2) {
|
|
1745
1753
|
let deferred0_0;
|
|
1746
1754
|
let deferred0_1;
|
|
@@ -1841,6 +1849,10 @@ const imports = {
|
|
|
1841
1849
|
const ret = arg0.getStaticDepositSecretSource(arg1 >>> 0);
|
|
1842
1850
|
return ret;
|
|
1843
1851
|
}, arguments) },
|
|
1852
|
+
__wbg_getTokenBalances_2e44f820b2d89c1e: function() { return handleError(function (arg0) {
|
|
1853
|
+
const ret = arg0.getTokenBalances();
|
|
1854
|
+
return ret;
|
|
1855
|
+
}, arguments) },
|
|
1844
1856
|
__wbg_getTokenOutputs_f51d6f5d47330273: function() { return handleError(function (arg0, arg1) {
|
|
1845
1857
|
const ret = arg0.getTokenOutputs(arg1);
|
|
1846
1858
|
return ret;
|
|
@@ -2099,7 +2111,7 @@ const imports = {
|
|
|
2099
2111
|
const a = state0.a;
|
|
2100
2112
|
state0.a = 0;
|
|
2101
2113
|
try {
|
|
2102
|
-
return
|
|
2114
|
+
return __wbg_adapter_445(a, state0.b, arg0, arg1);
|
|
2103
2115
|
} finally {
|
|
2104
2116
|
state0.a = a;
|
|
2105
2117
|
}
|
|
@@ -2526,6 +2538,13 @@ const imports = {
|
|
|
2526
2538
|
const ret = arg0.then(arg1, arg2);
|
|
2527
2539
|
return ret;
|
|
2528
2540
|
},
|
|
2541
|
+
__wbg_toString_2f76f493957b63da: function(arg0, arg1, arg2) {
|
|
2542
|
+
const ret = arg1.toString(arg2);
|
|
2543
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2544
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2545
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
2546
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
2547
|
+
},
|
|
2529
2548
|
__wbg_toString_5285597960676b7b: function(arg0) {
|
|
2530
2549
|
const ret = arg0.toString();
|
|
2531
2550
|
return ret;
|
|
@@ -2639,24 +2658,24 @@ const imports = {
|
|
|
2639
2658
|
const ret = false;
|
|
2640
2659
|
return ret;
|
|
2641
2660
|
},
|
|
2642
|
-
|
|
2643
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2661
|
+
__wbindgen_closure_wrapper13524: function(arg0, arg1, arg2) {
|
|
2662
|
+
const ret = makeMutClosure(arg0, arg1, 872, __wbg_adapter_73);
|
|
2644
2663
|
return ret;
|
|
2645
2664
|
},
|
|
2646
|
-
|
|
2647
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2665
|
+
__wbindgen_closure_wrapper15546: function(arg0, arg1, arg2) {
|
|
2666
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2648
2667
|
return ret;
|
|
2649
2668
|
},
|
|
2650
|
-
|
|
2651
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2669
|
+
__wbindgen_closure_wrapper6018: function(arg0, arg1, arg2) {
|
|
2670
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2652
2671
|
return ret;
|
|
2653
2672
|
},
|
|
2654
|
-
|
|
2655
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2673
|
+
__wbindgen_closure_wrapper6025: function(arg0, arg1, arg2) {
|
|
2674
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2656
2675
|
return ret;
|
|
2657
2676
|
},
|
|
2658
|
-
|
|
2659
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2677
|
+
__wbindgen_closure_wrapper7640: function(arg0, arg1, arg2) {
|
|
2678
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_73);
|
|
2660
2679
|
return ret;
|
|
2661
2680
|
},
|
|
2662
2681
|
__wbindgen_debug_string: function(arg0, arg1) {
|
|
@@ -2717,10 +2736,18 @@ const imports = {
|
|
|
2717
2736
|
const ret = arg0 == arg1;
|
|
2718
2737
|
return ret;
|
|
2719
2738
|
},
|
|
2739
|
+
__wbindgen_lt: function(arg0, arg1) {
|
|
2740
|
+
const ret = arg0 < arg1;
|
|
2741
|
+
return ret;
|
|
2742
|
+
},
|
|
2720
2743
|
__wbindgen_memory: function() {
|
|
2721
2744
|
const ret = wasm.memory;
|
|
2722
2745
|
return ret;
|
|
2723
2746
|
},
|
|
2747
|
+
__wbindgen_neg: function(arg0) {
|
|
2748
|
+
const ret = -arg0;
|
|
2749
|
+
return ret;
|
|
2750
|
+
},
|
|
2724
2751
|
__wbindgen_number_get: function(arg0, arg1) {
|
|
2725
2752
|
const obj = arg1;
|
|
2726
2753
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
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
|
|
131
|
+
export const closure388_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 closure668_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
134
134
|
export const __wbindgen_start: () => void;
|
|
@@ -65,6 +65,7 @@ type ReserveResult =
|
|
|
65
65
|
export interface TreeStore {
|
|
66
66
|
addLeaves: (leaves: TreeNode[]) => Promise<void>;
|
|
67
67
|
getLeaves: () => Promise<Leaves>;
|
|
68
|
+
getAvailableBalance: () => Promise<bigint | number>;
|
|
68
69
|
setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
|
|
69
70
|
cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
|
|
70
71
|
finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
|
|
@@ -152,6 +153,7 @@ type WasmReservationTarget =
|
|
|
152
153
|
export interface TokenStore {
|
|
153
154
|
setTokensOutputs: (tokenOutputs: WasmTokenOutputs[], refreshStartedAtMs: number) => Promise<void>;
|
|
154
155
|
listTokensOutputs: () => Promise<WasmTokenOutputsPerStatus[]>;
|
|
156
|
+
getTokenBalances: () => Promise<WasmTokenBalance[]>;
|
|
155
157
|
getTokenOutputs: (filter: WasmGetTokenOutputsFilter) => Promise<WasmTokenOutputsPerStatus>;
|
|
156
158
|
insertTokenOutputs: (tokenOutputs: WasmTokenOutputs) => Promise<void>;
|
|
157
159
|
reserveTokenOutputs: (
|
|
@@ -329,16 +329,16 @@ module.exports.task_worker_entry_point = function(ptr) {
|
|
|
329
329
|
}
|
|
330
330
|
};
|
|
331
331
|
|
|
332
|
-
function
|
|
333
|
-
wasm.
|
|
332
|
+
function __wbg_adapter_68(arg0, arg1, arg2) {
|
|
333
|
+
wasm.closure388_externref_shim(arg0, arg1, arg2);
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
function
|
|
336
|
+
function __wbg_adapter_73(arg0, arg1) {
|
|
337
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
|
|
341
|
-
wasm.
|
|
340
|
+
function __wbg_adapter_445(arg0, arg1, arg2, arg3) {
|
|
341
|
+
wasm.closure668_externref_shim(arg0, arg1, arg2, arg3);
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
|
|
@@ -1390,6 +1390,11 @@ class TokenIssuer {
|
|
|
1390
1390
|
}
|
|
1391
1391
|
module.exports.TokenIssuer = TokenIssuer;
|
|
1392
1392
|
|
|
1393
|
+
module.exports.__wbg_BigInt_470dd987b8190f8e = function(arg0) {
|
|
1394
|
+
const ret = BigInt(arg0);
|
|
1395
|
+
return ret;
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1393
1398
|
module.exports.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
|
|
1394
1399
|
const ret = String(arg1);
|
|
1395
1400
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -1821,6 +1826,11 @@ module.exports.__wbg_getAddressUtxos_328ceb8b4a63a6da = function() { return hand
|
|
|
1821
1826
|
}
|
|
1822
1827
|
}, arguments) };
|
|
1823
1828
|
|
|
1829
|
+
module.exports.__wbg_getAvailableBalance_c24d30be8dc60bd5 = function() { return handleError(function (arg0) {
|
|
1830
|
+
const ret = arg0.getAvailableBalance();
|
|
1831
|
+
return ret;
|
|
1832
|
+
}, arguments) };
|
|
1833
|
+
|
|
1824
1834
|
module.exports.__wbg_getCachedItem_de40d6348815c7b9 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
1825
1835
|
let deferred0_0;
|
|
1826
1836
|
let deferred0_1;
|
|
@@ -1936,6 +1946,11 @@ module.exports.__wbg_getStaticDepositSecretSource_8e310c718339e400 = function()
|
|
|
1936
1946
|
return ret;
|
|
1937
1947
|
}, arguments) };
|
|
1938
1948
|
|
|
1949
|
+
module.exports.__wbg_getTokenBalances_2e44f820b2d89c1e = function() { return handleError(function (arg0) {
|
|
1950
|
+
const ret = arg0.getTokenBalances();
|
|
1951
|
+
return ret;
|
|
1952
|
+
}, arguments) };
|
|
1953
|
+
|
|
1939
1954
|
module.exports.__wbg_getTokenOutputs_f51d6f5d47330273 = function() { return handleError(function (arg0, arg1) {
|
|
1940
1955
|
const ret = arg0.getTokenOutputs(arg1);
|
|
1941
1956
|
return ret;
|
|
@@ -2235,7 +2250,7 @@ module.exports.__wbg_new_23a2665fac83c611 = function(arg0, arg1) {
|
|
|
2235
2250
|
const a = state0.a;
|
|
2236
2251
|
state0.a = 0;
|
|
2237
2252
|
try {
|
|
2238
|
-
return
|
|
2253
|
+
return __wbg_adapter_445(a, state0.b, arg0, arg1);
|
|
2239
2254
|
} finally {
|
|
2240
2255
|
state0.a = a;
|
|
2241
2256
|
}
|
|
@@ -2756,6 +2771,14 @@ module.exports.__wbg_then_48b406749878a531 = function(arg0, arg1, arg2) {
|
|
|
2756
2771
|
return ret;
|
|
2757
2772
|
};
|
|
2758
2773
|
|
|
2774
|
+
module.exports.__wbg_toString_2f76f493957b63da = function(arg0, arg1, arg2) {
|
|
2775
|
+
const ret = arg1.toString(arg2);
|
|
2776
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2777
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2778
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
2779
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
2780
|
+
};
|
|
2781
|
+
|
|
2759
2782
|
module.exports.__wbg_toString_5285597960676b7b = function(arg0) {
|
|
2760
2783
|
const ret = arg0.toString();
|
|
2761
2784
|
return ret;
|
|
@@ -2888,28 +2911,28 @@ module.exports.__wbindgen_cb_drop = function(arg0) {
|
|
|
2888
2911
|
return ret;
|
|
2889
2912
|
};
|
|
2890
2913
|
|
|
2891
|
-
module.exports.
|
|
2892
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2914
|
+
module.exports.__wbindgen_closure_wrapper13524 = function(arg0, arg1, arg2) {
|
|
2915
|
+
const ret = makeMutClosure(arg0, arg1, 872, __wbg_adapter_73);
|
|
2893
2916
|
return ret;
|
|
2894
2917
|
};
|
|
2895
2918
|
|
|
2896
|
-
module.exports.
|
|
2897
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2919
|
+
module.exports.__wbindgen_closure_wrapper15546 = function(arg0, arg1, arg2) {
|
|
2920
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2898
2921
|
return ret;
|
|
2899
2922
|
};
|
|
2900
2923
|
|
|
2901
|
-
module.exports.
|
|
2902
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2924
|
+
module.exports.__wbindgen_closure_wrapper6018 = function(arg0, arg1, arg2) {
|
|
2925
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2903
2926
|
return ret;
|
|
2904
2927
|
};
|
|
2905
2928
|
|
|
2906
|
-
module.exports.
|
|
2907
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2929
|
+
module.exports.__wbindgen_closure_wrapper6025 = function(arg0, arg1, arg2) {
|
|
2930
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2908
2931
|
return ret;
|
|
2909
2932
|
};
|
|
2910
2933
|
|
|
2911
|
-
module.exports.
|
|
2912
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2934
|
+
module.exports.__wbindgen_closure_wrapper7640 = function(arg0, arg1, arg2) {
|
|
2935
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_73);
|
|
2913
2936
|
return ret;
|
|
2914
2937
|
};
|
|
2915
2938
|
|
|
@@ -2983,11 +3006,21 @@ module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
|
|
|
2983
3006
|
return ret;
|
|
2984
3007
|
};
|
|
2985
3008
|
|
|
3009
|
+
module.exports.__wbindgen_lt = function(arg0, arg1) {
|
|
3010
|
+
const ret = arg0 < arg1;
|
|
3011
|
+
return ret;
|
|
3012
|
+
};
|
|
3013
|
+
|
|
2986
3014
|
module.exports.__wbindgen_memory = function() {
|
|
2987
3015
|
const ret = wasm.memory;
|
|
2988
3016
|
return ret;
|
|
2989
3017
|
};
|
|
2990
3018
|
|
|
3019
|
+
module.exports.__wbindgen_neg = function(arg0) {
|
|
3020
|
+
const ret = -arg0;
|
|
3021
|
+
return ret;
|
|
3022
|
+
};
|
|
3023
|
+
|
|
2991
3024
|
module.exports.__wbindgen_number_get = function(arg0, arg1) {
|
|
2992
3025
|
const obj = arg1;
|
|
2993
3026
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
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
|
|
131
|
+
export const closure388_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 closure668_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
134
134
|
export const __wbindgen_start: () => void;
|
|
@@ -75,7 +75,9 @@ class PostgresTokenStore {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
* 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`).
|
|
79
81
|
* @param {function(import('pg').PoolClient): Promise<T>} fn
|
|
80
82
|
* @returns {Promise<T>}
|
|
81
83
|
* @template T
|
|
@@ -96,6 +98,30 @@ class PostgresTokenStore {
|
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
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
|
+
|
|
99
125
|
// ===== TokenOutputStore Methods =====
|
|
100
126
|
|
|
101
127
|
/**
|
|
@@ -266,6 +292,58 @@ class PostgresTokenStore {
|
|
|
266
292
|
* List all token outputs grouped by status.
|
|
267
293
|
* @returns {Promise<Array<{metadata: Object, available: Array, reservedForPayment: Array, reservedForSwap: Array}>>}
|
|
268
294
|
*/
|
|
295
|
+
/**
|
|
296
|
+
* Returns the spendable per-token balances aggregated server-side.
|
|
297
|
+
* Each entry includes full token metadata + the available + swap-reserved sum.
|
|
298
|
+
* Tokens with zero spendable balance are filtered out by the HAVING clause.
|
|
299
|
+
* @returns {Promise<Array<{metadata: object, balance: string}>>}
|
|
300
|
+
*/
|
|
301
|
+
async getTokenBalances() {
|
|
302
|
+
try {
|
|
303
|
+
const result = await this.pool.query(`
|
|
304
|
+
SELECT m.identifier, m.issuer_public_key, m.name, m.ticker, m.decimals,
|
|
305
|
+
m.max_supply, m.is_freezable, m.creation_entity_public_key,
|
|
306
|
+
COALESCE(SUM(
|
|
307
|
+
CASE
|
|
308
|
+
WHEN o.reservation_id IS NULL THEN o.token_amount::numeric
|
|
309
|
+
WHEN r.purpose = 'Swap' THEN o.token_amount::numeric
|
|
310
|
+
ELSE 0
|
|
311
|
+
END
|
|
312
|
+
), 0)::text AS balance
|
|
313
|
+
FROM token_metadata m
|
|
314
|
+
JOIN token_outputs o ON o.token_identifier = m.identifier
|
|
315
|
+
LEFT JOIN token_reservations r ON o.reservation_id = r.id
|
|
316
|
+
GROUP BY m.identifier, m.issuer_public_key, m.name, m.ticker,
|
|
317
|
+
m.decimals, m.max_supply, m.is_freezable, m.creation_entity_public_key
|
|
318
|
+
HAVING COALESCE(SUM(
|
|
319
|
+
CASE
|
|
320
|
+
WHEN o.reservation_id IS NULL THEN o.token_amount::numeric
|
|
321
|
+
WHEN r.purpose = 'Swap' THEN o.token_amount::numeric
|
|
322
|
+
ELSE 0
|
|
323
|
+
END
|
|
324
|
+
), 0) > 0
|
|
325
|
+
`);
|
|
326
|
+
return result.rows.map((row) => ({
|
|
327
|
+
metadata: {
|
|
328
|
+
identifier: row.identifier,
|
|
329
|
+
issuerPublicKey: row.issuer_public_key,
|
|
330
|
+
name: row.name,
|
|
331
|
+
ticker: row.ticker,
|
|
332
|
+
decimals: row.decimals,
|
|
333
|
+
maxSupply: row.max_supply,
|
|
334
|
+
isFreezable: row.is_freezable,
|
|
335
|
+
creationEntityPublicKey: row.creation_entity_public_key,
|
|
336
|
+
},
|
|
337
|
+
balance: row.balance,
|
|
338
|
+
}));
|
|
339
|
+
} catch (error) {
|
|
340
|
+
throw new TokenStoreError(
|
|
341
|
+
`Failed to get token balances: ${error.message}`,
|
|
342
|
+
error
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
269
347
|
async listTokensOutputs() {
|
|
270
348
|
try {
|
|
271
349
|
const result = await this.pool.query(
|
|
@@ -614,7 +692,7 @@ class PostgresTokenStore {
|
|
|
614
692
|
*/
|
|
615
693
|
async cancelReservation(id) {
|
|
616
694
|
try {
|
|
617
|
-
await this.
|
|
695
|
+
await this._withTransaction(async (client) => {
|
|
618
696
|
// Clear reservation_id from outputs
|
|
619
697
|
await client.query(
|
|
620
698
|
"UPDATE token_outputs SET reservation_id = NULL WHERE reservation_id = $1",
|
|
@@ -642,7 +720,7 @@ class PostgresTokenStore {
|
|
|
642
720
|
*/
|
|
643
721
|
async finalizeReservation(id) {
|
|
644
722
|
try {
|
|
645
|
-
await this.
|
|
723
|
+
await this._withTransaction(async (client) => {
|
|
646
724
|
// Get reservation purpose
|
|
647
725
|
const reservationResult = await client.query(
|
|
648
726
|
"SELECT purpose FROM token_reservations WHERE id = $1",
|
|
@@ -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.
|
|
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);
|
|
@@ -127,6 +154,30 @@ class PostgresTreeStore {
|
|
|
127
154
|
* Get all leaves categorized by status.
|
|
128
155
|
* @returns {Promise<Object>} Leaves object with available, notAvailable, etc.
|
|
129
156
|
*/
|
|
157
|
+
/**
|
|
158
|
+
* Returns the wallet's spendable balance (available + missing-from-operators
|
|
159
|
+
* + swap-reserved). Aggregated server-side so we don't fetch every leaf.
|
|
160
|
+
* @returns {Promise<bigint>}
|
|
161
|
+
*/
|
|
162
|
+
async getAvailableBalance() {
|
|
163
|
+
try {
|
|
164
|
+
const result = await this.pool.query(`
|
|
165
|
+
SELECT COALESCE(SUM((l.data->>'value')::bigint), 0)::bigint AS balance
|
|
166
|
+
FROM tree_leaves l
|
|
167
|
+
LEFT JOIN tree_reservations r ON l.reservation_id = r.id
|
|
168
|
+
WHERE
|
|
169
|
+
(l.reservation_id IS NULL AND l.status = 'Available')
|
|
170
|
+
OR r.purpose = 'Swap'
|
|
171
|
+
`);
|
|
172
|
+
return BigInt(result.rows[0].balance);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
throw new TreeStoreError(
|
|
175
|
+
`Failed to get available balance: ${error.message}`,
|
|
176
|
+
error
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
130
181
|
async getLeaves() {
|
|
131
182
|
try {
|
|
132
183
|
const result = await this.pool.query(`
|
|
@@ -254,7 +305,7 @@ class PostgresTreeStore {
|
|
|
254
305
|
*/
|
|
255
306
|
async cancelReservation(id, leavesToKeep) {
|
|
256
307
|
try {
|
|
257
|
-
await this.
|
|
308
|
+
await this._withTransaction(async (client) => {
|
|
258
309
|
const res = await client.query(
|
|
259
310
|
"SELECT id FROM tree_reservations WHERE id = $1",
|
|
260
311
|
[id]
|
|
@@ -294,7 +345,7 @@ class PostgresTreeStore {
|
|
|
294
345
|
*/
|
|
295
346
|
async finalizeReservation(id, newLeaves) {
|
|
296
347
|
try {
|
|
297
|
-
await this.
|
|
348
|
+
await this._withTransaction(async (client) => {
|
|
298
349
|
// Check if reservation exists and get purpose
|
|
299
350
|
const res = await client.query(
|
|
300
351
|
"SELECT id, purpose FROM tree_reservations WHERE id = $1",
|
|
@@ -353,59 +404,98 @@ class PostgresTreeStore {
|
|
|
353
404
|
try {
|
|
354
405
|
return await this._withWriteTransaction(async (client) => {
|
|
355
406
|
const targetAmount = targetAmounts ? this._totalSats(targetAmounts) : 0;
|
|
407
|
+
const maxTarget = this._maxTargetForPrefilter(targetAmounts);
|
|
356
408
|
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
|
|
409
|
+
// True total available, computed server-side over ALL eligible leaves.
|
|
410
|
+
// Required for the WaitForPending decision below — must NOT be derived
|
|
411
|
+
// from the prefiltered set since the prefilter may exclude big leaves.
|
|
412
|
+
const totalResult = await client.query(`
|
|
413
|
+
SELECT COALESCE(SUM((data->>'value')::bigint), 0)::bigint AS total
|
|
360
414
|
FROM tree_leaves
|
|
361
415
|
WHERE status = 'Available'
|
|
362
416
|
AND is_missing_from_operators = FALSE
|
|
363
417
|
AND reservation_id IS NULL
|
|
364
418
|
`);
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
419
|
+
const available = Number(totalResult.rows[0].total);
|
|
420
|
+
|
|
421
|
+
// Slim projection: only (id, value) for leaves the selection might use.
|
|
422
|
+
// Includes all leaves with value <= maxTarget (covers exact-match + the
|
|
423
|
+
// small-leaf accumulators for the minimum-amount path) plus the single
|
|
424
|
+
// smallest leaf with value > maxTarget (covers the minimum-amount
|
|
425
|
+
// fallback case where one larger leaf is sufficient).
|
|
426
|
+
const slimResult = await client.query(`
|
|
427
|
+
SELECT id, (data->>'value')::bigint AS value
|
|
428
|
+
FROM tree_leaves
|
|
429
|
+
WHERE status = 'Available'
|
|
430
|
+
AND is_missing_from_operators = FALSE
|
|
431
|
+
AND reservation_id IS NULL
|
|
432
|
+
AND (
|
|
433
|
+
(data->>'value')::bigint <= $1
|
|
434
|
+
OR id = (
|
|
435
|
+
SELECT id FROM tree_leaves
|
|
436
|
+
WHERE status = 'Available'
|
|
437
|
+
AND is_missing_from_operators = FALSE
|
|
438
|
+
AND reservation_id IS NULL
|
|
439
|
+
AND (data->>'value')::bigint > $1
|
|
440
|
+
ORDER BY (data->>'value')::bigint
|
|
441
|
+
LIMIT 1
|
|
442
|
+
)
|
|
443
|
+
)
|
|
444
|
+
`, [maxTarget]);
|
|
445
|
+
|
|
446
|
+
const slimLeaves = slimResult.rows.map((r) => ({
|
|
447
|
+
id: r.id,
|
|
448
|
+
value: Number(r.value),
|
|
449
|
+
}));
|
|
368
450
|
|
|
369
451
|
// Calculate pending balance
|
|
370
452
|
const pending = await this._calculatePendingBalance(client);
|
|
371
453
|
|
|
372
|
-
// Try exact selection
|
|
373
|
-
const selected = this._selectLeavesByTargetAmounts(
|
|
454
|
+
// Try exact selection on slim leaves — selection only reads .id/.value
|
|
455
|
+
const selected = this._selectLeavesByTargetAmounts(slimLeaves, targetAmounts);
|
|
374
456
|
|
|
375
457
|
if (selected !== null) {
|
|
376
458
|
if (selected.length === 0) {
|
|
377
459
|
throw new TreeStoreError("NonReservableLeaves");
|
|
378
460
|
}
|
|
379
461
|
|
|
462
|
+
const fullLeaves = await this._fetchFullLeavesByIds(
|
|
463
|
+
client,
|
|
464
|
+
selected.map((l) => l.id)
|
|
465
|
+
);
|
|
380
466
|
const reservationId = this._generateId();
|
|
381
|
-
await this._createReservation(client, reservationId,
|
|
467
|
+
await this._createReservation(client, reservationId, fullLeaves, purpose, 0);
|
|
382
468
|
|
|
383
469
|
return {
|
|
384
470
|
type: "success",
|
|
385
471
|
reservation: {
|
|
386
472
|
id: reservationId,
|
|
387
|
-
leaves:
|
|
473
|
+
leaves: fullLeaves,
|
|
388
474
|
},
|
|
389
475
|
};
|
|
390
476
|
}
|
|
391
477
|
|
|
392
478
|
if (!exactOnly) {
|
|
393
|
-
// Try minimum amount selection
|
|
394
|
-
const minSelected = this._selectLeavesByMinimumAmount(
|
|
479
|
+
// Try minimum amount selection on the slim set
|
|
480
|
+
const minSelected = this._selectLeavesByMinimumAmount(slimLeaves, targetAmount);
|
|
395
481
|
if (minSelected !== null) {
|
|
396
|
-
const
|
|
482
|
+
const fullLeaves = await this._fetchFullLeavesByIds(
|
|
483
|
+
client,
|
|
484
|
+
minSelected.map((l) => l.id)
|
|
485
|
+
);
|
|
486
|
+
const reservedAmount = fullLeaves.reduce((sum, l) => sum + l.value, 0);
|
|
397
487
|
const pendingChange = reservedAmount > targetAmount && targetAmount > 0
|
|
398
488
|
? reservedAmount - targetAmount
|
|
399
489
|
: 0;
|
|
400
490
|
|
|
401
491
|
const reservationId = this._generateId();
|
|
402
|
-
await this._createReservation(client, reservationId,
|
|
492
|
+
await this._createReservation(client, reservationId, fullLeaves, purpose, pendingChange);
|
|
403
493
|
|
|
404
494
|
return {
|
|
405
495
|
type: "success",
|
|
406
496
|
reservation: {
|
|
407
497
|
id: reservationId,
|
|
408
|
-
leaves:
|
|
498
|
+
leaves: fullLeaves,
|
|
409
499
|
},
|
|
410
500
|
};
|
|
411
501
|
}
|
|
@@ -432,6 +522,34 @@ class PostgresTreeStore {
|
|
|
432
522
|
}
|
|
433
523
|
}
|
|
434
524
|
|
|
525
|
+
/**
|
|
526
|
+
* Largest single value the selection algorithm could possibly need.
|
|
527
|
+
* For an unbounded target we have to return all leaves (no prefilter).
|
|
528
|
+
*/
|
|
529
|
+
_maxTargetForPrefilter(targetAmounts) {
|
|
530
|
+
if (!targetAmounts) return Number.MAX_SAFE_INTEGER;
|
|
531
|
+
if (targetAmounts.type === "amountAndFee") {
|
|
532
|
+
return Math.max(targetAmounts.amountSats, targetAmounts.feeSats || 0);
|
|
533
|
+
}
|
|
534
|
+
if (targetAmounts.type === "exactDenominations") {
|
|
535
|
+
return targetAmounts.denominations.reduce((m, v) => Math.max(m, v), 0);
|
|
536
|
+
}
|
|
537
|
+
return Number.MAX_SAFE_INTEGER;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Pull the full `data` JSON for the leaves the selection algorithm picked.
|
|
542
|
+
* Typically this is 1-3 rows even when the prefiltered set was thousands.
|
|
543
|
+
*/
|
|
544
|
+
async _fetchFullLeavesByIds(client, ids) {
|
|
545
|
+
if (!ids || ids.length === 0) return [];
|
|
546
|
+
const result = await client.query(
|
|
547
|
+
"SELECT data FROM tree_leaves WHERE id = ANY($1)",
|
|
548
|
+
[ids]
|
|
549
|
+
);
|
|
550
|
+
return result.rows.map((r) => r.data);
|
|
551
|
+
}
|
|
552
|
+
|
|
435
553
|
/**
|
|
436
554
|
* Get current database time as epoch milliseconds.
|
|
437
555
|
* @returns {Promise<number>}
|
|
@@ -457,7 +575,7 @@ class PostgresTreeStore {
|
|
|
457
575
|
*/
|
|
458
576
|
async updateReservation(reservationId, reservedLeaves, changeLeaves) {
|
|
459
577
|
try {
|
|
460
|
-
return await this.
|
|
578
|
+
return await this._withTransaction(async (client) => {
|
|
461
579
|
// Check if reservation exists
|
|
462
580
|
const res = await client.query(
|
|
463
581
|
"SELECT id FROM tree_reservations WHERE id = $1",
|
package/package.json
CHANGED
|
@@ -65,6 +65,7 @@ type ReserveResult =
|
|
|
65
65
|
export interface TreeStore {
|
|
66
66
|
addLeaves: (leaves: TreeNode[]) => Promise<void>;
|
|
67
67
|
getLeaves: () => Promise<Leaves>;
|
|
68
|
+
getAvailableBalance: () => Promise<bigint | number>;
|
|
68
69
|
setLeaves: (leaves: TreeNode[], missingLeaves: TreeNode[], refreshStartedAtMs: number) => Promise<void>;
|
|
69
70
|
cancelReservation: (id: string, leavesToKeep: TreeNode[]) => Promise<void>;
|
|
70
71
|
finalizeReservation: (id: string, newLeaves: TreeNode[] | null) => Promise<void>;
|
|
@@ -152,6 +153,7 @@ type WasmReservationTarget =
|
|
|
152
153
|
export interface TokenStore {
|
|
153
154
|
setTokensOutputs: (tokenOutputs: WasmTokenOutputs[], refreshStartedAtMs: number) => Promise<void>;
|
|
154
155
|
listTokensOutputs: () => Promise<WasmTokenOutputsPerStatus[]>;
|
|
156
|
+
getTokenBalances: () => Promise<WasmTokenBalance[]>;
|
|
155
157
|
getTokenOutputs: (filter: WasmGetTokenOutputsFilter) => Promise<WasmTokenOutputsPerStatus>;
|
|
156
158
|
insertTokenOutputs: (tokenOutputs: WasmTokenOutputs) => Promise<void>;
|
|
157
159
|
reserveTokenOutputs: (
|
|
@@ -1669,9 +1671,9 @@ export interface InitOutput {
|
|
|
1669
1671
|
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
1670
1672
|
readonly __wbindgen_export_7: WebAssembly.Table;
|
|
1671
1673
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
1672
|
-
readonly
|
|
1674
|
+
readonly closure388_externref_shim: (a: number, b: number, c: any) => void;
|
|
1673
1675
|
readonly _dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1015faeeadd5b26c: (a: number, b: number) => void;
|
|
1674
|
-
readonly
|
|
1676
|
+
readonly closure668_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
1675
1677
|
readonly __wbindgen_start: () => void;
|
|
1676
1678
|
}
|
|
1677
1679
|
|
|
@@ -325,16 +325,16 @@ export function task_worker_entry_point(ptr) {
|
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
-
function
|
|
329
|
-
wasm.
|
|
328
|
+
function __wbg_adapter_68(arg0, arg1, arg2) {
|
|
329
|
+
wasm.closure388_externref_shim(arg0, arg1, arg2);
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
function
|
|
332
|
+
function __wbg_adapter_73(arg0, arg1) {
|
|
333
333
|
wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h1015faeeadd5b26c(arg0, arg1);
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
function
|
|
337
|
-
wasm.
|
|
336
|
+
function __wbg_adapter_445(arg0, arg1, arg2, arg3) {
|
|
337
|
+
wasm.closure668_externref_shim(arg0, arg1, arg2, arg3);
|
|
338
338
|
}
|
|
339
339
|
|
|
340
340
|
const __wbindgen_enum_BinaryType = ["blob", "arraybuffer"];
|
|
@@ -1412,6 +1412,10 @@ async function __wbg_load(module, imports) {
|
|
|
1412
1412
|
function __wbg_get_imports() {
|
|
1413
1413
|
const imports = {};
|
|
1414
1414
|
imports.wbg = {};
|
|
1415
|
+
imports.wbg.__wbg_BigInt_470dd987b8190f8e = function(arg0) {
|
|
1416
|
+
const ret = BigInt(arg0);
|
|
1417
|
+
return ret;
|
|
1418
|
+
};
|
|
1415
1419
|
imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
|
|
1416
1420
|
const ret = String(arg1);
|
|
1417
1421
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -1782,6 +1786,10 @@ function __wbg_get_imports() {
|
|
|
1782
1786
|
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
1783
1787
|
}
|
|
1784
1788
|
}, arguments) };
|
|
1789
|
+
imports.wbg.__wbg_getAvailableBalance_c24d30be8dc60bd5 = function() { return handleError(function (arg0) {
|
|
1790
|
+
const ret = arg0.getAvailableBalance();
|
|
1791
|
+
return ret;
|
|
1792
|
+
}, arguments) };
|
|
1785
1793
|
imports.wbg.__wbg_getCachedItem_de40d6348815c7b9 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
1786
1794
|
let deferred0_0;
|
|
1787
1795
|
let deferred0_1;
|
|
@@ -1882,6 +1890,10 @@ function __wbg_get_imports() {
|
|
|
1882
1890
|
const ret = arg0.getStaticDepositSecretSource(arg1 >>> 0);
|
|
1883
1891
|
return ret;
|
|
1884
1892
|
}, arguments) };
|
|
1893
|
+
imports.wbg.__wbg_getTokenBalances_2e44f820b2d89c1e = function() { return handleError(function (arg0) {
|
|
1894
|
+
const ret = arg0.getTokenBalances();
|
|
1895
|
+
return ret;
|
|
1896
|
+
}, arguments) };
|
|
1885
1897
|
imports.wbg.__wbg_getTokenOutputs_f51d6f5d47330273 = function() { return handleError(function (arg0, arg1) {
|
|
1886
1898
|
const ret = arg0.getTokenOutputs(arg1);
|
|
1887
1899
|
return ret;
|
|
@@ -2140,7 +2152,7 @@ function __wbg_get_imports() {
|
|
|
2140
2152
|
const a = state0.a;
|
|
2141
2153
|
state0.a = 0;
|
|
2142
2154
|
try {
|
|
2143
|
-
return
|
|
2155
|
+
return __wbg_adapter_445(a, state0.b, arg0, arg1);
|
|
2144
2156
|
} finally {
|
|
2145
2157
|
state0.a = a;
|
|
2146
2158
|
}
|
|
@@ -2567,6 +2579,13 @@ function __wbg_get_imports() {
|
|
|
2567
2579
|
const ret = arg0.then(arg1, arg2);
|
|
2568
2580
|
return ret;
|
|
2569
2581
|
};
|
|
2582
|
+
imports.wbg.__wbg_toString_2f76f493957b63da = function(arg0, arg1, arg2) {
|
|
2583
|
+
const ret = arg1.toString(arg2);
|
|
2584
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
2585
|
+
const len1 = WASM_VECTOR_LEN;
|
|
2586
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
2587
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
2588
|
+
};
|
|
2570
2589
|
imports.wbg.__wbg_toString_5285597960676b7b = function(arg0) {
|
|
2571
2590
|
const ret = arg0.toString();
|
|
2572
2591
|
return ret;
|
|
@@ -2680,24 +2699,24 @@ function __wbg_get_imports() {
|
|
|
2680
2699
|
const ret = false;
|
|
2681
2700
|
return ret;
|
|
2682
2701
|
};
|
|
2683
|
-
imports.wbg.
|
|
2684
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2702
|
+
imports.wbg.__wbindgen_closure_wrapper13524 = function(arg0, arg1, arg2) {
|
|
2703
|
+
const ret = makeMutClosure(arg0, arg1, 872, __wbg_adapter_73);
|
|
2685
2704
|
return ret;
|
|
2686
2705
|
};
|
|
2687
|
-
imports.wbg.
|
|
2688
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2706
|
+
imports.wbg.__wbindgen_closure_wrapper15546 = function(arg0, arg1, arg2) {
|
|
2707
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2689
2708
|
return ret;
|
|
2690
2709
|
};
|
|
2691
|
-
imports.wbg.
|
|
2692
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2710
|
+
imports.wbg.__wbindgen_closure_wrapper6018 = function(arg0, arg1, arg2) {
|
|
2711
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2693
2712
|
return ret;
|
|
2694
2713
|
};
|
|
2695
|
-
imports.wbg.
|
|
2696
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2714
|
+
imports.wbg.__wbindgen_closure_wrapper6025 = function(arg0, arg1, arg2) {
|
|
2715
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_68);
|
|
2697
2716
|
return ret;
|
|
2698
2717
|
};
|
|
2699
|
-
imports.wbg.
|
|
2700
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
2718
|
+
imports.wbg.__wbindgen_closure_wrapper7640 = function(arg0, arg1, arg2) {
|
|
2719
|
+
const ret = makeMutClosure(arg0, arg1, 389, __wbg_adapter_73);
|
|
2701
2720
|
return ret;
|
|
2702
2721
|
};
|
|
2703
2722
|
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
|
@@ -2758,10 +2777,18 @@ function __wbg_get_imports() {
|
|
|
2758
2777
|
const ret = arg0 == arg1;
|
|
2759
2778
|
return ret;
|
|
2760
2779
|
};
|
|
2780
|
+
imports.wbg.__wbindgen_lt = function(arg0, arg1) {
|
|
2781
|
+
const ret = arg0 < arg1;
|
|
2782
|
+
return ret;
|
|
2783
|
+
};
|
|
2761
2784
|
imports.wbg.__wbindgen_memory = function() {
|
|
2762
2785
|
const ret = wasm.memory;
|
|
2763
2786
|
return ret;
|
|
2764
2787
|
};
|
|
2788
|
+
imports.wbg.__wbindgen_neg = function(arg0) {
|
|
2789
|
+
const ret = -arg0;
|
|
2790
|
+
return ret;
|
|
2791
|
+
};
|
|
2765
2792
|
imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
|
|
2766
2793
|
const obj = arg1;
|
|
2767
2794
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
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
|
|
131
|
+
export const closure388_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 closure668_externref_shim: (a: number, b: number, c: any, d: any) => void;
|
|
134
134
|
export const __wbindgen_start: () => void;
|