@arkade-os/sdk 0.5.4 → 0.5.6
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 +103 -17
- package/dist/adapters/expo.cjs +7 -6
- package/dist/adapters/expo.d.cts +4 -3
- package/dist/adapters/expo.d.ts +4 -3
- package/dist/adapters/expo.js +4 -3
- package/dist/{asyncStorageTaskQueue-DTBa8EH7.d.cts → asyncStorageTaskQueue-Bh2n0msM.d.cts} +2 -2
- package/dist/{asyncStorageTaskQueue-DHMIxY04.d.ts → asyncStorageTaskQueue-CpkstKZ5.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-6CUP6ZIF.js → chunk-47Z4LEIW.js} +17 -841
- package/dist/chunk-47Z4LEIW.js.map +1 -0
- package/dist/{chunk-DNITZVNG.cjs → chunk-4X67IB2V.cjs} +18 -17
- package/dist/chunk-4X67IB2V.cjs.map +1 -0
- package/dist/{chunk-BTRCN4JJ.js → chunk-C7NY6WSA.js} +64 -4
- package/dist/chunk-C7NY6WSA.js.map +1 -0
- package/dist/{chunk-TUOLZBNC.js → chunk-DJYX73W2.js} +5 -4
- package/dist/chunk-DJYX73W2.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-WXNSISXK.cjs → chunk-HKEPJBTY.cjs} +79 -18
- package/dist/chunk-HKEPJBTY.cjs.map +1 -0
- package/dist/chunk-JFJNB7ZH.cjs +884 -0
- package/dist/chunk-JFJNB7ZH.cjs.map +1 -0
- package/dist/{chunk-GHUUT54D.cjs → chunk-LZAINCGU.cjs} +89 -933
- package/dist/chunk-LZAINCGU.cjs.map +1 -0
- package/dist/{chunk-E6OOJEHL.cjs → chunk-NDQ4LB4X.cjs} +60 -934
- package/dist/chunk-NDQ4LB4X.cjs.map +1 -0
- package/dist/{chunk-AG4TFD6F.js → chunk-QTMK34TP.js} +79 -884
- package/dist/chunk-QTMK34TP.js.map +1 -0
- package/dist/chunk-V3ZLL5VY.js +380 -0
- package/dist/chunk-V3ZLL5VY.js.map +1 -0
- package/dist/{chunk-MWVAWFX6.js → chunk-VWW2ZBPI.js} +4 -4
- package/dist/{chunk-MWVAWFX6.js.map → chunk-VWW2ZBPI.js.map} +1 -1
- package/dist/chunk-X6ZI53DZ.cjs +383 -0
- package/dist/chunk-X6ZI53DZ.cjs.map +1 -0
- package/dist/{chunk-F3FAE7VJ.cjs → chunk-Y3CDDPWI.cjs} +3138 -1764
- package/dist/chunk-Y3CDDPWI.cjs.map +1 -0
- package/dist/{chunk-ZJHLLDBP.js → chunk-YKT4NAQG.js} +2653 -1295
- package/dist/chunk-YKT4NAQG.js.map +1 -0
- package/dist/{chunk-B6VNKGIH.cjs → chunk-YS76JSGP.cjs} +10 -10
- package/dist/{chunk-B6VNKGIH.cjs.map → chunk-YS76JSGP.cjs.map} +1 -1
- 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-xrSBNybC.d.ts → delegate-gGkUnYpi.d.cts} +1 -1
- package/dist/{delegate-f4_t864Z.d.cts → delegate-iyDum4fw.d.ts} +1 -1
- package/dist/{index-BJDz15ms.d.ts → index-2wKMrT0a.d.ts} +5 -270
- package/dist/{index-BjiVGtp8.d.cts → index-46g577Ka.d.cts} +5 -270
- package/dist/{index-DRwe0UDN.d.cts → index-C66rjxz2.d.ts} +1603 -1721
- package/dist/{index-DRwe0UDN.d.ts → index-Dqk07NwJ.d.cts} +1603 -1721
- package/dist/index.cjs +457 -378
- package/dist/index.d.cts +640 -385
- package/dist/index.d.ts +640 -385
- package/dist/index.js +7 -4
- package/dist/{wallet-jVBDQl6R.d.cts → keyringDescriptorProvider-DiBM4GmB.d.ts} +417 -366
- package/dist/{wallet-Oc3Wd5gv.d.ts → keyringDescriptorProvider-DnaLUC7v.d.cts} +417 -366
- package/dist/program-BARSNg3X.d.ts +286 -0
- package/dist/program-znrWkxE4.d.cts +286 -0
- package/dist/repositories/realm/index.cjs +71 -51
- package/dist/repositories/realm/index.cjs.map +1 -1
- package/dist/repositories/realm/index.d.cts +20 -9
- package/dist/repositories/realm/index.d.ts +20 -9
- package/dist/repositories/realm/index.js +42 -23
- package/dist/repositories/realm/index.js.map +1 -1
- package/dist/repositories/sqlite/index.cjs +81 -56
- package/dist/repositories/sqlite/index.cjs.map +1 -1
- package/dist/repositories/sqlite/index.d.cts +17 -8
- package/dist/repositories/sqlite/index.d.ts +17 -8
- package/dist/repositories/sqlite/index.js +55 -31
- package/dist/repositories/sqlite/index.js.map +1 -1
- package/dist/{taskRunner-CDlNeth0.d.ts → taskRunner-BM6IAKlS.d.ts} +2 -2
- package/dist/{taskRunner-BPPU-YHG.d.cts → taskRunner-BmDIZiSl.d.cts} +2 -2
- 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 +9 -6
- 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 +19 -6
- 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-6CUP6ZIF.js.map +0 -1
- package/dist/chunk-AG4TFD6F.js.map +0 -1
- package/dist/chunk-BTRCN4JJ.js.map +0 -1
- package/dist/chunk-DNITZVNG.cjs.map +0 -1
- package/dist/chunk-E6OOJEHL.cjs.map +0 -1
- package/dist/chunk-F3FAE7VJ.cjs.map +0 -1
- package/dist/chunk-GHUUT54D.cjs.map +0 -1
- package/dist/chunk-TUOLZBNC.js.map +0 -1
- package/dist/chunk-WXNSISXK.cjs.map +0 -1
- package/dist/chunk-ZJHLLDBP.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkY3CDDPWI_cjs = require('./chunk-Y3CDDPWI.cjs');
|
|
4
|
+
var chunkLZAINCGU_cjs = require('./chunk-LZAINCGU.cjs');
|
|
5
5
|
|
|
6
6
|
// src/worker/expo/taskRunner.ts
|
|
7
7
|
async function runTasks(queue, processors, deps) {
|
|
@@ -33,7 +33,7 @@ async function runTasks(queue, processors, deps) {
|
|
|
33
33
|
}
|
|
34
34
|
const result = {
|
|
35
35
|
...partial,
|
|
36
|
-
id:
|
|
36
|
+
id: chunkY3CDDPWI_cjs.getRandomId(),
|
|
37
37
|
executedAt: Date.now()
|
|
38
38
|
};
|
|
39
39
|
await queue.pushResult(result);
|
|
@@ -45,7 +45,7 @@ async function runTasks(queue, processors, deps) {
|
|
|
45
45
|
function createTaskDependencies(options) {
|
|
46
46
|
return {
|
|
47
47
|
...options,
|
|
48
|
-
extendVtxo: (vtxo, contract) =>
|
|
48
|
+
extendVtxo: (vtxo, contract) => chunkY3CDDPWI_cjs.extendVirtualCoinForContract(vtxo, contract)
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -55,7 +55,7 @@ var contractPollProcessor = {
|
|
|
55
55
|
taskType: CONTRACT_POLL_TASK_TYPE,
|
|
56
56
|
async execute(item, deps) {
|
|
57
57
|
const { contractRepository, walletRepository, indexerProvider, extendVtxo } = deps;
|
|
58
|
-
const contracts = await
|
|
58
|
+
const contracts = await chunkY3CDDPWI_cjs.collectContracts(contractRepository, {
|
|
59
59
|
watch: ["watched", "awaiting-funds"]
|
|
60
60
|
});
|
|
61
61
|
let contractsProcessed = 0;
|
|
@@ -66,7 +66,7 @@ var contractPollProcessor = {
|
|
|
66
66
|
let hasMore = true;
|
|
67
67
|
const allVtxos = [];
|
|
68
68
|
while (hasMore) {
|
|
69
|
-
const { vtxos, page } = await
|
|
69
|
+
const { vtxos, page } = await chunkLZAINCGU_cjs.getNormalizedVtxos(indexerProvider, {
|
|
70
70
|
scripts: [contract.script],
|
|
71
71
|
pageIndex,
|
|
72
72
|
pageSize
|
|
@@ -77,12 +77,12 @@ var contractPollProcessor = {
|
|
|
77
77
|
hasMore = page ? vtxos.length === pageSize : false;
|
|
78
78
|
pageIndex++;
|
|
79
79
|
}
|
|
80
|
-
const filtered =
|
|
80
|
+
const filtered = chunkY3CDDPWI_cjs.warnAndFilterVtxosForScript(
|
|
81
81
|
allVtxos,
|
|
82
82
|
contract.script,
|
|
83
83
|
"contractPollProcessor"
|
|
84
84
|
);
|
|
85
|
-
await
|
|
85
|
+
await chunkY3CDDPWI_cjs.saveVtxosForContract(walletRepository, contract, filtered);
|
|
86
86
|
vtxosSaved += filtered.length;
|
|
87
87
|
contractsProcessed++;
|
|
88
88
|
}
|
|
@@ -99,5 +99,5 @@ exports.CONTRACT_POLL_TASK_TYPE = CONTRACT_POLL_TASK_TYPE;
|
|
|
99
99
|
exports.contractPollProcessor = contractPollProcessor;
|
|
100
100
|
exports.createTaskDependencies = createTaskDependencies;
|
|
101
101
|
exports.runTasks = runTasks;
|
|
102
|
-
//# sourceMappingURL=chunk-
|
|
103
|
-
//# sourceMappingURL=chunk-
|
|
102
|
+
//# sourceMappingURL=chunk-YS76JSGP.cjs.map
|
|
103
|
+
//# sourceMappingURL=chunk-YS76JSGP.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/worker/expo/taskRunner.ts","../src/worker/expo/processors/contractPollProcessor.ts"],"names":["getRandomId","extendVirtualCoinForContract","collectContracts","getNormalizedVtxos","warnAndFilterVtxosForScript","saveVtxosForContract"],"mappings":";;;;;;AAkDA,eAAsB,QAAA,CAClB,KAAA,EACA,UAAA,EACA,IAAA,EACqB;AACrB,EAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,CAAM,QAAA,EAAS;AACnC,EAAA,MAAM,YAAA,GAAe,IAAI,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,CAAC,CAAA,KAAM,CAAC,CAAA,CAAE,QAAA,EAAU,CAAC,CAAC,CAAC,CAAA;AACnE,EAAA,MAAM,UAAwB,EAAC;AAE/B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACtB,IAAA,MAAM,SAAA,GAAY,YAAA,CAAa,GAAA,CAAI,IAAA,CAAK,IAAI,CAAA;AAE5C,IAAA,IAAI,OAAA;AAEJ,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,OAAA,GAAU;AAAA,QACN,YAAY,IAAA,CAAK,EAAA;AAAA,QACjB,MAAM,IAAA,CAAK,IAAA;AAAA,QACX,MAAA,EAAQ;AAAA,OACZ;AAAA,IACJ,CAAA,MAAO;AACH,MAAA,IAAI;AACA,QAAA,OAAA,GAAU,MAAM,SAAA,CAAU,OAAA,CAAQ,IAAA,EAAM,IAAI,CAAA;AAAA,MAChD,SAAS,KAAA,EAAO;AACZ,QAAA,OAAA,GAAU;AAAA,UACN,YAAY,IAAA,CAAK,EAAA;AAAA,UACjB,MAAM,IAAA,CAAK,IAAA;A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AA;AAChB,MAAA,IAAI,OAAA,GAAU,IAAA;AACd,MAAA,MAAM,WAAkC,EAAC;AAEzC,MAAA,OAAO,OAAA,EAAS;AACZ,QAAA,MAAM,EAAE,KAAA,EAAO,IAAA,EAAK,GAAI,MAAMC,qCAAmB,eAAA,EAAiB;AAAA,UAC9D,OAAA,EAAS,CAAC,QAAA,CAAS,MAAM,CAAA;AAAA,UACzB,SAAA;AAAA,UACA;AAAA,SACH,CAAA;AAED,QAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACtB,UAAA,QAAA,CAAS,IAAA,CAAK,UAAA,CAAW,IAAA,EAAM,QAAQ,CAAC,CAAA;AAAA,QAC5C;AAEA,QAAA,OAAA,GAAU,IAAA,GAAO,KAAA,CAAM,MAAA,KAAW,QAAA,GAAW,KAAA;AAC7C,QAAA,SAAA,EAAA;AAAA,MACJ;AAKA,MAAA,MAAM,QAAA,GAAWC,6CAAA;AAAA,QACb,QAAA;AAAA,QACA,QAAA,CAAS,MAAA;AAAA,QACT;AAAA,OACJ;AACA,MAAA,MAAMC,sCAAA,CAAqB,gBAAA,EAAkB,QAAA,EAAU,QAAQ,CAAA;AAC/D,MAAA,UAAA,IAAc,QAAA,CAAS,MAAA;AACvB,MAAA,kBAAA,EAAA;AAAA,IACJ;AAEA,IAAA,OAAO;AAAA,MACH,YAAY,IAAA,CAAK,EAAA;AAAA,MACjB,IAAA,EAAM,uBAAA;AAAA,MACN,MAAA,EAAQ,SAAA;AAAA,MACR,IAAA,EAAM,EAAE,kBAAA,EAAoB,UAAA;AAAW,KAC3C;AAAA,EACJ;AACJ","file":"chunk-B6VNKGIH.cjs","sourcesContent":["import type { TaskItem, TaskResult, TaskQueue } from \"./taskQueue\";\nimport type { WalletRepository } from \"../../repositories/walletRepository\";\nimport type { ContractRepository } from \"../../repositories/contractRepository\";\nimport type { IndexerProvider } from \"../../providers/indexer\";\nimport type { OperatorProvider } from \"../../providers/ark\";\nimport type { ExtendedVirtualCoin, VirtualCoin } from \"../../wallet\";\nimport type { Contract } from \"../../contracts/types\";\nimport { getRandomId, extendVirtualCoinForContract } from \"../../wallet/utils\";\n\n/**\n * Shared dependencies injected into every processor at runtime.\n *\n * `extendVtxo` requires the owning contract — processors must resolve each\n * vtxo's `script` to a known contract (via the contract repository) before\n * calling this. The strict signature prevents the footgun where a missing\n * contract silently falls back to the wallet's default tapscript.\n */\nexport interface TaskDependencies {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: OperatorProvider;\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) => ExtendedVirtualCoin;\n}\n\n/**\n * A stateless unit that handles one type of task item.\n *\n * Processors must not keep in-memory state across invocations —\n * all coordination lives in the @see TaskQueue and repositories.\n *\n * The `TDeps` parameter defaults to @see TaskDependencies but\n * can be overridden for domain-specific processors (e.g. swap processing).\n */\nexport interface TaskProcessor<TDeps = TaskDependencies> {\n readonly taskType: string;\n execute(item: TaskItem, deps: TDeps): Promise<Omit<TaskResult, \"id\" | \"executedAt\">>;\n}\n\n/**\n * Run all pending tasks from the queue through matching processors.\n *\n * For each task in the inbox:\n * 1. Find the processor whose `taskType` matches `task.type`.\n * 2. Execute it, producing a @see TaskResult.\n * 3. Push the result to the outbox and remove the task from the inbox.\n *\n * Tasks with no matching processor produce a `\"noop\"` result.\n * Processor errors produce a `\"failed\"` result with the error message.\n */\nexport async function runTasks<TDeps = TaskDependencies>(\n queue: TaskQueue,\n processors: TaskProcessor<TDeps>[],\n deps: TDeps,\n): Promise<TaskResult[]> {\n const tasks = await queue.getTasks();\n const processorMap = new Map(processors.map((p) => [p.taskType, p]));\n const results: TaskResult[] = [];\n\n for (const task of tasks) {\n const processor = processorMap.get(task.type);\n\n let partial: Omit<TaskResult, \"id\" | \"executedAt\">;\n\n if (!processor) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"noop\",\n };\n } else {\n try {\n partial = await processor.execute(task, deps);\n } catch (error) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"failed\",\n data: {\n error: error instanceof Error ? error.message : String(error),\n },\n };\n }\n }\n\n const result: TaskResult = {\n ...partial,\n id: getRandomId(),\n executedAt: Date.now(),\n };\n\n await queue.pushResult(result);\n await queue.removeTask(task.id);\n results.push(result);\n }\n\n return results;\n}\n\n/**\n * Options for @see createTaskDependencies.\n */\nexport interface CreateTaskDependenciesOptions {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: OperatorProvider;\n}\n\n/**\n * Build the @see TaskDependencies needed by task processors\n * (e.g. `src/worker/expo/processors/contractPollProcessor.ts`)\n *\n * This is the same construction that `defineExpoBackgroundTask` does\n * internally, extracted so that consumers with custom schedulers\n * (e.g. bare React Native with `react-native-background-fetch`)\n * can build deps without depending on Expo.\n */\nexport function createTaskDependencies(options: CreateTaskDependenciesOptions): TaskDependencies {\n return {\n ...options,\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) =>\n extendVirtualCoinForContract(vtxo, contract),\n };\n}\n","import { collectContracts } from \"../../../repositories/contractRepository\";\nimport type { TaskItem, TaskResult } from \"../taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../taskRunner\";\nimport type { ExtendedVirtualCoin } from \"../../../wallet\";\nimport { getNormalizedVtxos } from \"../../../wallet/vtxo\";\nimport {\n warnAndFilterVtxosForScript,\n saveVtxosForContract,\n} from \"../../../contracts/vtxoOwnership\";\n\nexport const CONTRACT_POLL_TASK_TYPE = \"contract-poll\";\n\n/**\n * Polls the indexer for the latest VTXO state of every contract and\n * persists the results to the wallet repository.\n *\n * Replicates the polling subset of @see ContractManager.initialize:\n * 1. Load every watched contract from the contract repository.\n * 2. Paginated fetch of every VTXO (including spent) from the indexer.\n * 3. Extend each VTXO with tapscript data.\n * 4. Save to the wallet repository.\n *\n * NOTE: the indexer query deliberately omits `spendableOnly`. Every\n * repository implements `saveVtxos` as an upsert with no batch delete,\n * so filtering to spendable-only would leave VTXOs that became spent\n * between polls marked as spendable forever. Fetching the full set lets\n * the upsert overwrite stale records with their latest state.\n */\nexport const contractPollProcessor: TaskProcessor = {\n taskType: CONTRACT_POLL_TASK_TYPE,\n\n async execute(\n item: TaskItem,\n deps: TaskDependencies,\n ): Promise<Omit<TaskResult, \"id\" | \"executedAt\">> {\n const { contractRepository, walletRepository, indexerProvider, extendVtxo } = deps;\n\n // Background channel, so it covers exactly what the watcher's\n // subscription covers: `retained` rows are kept for reads only.\n const contracts = await collectContracts(contractRepository, {\n watch: [\"watched\", \"awaiting-funds\"],\n });\n let contractsProcessed = 0;\n let vtxosSaved = 0;\n\n for (const contract of contracts) {\n // Paginated fetch of spendable virtual outputs\n const pageSize = 100;\n let pageIndex = 0;\n let hasMore = true;\n const allVtxos: ExtendedVirtualCoin[] = [];\n\n while (hasMore) {\n const { vtxos, page } = await getNormalizedVtxos(indexerProvider, {\n scripts: [contract.script],\n pageIndex,\n pageSize,\n });\n\n for (const vtxo of vtxos) {\n allVtxos.push(extendVtxo(vtxo, contract));\n }\n\n hasMore = page ? vtxos.length === pageSize : false;\n pageIndex++;\n }\n\n // Skip wrong-script rows (legacy duplicates or indexer drift)\n // before persisting; the loop must keep going for the remaining\n // contracts even when one row is rejected.\n const filtered = warnAndFilterVtxosForScript(\n allVtxos,\n contract.script,\n \"contractPollProcessor\",\n );\n await saveVtxosForContract(walletRepository, contract, filtered);\n vtxosSaved += filtered.length;\n contractsProcessed++;\n }\n\n return {\n taskItemId: item.id,\n type: CONTRACT_POLL_TASK_TYPE,\n status: \"success\",\n data: { contractsProcessed, vtxosSaved },\n };\n },\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/worker/expo/taskRunner.ts","../src/worker/expo/processors/contractPollProcessor.ts"],"names":["getRandomId","extendVirtualCoinForContract","collectContracts","getNormalizedVtxos","warnAndFilterVtxosForScript","saveVtxosForContract"],"mappings":";;;;;;AAkDA,eAAsB,QAAA,CAClB,KAAA,EACA,UAAA,EACA,IAAA,EACqB;AAC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A,GAAU,IAAA,GAAO,KAAA,CAAM,MAAA,KAAW,QAAA,GAAW,KAAA;AAC7C,QAAA,SAAA,EAAA;AAAA,MACJ;AAKA,MAAA,MAAM,QAAA,GAAWC,6CAAA;AAAA,QACb,QAAA;AAAA,QACA,QAAA,CAAS,MAAA;AAAA,QACT;AAAA,OACJ;AACA,MAAA,MAAMC,sCAAA,CAAqB,gBAAA,EAAkB,QAAA,EAAU,QAAQ,CAAA;AAC/D,MAAA,UAAA,IAAc,QAAA,CAAS,MAAA;AACvB,MAAA,kBAAA,EAAA;AAAA,IACJ;AAEA,IAAA,OAAO;AAAA,MACH,YAAY,IAAA,CAAK,EAAA;AAAA,MACjB,IAAA,EAAM,uBAAA;AAAA,MACN,MAAA,EAAQ,SAAA;AAAA,MACR,IAAA,EAAM,EAAE,kBAAA,EAAoB,UAAA;AAAW,KAC3C;AAAA,EACJ;AACJ","file":"chunk-YS76JSGP.cjs","sourcesContent":["import type { TaskItem, TaskResult, TaskQueue } from \"./taskQueue\";\nimport type { WalletRepository } from \"../../repositories/walletRepository\";\nimport type { ContractRepository } from \"../../repositories/contractRepository\";\nimport type { IndexerProvider } from \"../../providers/indexer\";\nimport type { OperatorProvider } from \"../../providers/ark\";\nimport type { ExtendedVirtualCoin, VirtualCoin } from \"../../wallet\";\nimport type { Contract } from \"../../contracts/types\";\nimport { getRandomId, extendVirtualCoinForContract } from \"../../wallet/utils\";\n\n/**\n * Shared dependencies injected into every processor at runtime.\n *\n * `extendVtxo` requires the owning contract — processors must resolve each\n * vtxo's `script` to a known contract (via the contract repository) before\n * calling this. The strict signature prevents the footgun where a missing\n * contract silently falls back to the wallet's default tapscript.\n */\nexport interface TaskDependencies {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: OperatorProvider;\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) => ExtendedVirtualCoin;\n}\n\n/**\n * A stateless unit that handles one type of task item.\n *\n * Processors must not keep in-memory state across invocations —\n * all coordination lives in the @see TaskQueue and repositories.\n *\n * The `TDeps` parameter defaults to @see TaskDependencies but\n * can be overridden for domain-specific processors (e.g. swap processing).\n */\nexport interface TaskProcessor<TDeps = TaskDependencies> {\n readonly taskType: string;\n execute(item: TaskItem, deps: TDeps): Promise<Omit<TaskResult, \"id\" | \"executedAt\">>;\n}\n\n/**\n * Run all pending tasks from the queue through matching processors.\n *\n * For each task in the inbox:\n * 1. Find the processor whose `taskType` matches `task.type`.\n * 2. Execute it, producing a @see TaskResult.\n * 3. Push the result to the outbox and remove the task from the inbox.\n *\n * Tasks with no matching processor produce a `\"noop\"` result.\n * Processor errors produce a `\"failed\"` result with the error message.\n */\nexport async function runTasks<TDeps = TaskDependencies>(\n queue: TaskQueue,\n processors: TaskProcessor<TDeps>[],\n deps: TDeps,\n): Promise<TaskResult[]> {\n const tasks = await queue.getTasks();\n const processorMap = new Map(processors.map((p) => [p.taskType, p]));\n const results: TaskResult[] = [];\n\n for (const task of tasks) {\n const processor = processorMap.get(task.type);\n\n let partial: Omit<TaskResult, \"id\" | \"executedAt\">;\n\n if (!processor) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"noop\",\n };\n } else {\n try {\n partial = await processor.execute(task, deps);\n } catch (error) {\n partial = {\n taskItemId: task.id,\n type: task.type,\n status: \"failed\",\n data: {\n error: error instanceof Error ? error.message : String(error),\n },\n };\n }\n }\n\n const result: TaskResult = {\n ...partial,\n id: getRandomId(),\n executedAt: Date.now(),\n };\n\n await queue.pushResult(result);\n await queue.removeTask(task.id);\n results.push(result);\n }\n\n return results;\n}\n\n/**\n * Options for @see createTaskDependencies.\n */\nexport interface CreateTaskDependenciesOptions {\n walletRepository: WalletRepository;\n contractRepository: ContractRepository;\n indexerProvider: IndexerProvider;\n arkProvider: OperatorProvider;\n}\n\n/**\n * Build the @see TaskDependencies needed by task processors\n * (e.g. `src/worker/expo/processors/contractPollProcessor.ts`)\n *\n * This is the same construction that `defineExpoBackgroundTask` does\n * internally, extracted so that consumers with custom schedulers\n * (e.g. bare React Native with `react-native-background-fetch`)\n * can build deps without depending on Expo.\n */\nexport function createTaskDependencies(options: CreateTaskDependenciesOptions): TaskDependencies {\n return {\n ...options,\n extendVtxo: (vtxo: VirtualCoin, contract: Contract) =>\n extendVirtualCoinForContract(vtxo, contract),\n };\n}\n","import { collectContracts } from \"../../../repositories/contractRepository\";\nimport type { TaskItem, TaskResult } from \"../taskQueue\";\nimport type { TaskProcessor, TaskDependencies } from \"../taskRunner\";\nimport type { ExtendedVirtualCoin } from \"../../../wallet\";\nimport { getNormalizedVtxos } from \"../../../wallet/vtxo\";\nimport {\n warnAndFilterVtxosForScript,\n saveVtxosForContract,\n} from \"../../../contracts/vtxoOwnership\";\n\nexport const CONTRACT_POLL_TASK_TYPE = \"contract-poll\";\n\n/**\n * Polls the indexer for the latest VTXO state of every contract and\n * persists the results to the wallet repository.\n *\n * Replicates the polling subset of @see ContractManager.initialize:\n * 1. Load every watched contract from the contract repository.\n * 2. Paginated fetch of every VTXO (including spent) from the indexer.\n * 3. Extend each VTXO with tapscript data.\n * 4. Save to the wallet repository.\n *\n * NOTE: the indexer query deliberately omits `spendableOnly`. Every\n * repository implements `saveVtxos` as an upsert with no batch delete,\n * so filtering to spendable-only would leave VTXOs that became spent\n * between polls marked as spendable forever. Fetching the full set lets\n * the upsert overwrite stale records with their latest state.\n */\nexport const contractPollProcessor: TaskProcessor = {\n taskType: CONTRACT_POLL_TASK_TYPE,\n\n async execute(\n item: TaskItem,\n deps: TaskDependencies,\n ): Promise<Omit<TaskResult, \"id\" | \"executedAt\">> {\n const { contractRepository, walletRepository, indexerProvider, extendVtxo } = deps;\n\n // Background channel, so it covers exactly what the watcher's\n // subscription covers: `retained` rows are kept for reads only.\n const contracts = await collectContracts(contractRepository, {\n watch: [\"watched\", \"awaiting-funds\"],\n });\n let contractsProcessed = 0;\n let vtxosSaved = 0;\n\n for (const contract of contracts) {\n // Paginated fetch of spendable virtual outputs\n const pageSize = 100;\n let pageIndex = 0;\n let hasMore = true;\n const allVtxos: ExtendedVirtualCoin[] = [];\n\n while (hasMore) {\n const { vtxos, page } = await getNormalizedVtxos(indexerProvider, {\n scripts: [contract.script],\n pageIndex,\n pageSize,\n });\n\n for (const vtxo of vtxos) {\n allVtxos.push(extendVtxo(vtxo, contract));\n }\n\n hasMore = page ? vtxos.length === pageSize : false;\n pageIndex++;\n }\n\n // Skip wrong-script rows (legacy duplicates or indexer drift)\n // before persisting; the loop must keep going for the remaining\n // contracts even when one row is rejected.\n const filtered = warnAndFilterVtxosForScript(\n allVtxos,\n contract.script,\n \"contractPollProcessor\",\n );\n await saveVtxosForContract(walletRepository, contract, filtered);\n vtxosSaved += filtered.length;\n contractsProcessed++;\n }\n\n return {\n taskItemId: item.id,\n type: CONTRACT_POLL_TASK_TYPE,\n status: \"success\",\n data: { contractsProcessed, vtxosSaved },\n };\n },\n};\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkX6ZI53DZ_cjs = require('./chunk-X6ZI53DZ.cjs');
|
|
4
|
+
require('./chunk-JFJNB7ZH.cjs');
|
|
5
|
+
require('./chunk-FLPWNMX3.cjs');
|
|
6
|
+
|
|
7
|
+
// src/compiler.ts
|
|
8
|
+
var CompileError = class extends Error {
|
|
9
|
+
constructor(diagnostics) {
|
|
10
|
+
super(
|
|
11
|
+
diagnostics.filter((d) => d.severity === "error").map(
|
|
12
|
+
(d) => `${d.file}${d.start ? `:${d.start.line}:${d.start.column}` : ""}: ${d.message}`
|
|
13
|
+
).join("\n") || "compilation failed"
|
|
14
|
+
);
|
|
15
|
+
this.diagnostics = diagnostics;
|
|
16
|
+
}
|
|
17
|
+
diagnostics;
|
|
18
|
+
name = "CompileError";
|
|
19
|
+
};
|
|
20
|
+
var PEER = "@arkade-os/compiler";
|
|
21
|
+
async function compile(input, options) {
|
|
22
|
+
let compiler;
|
|
23
|
+
try {
|
|
24
|
+
compiler = await import('@arkade-os/compiler');
|
|
25
|
+
} catch (error) {
|
|
26
|
+
const code = error?.code;
|
|
27
|
+
if ((code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && String(error.message).includes(`'${PEER}'`)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`@arkade-os/sdk/compiler needs the optional peer ${PEER}: npm install --save-exact ${PEER}`,
|
|
30
|
+
{ cause: error }
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
const { debug = true, ...compilerOptions } = options ?? {};
|
|
36
|
+
const result = await compiler.compile(input, compilerOptions);
|
|
37
|
+
if (result.artifact === null) throw new CompileError(result.diagnostics);
|
|
38
|
+
const kept = debug ? result.debug : void 0;
|
|
39
|
+
return {
|
|
40
|
+
program: chunkX6ZI53DZ_cjs.programFromArtifact(result.artifact, kept),
|
|
41
|
+
artifact: result.artifact,
|
|
42
|
+
...kept ? { debug: kept } : {},
|
|
43
|
+
diagnostics: result.diagnostics
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.CompileError = CompileError;
|
|
48
|
+
exports.compile = compile;
|
|
49
|
+
//# sourceMappingURL=compiler.cjs.map
|
|
50
|
+
//# sourceMappingURL=compiler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/compiler.ts"],"names":["programFromArtifact"],"mappings":";;;;;;;AAoCO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EAEpC,YAAqB,WAAA,EAA2B;AAC5C,IAAA,KAAA;AAAA,MACI,YACK,MAAA,CAAO,CAAC,MAAM,CAAA,CAAE,QAAA,KAAa,OAAO,CAAA,CACpC,GAAA;AAAA,QACG,CAAC,MACG,CAAA,EAAG,CAAA,CAAE,IAAI,CAAA,EAAG,CAAA,CAAE,QAAQ,CAAA,CAAA,EAAI,CAAA,CAAE,MAAM,IAAI,CAAA,CAAA,EAAI,EAAE,KA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B,MAAA,CAAO,QAAA,EAAU,IAAI,CAAA;AAAA,IAClD,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,GAAI,IAAA,GAAO,EAAE,KAAA,EAAO,IAAA,KAAS,EAAC;AAAA,IAC9B,aAAa,MAAA,CAAO;AAAA,GACxB;AACJ","file":"compiler.cjs","sourcesContent":["/**\n * Compile Arkade source into an SDK {@link Program}. Needs the optional peer\n * `@arkade-os/compiler`, which is loaded on the first {@link compile} call.\n *\n * @module compiler\n */\n\nimport type {\n CompileInput,\n CompileOptions as CompilerOptions,\n CompilerArtifact,\n DebugInfo,\n Diagnostic,\n} from \"@arkade-os/compiler\";\n\nimport { programFromArtifact } from \"./arkade/artifact\";\nimport type { Program } from \"./arkade/program\";\n\nexport type { CompileInput, CompilerArtifact, DebugInfo, Diagnostic };\n\nexport interface CompileOptions extends CompilerOptions {\n /** Return the debug file and put its source maps on `program`. Defaults to `true`. */\n debug?: boolean;\n}\n\nexport interface CompileOutput {\n program: Program;\n /** The compiler's artifact, carrying the source bundle, compiler version and fingerprint. */\n artifact: CompilerArtifact;\n /** The debug file: each covenant's source map. Absent with `debug: false`. */\n debug?: DebugInfo;\n /** Warnings; errors reject with {@link CompileError}. */\n diagnostics: Diagnostic[];\n}\n\n/** The source did not compile. `diagnostics` lists every error and warning. */\nexport class CompileError extends Error {\n override readonly name = \"CompileError\";\n constructor(readonly diagnostics: Diagnostic[]) {\n super(\n diagnostics\n .filter((d) => d.severity === \"error\")\n .map(\n (d) =>\n `${d.file}${d.start ? `:${d.start.line}:${d.start.column}` : \"\"}: ${d.message}`,\n )\n .join(\"\\n\") || \"compilation failed\",\n );\n }\n}\n\nconst PEER = \"@arkade-os/compiler\";\n\n/** Compile `input.entry` and its relative imports from `input.files` into a {@link Program}. */\nexport async function compile(\n input: CompileInput,\n options?: CompileOptions,\n): Promise<CompileOutput> {\n let compiler: typeof import(\"@arkade-os/compiler\");\n try {\n compiler = await import(\"@arkade-os/compiler\");\n } catch (error) {\n // Only a missing peer gets the install hint; anything else keeps its own error.\n const code = (error as { code?: unknown } | null)?.code;\n if (\n (code === \"ERR_MODULE_NOT_FOUND\" || code === \"MODULE_NOT_FOUND\") &&\n String((error as Error).message).includes(`'${PEER}'`)\n ) {\n throw new Error(\n `@arkade-os/sdk/compiler needs the optional peer ${PEER}: npm install --save-exact ${PEER}`,\n { cause: error },\n );\n }\n throw error;\n }\n const { debug = true, ...compilerOptions } = options ?? {};\n const result = await compiler.compile(input, compilerOptions);\n if (result.artifact === null) throw new CompileError(result.diagnostics);\n // ponytail: the compiler always builds the debug file; it will take an option to skip it soon,\n // until then `debug: false` only drops it.\n const kept = debug ? result.debug : undefined;\n return {\n program: programFromArtifact(result.artifact, kept),\n artifact: result.artifact,\n ...(kept ? { debug: kept } : {}),\n diagnostics: result.diagnostics,\n };\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Diagnostic, CompileOptions as CompileOptions$1, CompilerArtifact, DebugInfo, CompileInput } from '@arkade-os/compiler';
|
|
2
|
+
export { CompileInput, CompilerArtifact, DebugInfo, Diagnostic } from '@arkade-os/compiler';
|
|
3
|
+
import { P as Program } from './program-znrWkxE4.cjs';
|
|
4
|
+
import './base-C-Y5t_0F.cjs';
|
|
5
|
+
import '@scure/btc-signer';
|
|
6
|
+
import '@scure/btc-signer/psbt.js';
|
|
7
|
+
import '@scure/btc-signer/utils.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Compile Arkade source into an SDK {@link Program}. Needs the optional peer
|
|
11
|
+
* `@arkade-os/compiler`, which is loaded on the first {@link compile} call.
|
|
12
|
+
*
|
|
13
|
+
* @module compiler
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface CompileOptions extends CompileOptions$1 {
|
|
17
|
+
/** Return the debug file and put its source maps on `program`. Defaults to `true`. */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface CompileOutput {
|
|
21
|
+
program: Program;
|
|
22
|
+
/** The compiler's artifact, carrying the source bundle, compiler version and fingerprint. */
|
|
23
|
+
artifact: CompilerArtifact;
|
|
24
|
+
/** The debug file: each covenant's source map. Absent with `debug: false`. */
|
|
25
|
+
debug?: DebugInfo;
|
|
26
|
+
/** Warnings; errors reject with {@link CompileError}. */
|
|
27
|
+
diagnostics: Diagnostic[];
|
|
28
|
+
}
|
|
29
|
+
/** The source did not compile. `diagnostics` lists every error and warning. */
|
|
30
|
+
declare class CompileError extends Error {
|
|
31
|
+
readonly diagnostics: Diagnostic[];
|
|
32
|
+
readonly name = "CompileError";
|
|
33
|
+
constructor(diagnostics: Diagnostic[]);
|
|
34
|
+
}
|
|
35
|
+
/** Compile `input.entry` and its relative imports from `input.files` into a {@link Program}. */
|
|
36
|
+
declare function compile(input: CompileInput, options?: CompileOptions): Promise<CompileOutput>;
|
|
37
|
+
|
|
38
|
+
export { CompileError, type CompileOptions, type CompileOutput, compile };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Diagnostic, CompileOptions as CompileOptions$1, CompilerArtifact, DebugInfo, CompileInput } from '@arkade-os/compiler';
|
|
2
|
+
export { CompileInput, CompilerArtifact, DebugInfo, Diagnostic } from '@arkade-os/compiler';
|
|
3
|
+
import { P as Program } from './program-BARSNg3X.js';
|
|
4
|
+
import './base-C-Y5t_0F.js';
|
|
5
|
+
import '@scure/btc-signer';
|
|
6
|
+
import '@scure/btc-signer/psbt.js';
|
|
7
|
+
import '@scure/btc-signer/utils.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Compile Arkade source into an SDK {@link Program}. Needs the optional peer
|
|
11
|
+
* `@arkade-os/compiler`, which is loaded on the first {@link compile} call.
|
|
12
|
+
*
|
|
13
|
+
* @module compiler
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface CompileOptions extends CompileOptions$1 {
|
|
17
|
+
/** Return the debug file and put its source maps on `program`. Defaults to `true`. */
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface CompileOutput {
|
|
21
|
+
program: Program;
|
|
22
|
+
/** The compiler's artifact, carrying the source bundle, compiler version and fingerprint. */
|
|
23
|
+
artifact: CompilerArtifact;
|
|
24
|
+
/** The debug file: each covenant's source map. Absent with `debug: false`. */
|
|
25
|
+
debug?: DebugInfo;
|
|
26
|
+
/** Warnings; errors reject with {@link CompileError}. */
|
|
27
|
+
diagnostics: Diagnostic[];
|
|
28
|
+
}
|
|
29
|
+
/** The source did not compile. `diagnostics` lists every error and warning. */
|
|
30
|
+
declare class CompileError extends Error {
|
|
31
|
+
readonly diagnostics: Diagnostic[];
|
|
32
|
+
readonly name = "CompileError";
|
|
33
|
+
constructor(diagnostics: Diagnostic[]);
|
|
34
|
+
}
|
|
35
|
+
/** Compile `input.entry` and its relative imports from `input.files` into a {@link Program}. */
|
|
36
|
+
declare function compile(input: CompileInput, options?: CompileOptions): Promise<CompileOutput>;
|
|
37
|
+
|
|
38
|
+
export { CompileError, type CompileOptions, type CompileOutput, compile };
|
package/dist/compiler.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { programFromArtifact } from './chunk-V3ZLL5VY.js';
|
|
2
|
+
import './chunk-DNFTHG73.js';
|
|
3
|
+
import './chunk-FDJ734CH.js';
|
|
4
|
+
|
|
5
|
+
// src/compiler.ts
|
|
6
|
+
var CompileError = class extends Error {
|
|
7
|
+
constructor(diagnostics) {
|
|
8
|
+
super(
|
|
9
|
+
diagnostics.filter((d) => d.severity === "error").map(
|
|
10
|
+
(d) => `${d.file}${d.start ? `:${d.start.line}:${d.start.column}` : ""}: ${d.message}`
|
|
11
|
+
).join("\n") || "compilation failed"
|
|
12
|
+
);
|
|
13
|
+
this.diagnostics = diagnostics;
|
|
14
|
+
}
|
|
15
|
+
diagnostics;
|
|
16
|
+
name = "CompileError";
|
|
17
|
+
};
|
|
18
|
+
var PEER = "@arkade-os/compiler";
|
|
19
|
+
async function compile(input, options) {
|
|
20
|
+
let compiler;
|
|
21
|
+
try {
|
|
22
|
+
compiler = await import('@arkade-os/compiler');
|
|
23
|
+
} catch (error) {
|
|
24
|
+
const code = error?.code;
|
|
25
|
+
if ((code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && String(error.message).includes(`'${PEER}'`)) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`@arkade-os/sdk/compiler needs the optional peer ${PEER}: npm install --save-exact ${PEER}`,
|
|
28
|
+
{ cause: error }
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
const { debug = true, ...compilerOptions } = options ?? {};
|
|
34
|
+
const result = await compiler.compile(input, compilerOptions);
|
|
35
|
+
if (result.artifact === null) throw new CompileError(result.diagnostics);
|
|
36
|
+
const kept = debug ? result.debug : void 0;
|
|
37
|
+
return {
|
|
38
|
+
program: programFromArtifact(result.artifact, kept),
|
|
39
|
+
artifact: result.artifact,
|
|
40
|
+
...kept ? { debug: kept } : {},
|
|
41
|
+
diagnostics: result.diagnostics
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { CompileError, compile };
|
|
46
|
+
//# sourceMappingURL=compiler.js.map
|
|
47
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/compiler.ts"],"names":[],"mappings":";;;;;AAoCO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EAEpC,YAAqB,WAAA,EAA2B;AAC5C,IAAA,KAAA;AAAA,MACI,YACK,MAAA,CAAO,CAAC,MAAM,CAAA,CAAE,QAAA,KAAa,OAAO,CAAA,CACpC,GAAA;AAAA,QACG,CAAC,MACG,CAAA,EAAG,CAAA,CAAE,IAAI,CAAA,EAAG,CAAA,CAAE,QAAQ,CAAA,CAAA,EAAI,CAAA,CAAE,MAAM,IAAI,CAAA,CAAA,EAAI,EAAE,KAAA,CAAM,MAAM,KAAK,EAAE,CAAA,E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AA;AAAA,IAClD,UAAU,MAAA,CAAO,QAAA;AAAA,IACjB,GAAI,IAAA,GAAO,EAAE,KAAA,EAAO,IAAA,KAAS,EAAC;AAAA,IAC9B,aAAa,MAAA,CAAO;AAAA,GACxB;AACJ","file":"compiler.js","sourcesContent":["/**\n * Compile Arkade source into an SDK {@link Program}. Needs the optional peer\n * `@arkade-os/compiler`, which is loaded on the first {@link compile} call.\n *\n * @module compiler\n */\n\nimport type {\n CompileInput,\n CompileOptions as CompilerOptions,\n CompilerArtifact,\n DebugInfo,\n Diagnostic,\n} from \"@arkade-os/compiler\";\n\nimport { programFromArtifact } from \"./arkade/artifact\";\nimport type { Program } from \"./arkade/program\";\n\nexport type { CompileInput, CompilerArtifact, DebugInfo, Diagnostic };\n\nexport interface CompileOptions extends CompilerOptions {\n /** Return the debug file and put its source maps on `program`. Defaults to `true`. */\n debug?: boolean;\n}\n\nexport interface CompileOutput {\n program: Program;\n /** The compiler's artifact, carrying the source bundle, compiler version and fingerprint. */\n artifact: CompilerArtifact;\n /** The debug file: each covenant's source map. Absent with `debug: false`. */\n debug?: DebugInfo;\n /** Warnings; errors reject with {@link CompileError}. */\n diagnostics: Diagnostic[];\n}\n\n/** The source did not compile. `diagnostics` lists every error and warning. */\nexport class CompileError extends Error {\n override readonly name = \"CompileError\";\n constructor(readonly diagnostics: Diagnostic[]) {\n super(\n diagnostics\n .filter((d) => d.severity === \"error\")\n .map(\n (d) =>\n `${d.file}${d.start ? `:${d.start.line}:${d.start.column}` : \"\"}: ${d.message}`,\n )\n .join(\"\\n\") || \"compilation failed\",\n );\n }\n}\n\nconst PEER = \"@arkade-os/compiler\";\n\n/** Compile `input.entry` and its relative imports from `input.files` into a {@link Program}. */\nexport async function compile(\n input: CompileInput,\n options?: CompileOptions,\n): Promise<CompileOutput> {\n let compiler: typeof import(\"@arkade-os/compiler\");\n try {\n compiler = await import(\"@arkade-os/compiler\");\n } catch (error) {\n // Only a missing peer gets the install hint; anything else keeps its own error.\n const code = (error as { code?: unknown } | null)?.code;\n if (\n (code === \"ERR_MODULE_NOT_FOUND\" || code === \"MODULE_NOT_FOUND\") &&\n String((error as Error).message).includes(`'${PEER}'`)\n ) {\n throw new Error(\n `@arkade-os/sdk/compiler needs the optional peer ${PEER}: npm install --save-exact ${PEER}`,\n { cause: error },\n );\n }\n throw error;\n }\n const { debug = true, ...compilerOptions } = options ?? {};\n const result = await compiler.compile(input, compilerOptions);\n if (result.artifact === null) throw new CompileError(result.diagnostics);\n // ponytail: the compiler always builds the debug file; it will take an option to skip it soon,\n // until then `debug: false` only drops it.\n const kept = debug ? result.debug : undefined;\n return {\n program: programFromArtifact(result.artifact, kept),\n artifact: result.artifact,\n ...(kept ? { debug: kept } : {}),\n diagnostics: result.diagnostics,\n };\n}\n"]}
|
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
var chunkNDQ4LB4X_cjs = require('../../chunk-NDQ4LB4X.cjs');
|
|
4
|
+
require('../../chunk-JFJNB7ZH.cjs');
|
|
5
|
+
require('../../chunk-LZAINCGU.cjs');
|
|
6
|
+
require('../../chunk-FLPWNMX3.cjs');
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
Object.defineProperty(exports, "ArkadeContractHandler", {
|
|
9
11
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
12
|
+
get: function () { return chunkNDQ4LB4X_cjs.ArkadeContractHandler; }
|
|
11
13
|
});
|
|
12
14
|
Object.defineProperty(exports, "BoardingContractHandler", {
|
|
13
15
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
16
|
+
get: function () { return chunkNDQ4LB4X_cjs.BoardingContractHandler; }
|
|
15
17
|
});
|
|
16
18
|
Object.defineProperty(exports, "DefaultContractHandler", {
|
|
17
19
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
20
|
+
get: function () { return chunkNDQ4LB4X_cjs.DefaultContractHandler; }
|
|
19
21
|
});
|
|
20
22
|
Object.defineProperty(exports, "DelegateContractHandler", {
|
|
21
23
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
24
|
+
get: function () { return chunkNDQ4LB4X_cjs.DelegateContractHandler; }
|
|
23
25
|
});
|
|
24
26
|
Object.defineProperty(exports, "VHTLCContractHandler", {
|
|
25
27
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
28
|
+
get: function () { return chunkNDQ4LB4X_cjs.VHTLCContractHandler; }
|
|
27
29
|
});
|
|
28
30
|
Object.defineProperty(exports, "VHTLCV2ContractHandler", {
|
|
29
31
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
32
|
+
get: function () { return chunkNDQ4LB4X_cjs.VHTLCV2ContractHandler; }
|
|
31
33
|
});
|
|
32
34
|
Object.defineProperty(exports, "contractHandlers", {
|
|
33
35
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
36
|
+
get: function () { return chunkNDQ4LB4X_cjs.contractHandlers; }
|
|
35
37
|
});
|
|
36
38
|
//# sourceMappingURL=index.cjs.map
|
|
37
39
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import '../../index-
|
|
1
|
+
export { A as ArkadeContractHandler, B as BoardingContractHandler, a as BoardingContractParams, D as DefaultContractHandler, b as DefaultContractParams, c as DelegateContractHandler, d as DelegateContractParams, e as VHTLCContractHandler, f as VHTLCContractParams, g as VHTLCV2ContractHandler, h as VHTLCV2ContractParams, i as contractHandlers } from '../../index-46g577Ka.cjs';
|
|
2
|
+
import '../../index-Dqk07NwJ.cjs';
|
|
3
3
|
import '@scure/btc-signer/utils.js';
|
|
4
|
-
import '@scure/btc-signer/psbt.js';
|
|
5
4
|
import '@scure/btc-signer';
|
|
5
|
+
import '@scure/btc-signer/psbt.js';
|
|
6
|
+
import '../../base-C-Y5t_0F.cjs';
|
|
6
7
|
import '@scure/btc-signer/transaction.js';
|
|
7
|
-
import '../../delegate-
|
|
8
|
+
import '../../delegate-gGkUnYpi.cjs';
|
|
9
|
+
import '../../program-znrWkxE4.cjs';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import '../../index-
|
|
1
|
+
export { A as ArkadeContractHandler, B as BoardingContractHandler, a as BoardingContractParams, D as DefaultContractHandler, b as DefaultContractParams, c as DelegateContractHandler, d as DelegateContractParams, e as VHTLCContractHandler, f as VHTLCContractParams, g as VHTLCV2ContractHandler, h as VHTLCV2ContractParams, i as contractHandlers } from '../../index-2wKMrT0a.js';
|
|
2
|
+
import '../../index-C66rjxz2.js';
|
|
3
3
|
import '@scure/btc-signer/utils.js';
|
|
4
|
-
import '@scure/btc-signer/psbt.js';
|
|
5
4
|
import '@scure/btc-signer';
|
|
5
|
+
import '@scure/btc-signer/psbt.js';
|
|
6
|
+
import '../../base-C-Y5t_0F.js';
|
|
6
7
|
import '@scure/btc-signer/transaction.js';
|
|
7
|
-
import '../../delegate-
|
|
8
|
+
import '../../delegate-iyDum4fw.js';
|
|
9
|
+
import '../../program-BARSNg3X.js';
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export { ArkadeContractHandler, BoardingContractHandler, DefaultContractHandler, DelegateContractHandler, VHTLCContractHandler, VHTLCV2ContractHandler, contractHandlers } from '../../chunk-
|
|
2
|
-
import '../../chunk-
|
|
1
|
+
export { ArkadeContractHandler, BoardingContractHandler, DefaultContractHandler, DelegateContractHandler, VHTLCContractHandler, VHTLCV2ContractHandler, contractHandlers } from '../../chunk-47Z4LEIW.js';
|
|
2
|
+
import '../../chunk-DNFTHG73.js';
|
|
3
|
+
import '../../chunk-QTMK34TP.js';
|
|
4
|
+
import '../../chunk-FDJ734CH.js';
|
|
3
5
|
//# sourceMappingURL=index.js.map
|
|
4
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Bytes } from '@scure/btc-signer/utils.js';
|
|
2
|
-
import {
|
|
2
|
+
import { R as RelativeTimelock, V as VtxoScript, T as TapLeafScript } from './base-C-Y5t_0F.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* DefaultVtxo is the default implementation of a VtxoScript.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Bytes } from '@scure/btc-signer/utils.js';
|
|
2
|
-
import {
|
|
2
|
+
import { R as RelativeTimelock, V as VtxoScript, T as TapLeafScript } from './base-C-Y5t_0F.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* DefaultVtxo is the default implementation of a VtxoScript.
|