@arkade-os/sdk 0.4.42 → 0.4.44
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 +65 -0
- package/dist/adapters/expo.cjs +4 -4
- package/dist/adapters/expo.d.cts +2 -2
- package/dist/adapters/expo.d.ts +2 -2
- package/dist/adapters/expo.js +2 -2
- package/dist/adapters/indexedDB.cjs +3 -3
- package/dist/adapters/indexedDB.js +2 -2
- package/dist/{ark-CKDWpuGL.d.cts → ark-I8jfe5VE.d.cts} +157 -2
- package/dist/{ark-CKDWpuGL.d.ts → ark-I8jfe5VE.d.ts} +157 -2
- package/dist/{asyncStorageTaskQueue-BB2MffwG.d.ts → asyncStorageTaskQueue-BtSOVZFn.d.ts} +2 -2
- package/dist/{asyncStorageTaskQueue-BpN8RRHR.d.cts → asyncStorageTaskQueue-Dap7qUlF.d.cts} +2 -2
- package/dist/{chunk-V3FCNVJE.js → chunk-FMI2GKYO.js} +2158 -502
- package/dist/chunk-FMI2GKYO.js.map +1 -0
- package/dist/{chunk-FLPPSRYH.js → chunk-LCQQPOIT.js} +3 -3
- package/dist/{chunk-FLPPSRYH.js.map → chunk-LCQQPOIT.js.map} +1 -1
- package/dist/{chunk-5X5YMZHB.js → chunk-LJ35HPJW.js} +39 -5
- package/dist/chunk-LJ35HPJW.js.map +1 -0
- package/dist/{chunk-HHPUCCB3.cjs → chunk-RJ6XVCX4.cjs} +7 -7
- package/dist/{chunk-HHPUCCB3.cjs.map → chunk-RJ6XVCX4.cjs.map} +1 -1
- package/dist/{chunk-YEF5FL6E.cjs → chunk-UBYY2TPK.cjs} +39 -4
- package/dist/chunk-UBYY2TPK.cjs.map +1 -0
- package/dist/{chunk-2V3BU2X6.js → chunk-V7WIZR2B.js} +3 -3
- package/dist/{chunk-2V3BU2X6.js.map → chunk-V7WIZR2B.js.map} +1 -1
- package/dist/{chunk-T2ACJD22.cjs → chunk-X37EKDIH.cjs} +11 -11
- package/dist/{chunk-T2ACJD22.cjs.map → chunk-X37EKDIH.cjs.map} +1 -1
- package/dist/{chunk-ED7JDFX4.cjs → chunk-XIVCG6EP.cjs} +2248 -578
- package/dist/chunk-XIVCG6EP.cjs.map +1 -0
- package/dist/contracts/handlers/index.d.cts +3 -3
- package/dist/contracts/handlers/index.d.ts +3 -3
- package/dist/{delegate-yjhcR9n4.d.cts → delegate-BRqbh2fW.d.cts} +1 -1
- package/dist/{delegate-DllAQ3Eu.d.ts → delegate-CgjVjYOP.d.ts} +1 -1
- package/dist/{index-D1te-ZR6.d.cts → index-DHuXlDEg.d.cts} +2 -2
- package/dist/{index-DVdCGyyH.d.ts → index-DvWNB_rl.d.ts} +2 -2
- package/dist/index.cjs +162 -118
- package/dist/index.d.cts +344 -9
- package/dist/index.d.ts +344 -9
- package/dist/index.js +2 -2
- package/dist/repositories/realm/index.cjs +268 -12
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +101 -3
- package/dist/repositories/realm/index.d.ts +101 -3
- package/dist/repositories/realm/index.js +254 -4
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +366 -40
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +52 -6
- package/dist/repositories/sqlite/index.d.ts +52 -6
- package/dist/repositories/sqlite/index.js +353 -32
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-BdiRy4iI.d.ts → taskRunner-Bptw9UMa.d.ts} +2 -2
- package/dist/{taskRunner-CuTk8RYg.d.cts → taskRunner-CeFxKhSH.d.cts} +2 -2
- package/dist/wallet/expo/background.cjs +12 -12
- package/dist/wallet/expo/background.d.cts +3 -3
- package/dist/wallet/expo/background.d.ts +3 -3
- package/dist/wallet/expo/background.js +4 -4
- package/dist/wallet/expo/index.cjs +12 -12
- package/dist/wallet/expo/index.d.cts +4 -4
- package/dist/wallet/expo/index.d.ts +4 -4
- package/dist/wallet/expo/index.js +3 -3
- package/dist/{wallet-CyPOQ0oM.d.cts → wallet-BsqRU8KM.d.cts} +29 -5
- package/dist/{wallet-CrIVUQMb.d.ts → wallet-D9z7wssl.d.ts} +29 -5
- package/dist/worker/expo/index.cjs +7 -7
- package/dist/worker/expo/index.d.cts +4 -4
- package/dist/worker/expo/index.d.ts +4 -4
- package/dist/worker/expo/index.js +3 -3
- package/package.json +2 -2
- package/dist/chunk-5X5YMZHB.js.map +0 -1
- package/dist/chunk-ED7JDFX4.cjs.map +0 -1
- package/dist/chunk-V3FCNVJE.js.map +0 -1
- package/dist/chunk-YEF5FL6E.cjs.map +0 -1
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
var chunkXIVCG6EP_cjs = require('../../chunk-XIVCG6EP.cjs');
|
|
4
|
+
require('../../chunk-UBYY2TPK.cjs');
|
|
5
5
|
require('../../chunk-32YKLQPS.cjs');
|
|
6
6
|
require('../../chunk-HXDZ2QTW.cjs');
|
|
7
7
|
require('../../chunk-5BLDMQED.cjs');
|
|
8
8
|
|
|
9
|
+
// src/repositories/sqlite/transaction.ts
|
|
10
|
+
var writeChains = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
function runInTransaction(db, fn) {
|
|
12
|
+
const prev = writeChains.get(db) ?? Promise.resolve();
|
|
13
|
+
const run = prev.then(async () => {
|
|
14
|
+
await db.run("BEGIN IMMEDIATE");
|
|
15
|
+
try {
|
|
16
|
+
await fn();
|
|
17
|
+
await db.run("COMMIT");
|
|
18
|
+
} catch (e) {
|
|
19
|
+
try {
|
|
20
|
+
await db.run("ROLLBACK");
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
writeChains.set(
|
|
27
|
+
db,
|
|
28
|
+
run.catch(() => {
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
return run;
|
|
32
|
+
}
|
|
33
|
+
|
|
9
34
|
// src/repositories/sqlite/walletRepository.ts
|
|
10
35
|
var SQLiteWalletRepository = class {
|
|
11
36
|
constructor(db, options) {
|
|
@@ -96,29 +121,31 @@ var SQLiteWalletRepository = class {
|
|
|
96
121
|
* indexer would have returned — new rows from the indexer always carry a
|
|
97
122
|
* populated `script`, so the migration is idempotent.
|
|
98
123
|
*
|
|
99
|
-
* The
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
124
|
+
* The whole check-and-migrate runs inside one transaction, not just the
|
|
125
|
+
* rebuild: the schema inspection is the decision point, so a second
|
|
126
|
+
* concurrent init on the same connection must not read a pre-migration
|
|
127
|
+
* schema and then re-run `ADD COLUMN` (duplicate column) after the first
|
|
128
|
+
* migration already committed. It also guards the crash window between the
|
|
129
|
+
* `DROP TABLE vtxos` and the `RENAME tmp → vtxos`, which would otherwise
|
|
130
|
+
* leave the next startup seeing no `vtxos` table.
|
|
103
131
|
*/
|
|
104
132
|
async migrateVtxosTable() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
try {
|
|
133
|
+
await runInTransaction(this.db, async () => {
|
|
134
|
+
const tableExists = await this.db.get(
|
|
135
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
|
|
136
|
+
[this.tables.vtxos]
|
|
137
|
+
);
|
|
138
|
+
if (!tableExists) {
|
|
139
|
+
await this.db.run(this.vtxosCreateSql(this.tables.vtxos));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const cols = await this.db.all(
|
|
143
|
+
`PRAGMA table_info(${this.tables.vtxos})`
|
|
144
|
+
);
|
|
145
|
+
const scriptCol = cols.find((c) => c.name === "script");
|
|
146
|
+
if (scriptCol && scriptCol.notnull === 1) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
122
149
|
if (!scriptCol) {
|
|
123
150
|
await this.db.run(`ALTER TABLE ${this.tables.vtxos} ADD COLUMN script TEXT`);
|
|
124
151
|
}
|
|
@@ -126,7 +153,7 @@ var SQLiteWalletRepository = class {
|
|
|
126
153
|
for (const row of nullRows) {
|
|
127
154
|
await this.db.run(
|
|
128
155
|
`UPDATE ${this.tables.vtxos} SET script = ? WHERE txid = ? AND vout = ?`,
|
|
129
|
-
[
|
|
156
|
+
[chunkXIVCG6EP_cjs.scriptFromArkAddress(row.address), row.txid, row.vout]
|
|
130
157
|
);
|
|
131
158
|
}
|
|
132
159
|
const tempName = `${this.tables.vtxos}__migrate_tmp`;
|
|
@@ -148,14 +175,7 @@ var SQLiteWalletRepository = class {
|
|
|
148
175
|
`);
|
|
149
176
|
await this.db.run(`DROP TABLE ${this.tables.vtxos}`);
|
|
150
177
|
await this.db.run(`ALTER TABLE ${tempName} RENAME TO ${this.tables.vtxos}`);
|
|
151
|
-
|
|
152
|
-
} catch (e) {
|
|
153
|
-
try {
|
|
154
|
-
await this.db.run("ROLLBACK");
|
|
155
|
-
} catch {
|
|
156
|
-
}
|
|
157
|
-
throw e;
|
|
158
|
-
}
|
|
178
|
+
});
|
|
159
179
|
}
|
|
160
180
|
vtxosCreateSql(tableName) {
|
|
161
181
|
return `CREATE TABLE ${tableName} (
|
|
@@ -204,7 +224,7 @@ var SQLiteWalletRepository = class {
|
|
|
204
224
|
async saveVtxos(address, vtxos) {
|
|
205
225
|
await this.ensureInit();
|
|
206
226
|
for (const vtxo of vtxos) {
|
|
207
|
-
const s =
|
|
227
|
+
const s = chunkXIVCG6EP_cjs.serializeVtxo(vtxo);
|
|
208
228
|
await this.db.run(
|
|
209
229
|
`INSERT OR REPLACE INTO ${this.tables.vtxos}
|
|
210
230
|
(txid, vout, value, address,
|
|
@@ -259,7 +279,7 @@ var SQLiteWalletRepository = class {
|
|
|
259
279
|
throw new Error("SQLiteWalletRepository requires an address");
|
|
260
280
|
}
|
|
261
281
|
for (const vtxo of vtxos) {
|
|
262
|
-
if (!
|
|
282
|
+
if (!chunkXIVCG6EP_cjs.isVtxoForScript(vtxo, key.script)) {
|
|
263
283
|
throw new Error(
|
|
264
284
|
`VTXO ${vtxo.txid}:${vtxo.vout} script mismatch: expected ${key.script}, got ${vtxo.script}`
|
|
265
285
|
);
|
|
@@ -283,7 +303,7 @@ var SQLiteWalletRepository = class {
|
|
|
283
303
|
async saveUtxos(address, utxos) {
|
|
284
304
|
await this.ensureInit();
|
|
285
305
|
for (const utxo of utxos) {
|
|
286
|
-
const s =
|
|
306
|
+
const s = chunkXIVCG6EP_cjs.serializeUtxo(utxo);
|
|
287
307
|
await this.db.run(
|
|
288
308
|
`INSERT OR REPLACE INTO ${this.tables.utxos}
|
|
289
309
|
(txid, vout, value, address,
|
|
@@ -339,7 +359,7 @@ var SQLiteWalletRepository = class {
|
|
|
339
359
|
tx.amount,
|
|
340
360
|
tx.settled ? 1 : 0,
|
|
341
361
|
tx.createdAt,
|
|
342
|
-
tx.assets ? JSON.stringify(
|
|
362
|
+
tx.assets ? JSON.stringify(chunkXIVCG6EP_cjs.serializeAssets(tx.assets)) : null
|
|
343
363
|
]
|
|
344
364
|
);
|
|
345
365
|
}
|
|
@@ -413,9 +433,9 @@ function vtxoRowToDomain(row) {
|
|
|
413
433
|
// Post-migration every row has `script`, but the backfill is
|
|
414
434
|
// idempotent: derive from `address` if the legacy column is still
|
|
415
435
|
// null (e.g. the migration hasn't run yet on this handle).
|
|
416
|
-
script: row.script ??
|
|
436
|
+
script: row.script ?? chunkXIVCG6EP_cjs.scriptFromArkAddress(row.address)
|
|
417
437
|
};
|
|
418
|
-
return
|
|
438
|
+
return chunkXIVCG6EP_cjs.deserializeVtxo(serialized);
|
|
419
439
|
}
|
|
420
440
|
function utxoRowToDomain(row) {
|
|
421
441
|
const serialized = {
|
|
@@ -434,7 +454,7 @@ function utxoRowToDomain(row) {
|
|
|
434
454
|
status: JSON.parse(row.status_json),
|
|
435
455
|
extraWitness: row.extra_witness_json ? JSON.parse(row.extra_witness_json) : void 0
|
|
436
456
|
};
|
|
437
|
-
return
|
|
457
|
+
return chunkXIVCG6EP_cjs.deserializeUtxo(serialized);
|
|
438
458
|
}
|
|
439
459
|
function txRowToDomain(row) {
|
|
440
460
|
const tx = {
|
|
@@ -449,7 +469,7 @@ function txRowToDomain(row) {
|
|
|
449
469
|
createdAt: row.created_at
|
|
450
470
|
};
|
|
451
471
|
if (row.assets_json) {
|
|
452
|
-
tx.assets =
|
|
472
|
+
tx.assets = chunkXIVCG6EP_cjs.deserializeAssets(JSON.parse(row.assets_json));
|
|
453
473
|
}
|
|
454
474
|
return tx;
|
|
455
475
|
}
|
|
@@ -582,7 +602,313 @@ function contractRowToDomain(row) {
|
|
|
582
602
|
return contract;
|
|
583
603
|
}
|
|
584
604
|
|
|
605
|
+
// src/repositories/sqlite/intentRepository.ts
|
|
606
|
+
var SAFE_PREFIX3 = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
607
|
+
function sanitizePrefix3(p) {
|
|
608
|
+
if (!SAFE_PREFIX3.test(p)) throw new Error(`Invalid table prefix "${p}"`);
|
|
609
|
+
return p;
|
|
610
|
+
}
|
|
611
|
+
var SQLiteIntentRepository = class {
|
|
612
|
+
constructor(db, options) {
|
|
613
|
+
this.db = db;
|
|
614
|
+
this.prefix = sanitizePrefix3(options?.prefix ?? "ark_");
|
|
615
|
+
this.t = `${this.prefix}intents`;
|
|
616
|
+
}
|
|
617
|
+
version = 1;
|
|
618
|
+
initPromise = null;
|
|
619
|
+
prefix;
|
|
620
|
+
t;
|
|
621
|
+
ensureInit() {
|
|
622
|
+
if (!this.initPromise) this.initPromise = this.init();
|
|
623
|
+
return this.initPromise;
|
|
624
|
+
}
|
|
625
|
+
async init() {
|
|
626
|
+
await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.t} (
|
|
627
|
+
intent_tx_id TEXT PRIMARY KEY,
|
|
628
|
+
intent_id TEXT,
|
|
629
|
+
state TEXT NOT NULL,
|
|
630
|
+
valid_from INTEGER,
|
|
631
|
+
valid_until INTEGER,
|
|
632
|
+
created_at INTEGER NOT NULL,
|
|
633
|
+
updated_at INTEGER NOT NULL,
|
|
634
|
+
register_proof TEXT NOT NULL,
|
|
635
|
+
register_proof_message TEXT NOT NULL,
|
|
636
|
+
delete_proof TEXT NOT NULL,
|
|
637
|
+
delete_proof_message TEXT NOT NULL,
|
|
638
|
+
batch_id TEXT,
|
|
639
|
+
commitment_txid TEXT,
|
|
640
|
+
cancellation_reason TEXT,
|
|
641
|
+
partial_forfeits_json TEXT NOT NULL,
|
|
642
|
+
signer_descriptor TEXT,
|
|
643
|
+
intent_vtxos_json TEXT NOT NULL
|
|
644
|
+
)`);
|
|
645
|
+
await this.db.run(
|
|
646
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS idx_${this.prefix}intent_id ON ${this.t} (intent_id) WHERE intent_id IS NOT NULL`
|
|
647
|
+
);
|
|
648
|
+
await this.db.run(
|
|
649
|
+
`CREATE INDEX IF NOT EXISTS idx_${this.prefix}intent_state ON ${this.t} (state)`
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
withTx(fn) {
|
|
653
|
+
return runInTransaction(this.db, fn);
|
|
654
|
+
}
|
|
655
|
+
async clear() {
|
|
656
|
+
await this.ensureInit();
|
|
657
|
+
await this.withTx(async () => {
|
|
658
|
+
await this.db.run(`DELETE FROM ${this.t}`);
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
async saveIntent(intent) {
|
|
662
|
+
await this.ensureInit();
|
|
663
|
+
const now = Date.now();
|
|
664
|
+
await this.withTx(async () => {
|
|
665
|
+
await this.db.run(
|
|
666
|
+
`INSERT INTO ${this.t}
|
|
667
|
+
(intent_tx_id, intent_id, state, valid_from, valid_until,
|
|
668
|
+
created_at, updated_at, register_proof, register_proof_message,
|
|
669
|
+
delete_proof, delete_proof_message, batch_id, commitment_txid,
|
|
670
|
+
cancellation_reason, partial_forfeits_json, signer_descriptor,
|
|
671
|
+
intent_vtxos_json)
|
|
672
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
673
|
+
ON CONFLICT(intent_tx_id) DO UPDATE SET
|
|
674
|
+
intent_id = excluded.intent_id,
|
|
675
|
+
state = excluded.state,
|
|
676
|
+
valid_from = excluded.valid_from,
|
|
677
|
+
valid_until = excluded.valid_until,
|
|
678
|
+
created_at = excluded.created_at,
|
|
679
|
+
updated_at = excluded.updated_at,
|
|
680
|
+
register_proof = excluded.register_proof,
|
|
681
|
+
register_proof_message = excluded.register_proof_message,
|
|
682
|
+
delete_proof = excluded.delete_proof,
|
|
683
|
+
delete_proof_message = excluded.delete_proof_message,
|
|
684
|
+
batch_id = excluded.batch_id,
|
|
685
|
+
commitment_txid = excluded.commitment_txid,
|
|
686
|
+
cancellation_reason = excluded.cancellation_reason,
|
|
687
|
+
partial_forfeits_json = excluded.partial_forfeits_json,
|
|
688
|
+
signer_descriptor = excluded.signer_descriptor,
|
|
689
|
+
intent_vtxos_json = excluded.intent_vtxos_json`,
|
|
690
|
+
[
|
|
691
|
+
intent.intentTxId,
|
|
692
|
+
intent.intentId ?? null,
|
|
693
|
+
intent.state,
|
|
694
|
+
intent.validFrom ?? null,
|
|
695
|
+
intent.validUntil ?? null,
|
|
696
|
+
intent.createdAt,
|
|
697
|
+
now,
|
|
698
|
+
intent.registerProof,
|
|
699
|
+
intent.registerProofMessage,
|
|
700
|
+
intent.deleteProof,
|
|
701
|
+
intent.deleteProofMessage,
|
|
702
|
+
intent.batchId ?? null,
|
|
703
|
+
intent.commitmentTransactionId ?? null,
|
|
704
|
+
intent.cancellationReason ?? null,
|
|
705
|
+
JSON.stringify(intent.partialForfeits),
|
|
706
|
+
intent.signerDescriptor ?? null,
|
|
707
|
+
JSON.stringify(intent.intentVtxos)
|
|
708
|
+
]
|
|
709
|
+
);
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
async getIntents(filter) {
|
|
713
|
+
await this.ensureInit();
|
|
714
|
+
const rows = await this.db.all(
|
|
715
|
+
`SELECT * FROM ${this.t} ORDER BY created_at ASC, intent_tx_id ASC`
|
|
716
|
+
);
|
|
717
|
+
let out = rows.map(rowToIntent);
|
|
718
|
+
if (filter) out = out.filter((i) => chunkXIVCG6EP_cjs.intentMatchesFilter(i, filter));
|
|
719
|
+
const { skip, end } = chunkXIVCG6EP_cjs.intentPageBounds(filter, out.length);
|
|
720
|
+
return out.slice(skip, end);
|
|
721
|
+
}
|
|
722
|
+
async getLockedVtxoOutpoints() {
|
|
723
|
+
await this.ensureInit();
|
|
724
|
+
const rows = await this.db.all(`SELECT * FROM ${this.t}`);
|
|
725
|
+
const out = [];
|
|
726
|
+
for (const r of rows) {
|
|
727
|
+
if (chunkXIVCG6EP_cjs.isTerminalIntentState(r.state)) continue;
|
|
728
|
+
for (const o of JSON.parse(r.intent_vtxos_json)) out.push(o);
|
|
729
|
+
}
|
|
730
|
+
return out;
|
|
731
|
+
}
|
|
732
|
+
async [Symbol.asyncDispose]() {
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
function rowToIntent(r) {
|
|
736
|
+
return {
|
|
737
|
+
intentTxId: r.intent_tx_id,
|
|
738
|
+
intentId: r.intent_id ?? void 0,
|
|
739
|
+
state: r.state,
|
|
740
|
+
validFrom: r.valid_from ?? void 0,
|
|
741
|
+
validUntil: r.valid_until ?? void 0,
|
|
742
|
+
createdAt: r.created_at,
|
|
743
|
+
updatedAt: r.updated_at,
|
|
744
|
+
registerProof: r.register_proof,
|
|
745
|
+
registerProofMessage: r.register_proof_message,
|
|
746
|
+
deleteProof: r.delete_proof,
|
|
747
|
+
deleteProofMessage: r.delete_proof_message,
|
|
748
|
+
batchId: r.batch_id ?? void 0,
|
|
749
|
+
commitmentTransactionId: r.commitment_txid ?? void 0,
|
|
750
|
+
cancellationReason: r.cancellation_reason ?? void 0,
|
|
751
|
+
partialForfeits: JSON.parse(r.partial_forfeits_json),
|
|
752
|
+
signerDescriptor: r.signer_descriptor ?? void 0,
|
|
753
|
+
intentVtxos: JSON.parse(r.intent_vtxos_json)
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// src/repositories/sqlite/virtualTxRepository.ts
|
|
758
|
+
var SAFE_PREFIX4 = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
759
|
+
function sanitizePrefix4(p) {
|
|
760
|
+
if (!SAFE_PREFIX4.test(p)) throw new Error(`Invalid table prefix "${p}"`);
|
|
761
|
+
return p;
|
|
762
|
+
}
|
|
763
|
+
var SQLiteVirtualTxRepository = class {
|
|
764
|
+
constructor(db, options) {
|
|
765
|
+
this.db = db;
|
|
766
|
+
this.prefix = sanitizePrefix4(options?.prefix ?? "ark_");
|
|
767
|
+
this.tTx = `${this.prefix}virtual_txs`;
|
|
768
|
+
this.tBranch = `${this.prefix}vtxo_branches`;
|
|
769
|
+
}
|
|
770
|
+
version = 1;
|
|
771
|
+
initPromise = null;
|
|
772
|
+
prefix;
|
|
773
|
+
tTx;
|
|
774
|
+
tBranch;
|
|
775
|
+
ensureInit() {
|
|
776
|
+
if (!this.initPromise) this.initPromise = this.init();
|
|
777
|
+
return this.initPromise;
|
|
778
|
+
}
|
|
779
|
+
async init() {
|
|
780
|
+
await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.tTx} (
|
|
781
|
+
txid TEXT PRIMARY KEY,
|
|
782
|
+
psbt TEXT,
|
|
783
|
+
expires_at INTEGER,
|
|
784
|
+
type INTEGER NOT NULL DEFAULT 0
|
|
785
|
+
)`);
|
|
786
|
+
await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.tBranch} (
|
|
787
|
+
vtxo_txid TEXT NOT NULL,
|
|
788
|
+
vtxo_vout INTEGER NOT NULL,
|
|
789
|
+
virtual_txid TEXT NOT NULL,
|
|
790
|
+
position INTEGER NOT NULL,
|
|
791
|
+
PRIMARY KEY (vtxo_txid, vtxo_vout, position)
|
|
792
|
+
)`);
|
|
793
|
+
await this.db.run(
|
|
794
|
+
`CREATE INDEX IF NOT EXISTS idx_${this.prefix}branch_vtxid ON ${this.tBranch} (virtual_txid)`
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
tx(fn) {
|
|
798
|
+
return runInTransaction(this.db, fn);
|
|
799
|
+
}
|
|
800
|
+
async clear() {
|
|
801
|
+
await this.ensureInit();
|
|
802
|
+
await this.tx(async () => {
|
|
803
|
+
await this.db.run(`DELETE FROM ${this.tTx}`);
|
|
804
|
+
await this.db.run(`DELETE FROM ${this.tBranch}`);
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
async upsertVirtualTxs(txs) {
|
|
808
|
+
if (txs.length === 0) return;
|
|
809
|
+
await this.ensureInit();
|
|
810
|
+
await this.tx(async () => {
|
|
811
|
+
const placeholders = txs.map(() => "?").join(", ");
|
|
812
|
+
const existing = await this.db.all(
|
|
813
|
+
`SELECT * FROM ${this.tTx} WHERE txid IN (${placeholders})`,
|
|
814
|
+
txs.map((t) => t.txid)
|
|
815
|
+
);
|
|
816
|
+
const prevByTxid = new Map(existing.map((r) => [r.txid, r]));
|
|
817
|
+
for (const t of txs) {
|
|
818
|
+
const prev = prevByTxid.get(t.txid);
|
|
819
|
+
const psbt = t.psbt ?? prev?.psbt ?? null;
|
|
820
|
+
const expires = t.expiresAt ?? prev?.expires_at ?? null;
|
|
821
|
+
const type = chunkXIVCG6EP_cjs.mergeChainedTxType(t.type, prev?.type);
|
|
822
|
+
await this.db.run(
|
|
823
|
+
`INSERT OR REPLACE INTO ${this.tTx} (txid, psbt, expires_at, type) VALUES (?, ?, ?, ?)`,
|
|
824
|
+
[t.txid, psbt, expires, type]
|
|
825
|
+
);
|
|
826
|
+
prevByTxid.set(t.txid, { txid: t.txid, psbt, expires_at: expires, type });
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
async getVirtualTx(txid) {
|
|
831
|
+
await this.ensureInit();
|
|
832
|
+
const row = await this.db.get(`SELECT * FROM ${this.tTx} WHERE txid = ?`, [txid]);
|
|
833
|
+
return row ? rowToTx(row) : null;
|
|
834
|
+
}
|
|
835
|
+
async setBranch(vtxo, branch) {
|
|
836
|
+
await this.ensureInit();
|
|
837
|
+
await this.tx(async () => {
|
|
838
|
+
await this.db.run(`DELETE FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`, [
|
|
839
|
+
vtxo.txid,
|
|
840
|
+
vtxo.vout
|
|
841
|
+
]);
|
|
842
|
+
for (const b of branch) {
|
|
843
|
+
await this.db.run(
|
|
844
|
+
`INSERT OR REPLACE INTO ${this.tBranch} (vtxo_txid, vtxo_vout, virtual_txid, position) VALUES (?, ?, ?, ?)`,
|
|
845
|
+
[b.vtxoTxid, b.vtxoVout, b.virtualTxid, b.position]
|
|
846
|
+
);
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
async getBranch(vtxo) {
|
|
851
|
+
await this.ensureInit();
|
|
852
|
+
const rows = await this.db.all(
|
|
853
|
+
`SELECT t.txid, t.psbt, t.expires_at, t.type
|
|
854
|
+
FROM ${this.tBranch} b
|
|
855
|
+
JOIN ${this.tTx} t ON t.txid = b.virtual_txid
|
|
856
|
+
WHERE b.vtxo_txid = ? AND b.vtxo_vout = ?
|
|
857
|
+
ORDER BY b.position ASC`,
|
|
858
|
+
[vtxo.txid, vtxo.vout]
|
|
859
|
+
);
|
|
860
|
+
return rows.map(rowToTx);
|
|
861
|
+
}
|
|
862
|
+
async hasBranch(vtxo) {
|
|
863
|
+
await this.ensureInit();
|
|
864
|
+
const r = await this.db.get(
|
|
865
|
+
`SELECT COUNT(*) AS c FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`,
|
|
866
|
+
[vtxo.txid, vtxo.vout]
|
|
867
|
+
);
|
|
868
|
+
return (r?.c ?? 0) > 0;
|
|
869
|
+
}
|
|
870
|
+
async pruneForSpentVtxo(vtxo) {
|
|
871
|
+
await this.ensureInit();
|
|
872
|
+
await this.tx(async () => {
|
|
873
|
+
const removed = await this.db.all(
|
|
874
|
+
`SELECT DISTINCT virtual_txid FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`,
|
|
875
|
+
[vtxo.txid, vtxo.vout]
|
|
876
|
+
);
|
|
877
|
+
await this.db.run(`DELETE FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`, [
|
|
878
|
+
vtxo.txid,
|
|
879
|
+
vtxo.vout
|
|
880
|
+
]);
|
|
881
|
+
if (removed.length === 0) return;
|
|
882
|
+
const placeholders = removed.map(() => "?").join(", ");
|
|
883
|
+
await this.db.run(
|
|
884
|
+
`DELETE FROM ${this.tTx}
|
|
885
|
+
WHERE txid IN (${placeholders})
|
|
886
|
+
AND NOT EXISTS (
|
|
887
|
+
SELECT 1 FROM ${this.tBranch} b WHERE b.virtual_txid = ${this.tTx}.txid
|
|
888
|
+
)`,
|
|
889
|
+
removed.map((r) => r.virtual_txid)
|
|
890
|
+
);
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
async [Symbol.asyncDispose]() {
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
function rowToTx(r) {
|
|
897
|
+
return {
|
|
898
|
+
txid: r.txid,
|
|
899
|
+
psbt: r.psbt ?? null,
|
|
900
|
+
expiresAt: r.expires_at ?? null,
|
|
901
|
+
type: r.type
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
Object.defineProperty(exports, "ChainedTxType", {
|
|
906
|
+
enumerable: true,
|
|
907
|
+
get: function () { return chunkXIVCG6EP_cjs.ChainedTxType; }
|
|
908
|
+
});
|
|
585
909
|
exports.SQLiteContractRepository = SQLiteContractRepository;
|
|
910
|
+
exports.SQLiteIntentRepository = SQLiteIntentRepository;
|
|
911
|
+
exports.SQLiteVirtualTxRepository = SQLiteVirtualTxRepository;
|
|
586
912
|
exports.SQLiteWalletRepository = SQLiteWalletRepository;
|
|
587
913
|
//# sourceMappingURL=index.cjs.map
|
|
588
914
|
//# sourceMappingURL=index.cjs.map
|