@arkade-os/sdk 0.5.0-rc.2 → 0.5.0-rc.20

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.
Files changed (126) hide show
  1. package/README.md +90 -83
  2. package/dist/adapters/expo.cjs +5 -6
  3. package/dist/adapters/expo.d.cts +4 -4
  4. package/dist/adapters/expo.d.ts +4 -4
  5. package/dist/adapters/expo.js +3 -4
  6. package/dist/{asyncStorageTaskQueue-C5rBYlru.d.ts → asyncStorageTaskQueue-aL7K14e4.d.ts} +2 -2
  7. package/dist/{asyncStorageTaskQueue-BuDvgWh6.d.cts → asyncStorageTaskQueue-x8ok3tJy.d.cts} +2 -2
  8. package/dist/{chunk-43FKNLX4.cjs → chunk-5SLUXXWQ.cjs} +357 -1114
  9. package/dist/chunk-5SLUXXWQ.cjs.map +1 -0
  10. package/dist/{chunk-HLCGYOIH.cjs → chunk-6YVGWOLG.cjs} +37 -36
  11. package/dist/chunk-6YVGWOLG.cjs.map +1 -0
  12. package/dist/{chunk-4PKLULWT.js → chunk-AARSVV3S.js} +109 -246
  13. package/dist/chunk-AARSVV3S.js.map +1 -0
  14. package/dist/{chunk-D25O4EGY.cjs → chunk-AFJSJACF.cjs} +12 -10
  15. package/dist/chunk-AFJSJACF.cjs.map +1 -0
  16. package/dist/{chunk-6DNR46C7.js → chunk-IM3J3T5P.js} +7 -5
  17. package/dist/chunk-IM3J3T5P.js.map +1 -0
  18. package/dist/{chunk-ISO4TI5J.js → chunk-NR4XYTN3.js} +566 -459
  19. package/dist/chunk-NR4XYTN3.js.map +1 -0
  20. package/dist/{chunk-ZRNQV6HV.js → chunk-O2ZZD5Z6.js} +4578 -4396
  21. package/dist/chunk-O2ZZD5Z6.js.map +1 -0
  22. package/dist/{chunk-ZOTXDOS5.js → chunk-P267BXL7.js} +30 -29
  23. package/dist/chunk-P267BXL7.js.map +1 -0
  24. package/dist/{chunk-NVZJSKZS.cjs → chunk-P42MGA4K.cjs} +121 -257
  25. package/dist/chunk-P42MGA4K.cjs.map +1 -0
  26. package/dist/{chunk-GMZZQXV5.cjs → chunk-QARA4IYT.cjs} +4961 -4767
  27. package/dist/chunk-QARA4IYT.cjs.map +1 -0
  28. package/dist/{chunk-JZWLXNHV.cjs → chunk-T6N6B7HK.cjs} +574 -464
  29. package/dist/chunk-T6N6B7HK.cjs.map +1 -0
  30. package/dist/{chunk-3R476TDV.js → chunk-TIVYJIIX.js} +293 -1071
  31. package/dist/chunk-TIVYJIIX.js.map +1 -0
  32. package/dist/contracts/handlers/index.cjs +9 -10
  33. package/dist/contracts/handlers/index.d.cts +5 -5
  34. package/dist/contracts/handlers/index.d.ts +5 -5
  35. package/dist/contracts/handlers/index.js +2 -3
  36. package/dist/{delegate-BAX5QftB.d.ts → delegate-BT5iON1T.d.ts} +1 -1
  37. package/dist/{delegate-1yp1HyP7.d.cts → delegate-u6kXTtWY.d.cts} +1 -1
  38. package/dist/index-BCnhItOQ.d.cts +639 -0
  39. package/dist/{index-DUxufw76.d.cts → index-CK5QbTmZ.d.cts} +1387 -2404
  40. package/dist/{index-DUxufw76.d.ts → index-CK5QbTmZ.d.ts} +1387 -2404
  41. package/dist/index-D1D4cR-G.d.ts +639 -0
  42. package/dist/index.cjs +375 -340
  43. package/dist/index.d.cts +784 -1197
  44. package/dist/index.d.ts +784 -1197
  45. package/dist/index.js +4 -5
  46. package/dist/repositories/realm/index.cjs +201 -106
  47. package/dist/repositories/realm/index.cjs.map +1 -1
  48. package/dist/repositories/realm/index.d.cts +28 -16
  49. package/dist/repositories/realm/index.d.ts +28 -16
  50. package/dist/repositories/realm/index.js +190 -95
  51. package/dist/repositories/realm/index.js.map +1 -1
  52. package/dist/repositories/sqlite/index.cjs +301 -189
  53. package/dist/repositories/sqlite/index.cjs.map +1 -1
  54. package/dist/repositories/sqlite/index.d.cts +32 -21
  55. package/dist/repositories/sqlite/index.d.ts +32 -21
  56. package/dist/repositories/sqlite/index.js +294 -182
  57. package/dist/repositories/sqlite/index.js.map +1 -1
  58. package/dist/{taskRunner-D_iPiZIi.d.ts → taskRunner-BeYR6NpQ.d.ts} +2 -2
  59. package/dist/{taskRunner-Dr3NStc0.d.cts → taskRunner-Csey3EYJ.d.cts} +2 -2
  60. package/dist/wallet/expo/background.cjs +14 -15
  61. package/dist/wallet/expo/background.cjs.map +1 -1
  62. package/dist/wallet/expo/background.d.cts +10 -16
  63. package/dist/wallet/expo/background.d.ts +10 -16
  64. package/dist/wallet/expo/background.js +6 -7
  65. package/dist/wallet/expo/background.js.map +1 -1
  66. package/dist/wallet/expo/index.cjs +16 -23
  67. package/dist/wallet/expo/index.cjs.map +1 -1
  68. package/dist/wallet/expo/index.d.cts +6 -9
  69. package/dist/wallet/expo/index.d.ts +6 -9
  70. package/dist/wallet/expo/index.js +8 -15
  71. package/dist/wallet/expo/index.js.map +1 -1
  72. package/dist/wallet-DG3Qmbmt.d.cts +1848 -0
  73. package/dist/wallet-DzSLMxBZ.d.ts +1848 -0
  74. package/dist/worker/expo/index.cjs +9 -10
  75. package/dist/worker/expo/index.cjs.map +1 -1
  76. package/dist/worker/expo/index.d.cts +6 -6
  77. package/dist/worker/expo/index.d.ts +6 -6
  78. package/dist/worker/expo/index.js +5 -6
  79. package/dist/worker/expo/index.js.map +1 -1
  80. package/package.json +12 -51
  81. package/dist/adapters/asyncStorage.cjs +0 -48
  82. package/dist/adapters/asyncStorage.cjs.map +0 -1
  83. package/dist/adapters/asyncStorage.d.cts +0 -16
  84. package/dist/adapters/asyncStorage.d.ts +0 -16
  85. package/dist/adapters/asyncStorage.js +0 -46
  86. package/dist/adapters/asyncStorage.js.map +0 -1
  87. package/dist/adapters/fileSystem.cjs +0 -116
  88. package/dist/adapters/fileSystem.cjs.map +0 -1
  89. package/dist/adapters/fileSystem.d.cts +0 -17
  90. package/dist/adapters/fileSystem.d.ts +0 -17
  91. package/dist/adapters/fileSystem.js +0 -93
  92. package/dist/adapters/fileSystem.js.map +0 -1
  93. package/dist/adapters/indexedDB.cjs +0 -103
  94. package/dist/adapters/indexedDB.cjs.map +0 -1
  95. package/dist/adapters/indexedDB.d.cts +0 -18
  96. package/dist/adapters/indexedDB.d.ts +0 -18
  97. package/dist/adapters/indexedDB.js +0 -101
  98. package/dist/adapters/indexedDB.js.map +0 -1
  99. package/dist/adapters/localStorage.cjs +0 -50
  100. package/dist/adapters/localStorage.cjs.map +0 -1
  101. package/dist/adapters/localStorage.d.cts +0 -14
  102. package/dist/adapters/localStorage.d.ts +0 -14
  103. package/dist/adapters/localStorage.js +0 -48
  104. package/dist/adapters/localStorage.js.map +0 -1
  105. package/dist/chunk-3R476TDV.js.map +0 -1
  106. package/dist/chunk-43FKNLX4.cjs.map +0 -1
  107. package/dist/chunk-4PKLULWT.js.map +0 -1
  108. package/dist/chunk-5BLDMQED.cjs +0 -18
  109. package/dist/chunk-5BLDMQED.cjs.map +0 -1
  110. package/dist/chunk-6DNR46C7.js.map +0 -1
  111. package/dist/chunk-D25O4EGY.cjs.map +0 -1
  112. package/dist/chunk-GMZZQXV5.cjs.map +0 -1
  113. package/dist/chunk-HLCGYOIH.cjs.map +0 -1
  114. package/dist/chunk-ISO4TI5J.js.map +0 -1
  115. package/dist/chunk-JZWLXNHV.cjs.map +0 -1
  116. package/dist/chunk-NSBPE2FW.js +0 -15
  117. package/dist/chunk-NSBPE2FW.js.map +0 -1
  118. package/dist/chunk-NVZJSKZS.cjs.map +0 -1
  119. package/dist/chunk-ZOTXDOS5.js.map +0 -1
  120. package/dist/chunk-ZRNQV6HV.js.map +0 -1
  121. package/dist/hdWalletCapable-CmEU0NP1.d.ts +0 -2232
  122. package/dist/hdWalletCapable-eJgaT-ec.d.cts +0 -2232
  123. package/dist/index-Bem5vKzX.d.ts +0 -850
  124. package/dist/index-C0IanN1m.d.cts +0 -11
  125. package/dist/index-C0IanN1m.d.ts +0 -11
  126. package/dist/index-W_oMcOmG.d.cts +0 -850
