@arkade-os/sdk 0.4.42 → 0.4.43
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/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-CjoL-35w.d.ts} +1 -1
- package/dist/{asyncStorageTaskQueue-BpN8RRHR.d.cts → asyncStorageTaskQueue-D1FfHfgK.d.cts} +1 -1
- package/dist/{chunk-YEF5FL6E.cjs → chunk-3AQNLQPM.cjs} +39 -4
- package/dist/chunk-3AQNLQPM.cjs.map +1 -0
- package/dist/{chunk-5X5YMZHB.js → chunk-763XHDAJ.js} +39 -5
- package/dist/chunk-763XHDAJ.js.map +1 -0
- package/dist/{chunk-V3FCNVJE.js → chunk-B4R36PRN.js} +1105 -356
- package/dist/chunk-B4R36PRN.js.map +1 -0
- package/dist/{chunk-HHPUCCB3.cjs → chunk-JIWCE2IK.cjs} +7 -7
- package/dist/{chunk-HHPUCCB3.cjs.map → chunk-JIWCE2IK.cjs.map} +1 -1
- package/dist/{chunk-T2ACJD22.cjs → chunk-PLJZRIFZ.cjs} +11 -11
- package/dist/{chunk-T2ACJD22.cjs.map → chunk-PLJZRIFZ.cjs.map} +1 -1
- package/dist/{chunk-ED7JDFX4.cjs → chunk-QGNTDGMN.cjs} +1189 -429
- package/dist/chunk-QGNTDGMN.cjs.map +1 -0
- package/dist/{chunk-FLPPSRYH.js → chunk-US274KZO.js} +3 -3
- package/dist/{chunk-FLPPSRYH.js.map → chunk-US274KZO.js.map} +1 -1
- package/dist/{chunk-2V3BU2X6.js → chunk-VKKLOT2E.js} +3 -3
- package/dist/{chunk-2V3BU2X6.js.map → chunk-VKKLOT2E.js.map} +1 -1
- 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 +150 -118
- package/dist/index.d.cts +113 -9
- package/dist/index.d.ts +113 -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-CuTk8RYg.d.cts → taskRunner-BSnslNmq.d.cts} +1 -1
- package/dist/{taskRunner-BdiRy4iI.d.ts → taskRunner-Djlhfgi1.d.ts} +1 -1
- 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,9 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { serializeVtxo, isVtxoForScript, serializeUtxo, serializeAssets, scriptFromArkAddress, deserializeVtxo, deserializeUtxo, deserializeAssets, intentMatchesFilter, intentPageBounds, isTerminalIntentState, mergeChainedTxType } from '../../chunk-B4R36PRN.js';
|
|
2
|
+
export { ChainedTxType } from '../../chunk-B4R36PRN.js';
|
|
3
|
+
import '../../chunk-763XHDAJ.js';
|
|
3
4
|
import '../../chunk-YNEDJTX2.js';
|
|
4
5
|
import '../../chunk-BE5MUB7T.js';
|
|
5
6
|
import '../../chunk-NSBPE2FW.js';
|
|
6
7
|
|
|
8
|
+
// src/repositories/sqlite/transaction.ts
|
|
9
|
+
var writeChains = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
function runInTransaction(db, fn) {
|
|
11
|
+
const prev = writeChains.get(db) ?? Promise.resolve();
|
|
12
|
+
const run = prev.then(async () => {
|
|
13
|
+
await db.run("BEGIN IMMEDIATE");
|
|
14
|
+
try {
|
|
15
|
+
await fn();
|
|
16
|
+
await db.run("COMMIT");
|
|
17
|
+
} catch (e) {
|
|
18
|
+
try {
|
|
19
|
+
await db.run("ROLLBACK");
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
throw e;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
writeChains.set(
|
|
26
|
+
db,
|
|
27
|
+
run.catch(() => {
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
return run;
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
// src/repositories/sqlite/walletRepository.ts
|
|
8
34
|
var SQLiteWalletRepository = class {
|
|
9
35
|
constructor(db, options) {
|
|
@@ -94,29 +120,31 @@ var SQLiteWalletRepository = class {
|
|
|
94
120
|
* indexer would have returned — new rows from the indexer always carry a
|
|
95
121
|
* populated `script`, so the migration is idempotent.
|
|
96
122
|
*
|
|
97
|
-
* The
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
123
|
+
* The whole check-and-migrate runs inside one transaction, not just the
|
|
124
|
+
* rebuild: the schema inspection is the decision point, so a second
|
|
125
|
+
* concurrent init on the same connection must not read a pre-migration
|
|
126
|
+
* schema and then re-run `ADD COLUMN` (duplicate column) after the first
|
|
127
|
+
* migration already committed. It also guards the crash window between the
|
|
128
|
+
* `DROP TABLE vtxos` and the `RENAME tmp → vtxos`, which would otherwise
|
|
129
|
+
* leave the next startup seeing no `vtxos` table.
|
|
101
130
|
*/
|
|
102
131
|
async migrateVtxosTable() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
try {
|
|
132
|
+
await runInTransaction(this.db, async () => {
|
|
133
|
+
const tableExists = await this.db.get(
|
|
134
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
|
|
135
|
+
[this.tables.vtxos]
|
|
136
|
+
);
|
|
137
|
+
if (!tableExists) {
|
|
138
|
+
await this.db.run(this.vtxosCreateSql(this.tables.vtxos));
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const cols = await this.db.all(
|
|
142
|
+
`PRAGMA table_info(${this.tables.vtxos})`
|
|
143
|
+
);
|
|
144
|
+
const scriptCol = cols.find((c) => c.name === "script");
|
|
145
|
+
if (scriptCol && scriptCol.notnull === 1) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
120
148
|
if (!scriptCol) {
|
|
121
149
|
await this.db.run(`ALTER TABLE ${this.tables.vtxos} ADD COLUMN script TEXT`);
|
|
122
150
|
}
|
|
@@ -146,14 +174,7 @@ var SQLiteWalletRepository = class {
|
|
|
146
174
|
`);
|
|
147
175
|
await this.db.run(`DROP TABLE ${this.tables.vtxos}`);
|
|
148
176
|
await this.db.run(`ALTER TABLE ${tempName} RENAME TO ${this.tables.vtxos}`);
|
|
149
|
-
|
|
150
|
-
} catch (e) {
|
|
151
|
-
try {
|
|
152
|
-
await this.db.run("ROLLBACK");
|
|
153
|
-
} catch {
|
|
154
|
-
}
|
|
155
|
-
throw e;
|
|
156
|
-
}
|
|
177
|
+
});
|
|
157
178
|
}
|
|
158
179
|
vtxosCreateSql(tableName) {
|
|
159
180
|
return `CREATE TABLE ${tableName} (
|
|
@@ -580,6 +601,306 @@ function contractRowToDomain(row) {
|
|
|
580
601
|
return contract;
|
|
581
602
|
}
|
|
582
603
|
|
|
583
|
-
|
|
604
|
+
// src/repositories/sqlite/intentRepository.ts
|
|
605
|
+
var SAFE_PREFIX3 = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
606
|
+
function sanitizePrefix3(p) {
|
|
607
|
+
if (!SAFE_PREFIX3.test(p)) throw new Error(`Invalid table prefix "${p}"`);
|
|
608
|
+
return p;
|
|
609
|
+
}
|
|
610
|
+
var SQLiteIntentRepository = class {
|
|
611
|
+
constructor(db, options) {
|
|
612
|
+
this.db = db;
|
|
613
|
+
this.prefix = sanitizePrefix3(options?.prefix ?? "ark_");
|
|
614
|
+
this.t = `${this.prefix}intents`;
|
|
615
|
+
}
|
|
616
|
+
version = 1;
|
|
617
|
+
initPromise = null;
|
|
618
|
+
prefix;
|
|
619
|
+
t;
|
|
620
|
+
ensureInit() {
|
|
621
|
+
if (!this.initPromise) this.initPromise = this.init();
|
|
622
|
+
return this.initPromise;
|
|
623
|
+
}
|
|
624
|
+
async init() {
|
|
625
|
+
await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.t} (
|
|
626
|
+
intent_tx_id TEXT PRIMARY KEY,
|
|
627
|
+
intent_id TEXT,
|
|
628
|
+
state TEXT NOT NULL,
|
|
629
|
+
valid_from INTEGER,
|
|
630
|
+
valid_until INTEGER,
|
|
631
|
+
created_at INTEGER NOT NULL,
|
|
632
|
+
updated_at INTEGER NOT NULL,
|
|
633
|
+
register_proof TEXT NOT NULL,
|
|
634
|
+
register_proof_message TEXT NOT NULL,
|
|
635
|
+
delete_proof TEXT NOT NULL,
|
|
636
|
+
delete_proof_message TEXT NOT NULL,
|
|
637
|
+
batch_id TEXT,
|
|
638
|
+
commitment_txid TEXT,
|
|
639
|
+
cancellation_reason TEXT,
|
|
640
|
+
partial_forfeits_json TEXT NOT NULL,
|
|
641
|
+
signer_descriptor TEXT,
|
|
642
|
+
intent_vtxos_json TEXT NOT NULL
|
|
643
|
+
)`);
|
|
644
|
+
await this.db.run(
|
|
645
|
+
`CREATE UNIQUE INDEX IF NOT EXISTS idx_${this.prefix}intent_id ON ${this.t} (intent_id) WHERE intent_id IS NOT NULL`
|
|
646
|
+
);
|
|
647
|
+
await this.db.run(
|
|
648
|
+
`CREATE INDEX IF NOT EXISTS idx_${this.prefix}intent_state ON ${this.t} (state)`
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
withTx(fn) {
|
|
652
|
+
return runInTransaction(this.db, fn);
|
|
653
|
+
}
|
|
654
|
+
async clear() {
|
|
655
|
+
await this.ensureInit();
|
|
656
|
+
await this.withTx(async () => {
|
|
657
|
+
await this.db.run(`DELETE FROM ${this.t}`);
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
async saveIntent(intent) {
|
|
661
|
+
await this.ensureInit();
|
|
662
|
+
const now = Date.now();
|
|
663
|
+
await this.withTx(async () => {
|
|
664
|
+
await this.db.run(
|
|
665
|
+
`INSERT INTO ${this.t}
|
|
666
|
+
(intent_tx_id, intent_id, state, valid_from, valid_until,
|
|
667
|
+
created_at, updated_at, register_proof, register_proof_message,
|
|
668
|
+
delete_proof, delete_proof_message, batch_id, commitment_txid,
|
|
669
|
+
cancellation_reason, partial_forfeits_json, signer_descriptor,
|
|
670
|
+
intent_vtxos_json)
|
|
671
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
672
|
+
ON CONFLICT(intent_tx_id) DO UPDATE SET
|
|
673
|
+
intent_id = excluded.intent_id,
|
|
674
|
+
state = excluded.state,
|
|
675
|
+
valid_from = excluded.valid_from,
|
|
676
|
+
valid_until = excluded.valid_until,
|
|
677
|
+
created_at = excluded.created_at,
|
|
678
|
+
updated_at = excluded.updated_at,
|
|
679
|
+
register_proof = excluded.register_proof,
|
|
680
|
+
register_proof_message = excluded.register_proof_message,
|
|
681
|
+
delete_proof = excluded.delete_proof,
|
|
682
|
+
delete_proof_message = excluded.delete_proof_message,
|
|
683
|
+
batch_id = excluded.batch_id,
|
|
684
|
+
commitment_txid = excluded.commitment_txid,
|
|
685
|
+
cancellation_reason = excluded.cancellation_reason,
|
|
686
|
+
partial_forfeits_json = excluded.partial_forfeits_json,
|
|
687
|
+
signer_descriptor = excluded.signer_descriptor,
|
|
688
|
+
intent_vtxos_json = excluded.intent_vtxos_json`,
|
|
689
|
+
[
|
|
690
|
+
intent.intentTxId,
|
|
691
|
+
intent.intentId ?? null,
|
|
692
|
+
intent.state,
|
|
693
|
+
intent.validFrom ?? null,
|
|
694
|
+
intent.validUntil ?? null,
|
|
695
|
+
intent.createdAt,
|
|
696
|
+
now,
|
|
697
|
+
intent.registerProof,
|
|
698
|
+
intent.registerProofMessage,
|
|
699
|
+
intent.deleteProof,
|
|
700
|
+
intent.deleteProofMessage,
|
|
701
|
+
intent.batchId ?? null,
|
|
702
|
+
intent.commitmentTransactionId ?? null,
|
|
703
|
+
intent.cancellationReason ?? null,
|
|
704
|
+
JSON.stringify(intent.partialForfeits),
|
|
705
|
+
intent.signerDescriptor ?? null,
|
|
706
|
+
JSON.stringify(intent.intentVtxos)
|
|
707
|
+
]
|
|
708
|
+
);
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
async getIntents(filter) {
|
|
712
|
+
await this.ensureInit();
|
|
713
|
+
const rows = await this.db.all(
|
|
714
|
+
`SELECT * FROM ${this.t} ORDER BY created_at ASC, intent_tx_id ASC`
|
|
715
|
+
);
|
|
716
|
+
let out = rows.map(rowToIntent);
|
|
717
|
+
if (filter) out = out.filter((i) => intentMatchesFilter(i, filter));
|
|
718
|
+
const { skip, end } = intentPageBounds(filter, out.length);
|
|
719
|
+
return out.slice(skip, end);
|
|
720
|
+
}
|
|
721
|
+
async getLockedVtxoOutpoints() {
|
|
722
|
+
await this.ensureInit();
|
|
723
|
+
const rows = await this.db.all(`SELECT * FROM ${this.t}`);
|
|
724
|
+
const out = [];
|
|
725
|
+
for (const r of rows) {
|
|
726
|
+
if (isTerminalIntentState(r.state)) continue;
|
|
727
|
+
for (const o of JSON.parse(r.intent_vtxos_json)) out.push(o);
|
|
728
|
+
}
|
|
729
|
+
return out;
|
|
730
|
+
}
|
|
731
|
+
async [Symbol.asyncDispose]() {
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
function rowToIntent(r) {
|
|
735
|
+
return {
|
|
736
|
+
intentTxId: r.intent_tx_id,
|
|
737
|
+
intentId: r.intent_id ?? void 0,
|
|
738
|
+
state: r.state,
|
|
739
|
+
validFrom: r.valid_from ?? void 0,
|
|
740
|
+
validUntil: r.valid_until ?? void 0,
|
|
741
|
+
createdAt: r.created_at,
|
|
742
|
+
updatedAt: r.updated_at,
|
|
743
|
+
registerProof: r.register_proof,
|
|
744
|
+
registerProofMessage: r.register_proof_message,
|
|
745
|
+
deleteProof: r.delete_proof,
|
|
746
|
+
deleteProofMessage: r.delete_proof_message,
|
|
747
|
+
batchId: r.batch_id ?? void 0,
|
|
748
|
+
commitmentTransactionId: r.commitment_txid ?? void 0,
|
|
749
|
+
cancellationReason: r.cancellation_reason ?? void 0,
|
|
750
|
+
partialForfeits: JSON.parse(r.partial_forfeits_json),
|
|
751
|
+
signerDescriptor: r.signer_descriptor ?? void 0,
|
|
752
|
+
intentVtxos: JSON.parse(r.intent_vtxos_json)
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// src/repositories/sqlite/virtualTxRepository.ts
|
|
757
|
+
var SAFE_PREFIX4 = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
758
|
+
function sanitizePrefix4(p) {
|
|
759
|
+
if (!SAFE_PREFIX4.test(p)) throw new Error(`Invalid table prefix "${p}"`);
|
|
760
|
+
return p;
|
|
761
|
+
}
|
|
762
|
+
var SQLiteVirtualTxRepository = class {
|
|
763
|
+
constructor(db, options) {
|
|
764
|
+
this.db = db;
|
|
765
|
+
this.prefix = sanitizePrefix4(options?.prefix ?? "ark_");
|
|
766
|
+
this.tTx = `${this.prefix}virtual_txs`;
|
|
767
|
+
this.tBranch = `${this.prefix}vtxo_branches`;
|
|
768
|
+
}
|
|
769
|
+
version = 1;
|
|
770
|
+
initPromise = null;
|
|
771
|
+
prefix;
|
|
772
|
+
tTx;
|
|
773
|
+
tBranch;
|
|
774
|
+
ensureInit() {
|
|
775
|
+
if (!this.initPromise) this.initPromise = this.init();
|
|
776
|
+
return this.initPromise;
|
|
777
|
+
}
|
|
778
|
+
async init() {
|
|
779
|
+
await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.tTx} (
|
|
780
|
+
txid TEXT PRIMARY KEY,
|
|
781
|
+
psbt TEXT,
|
|
782
|
+
expires_at INTEGER,
|
|
783
|
+
type INTEGER NOT NULL DEFAULT 0
|
|
784
|
+
)`);
|
|
785
|
+
await this.db.run(`CREATE TABLE IF NOT EXISTS ${this.tBranch} (
|
|
786
|
+
vtxo_txid TEXT NOT NULL,
|
|
787
|
+
vtxo_vout INTEGER NOT NULL,
|
|
788
|
+
virtual_txid TEXT NOT NULL,
|
|
789
|
+
position INTEGER NOT NULL,
|
|
790
|
+
PRIMARY KEY (vtxo_txid, vtxo_vout, position)
|
|
791
|
+
)`);
|
|
792
|
+
await this.db.run(
|
|
793
|
+
`CREATE INDEX IF NOT EXISTS idx_${this.prefix}branch_vtxid ON ${this.tBranch} (virtual_txid)`
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
tx(fn) {
|
|
797
|
+
return runInTransaction(this.db, fn);
|
|
798
|
+
}
|
|
799
|
+
async clear() {
|
|
800
|
+
await this.ensureInit();
|
|
801
|
+
await this.tx(async () => {
|
|
802
|
+
await this.db.run(`DELETE FROM ${this.tTx}`);
|
|
803
|
+
await this.db.run(`DELETE FROM ${this.tBranch}`);
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
async upsertVirtualTxs(txs) {
|
|
807
|
+
if (txs.length === 0) return;
|
|
808
|
+
await this.ensureInit();
|
|
809
|
+
await this.tx(async () => {
|
|
810
|
+
const placeholders = txs.map(() => "?").join(", ");
|
|
811
|
+
const existing = await this.db.all(
|
|
812
|
+
`SELECT * FROM ${this.tTx} WHERE txid IN (${placeholders})`,
|
|
813
|
+
txs.map((t) => t.txid)
|
|
814
|
+
);
|
|
815
|
+
const prevByTxid = new Map(existing.map((r) => [r.txid, r]));
|
|
816
|
+
for (const t of txs) {
|
|
817
|
+
const prev = prevByTxid.get(t.txid);
|
|
818
|
+
const psbt = t.psbt ?? prev?.psbt ?? null;
|
|
819
|
+
const expires = t.expiresAt ?? prev?.expires_at ?? null;
|
|
820
|
+
const type = mergeChainedTxType(t.type, prev?.type);
|
|
821
|
+
await this.db.run(
|
|
822
|
+
`INSERT OR REPLACE INTO ${this.tTx} (txid, psbt, expires_at, type) VALUES (?, ?, ?, ?)`,
|
|
823
|
+
[t.txid, psbt, expires, type]
|
|
824
|
+
);
|
|
825
|
+
prevByTxid.set(t.txid, { txid: t.txid, psbt, expires_at: expires, type });
|
|
826
|
+
}
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
async getVirtualTx(txid) {
|
|
830
|
+
await this.ensureInit();
|
|
831
|
+
const row = await this.db.get(`SELECT * FROM ${this.tTx} WHERE txid = ?`, [txid]);
|
|
832
|
+
return row ? rowToTx(row) : null;
|
|
833
|
+
}
|
|
834
|
+
async setBranch(vtxo, branch) {
|
|
835
|
+
await this.ensureInit();
|
|
836
|
+
await this.tx(async () => {
|
|
837
|
+
await this.db.run(`DELETE FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`, [
|
|
838
|
+
vtxo.txid,
|
|
839
|
+
vtxo.vout
|
|
840
|
+
]);
|
|
841
|
+
for (const b of branch) {
|
|
842
|
+
await this.db.run(
|
|
843
|
+
`INSERT OR REPLACE INTO ${this.tBranch} (vtxo_txid, vtxo_vout, virtual_txid, position) VALUES (?, ?, ?, ?)`,
|
|
844
|
+
[b.vtxoTxid, b.vtxoVout, b.virtualTxid, b.position]
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
async getBranch(vtxo) {
|
|
850
|
+
await this.ensureInit();
|
|
851
|
+
const rows = await this.db.all(
|
|
852
|
+
`SELECT t.txid, t.psbt, t.expires_at, t.type
|
|
853
|
+
FROM ${this.tBranch} b
|
|
854
|
+
JOIN ${this.tTx} t ON t.txid = b.virtual_txid
|
|
855
|
+
WHERE b.vtxo_txid = ? AND b.vtxo_vout = ?
|
|
856
|
+
ORDER BY b.position ASC`,
|
|
857
|
+
[vtxo.txid, vtxo.vout]
|
|
858
|
+
);
|
|
859
|
+
return rows.map(rowToTx);
|
|
860
|
+
}
|
|
861
|
+
async hasBranch(vtxo) {
|
|
862
|
+
await this.ensureInit();
|
|
863
|
+
const r = await this.db.get(
|
|
864
|
+
`SELECT COUNT(*) AS c FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`,
|
|
865
|
+
[vtxo.txid, vtxo.vout]
|
|
866
|
+
);
|
|
867
|
+
return (r?.c ?? 0) > 0;
|
|
868
|
+
}
|
|
869
|
+
async pruneForSpentVtxo(vtxo) {
|
|
870
|
+
await this.ensureInit();
|
|
871
|
+
await this.tx(async () => {
|
|
872
|
+
const removed = await this.db.all(
|
|
873
|
+
`SELECT DISTINCT virtual_txid FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`,
|
|
874
|
+
[vtxo.txid, vtxo.vout]
|
|
875
|
+
);
|
|
876
|
+
await this.db.run(`DELETE FROM ${this.tBranch} WHERE vtxo_txid = ? AND vtxo_vout = ?`, [
|
|
877
|
+
vtxo.txid,
|
|
878
|
+
vtxo.vout
|
|
879
|
+
]);
|
|
880
|
+
if (removed.length === 0) return;
|
|
881
|
+
const placeholders = removed.map(() => "?").join(", ");
|
|
882
|
+
await this.db.run(
|
|
883
|
+
`DELETE FROM ${this.tTx}
|
|
884
|
+
WHERE txid IN (${placeholders})
|
|
885
|
+
AND NOT EXISTS (
|
|
886
|
+
SELECT 1 FROM ${this.tBranch} b WHERE b.virtual_txid = ${this.tTx}.txid
|
|
887
|
+
)`,
|
|
888
|
+
removed.map((r) => r.virtual_txid)
|
|
889
|
+
);
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
async [Symbol.asyncDispose]() {
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
function rowToTx(r) {
|
|
896
|
+
return {
|
|
897
|
+
txid: r.txid,
|
|
898
|
+
psbt: r.psbt ?? null,
|
|
899
|
+
expiresAt: r.expires_at ?? null,
|
|
900
|
+
type: r.type
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
export { SQLiteContractRepository, SQLiteIntentRepository, SQLiteVirtualTxRepository, SQLiteWalletRepository };
|
|
584
905
|
//# sourceMappingURL=index.js.map
|
|
585
906
|
//# sourceMappingURL=index.js.map
|