@arkade-os/sdk 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +138 -50
- package/dist/adapters/expo.cjs +10 -5
- package/dist/adapters/expo.d.cts +13 -8
- package/dist/adapters/expo.d.ts +13 -8
- package/dist/adapters/expo.js +4 -3
- package/dist/{asyncStorageTaskQueue-C9PkPcW_.d.cts → asyncStorageTaskQueue-BbH-THYJ.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-B3U5gQ-i.d.ts → asyncStorageTaskQueue-BlvkJyTa.d.ts} +2 -2
- package/dist/base-C-Y5t_0F.d.cts +359 -0
- package/dist/base-C-Y5t_0F.d.ts +359 -0
- package/dist/{chunk-OPX2HRWM.js → chunk-4I53THL6.js} +210 -937
- package/dist/chunk-4I53THL6.js.map +1 -0
- package/dist/{chunk-5WRA66RV.cjs → chunk-5SYUEVJH.cjs} +10 -10
- package/dist/chunk-5SYUEVJH.cjs.map +1 -0
- package/dist/{chunk-6FL4N4S2.js → chunk-7GIKLFHC.js} +83 -20
- package/dist/chunk-7GIKLFHC.js.map +1 -0
- package/dist/{chunk-BYPBVHVA.cjs → chunk-AMH7Q3DF.cjs} +61 -935
- package/dist/chunk-AMH7Q3DF.cjs.map +1 -0
- package/dist/{chunk-P7B4LQ3H.js → chunk-BCA6D255.js} +18 -842
- package/dist/chunk-BCA6D255.js.map +1 -0
- package/dist/{chunk-T7C3E2HL.js → chunk-CE46RS6L.js} +20 -39
- package/dist/chunk-CE46RS6L.js.map +1 -0
- package/dist/chunk-DNFTHG73.js +829 -0
- package/dist/chunk-DNFTHG73.js.map +1 -0
- package/dist/chunk-FDJ734CH.js +882 -0
- package/dist/chunk-FDJ734CH.js.map +1 -0
- package/dist/chunk-FLPWNMX3.cjs +930 -0
- package/dist/chunk-FLPWNMX3.cjs.map +1 -0
- package/dist/{chunk-Y4BL3YYX.js → chunk-FVVXCDNE.js} +4 -4
- package/dist/chunk-FVVXCDNE.js.map +1 -0
- package/dist/{chunk-ZPF4I3K2.cjs → chunk-HQQ4NRXI.cjs} +29 -47
- package/dist/chunk-HQQ4NRXI.cjs.map +1 -0
- package/dist/chunk-JFJNB7ZH.cjs +884 -0
- package/dist/chunk-JFJNB7ZH.cjs.map +1 -0
- package/dist/{chunk-KW7ZEWYS.cjs → chunk-KCL5AVML.cjs} +223 -985
- package/dist/chunk-KCL5AVML.cjs.map +1 -0
- package/dist/{chunk-HAQAWBYG.js → chunk-OO2KEK64.js} +2860 -1366
- package/dist/chunk-OO2KEK64.js.map +1 -0
- package/dist/{chunk-OUTWUYJ4.cjs → chunk-T254PXSN.cjs} +3337 -1824
- package/dist/chunk-T254PXSN.cjs.map +1 -0
- package/dist/chunk-V3ZLL5VY.js +380 -0
- package/dist/chunk-V3ZLL5VY.js.map +1 -0
- package/dist/chunk-X6ZI53DZ.cjs +383 -0
- package/dist/chunk-X6ZI53DZ.cjs.map +1 -0
- package/dist/{chunk-ZMSM3NOH.cjs → chunk-XWUCNMPN.cjs} +98 -34
- package/dist/chunk-XWUCNMPN.cjs.map +1 -0
- package/dist/compiler.cjs +50 -0
- package/dist/compiler.cjs.map +1 -0
- package/dist/compiler.d.cts +38 -0
- package/dist/compiler.d.ts +38 -0
- package/dist/compiler.js +47 -0
- package/dist/compiler.js.map +1 -0
- package/dist/contracts/handlers/index.cjs +11 -9
- package/dist/contracts/handlers/index.d.cts +6 -4
- package/dist/contracts/handlers/index.d.ts +6 -4
- package/dist/contracts/handlers/index.js +4 -2
- package/dist/{delegate-Cd28gxpM.d.ts → delegate-gGkUnYpi.d.cts} +1 -1
- package/dist/{delegate-ByfKszb6.d.cts → delegate-iyDum4fw.d.ts} +1 -1
- package/dist/{index-B6X2E7W_.d.ts → index-BWwVnJhU.d.cts} +7 -272
- package/dist/{index-DgH_0j14.d.cts → index-Bx-iArDs.d.ts} +7 -272
- package/dist/{index-BURzbRup.d.cts → index-DCml4QJn.d.ts} +1090 -1140
- package/dist/{index-BURzbRup.d.ts → index-DkyzIzKL.d.cts} +1090 -1140
- package/dist/index.cjs +470 -371
- package/dist/index.d.cts +687 -410
- package/dist/index.d.ts +687 -410
- package/dist/index.js +7 -4
- package/dist/{wallet-BnmhohgZ.d.ts → keyringDescriptorProvider-CS4w4PWd.d.ts} +427 -372
- package/dist/{wallet-BjQugVUt.d.cts → keyringDescriptorProvider-CmHXrIXd.d.cts} +427 -372
- package/dist/program-BARSNg3X.d.ts +286 -0
- package/dist/program-znrWkxE4.d.cts +286 -0
- package/dist/repositories/realm/index.cjs +100 -51
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +25 -10
- package/dist/repositories/realm/index.d.ts +25 -10
- package/dist/repositories/realm/index.js +72 -24
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +222 -131
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +36 -17
- package/dist/repositories/sqlite/index.d.ts +36 -17
- package/dist/repositories/sqlite/index.js +196 -107
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-BaNCSxqK.d.ts → taskRunner-DgMLSk_O.d.ts} +4 -4
- package/dist/{taskRunner-i56-drQV.d.cts → taskRunner-buh6aFpG.d.cts} +4 -4
- package/dist/wallet/expo/background.cjs +17 -14
- package/dist/wallet/expo/background.cjs.map +1 -1
- package/dist/wallet/expo/background.d.cts +5 -4
- package/dist/wallet/expo/background.d.ts +5 -4
- package/dist/wallet/expo/background.js +10 -7
- package/dist/wallet/expo/background.js.map +1 -1
- package/dist/wallet/expo/index.cjs +29 -16
- package/dist/wallet/expo/index.cjs.map +1 -1
- package/dist/wallet/expo/index.d.cts +12 -7
- package/dist/wallet/expo/index.d.ts +12 -7
- package/dist/wallet/expo/index.js +20 -7
- package/dist/wallet/expo/index.js.map +1 -1
- package/dist/worker/expo/index.cjs +12 -9
- package/dist/worker/expo/index.cjs.map +1 -1
- package/dist/worker/expo/index.d.cts +6 -5
- package/dist/worker/expo/index.d.ts +6 -5
- package/dist/worker/expo/index.js +8 -5
- package/dist/worker/expo/index.js.map +1 -1
- package/package.json +16 -1
- package/dist/chunk-5WRA66RV.cjs.map +0 -1
- package/dist/chunk-6FL4N4S2.js.map +0 -1
- package/dist/chunk-BYPBVHVA.cjs.map +0 -1
- package/dist/chunk-HAQAWBYG.js.map +0 -1
- package/dist/chunk-KW7ZEWYS.cjs.map +0 -1
- package/dist/chunk-OPX2HRWM.js.map +0 -1
- package/dist/chunk-OUTWUYJ4.cjs.map +0 -1
- package/dist/chunk-P7B4LQ3H.js.map +0 -1
- package/dist/chunk-T7C3E2HL.js.map +0 -1
- package/dist/chunk-Y4BL3YYX.js.map +0 -1
- package/dist/chunk-ZMSM3NOH.cjs.map +0 -1
- package/dist/chunk-ZPF4I3K2.cjs.map +0 -1
|
@@ -1,32 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { ChainedTxType } from '../../chunk-
|
|
3
|
-
import '../../chunk-
|
|
4
|
-
import '../../chunk-
|
|
5
|
-
import
|
|
1
|
+
import { legacyVtxoFacts, serializeVtxo, createdAtToIso, assertPageRequest, pageResult, checkSaveVtxosForScript, utxoEntries, serializeUtxo, assertHistoryPageFilter, serializeAssets, scriptFromArkAddress, deserializeVtxo, deserializeUtxo, deserializeAssets, contractFilterMatchesNothing, scopeOf, intentMatchesFilter, isTerminalBatchRegistrationState, applyWalletStateUpdate, mergeChainedTxType } from '../../chunk-OO2KEK64.js';
|
|
2
|
+
export { ChainedTxType } from '../../chunk-OO2KEK64.js';
|
|
3
|
+
import '../../chunk-V3ZLL5VY.js';
|
|
4
|
+
import '../../chunk-7GIKLFHC.js';
|
|
5
|
+
import '../../chunk-BCA6D255.js';
|
|
6
|
+
import '../../chunk-DNFTHG73.js';
|
|
7
|
+
import { isVtxoSpent } from '../../chunk-4I53THL6.js';
|
|
8
|
+
import '../../chunk-FDJ734CH.js';
|
|
6
9
|
|
|
7
10
|
// src/repositories/sqlite/transaction.ts
|
|
8
|
-
var
|
|
11
|
+
var executorQueues = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
var STALL_WARN_MS = 1e4;
|
|
13
|
+
function enqueue(queue, operation) {
|
|
14
|
+
let stall;
|
|
15
|
+
if (queue.inTransaction) {
|
|
16
|
+
const site = new Error(
|
|
17
|
+
`SQLite operation waited ${STALL_WARN_MS / 1e3}s behind a transaction. A repository, getSerializedExecutor or runInTransaction call inside a runInTransaction callback deadlocks; use the callback's tx.`
|
|
18
|
+
);
|
|
19
|
+
stall = setTimeout(() => console.warn(site), STALL_WARN_MS);
|
|
20
|
+
}
|
|
21
|
+
const run = queue.tail.then(() => {
|
|
22
|
+
clearTimeout(stall);
|
|
23
|
+
return operation();
|
|
24
|
+
});
|
|
25
|
+
queue.tail = run.catch(() => void 0);
|
|
26
|
+
return run;
|
|
27
|
+
}
|
|
28
|
+
function queueFor(db) {
|
|
29
|
+
const existing = executorQueues.get(db);
|
|
30
|
+
if (existing) return existing;
|
|
31
|
+
const facade = {
|
|
32
|
+
run: (sql, params) => enqueue(queue, () => db.run(sql, params)),
|
|
33
|
+
get: (sql, params) => enqueue(queue, () => db.get(sql, params)),
|
|
34
|
+
all: (sql, params) => enqueue(queue, () => db.all(sql, params))
|
|
35
|
+
};
|
|
36
|
+
const queue = {
|
|
37
|
+
raw: db,
|
|
38
|
+
facade,
|
|
39
|
+
tail: Promise.resolve(),
|
|
40
|
+
inTransaction: false
|
|
41
|
+
};
|
|
42
|
+
executorQueues.set(db, queue);
|
|
43
|
+
executorQueues.set(facade, queue);
|
|
44
|
+
return queue;
|
|
45
|
+
}
|
|
46
|
+
function getSerializedExecutor(db) {
|
|
47
|
+
return queueFor(db).facade;
|
|
48
|
+
}
|
|
9
49
|
function runInTransaction(db, fn) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
50
|
+
const queue = queueFor(db);
|
|
51
|
+
return enqueue(queue, async () => {
|
|
52
|
+
const tx = queue.raw;
|
|
53
|
+
queue.inTransaction = true;
|
|
13
54
|
try {
|
|
14
|
-
await
|
|
15
|
-
await db.run("COMMIT");
|
|
16
|
-
} catch (e) {
|
|
55
|
+
await tx.run("BEGIN IMMEDIATE");
|
|
17
56
|
try {
|
|
18
|
-
await
|
|
19
|
-
|
|
57
|
+
await fn(tx);
|
|
58
|
+
await tx.run("COMMIT");
|
|
59
|
+
} catch (e) {
|
|
60
|
+
try {
|
|
61
|
+
await tx.run("ROLLBACK");
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
throw e;
|
|
20
65
|
}
|
|
21
|
-
|
|
66
|
+
} finally {
|
|
67
|
+
queue.inTransaction = false;
|
|
22
68
|
}
|
|
23
69
|
});
|
|
24
|
-
writeChains.set(
|
|
25
|
-
db,
|
|
26
|
-
run.catch(() => {
|
|
27
|
-
})
|
|
28
|
-
);
|
|
29
|
-
return run;
|
|
30
70
|
}
|
|
31
71
|
|
|
32
72
|
// src/repositories/sqlite/prefix.ts
|
|
@@ -39,8 +79,17 @@ function sanitizeTablePrefix(p) {
|
|
|
39
79
|
// src/repositories/sqlite/walletRepository.ts
|
|
40
80
|
var MAX_BOUND_PARAMETERS = 999;
|
|
41
81
|
var SQLiteWalletRepository = class {
|
|
82
|
+
version = 2;
|
|
83
|
+
atomicWalletState;
|
|
84
|
+
db;
|
|
85
|
+
initPromise = null;
|
|
86
|
+
prefix;
|
|
87
|
+
tables;
|
|
42
88
|
constructor(db, options) {
|
|
43
|
-
this.db = db;
|
|
89
|
+
this.db = getSerializedExecutor(db);
|
|
90
|
+
if (options?.walletStateTransactions === true) {
|
|
91
|
+
this.atomicWalletState = options.persistentWalletState === true ? { ...this.atomicState, persistent: true } : this.atomicState;
|
|
92
|
+
}
|
|
44
93
|
this.prefix = sanitizeTablePrefix(options?.prefix ?? "ark_");
|
|
45
94
|
this.tables = {
|
|
46
95
|
vtxos: `${this.prefix}vtxos`,
|
|
@@ -49,11 +98,6 @@ var SQLiteWalletRepository = class {
|
|
|
49
98
|
walletState: `${this.prefix}wallet_state`
|
|
50
99
|
};
|
|
51
100
|
}
|
|
52
|
-
db;
|
|
53
|
-
version = 2;
|
|
54
|
-
initPromise = null;
|
|
55
|
-
prefix;
|
|
56
|
-
tables;
|
|
57
101
|
// ── Lifecycle ──────────────────────────────────────────────────────
|
|
58
102
|
ensureInit() {
|
|
59
103
|
if (!this.initPromise) {
|
|
@@ -156,16 +200,16 @@ var SQLiteWalletRepository = class {
|
|
|
156
200
|
* leave the next startup seeing no `vtxos` table.
|
|
157
201
|
*/
|
|
158
202
|
async migrateVtxosTable() {
|
|
159
|
-
await runInTransaction(this.db, async () => {
|
|
160
|
-
const tableExists = await
|
|
203
|
+
await runInTransaction(this.db, async (tx) => {
|
|
204
|
+
const tableExists = await tx.get(
|
|
161
205
|
`SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
|
|
162
206
|
[this.tables.vtxos]
|
|
163
207
|
);
|
|
164
208
|
if (!tableExists) {
|
|
165
|
-
await
|
|
209
|
+
await tx.run(this.vtxosCreateSql(this.tables.vtxos));
|
|
166
210
|
return;
|
|
167
211
|
}
|
|
168
|
-
const cols = await
|
|
212
|
+
const cols = await tx.all(
|
|
169
213
|
`PRAGMA table_info(${this.tables.vtxos})`
|
|
170
214
|
);
|
|
171
215
|
const scriptCol = cols.find((c) => c.name === "script");
|
|
@@ -179,33 +223,31 @@ var SQLiteWalletRepository = class {
|
|
|
179
223
|
let addedCanonicalColumns = false;
|
|
180
224
|
for (const [name, type] of nullableCanonicalColumns) {
|
|
181
225
|
if (!cols.some((c) => c.name === name)) {
|
|
182
|
-
await this.
|
|
183
|
-
`ALTER TABLE ${this.tables.vtxos} ADD COLUMN ${name} ${type}`
|
|
184
|
-
);
|
|
226
|
+
await tx.run(`ALTER TABLE ${this.tables.vtxos} ADD COLUMN ${name} ${type}`);
|
|
185
227
|
addedCanonicalColumns = true;
|
|
186
228
|
}
|
|
187
229
|
}
|
|
188
230
|
const hasLegacyBlob = cols.some((c) => c.name === "virtual_status_json");
|
|
189
231
|
if (addedCanonicalColumns && hasLegacyBlob) {
|
|
190
|
-
await this.backfillCanonicalVtxoColumns();
|
|
232
|
+
await this.backfillCanonicalVtxoColumns(tx);
|
|
191
233
|
}
|
|
192
234
|
if (scriptCol && scriptCol.notnull === 1 && !hasLegacyBlob) {
|
|
193
235
|
return;
|
|
194
236
|
}
|
|
195
237
|
if (!scriptCol) {
|
|
196
|
-
await
|
|
238
|
+
await tx.run(`ALTER TABLE ${this.tables.vtxos} ADD COLUMN script TEXT`);
|
|
197
239
|
}
|
|
198
|
-
const nullRows = await
|
|
240
|
+
const nullRows = await tx.all(`SELECT txid, vout, address FROM ${this.tables.vtxos} WHERE script IS NULL`);
|
|
199
241
|
for (const row of nullRows) {
|
|
200
|
-
await
|
|
242
|
+
await tx.run(
|
|
201
243
|
`UPDATE ${this.tables.vtxos} SET script = ? WHERE txid = ? AND vout = ?`,
|
|
202
244
|
[scriptFromArkAddress(row.address), row.txid, row.vout]
|
|
203
245
|
);
|
|
204
246
|
}
|
|
205
247
|
const tempName = `${this.tables.vtxos}__migrate_tmp`;
|
|
206
|
-
await
|
|
207
|
-
await
|
|
208
|
-
await
|
|
248
|
+
await tx.run(`DROP TABLE IF EXISTS ${tempName}`);
|
|
249
|
+
await tx.run(this.vtxosCreateSql(tempName));
|
|
250
|
+
await tx.run(`
|
|
209
251
|
INSERT INTO ${tempName}
|
|
210
252
|
(txid, vout, value, address, tap_tree,
|
|
211
253
|
forfeit_cb, forfeit_s, intent_cb, intent_s,
|
|
@@ -221,8 +263,8 @@ var SQLiteWalletRepository = class {
|
|
|
221
263
|
spent_by, settled_by, ark_tx_id, extra_witness_json, assets_json, script
|
|
222
264
|
FROM ${this.tables.vtxos}
|
|
223
265
|
`);
|
|
224
|
-
await
|
|
225
|
-
await
|
|
266
|
+
await tx.run(`DROP TABLE ${this.tables.vtxos}`);
|
|
267
|
+
await tx.run(`ALTER TABLE ${tempName} RENAME TO ${this.tables.vtxos}`);
|
|
226
268
|
});
|
|
227
269
|
}
|
|
228
270
|
/**
|
|
@@ -234,15 +276,15 @@ var SQLiteWalletRepository = class {
|
|
|
234
276
|
* is missing or corrupt are left alone: a migration must not be stopped by one bad row, and
|
|
235
277
|
* the next sync repairs it.
|
|
236
278
|
*/
|
|
237
|
-
async backfillCanonicalVtxoColumns() {
|
|
238
|
-
const rows = await
|
|
279
|
+
async backfillCanonicalVtxoColumns(tx) {
|
|
280
|
+
const rows = await tx.all(
|
|
239
281
|
`SELECT txid, vout, virtual_status_json FROM ${this.tables.vtxos}
|
|
240
282
|
WHERE virtual_status_json IS NOT NULL AND is_swept IS NULL`
|
|
241
283
|
);
|
|
242
284
|
for (const row of rows) {
|
|
243
285
|
const facts = legacyVtxoFacts(row.virtual_status_json);
|
|
244
286
|
if (!facts) continue;
|
|
245
|
-
await
|
|
287
|
+
await tx.run(
|
|
246
288
|
`UPDATE ${this.tables.vtxos}
|
|
247
289
|
SET is_swept = ?, is_preconfirmed = ?, commitment_txids_json = ?,
|
|
248
290
|
expires_at = ?, expires_at_height = ?,
|
|
@@ -502,6 +544,32 @@ var SQLiteWalletRepository = class {
|
|
|
502
544
|
await this.db.run(`DELETE FROM ${this.tables.transactions} WHERE address = ?`, [address]);
|
|
503
545
|
}
|
|
504
546
|
// ── Wallet state ───────────────────────────────────────────────────
|
|
547
|
+
atomicState = {
|
|
548
|
+
version: 1,
|
|
549
|
+
update: async (updater) => {
|
|
550
|
+
await this.ensureInit();
|
|
551
|
+
await runInTransaction(this.db, async (tx) => {
|
|
552
|
+
const row = await tx.get(
|
|
553
|
+
`SELECT * FROM ${this.tables.walletState} WHERE key = ?`,
|
|
554
|
+
["state"]
|
|
555
|
+
);
|
|
556
|
+
const current = row ? {
|
|
557
|
+
settings: row.settings_json ? JSON.parse(row.settings_json) : void 0,
|
|
558
|
+
lastSyncTime: row.last_sync_time ?? void 0
|
|
559
|
+
} : {};
|
|
560
|
+
const state = applyWalletStateUpdate(current, updater);
|
|
561
|
+
await tx.run(
|
|
562
|
+
`INSERT OR REPLACE INTO ${this.tables.walletState}
|
|
563
|
+
(key, settings_json, last_sync_time) VALUES (?, ?, ?)`,
|
|
564
|
+
[
|
|
565
|
+
"state",
|
|
566
|
+
state.settings ? JSON.stringify(state.settings) : null,
|
|
567
|
+
state.lastSyncTime ?? null
|
|
568
|
+
]
|
|
569
|
+
);
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
};
|
|
505
573
|
async getWalletState() {
|
|
506
574
|
await this.ensureInit();
|
|
507
575
|
const row = await this.db.get(
|
|
@@ -606,16 +674,16 @@ function txRowToDomain(row) {
|
|
|
606
674
|
// src/repositories/sqlite/contractRepository.ts
|
|
607
675
|
var WATCH_STATE = "IFNULL(watch, 'watched')";
|
|
608
676
|
var SQLiteContractRepository = class {
|
|
609
|
-
|
|
610
|
-
this.db = db;
|
|
611
|
-
this.prefix = sanitizeTablePrefix(options?.prefix ?? "ark_");
|
|
612
|
-
this.table = `${this.prefix}contracts`;
|
|
613
|
-
}
|
|
677
|
+
version = 4;
|
|
614
678
|
db;
|
|
615
|
-
version = 3;
|
|
616
679
|
initPromise = null;
|
|
617
680
|
prefix;
|
|
618
681
|
table;
|
|
682
|
+
constructor(db, options) {
|
|
683
|
+
this.db = getSerializedExecutor(db);
|
|
684
|
+
this.prefix = sanitizeTablePrefix(options?.prefix ?? "ark_");
|
|
685
|
+
this.table = `${this.prefix}contracts`;
|
|
686
|
+
}
|
|
619
687
|
// ── Lifecycle ──────────────────────────────────────────────────────
|
|
620
688
|
ensureInit() {
|
|
621
689
|
if (!this.initPromise) {
|
|
@@ -635,10 +703,12 @@ var SQLiteContractRepository = class {
|
|
|
635
703
|
expires_at INTEGER,
|
|
636
704
|
label TEXT,
|
|
637
705
|
metadata_json TEXT,
|
|
638
|
-
watch TEXT
|
|
706
|
+
watch TEXT,
|
|
707
|
+
scope TEXT
|
|
639
708
|
)
|
|
640
709
|
`);
|
|
641
710
|
await this.addColumnIfMissing("watch", "TEXT");
|
|
711
|
+
await this.addColumnIfMissing("scope", "TEXT");
|
|
642
712
|
await this.db.run(
|
|
643
713
|
`CREATE INDEX IF NOT EXISTS idx_${this.prefix}contracts_type ON ${this.table} (type)`
|
|
644
714
|
);
|
|
@@ -677,25 +747,31 @@ var SQLiteContractRepository = class {
|
|
|
677
747
|
this.addFilterCondition(conditions, params, "type", filter.type);
|
|
678
748
|
this.addFilterCondition(conditions, params, WATCH_STATE, filter.watch);
|
|
679
749
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
750
|
+
const wanted = filter?.scope === void 0 ? void 0 : [filter.scope].flat();
|
|
751
|
+
const matches = [];
|
|
752
|
+
let after = page.after;
|
|
753
|
+
for (; ; ) {
|
|
754
|
+
const where = [...conditions, ...after === void 0 ? [] : ["script > ?"]];
|
|
755
|
+
const rows = await this.db.all(
|
|
756
|
+
`SELECT * FROM ${this.table}${where.length ? ` WHERE ${where.join(" AND ")}` : ""} ORDER BY script LIMIT ?`,
|
|
757
|
+
[...params, ...after === void 0 ? [] : [after], page.limit + 1]
|
|
758
|
+
);
|
|
759
|
+
for (const contract of rows.map(contractRowToDomain)) {
|
|
760
|
+
if (!wanted || wanted.includes(scopeOf(contract))) matches.push(contract);
|
|
761
|
+
}
|
|
762
|
+
if (!wanted || rows.length <= page.limit || matches.length > page.limit) break;
|
|
763
|
+
after = rows[rows.length - 1].script;
|
|
683
764
|
}
|
|
684
|
-
|
|
685
|
-
const rows = await this.db.all(
|
|
686
|
-
`SELECT * FROM ${this.table}${where} ORDER BY script LIMIT ?`,
|
|
687
|
-
[...params, page.limit + 1]
|
|
688
|
-
);
|
|
689
|
-
return pageResult(rows.map(contractRowToDomain), page.limit, (contract) => contract.script);
|
|
765
|
+
return pageResult(matches, page.limit, (contract) => contract.script);
|
|
690
766
|
}
|
|
691
767
|
async saveContract(contract) {
|
|
692
768
|
await this.ensureInit();
|
|
693
769
|
await this.db.run(
|
|
694
770
|
`INSERT OR REPLACE INTO ${this.table}
|
|
695
771
|
(script, address, type, state, params_json,
|
|
696
|
-
created_at, label, metadata_json, watch)
|
|
772
|
+
created_at, label, metadata_json, watch, scope)
|
|
697
773
|
VALUES (?, ?, ?, ?, ?,
|
|
698
|
-
?, ?, ?, ?)`,
|
|
774
|
+
?, ?, ?, ?, ?)`,
|
|
699
775
|
[
|
|
700
776
|
contract.script,
|
|
701
777
|
contract.address,
|
|
@@ -705,7 +781,8 @@ var SQLiteContractRepository = class {
|
|
|
705
781
|
contract.createdAt,
|
|
706
782
|
contract.label ?? null,
|
|
707
783
|
contract.metadata ? JSON.stringify(contract.metadata) : null,
|
|
708
|
-
contract.watch ?? null
|
|
784
|
+
contract.watch ?? null,
|
|
785
|
+
contract.scope ?? null
|
|
709
786
|
]
|
|
710
787
|
);
|
|
711
788
|
}
|
|
@@ -745,21 +822,24 @@ function contractRowToDomain(row) {
|
|
|
745
822
|
if (row.watch !== null && row.watch !== void 0) {
|
|
746
823
|
contract.watch = row.watch;
|
|
747
824
|
}
|
|
825
|
+
if (row.scope !== null && row.scope !== void 0) {
|
|
826
|
+
contract.scope = row.scope;
|
|
827
|
+
}
|
|
748
828
|
return contract;
|
|
749
829
|
}
|
|
750
830
|
|
|
751
831
|
// src/repositories/sqlite/intentRepository.ts
|
|
752
|
-
var
|
|
753
|
-
constructor(db, options) {
|
|
754
|
-
this.db = db;
|
|
755
|
-
this.prefix = sanitizeTablePrefix(options?.prefix ?? "ark_");
|
|
756
|
-
this.t = `${this.prefix}intents`;
|
|
757
|
-
}
|
|
758
|
-
db;
|
|
832
|
+
var SQLiteBatchRegistrationRepository = class {
|
|
759
833
|
version = 1;
|
|
834
|
+
db;
|
|
760
835
|
initPromise = null;
|
|
761
836
|
prefix;
|
|
762
837
|
t;
|
|
838
|
+
constructor(db, options) {
|
|
839
|
+
this.db = getSerializedExecutor(db);
|
|
840
|
+
this.prefix = sanitizeTablePrefix(options?.prefix ?? "ark_");
|
|
841
|
+
this.t = `${this.prefix}intents`;
|
|
842
|
+
}
|
|
763
843
|
ensureInit() {
|
|
764
844
|
if (!this.initPromise) this.initPromise = this.init();
|
|
765
845
|
return this.initPromise;
|
|
@@ -793,15 +873,15 @@ var SQLiteIntentRepository = class {
|
|
|
793
873
|
}
|
|
794
874
|
async clear() {
|
|
795
875
|
await this.ensureInit();
|
|
796
|
-
await runInTransaction(this.db, async () => {
|
|
797
|
-
await
|
|
876
|
+
await runInTransaction(this.db, async (tx) => {
|
|
877
|
+
await tx.run(`DELETE FROM ${this.t}`);
|
|
798
878
|
});
|
|
799
879
|
}
|
|
800
|
-
async
|
|
880
|
+
async saveBatchRegistration(intent) {
|
|
801
881
|
await this.ensureInit();
|
|
802
882
|
const now = Date.now();
|
|
803
|
-
await runInTransaction(this.db, async () => {
|
|
804
|
-
await
|
|
883
|
+
await runInTransaction(this.db, async (tx) => {
|
|
884
|
+
await tx.run(
|
|
805
885
|
`INSERT INTO ${this.t}
|
|
806
886
|
(intent_tx_id, intent_id, state, valid_from, valid_until,
|
|
807
887
|
created_at, updated_at, register_proof, register_proof_message,
|
|
@@ -827,8 +907,8 @@ var SQLiteIntentRepository = class {
|
|
|
827
907
|
signer_descriptor = excluded.signer_descriptor,
|
|
828
908
|
intent_vtxos_json = excluded.intent_vtxos_json`,
|
|
829
909
|
[
|
|
830
|
-
intent.
|
|
831
|
-
intent.
|
|
910
|
+
intent.proofTxId,
|
|
911
|
+
intent.registrationId ?? null,
|
|
832
912
|
intent.state,
|
|
833
913
|
intent.validFrom ?? null,
|
|
834
914
|
intent.validUntil ?? null,
|
|
@@ -843,12 +923,12 @@ var SQLiteIntentRepository = class {
|
|
|
843
923
|
intent.cancellationReason ?? null,
|
|
844
924
|
JSON.stringify(intent.partialForfeits),
|
|
845
925
|
intent.signerDescriptor ?? null,
|
|
846
|
-
JSON.stringify(intent.
|
|
926
|
+
JSON.stringify(intent.proofInputs)
|
|
847
927
|
]
|
|
848
928
|
);
|
|
849
929
|
});
|
|
850
930
|
}
|
|
851
|
-
async
|
|
931
|
+
async getBatchRegistrationsPage(filter, page) {
|
|
852
932
|
assertPageRequest(page);
|
|
853
933
|
await this.ensureInit();
|
|
854
934
|
if (filter?.states?.length === 0) return { items: [] };
|
|
@@ -871,25 +951,33 @@ var SQLiteIntentRepository = class {
|
|
|
871
951
|
}
|
|
872
952
|
if (batch.length < batchSize) break;
|
|
873
953
|
}
|
|
874
|
-
return pageResult(rows, page.limit, (intent) => intent.
|
|
954
|
+
return pageResult(rows, page.limit, (intent) => intent.proofTxId);
|
|
875
955
|
}
|
|
876
956
|
async getLockedVtxoOutpoints() {
|
|
877
957
|
await this.ensureInit();
|
|
878
958
|
const rows = await this.db.all(`SELECT * FROM ${this.t}`);
|
|
879
959
|
const out = [];
|
|
880
960
|
for (const r of rows) {
|
|
881
|
-
if (
|
|
961
|
+
if (isTerminalBatchRegistrationState(r.state)) continue;
|
|
882
962
|
for (const o of JSON.parse(r.intent_vtxos_json)) out.push(o);
|
|
883
963
|
}
|
|
884
964
|
return out;
|
|
885
965
|
}
|
|
966
|
+
/** @deprecated Use {@link saveBatchRegistration}. */
|
|
967
|
+
saveIntent(intent) {
|
|
968
|
+
return this.saveBatchRegistration(intent);
|
|
969
|
+
}
|
|
970
|
+
/** @deprecated Use {@link getBatchRegistrationsPage}. */
|
|
971
|
+
getIntentsPage(filter, page) {
|
|
972
|
+
return this.getBatchRegistrationsPage(filter, page);
|
|
973
|
+
}
|
|
886
974
|
async [Symbol.asyncDispose]() {
|
|
887
975
|
}
|
|
888
976
|
};
|
|
889
977
|
function rowToIntent(r) {
|
|
890
978
|
return {
|
|
891
|
-
|
|
892
|
-
|
|
979
|
+
proofTxId: r.intent_tx_id,
|
|
980
|
+
registrationId: r.intent_id ?? void 0,
|
|
893
981
|
state: r.state,
|
|
894
982
|
validFrom: r.valid_from ?? void 0,
|
|
895
983
|
validUntil: r.valid_until ?? void 0,
|
|
@@ -904,24 +992,25 @@ function rowToIntent(r) {
|
|
|
904
992
|
cancellationReason: r.cancellation_reason ?? void 0,
|
|
905
993
|
partialForfeits: JSON.parse(r.partial_forfeits_json),
|
|
906
994
|
signerDescriptor: r.signer_descriptor ?? void 0,
|
|
907
|
-
|
|
995
|
+
proofInputs: JSON.parse(r.intent_vtxos_json)
|
|
908
996
|
};
|
|
909
997
|
}
|
|
998
|
+
var SQLiteIntentRepository = SQLiteBatchRegistrationRepository;
|
|
910
999
|
|
|
911
1000
|
// src/repositories/sqlite/virtualTxRepository.ts
|
|
912
1001
|
var SQLiteVirtualTxRepository = class {
|
|
913
|
-
constructor(db, options) {
|
|
914
|
-
this.db = db;
|
|
915
|
-
this.prefix = sanitizeTablePrefix(options?.prefix ?? "ark_");
|
|
916
|
-
this.tTx = `${this.prefix}virtual_txs`;
|
|
917
|
-
this.tBranch = `${this.prefix}vtxo_branches`;
|
|
918
|
-
}
|
|
919
|
-
db;
|
|
920
1002
|
version = 1;
|
|
1003
|
+
db;
|
|
921
1004
|
initPromise = null;
|
|
922
1005
|
prefix;
|
|
923
1006
|
tTx;
|
|
924
1007
|
tBranch;
|
|
1008
|
+
constructor(db, options) {
|
|
1009
|
+
this.db = getSerializedExecutor(db);
|
|
1010
|
+
this.prefix = sanitizeTablePrefix(options?.prefix ?? "ark_");
|
|
1011
|
+
this.tTx = `${this.prefix}virtual_txs`;
|
|
1012
|
+
this.tBranch = `${this.prefix}vtxo_branches`;
|
|
1013
|
+
}
|
|
925
1014
|
ensureInit() {
|
|
926
1015
|
if (!this.initPromise) this.initPromise = this.init();
|
|
927
1016
|
return this.initPromise;
|
|
@@ -946,17 +1035,17 @@ var SQLiteVirtualTxRepository = class {
|
|
|
946
1035
|
}
|
|
947
1036
|
async clear() {
|
|
948
1037
|
await this.ensureInit();
|
|
949
|
-
await runInTransaction(this.db, async () => {
|
|
950
|
-
await
|
|
951
|
-
await
|
|
1038
|
+
await runInTransaction(this.db, async (tx) => {
|
|
1039
|
+
await tx.run(`DELETE FROM ${this.tTx}`);
|
|
1040
|
+
await tx.run(`DELETE FROM ${this.tBranch}`);
|
|
952
1041
|
});
|
|
953
1042
|
}
|
|
954
1043
|
async upsertVirtualTxs(txs) {
|
|
955
1044
|
if (txs.length === 0) return;
|
|
956
1045
|
await this.ensureInit();
|
|
957
|
-
await runInTransaction(this.db, async () => {
|
|
1046
|
+
await runInTransaction(this.db, async (tx) => {
|
|
958
1047
|
const placeholders = txs.map(() => "?").join(", ");
|
|
959
|
-
const existing = await
|
|
1048
|
+
const existing = await tx.all(
|
|
960
1049
|
`SELECT * FROM ${this.tTx} WHERE txid IN (${placeholders})`,
|
|
961
1050
|
txs.map((t) => t.txid)
|
|
962
1051
|
);
|
|
@@ -966,7 +1055,7 @@ var SQLiteVirtualTxRepository = class {
|
|
|
966
1055
|
const psbt = t.psbt ?? prev?.psbt ?? null;
|
|
967
1056
|
const expires = t.expiresAt ?? prev?.expires_at ?? null;
|
|
968
1057
|
const type = mergeChainedTxType(t.type, prev?.type);
|
|
969
|
-
await
|
|
1058
|
+
await tx.run(
|
|
970
1059
|
`INSERT OR REPLACE INTO ${this.tTx} (txid, psbt, expires_at, type) VALUES (?, ?, ?, ?)`,
|
|
971
1060
|
[t.txid, psbt, expires, type]
|
|
972
1061
|
);
|
|
@@ -981,13 +1070,13 @@ var SQLiteVirtualTxRepository = class {
|
|
|
981
1070
|
}
|
|
982
1071
|
async setBranch(vtxo, branch) {
|
|
983
1072
|
await this.ensureInit();
|
|
984
|
-
await runInTransaction(this.db, async () => {
|
|
985
|
-
await
|
|
1073
|
+
await runInTransaction(this.db, async (tx) => {
|
|
1074
|
+
await tx.run(`DELETE FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`, [
|
|
986
1075
|
vtxo.txid,
|
|
987
1076
|
vtxo.vout
|
|
988
1077
|
]);
|
|
989
1078
|
for (const b of branch) {
|
|
990
|
-
await
|
|
1079
|
+
await tx.run(
|
|
991
1080
|
`INSERT OR REPLACE INTO ${this.tBranch} (vtxo_txid, vtxo_vout, virtual_txid, position) VALUES (?, ?, ?, ?)`,
|
|
992
1081
|
[b.vtxoTxid, b.vtxoVout, b.virtualTxid, b.position]
|
|
993
1082
|
);
|
|
@@ -1016,18 +1105,18 @@ var SQLiteVirtualTxRepository = class {
|
|
|
1016
1105
|
}
|
|
1017
1106
|
async pruneForSpentVtxo(vtxo) {
|
|
1018
1107
|
await this.ensureInit();
|
|
1019
|
-
await runInTransaction(this.db, async () => {
|
|
1020
|
-
const removed = await
|
|
1108
|
+
await runInTransaction(this.db, async (tx) => {
|
|
1109
|
+
const removed = await tx.all(
|
|
1021
1110
|
`SELECT DISTINCT virtual_txid FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`,
|
|
1022
1111
|
[vtxo.txid, vtxo.vout]
|
|
1023
1112
|
);
|
|
1024
|
-
await
|
|
1113
|
+
await tx.run(`DELETE FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`, [
|
|
1025
1114
|
vtxo.txid,
|
|
1026
1115
|
vtxo.vout
|
|
1027
1116
|
]);
|
|
1028
1117
|
if (removed.length === 0) return;
|
|
1029
1118
|
const placeholders = removed.map(() => "?").join(", ");
|
|
1030
|
-
await
|
|
1119
|
+
await tx.run(
|
|
1031
1120
|
`DELETE FROM ${this.tTx}
|
|
1032
1121
|
WHERE txid IN (${placeholders})
|
|
1033
1122
|
AND NOT EXISTS (
|
|
@@ -1049,6 +1138,6 @@ function rowToTx(r) {
|
|
|
1049
1138
|
};
|
|
1050
1139
|
}
|
|
1051
1140
|
|
|
1052
|
-
export { SQLiteContractRepository, SQLiteIntentRepository, SQLiteVirtualTxRepository, SQLiteWalletRepository, runInTransaction, sanitizeTablePrefix };
|
|
1141
|
+
export { SQLiteBatchRegistrationRepository, SQLiteContractRepository, SQLiteIntentRepository, SQLiteVirtualTxRepository, SQLiteWalletRepository, getSerializedExecutor, runInTransaction, sanitizeTablePrefix };
|
|
1053
1142
|
//# sourceMappingURL=index.js.map
|
|
1054
1143
|
//# sourceMappingURL=index.js.map
|