@@ -1,9 +1,8 @@
1
- import { serializeVtxo, isVtxoForScript, serializeUtxo, serializeAssets, scriptFromArkAddress, deserializeVtxo, deserializeUtxo, deserializeAssets, assertIntentIdUnique, intentMatchesFilter, intentPageBounds, isTerminalIntentState, mergeChainedTxType } from '../../chunk-ZRNQV6HV.js';
2
- export { ChainedTxType } from '../../chunk-ZRNQV6HV.js';
3
- import '../../chunk-4PKLULWT.js';
4
- import '../../chunk-3R476TDV.js';
5
- import '../../chunk-ISO4TI5J.js';
6
- import '../../chunk-NSBPE2FW.js';
1
+ import { serializeVtxo, createdAtToIso, assertPageRequest, pageResult, checkSaveVtxosForScript, utxoEntries, serializeUtxo, assertHistoryPageFilter, compareHistoryCursors, serializeAssets, scriptFromArkAddress, deserializeVtxo, deserializeUtxo, deserializeAssets, contractFilterMatchesNothing, assertIntentIdUnique, intentMatchesFilter, isTerminalIntentState, mergeChainedTxType, legacyVtxoFacts } from '../../chunk-O2ZZD5Z6.js';
2
+ export { ChainedTxType } from '../../chunk-O2ZZD5Z6.js';
3
+ import '../../chunk-AARSVV3S.js';
4
+ import '../../chunk-TIVYJIIX.js';
5
+ import { isVtxoSpent } from '../../chunk-NR4XYTN3.js';
7
6
 
8
7
  // src/repositories/realm/walletRepository.ts
9
8
  var RealmWalletRepository = class {
@@ -11,7 +10,7 @@ var RealmWalletRepository = class {
11
10
  this.realm = realm;
12
11
  }
13
12
  realm;
14
- version = 1;
13
+ version = 2;
15
14
  // ── Lifecycle ──────────────────────────────────────────────────────
16
15
  async ensureInit() {
17
16
  }
@@ -28,10 +27,8 @@ var RealmWalletRepository = class {
28
27
  });
29
28
  }
30
29
  // ── VTXO management ────────────────────────────────────────────────
31
- async getVtxos(address) {
32
- await this.ensureInit();
33
- const results = this.realm.objects("ArkVtxo").filtered("address == $0", address);
34
- return [...results].map(vtxoObjectToDomain);
30
+ async getVtxosPage(address, page) {
31
+ return this.pageByAddress("ArkVtxo", address, page, vtxoObjectToDomain);
35
32
  }
36
33
  async saveVtxos(address, vtxos) {
37
34
  await this.ensureInit();
@@ -52,10 +49,14 @@ var RealmWalletRepository = class {
52
49
  intentCb: s.intentTapLeafScript.cb,
53
50
  intentS: s.intentTapLeafScript.s,
54
51
  statusJson: JSON.stringify(s.status),
55
- virtualStatusJson: JSON.stringify(s.virtualStatus),
56
- createdAt: typeof s.createdAt === "string" ? s.createdAt : s.createdAt instanceof Date ? s.createdAt.toISOString() : new Date(s.createdAt).toISOString(),
52
+ createdAt: createdAtToIso(s.createdAt),
57
53
  isUnrolled: s.isUnrolled ?? false,
58
54
  isSpent: s.isSpent === void 0 ? null : s.isSpent,
55
+ isSwept: s.isSwept === void 0 ? null : s.isSwept,
56
+ isPreconfirmed: s.isPreconfirmed === void 0 ? null : s.isPreconfirmed,
57
+ commitmentTxIdsJson: s.commitmentTxIds ? JSON.stringify(s.commitmentTxIds) : null,
58
+ expiresAt: s.expiresAt === void 0 ? null : new Date(s.expiresAt).toISOString(),
59
+ expiresAtHeight: s.expiresAtHeight ?? null,
59
60
  spentBy: s.spentBy ?? null,
60
61
  settledBy: s.settledBy ?? null,
61
62
  arkTxId: s.arkTxId ?? null,
@@ -69,47 +70,83 @@ var RealmWalletRepository = class {
69
70
  });
70
71
  }
71
72
  async deleteVtxos(address) {
72
- await this.ensureInit();
73
- this.realm.write(() => {
74
- const toDelete = this.realm.objects("ArkVtxo").filtered("address == $0", address);
75
- this.realm.delete(toDelete);
76
- });
73
+ return this.deleteWhere("ArkVtxo", "address", address);
77
74
  }
78
- async getVtxosForScript(script) {
75
+ async getVtxosForScriptPage(script, page, options) {
76
+ assertPageRequest(page);
79
77
  await this.ensureInit();
80
- const results = this.realm.objects("ArkVtxo").filtered("script == $0", script);
81
- return [...results].map(vtxoObjectToDomain);
82
- }
83
- async saveVtxosForScript(key, vtxos) {
84
- if (!key.address) {
85
- throw new Error("RealmWalletRepository requires an address");
78
+ let results = this.realm.objects("ArkVtxo").filtered("script == $0", script);
79
+ if (options?.unspentOnly) {
80
+ results = results.filtered(
81
+ "(isSpent == null OR isSpent == $0) AND (spentBy == null OR spentBy == $1) AND (settledBy == null OR settledBy == $1)",
82
+ false,
83
+ ""
84
+ );
86
85
  }
87
- for (const vtxo of vtxos) {
88
- if (!isVtxoForScript(vtxo, key.script)) {
89
- throw new Error(
90
- `VTXO ${vtxo.txid}:${vtxo.vout} script mismatch: expected ${key.script}, got ${vtxo.script}`
91
- );
92
- }
86
+ if (page.after) {
87
+ results = results.filtered(
88
+ "address > $0 OR (address == $0 AND (txid > $1 OR (txid == $1 AND vout > $2)))",
89
+ page.after.address,
90
+ page.after.txid,
91
+ page.after.vout
92
+ );
93
93
  }
94
- return this.saveVtxos(key.address, vtxos);
94
+ const rows = [];
95
+ for (const row of results.sorted([
96
+ ["address", false],
97
+ ["txid", false],
98
+ ["vout", false]
99
+ ])) {
100
+ rows.push({ address: row.address, vtxo: vtxoObjectToDomain(row) });
101
+ if (rows.length > page.limit) break;
102
+ }
103
+ const result = pageResult(rows, page.limit, (row) => ({
104
+ address: row.address,
105
+ txid: row.vtxo.txid,
106
+ vout: row.vtxo.vout
107
+ }));
108
+ return options?.unspentOnly ? { ...result, items: result.items.filter((row) => !isVtxoSpent(row.vtxo)) } : result;
109
+ }
110
+ async saveVtxosForScript(key, vtxos) {
111
+ return this.saveVtxos(checkSaveVtxosForScript("RealmWalletRepository", key, vtxos), vtxos);
95
112
  }
96
113
  async deleteVtxosForScript(script) {
97
- await this.ensureInit();
98
- this.realm.write(() => {
99
- const toDelete = this.realm.objects("ArkVtxo").filtered("script == $0", script);
100
- this.realm.delete(toDelete);
101
- });
114
+ return this.deleteWhere("ArkVtxo", "script", script);
102
115
  }
103
116
  // ── UTXO management ────────────────────────────────────────────────
104
- async getUtxos(address) {
117
+ async getUtxosPage(address, page) {
118
+ return this.pageByAddress("ArkUtxo", address, page, utxoObjectToDomain);
119
+ }
120
+ async pageByAddress(schema, address, page, deserialize) {
121
+ assertPageRequest(page);
105
122
  await this.ensureInit();
106
- const results = this.realm.objects("ArkUtxo").filtered("address == $0", address);
107
- return [...results].map(utxoObjectToDomain);
123
+ let results = this.realm.objects(schema).filtered("address == $0", address);
124
+ if (page.after) {
125
+ results = results.filtered(
126
+ "txid > $0 OR (txid == $0 AND vout > $1)",
127
+ page.after.txid,
128
+ page.after.vout
129
+ );
130
+ }
131
+ const rows = [];
132
+ for (const row of results.sorted([
133
+ ["txid", false],
134
+ ["vout", false]
135
+ ])) {
136
+ rows.push({ key: { txid: row.txid, vout: row.vout }, item: deserialize(row) });
137
+ if (rows.length > page.limit) break;
138
+ }
139
+ const result = pageResult(rows, page.limit, (row) => row.key);
140
+ return { items: result.items.map((row) => row.item), nextCursor: result.nextCursor };
108
141
  }
109
- async saveUtxos(address, utxos) {
142
+ async saveUtxos(addressOrBatch, utxos) {
110
143
  await this.ensureInit();
144
+ const rows = utxoEntries(addressOrBatch, utxos).flatMap(
145
+ ([address, list]) => list.map((utxo) => ({ address, utxo }))
146
+ );
147
+ if (rows.length === 0) return;
111
148
  this.realm.write(() => {
112
- for (const utxo of utxos) {
149
+ for (const { address, utxo } of rows) {
113
150
  const s = serializeUtxo(utxo);
114
151
  this.realm.create(
115
152
  "ArkUtxo",
@@ -133,19 +170,31 @@ var RealmWalletRepository = class {
133
170
  });
134
171
  }
135
172
  async deleteUtxos(address) {
136
- await this.ensureInit();
137
- this.realm.write(() => {
138
- const toDelete = this.realm.objects("ArkUtxo").filtered("address == $0", address);
139
- this.realm.delete(toDelete);
140
- });
173
+ return this.deleteWhere("ArkUtxo", "address", address);
141
174
  }
142
175
  // ── Transaction history ────────────────────────────────────────────
143
- async getTransactionHistory(address) {
144
- await this.ensureInit();
145
- const results = this.realm.objects("ArkTransaction").filtered("address == $0", address);
146
- const txs = [...results].map(txObjectToDomain);
147
- txs.sort((a, b) => a.createdAt - b.createdAt);
148
- return txs;
176
+ async getTransactionHistoryPage(filter, page) {
177
+ assertPageRequest(page);
178
+ assertHistoryPageFilter(filter);
179
+ let results = this.realm.objects("ArkTransaction").filtered("address == $0", filter.address);
180
+ results = results.filtered(
181
+ "createdAt >= $0",
182
+ Math.max(filter.since ?? 0, page.after?.createdAt ?? 0)
183
+ );
184
+ const rows = [];
185
+ for (const row of results.sorted([
186
+ ["createdAt", false],
187
+ ["boardingTxid", false],
188
+ ["commitmentTxid", false],
189
+ ["arkTxid", false]
190
+ ])) {
191
+ const tx = txObjectToDomain(row);
192
+ if (page.after !== void 0 && compareHistoryCursors({ createdAt: tx.createdAt, key: tx.key }, page.after) <= 0)
193
+ continue;
194
+ rows.push(tx);
195
+ if (rows.length > page.limit) break;
196
+ }
197
+ return pageResult(rows, page.limit, (tx) => ({ createdAt: tx.createdAt, key: tx.key }));
149
198
  }
150
199
  async saveTransactions(address, txs) {
151
200
  await this.ensureInit();
@@ -171,9 +220,12 @@ var RealmWalletRepository = class {
171
220
  });
172
221
  }
173
222
  async deleteTransactions(address) {
223
+ return this.deleteWhere("ArkTransaction", "address", address);
224
+ }
225
+ async deleteWhere(objectType, field, value) {
174
226
  await this.ensureInit();
175
227
  this.realm.write(() => {
176
- const toDelete = this.realm.objects("ArkTransaction").filtered("address == $0", address);
228
+ const toDelete = this.realm.objects(objectType).filtered(`${field} == $0`, value);
177
229
  this.realm.delete(toDelete);
178
230
  });
179
231
  }
@@ -221,10 +273,14 @@ function vtxoObjectToDomain(obj) {
221
273
  s: obj.intentS
222
274
  },
223
275
  status: JSON.parse(obj.statusJson),
224
- virtualStatus: JSON.parse(obj.virtualStatusJson),
225
276
  createdAt: new Date(obj.createdAt),
226
277
  isUnrolled: obj.isUnrolled,
227
278
  isSpent: obj.isSpent === null ? void 0 : obj.isSpent,
279
+ isSwept: obj.isSwept == null ? void 0 : obj.isSwept,
280
+ isPreconfirmed: obj.isPreconfirmed == null ? void 0 : obj.isPreconfirmed,
281
+ commitmentTxIds: obj.commitmentTxIdsJson ? JSON.parse(obj.commitmentTxIdsJson) : void 0,
282
+ expiresAt: obj.expiresAt ? new Date(obj.expiresAt) : void 0,
283
+ expiresAtHeight: obj.expiresAtHeight ?? void 0,
228
284
  spentBy: obj.spentBy ?? void 0,
229
285
  settledBy: obj.settledBy ?? void 0,
230
286
  arkTxId: obj.arkTxId ?? void 0,
@@ -280,7 +336,7 @@ var RealmContractRepository = class {
280
336
  this.realm = realm;
281
337
  }
282
338
  realm;
283
- version = 2;
339
+ version = 3;
284
340
  // ── Lifecycle ──────────────────────────────────────────────────────
285
341
  async ensureInit() {
286
342
  }
@@ -294,41 +350,47 @@ var RealmContractRepository = class {
294
350
  });
295
351
  }
296
352
  // ── Contract management ────────────────────────────────────────────
297
- async getContracts(filter) {
298
- await this.ensureInit();
353
+ async getContractsPage(filter, page) {
354
+ assertPageRequest(page);
355
+ if (contractFilterMatchesNothing(filter)) return { items: [] };
356
+ const toPage = (rows) => pageResult(rows.map(contractObjectToDomain), page.limit, (contract) => contract.script);
357
+ if (filter?.watch === void 0 || filter.script !== void 0) {
358
+ return toPage(this.readRows(filter, page));
359
+ }
360
+ const merged = [...new Set([filter.watch].flat())].flatMap((state) => state === "watched" ? [state, null] : [state]).flatMap(
361
+ (state) => state === "retained" ? this.readRows({ ...filter, watch: state }, page) : this.readRows({ ...filter, watch: void 0 }, page, state)
362
+ ).map((row) => ({ script: row.script, row })).sort((a, b) => a.script < b.script ? -1 : a.script > b.script ? 1 : 0);
363
+ return toPage(merged.slice(0, page.limit + 1).map(({ row }) => row));
364
+ }
365
+ /** Up to `limit + 1` rows in script order, led by `watch == leadingWatch` when one is given. */
366
+ readRows(filter, page, leadingWatch) {
299
367
  let results = this.realm.objects("ArkContract");
368
+ const parts = [];
369
+ const args = [];
370
+ let argIndex = 0;
300
371
  if (filter) {
301
- const filterParts = [];
302
- const filterArgs = [];
303
- let argIndex = 0;
304
- argIndex = this.addFilterCondition(
305
- filterParts,
306
- filterArgs,
307
- "script",
308
- filter.script,
309
- argIndex
310
- );
311
- argIndex = this.addFilterCondition(
312
- filterParts,
313
- filterArgs,
314
- "state",
315
- filter.state,
316
- argIndex
317
- );
318
- argIndex = this.addFilterCondition(
319
- filterParts,
320
- filterArgs,
321
- "type",
322
- filter.type,
323
- argIndex
324
- );
325
- argIndex = this.addWatchCondition(filterParts, filterArgs, filter.watch, argIndex);
326
- if (filterParts.length > 0) {
327
- const query = filterParts.join(" AND ");
328
- results = results.filtered(query, ...filterArgs);
329
- }
372
+ argIndex = this.addFilterCondition(parts, args, "script", filter.script, argIndex);
373
+ argIndex = this.addFilterCondition(parts, args, "state", filter.state, argIndex);
374
+ argIndex = this.addFilterCondition(parts, args, "type", filter.type, argIndex);
375
+ argIndex = this.addWatchCondition(parts, args, filter.watch, argIndex);
376
+ }
377
+ if (page.after !== void 0) {
378
+ parts.push(`script > $${argIndex}`);
379
+ args.push(page.after);
330
380
  }
331
- return [...results].map(contractObjectToDomain);
381
+ let query = parts.join(" AND ");
382
+ if (leadingWatch !== void 0) {
383
+ const lead = leadingWatch === null ? "watch == null" : `watch == $${args.length}`;
384
+ if (leadingWatch !== null) args.push(leadingWatch);
385
+ query = query ? `${lead} AND (${query})` : lead;
386
+ }
387
+ if (query) results = results.filtered(query, ...args);
388
+ const rows = [];
389
+ for (const row of results.sorted("script")) {
390
+ rows.push(row);
391
+ if (rows.length > page.limit) break;
392
+ }
393
+ return rows;
332
394
  }
333
395
  async saveContract(contract) {
334
396
  await this.ensureInit();
@@ -476,11 +538,18 @@ var RealmIntentRepository = class {
476
538
  );
477
539
  });
478
540
  }
479
- async getIntents(filter) {
480
- const all = [...this.realm.objects("ArkIntent")].map(toIntent).sort((a, b) => a.createdAt - b.createdAt || a.intentTxId.localeCompare(b.intentTxId));
481
- const out = filter ? all.filter((i) => intentMatchesFilter(i, filter)) : all;
482
- const { skip, end } = intentPageBounds(filter, out.length);
483
- return out.slice(skip, end);
541
+ async getIntentsPage(filter, page) {
542
+ assertPageRequest(page);
543
+ let results = this.realm.objects("ArkIntent");
544
+ if (page.after !== void 0) results = results.filtered("intentTxId > $0", page.after);
545
+ const rows = [];
546
+ for (const row of results.sorted("intentTxId")) {
547
+ const intent = toIntent(row);
548
+ if (filter && !intentMatchesFilter(intent, filter)) continue;
549
+ rows.push(intent);
550
+ if (rows.length > page.limit) break;
551
+ }
552
+ return pageResult(rows, page.limit, (intent) => intent.intentTxId);
484
553
  }
485
554
  async getLockedVtxoOutpoints() {
486
555
  const out = [];
@@ -618,7 +687,6 @@ var ArkVtxoSchema = {
618
687
  intentS: "string",
619
688
  extraWitnessJson: "string?",
620
689
  statusJson: "string",
621
- virtualStatusJson: "string",
622
690
  spentBy: "string?",
623
691
  settledBy: "string?",
624
692
  arkTxId: "string?",
@@ -626,6 +694,12 @@ var ArkVtxoSchema = {
626
694
  // ISO 8601
627
695
  isUnrolled: "bool",
628
696
  isSpent: "bool?",
697
+ isSwept: "bool?",
698
+ isPreconfirmed: "bool?",
699
+ commitmentTxIdsJson: "string?",
700
+ expiresAt: "string?",
701
+ // ISO 8601
702
+ expiresAtHeight: "int?",
629
703
  assetsJson: "string?",
630
704
  // scriptPubKey (hex) locking this VTXO, indexed so contract-scoped
631
705
  // queries can resolve ownership without touching address mapping.
@@ -755,14 +829,35 @@ var ArkExperimentalRealmSchemas = [
755
829
  ArkVirtualTxSchema,
756
830
  ArkVtxoBranchSchema
757
831
  ];
758
- var ARK_REALM_SCHEMA_VERSION = 3;
832
+ var ARK_REALM_SCHEMA_VERSION = 5;
759
833
  function runArkRealmMigrations(oldRealm, newRealm) {
834
+ const legacyByPk = /* @__PURE__ */ new Map();
835
+ const oldVtxos = oldRealm?.objects?.("ArkVtxo") ?? [];
836
+ for (let i = 0; i < oldVtxos.length; i++) {
837
+ const raw = oldVtxos[i].virtualStatusJson;
838
+ if (raw) legacyByPk.set(oldVtxos[i].pk, raw);
839
+ }
760
840
  const newVtxos = newRealm.objects("ArkVtxo");
761
841
  for (let i = 0; i < newVtxos.length; i++) {
762
842
  const newVtxo = newVtxos[i];
763
843
  if (!newVtxo.script) {
764
844
  newVtxo.script = scriptFromArkAddress(newVtxo.address);
765
845
  }
846
+ const facts = legacyVtxoFacts(legacyByPk.get(newVtxo.pk));
847
+ if (facts) {
848
+ if (newVtxo.isSpent == null) newVtxo.isSpent = facts.isSpent;
849
+ if (newVtxo.isSwept == null) newVtxo.isSwept = facts.isSwept;
850
+ if (newVtxo.isPreconfirmed == null) newVtxo.isPreconfirmed = facts.isPreconfirmed;
851
+ if (newVtxo.commitmentTxIdsJson == null && facts.commitmentTxIds) {
852
+ newVtxo.commitmentTxIdsJson = JSON.stringify(facts.commitmentTxIds);
853
+ }
854
+ if (newVtxo.expiresAt == null && facts.expiresAt) {
855
+ newVtxo.expiresAt = facts.expiresAt.toISOString();
856
+ }
857
+ if (newVtxo.expiresAtHeight == null && facts.expiresAtHeight !== void 0) {
858
+ newVtxo.expiresAtHeight = facts.expiresAtHeight;
859
+ }
860
+ }
766
861
  }
767
862
  const oldHasVirtualTx = Array.isArray(oldRealm?.schema) && oldRealm.schema.some((s) => s.name === "ArkVirtualTx");
768
863
  if (oldHasVirtualTx) {