@odatano/core 2.0.0-rc.4 → 2.0.0-rc.41

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 (166) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +251 -0
  2. package/@cds-models/CardanoAgentService/index.js +36 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +357 -0
  4. package/@cds-models/CardanoBackendService/index.js +40 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
  6. package/@cds-models/CardanoIndexerService/index.js +25 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +305 -7
  8. package/@cds-models/CardanoODataService/index.js +34 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +28 -3
  10. package/@cds-models/CardanoSignService/index.js +3 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +46 -13
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/index.d.ts +72 -0
  14. package/@cds-models/index.js +12 -0
  15. package/@cds-models/odatano/cardano/index.d.ts +408 -7
  16. package/@cds-models/odatano/cardano/index.js +42 -0
  17. package/README.md +64 -5
  18. package/db/schema.cds +2297 -1633
  19. package/db/types.cds +114 -0
  20. package/package.json +27 -6
  21. package/scripts/migrate-slot-leader.mjs +104 -0
  22. package/scripts/migrate-txseq.mjs +147 -0
  23. package/src/index.d.ts +18 -11
  24. package/src/index.js +44 -14
  25. package/src/plugin.js +42 -52
  26. package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
  27. package/srv/blockchain/backends/blockfrost-backend.js +53 -162
  28. package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
  29. package/srv/blockchain/backends/cardano-backend.js +19 -5
  30. package/srv/blockchain/backends/koios-backend.d.ts +126 -60
  31. package/srv/blockchain/backends/koios-backend.js +376 -235
  32. package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
  33. package/srv/blockchain/backends/odatano-backend.js +170 -0
  34. package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
  35. package/srv/blockchain/backends/ogmios-backend.js +556 -201
  36. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
  37. package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
  38. package/srv/blockchain/cardano-client.d.ts +87 -202
  39. package/srv/blockchain/cardano-client.js +210 -240
  40. package/srv/blockchain/cardano-indexer.d.ts +311 -242
  41. package/srv/blockchain/cardano-indexer.js +1238 -362
  42. package/srv/blockchain/cardano-tx-builder.d.ts +44 -81
  43. package/srv/blockchain/cardano-tx-builder.js +173 -132
  44. package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
  45. package/srv/blockchain/crawler/certificate-backfill.js +169 -0
  46. package/srv/blockchain/crawler/crawler.d.ts +139 -54
  47. package/srv/blockchain/crawler/crawler.js +478 -96
  48. package/srv/blockchain/crawler/hooks.d.ts +3 -14
  49. package/srv/blockchain/crawler/index.d.ts +5 -0
  50. package/srv/blockchain/crawler/index.js +35 -7
  51. package/srv/blockchain/crawler/sync-state.d.ts +46 -28
  52. package/srv/blockchain/crawler/sync-state.js +128 -43
  53. package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
  54. package/srv/blockchain/crawler/transaction-backfill.js +283 -0
  55. package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
  56. package/srv/blockchain/crawler/utxo-set-import.js +363 -0
  57. package/srv/blockchain/ledger-state.d.ts +101 -0
  58. package/srv/blockchain/ledger-state.js +432 -0
  59. package/srv/blockchain/pending-spends.d.ts +28 -0
  60. package/srv/blockchain/pending-spends.js +89 -0
  61. package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
  62. package/srv/blockchain/signing/cose-verifier.js +6 -12
  63. package/srv/blockchain/signing/external-signer.d.ts +16 -113
  64. package/srv/blockchain/signing/external-signer.js +19 -122
  65. package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
  66. package/srv/blockchain/signing/hsm-signer.js +23 -63
  67. package/srv/blockchain/signing/signature-verifier.d.ts +14 -45
  68. package/srv/blockchain/signing/signature-verifier.js +73 -76
  69. package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
  70. package/srv/blockchain/signing/submission-finalizer.js +16 -49
  71. package/srv/blockchain/stored-chain.d.ts +33 -0
  72. package/srv/blockchain/stored-chain.js +234 -0
  73. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +111 -173
  74. package/srv/blockchain/transaction-building/buildooor-tx.js +649 -326
  75. package/srv/blockchain/transaction-building/caller-datums.d.ts +29 -0
  76. package/srv/blockchain/transaction-building/caller-datums.js +139 -0
  77. package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
  78. package/srv/blockchain/transaction-rows.d.ts +12 -0
  79. package/srv/blockchain/transaction-rows.js +43 -0
  80. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
  81. package/srv/blockchain/wallet-worker/build-request.js +18 -23
  82. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
  83. package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
  84. package/srv/blockchain/wallet-worker/index.js +2 -8
  85. package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
  86. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  87. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
  88. package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
  89. package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
  90. package/srv/blockchain/wallet-worker/signers.js +3 -8
  91. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
  92. package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
  93. package/srv/cardano-agent-service.cds +146 -0
  94. package/srv/cardano-agent-service.d.ts +2 -0
  95. package/srv/cardano-agent-service.js +12 -0
  96. package/srv/cardano-backend-service.cds +52 -0
  97. package/srv/cardano-backend-service.d.ts +2 -0
  98. package/srv/cardano-backend-service.js +244 -0
  99. package/srv/cardano-indexer-service.cds +201 -73
  100. package/srv/cardano-indexer-service.js +280 -11
  101. package/srv/cardano-service.cds +65 -2
  102. package/srv/cardano-service.js +170 -129
  103. package/srv/cardano-sign-service.cds +200 -180
  104. package/srv/cardano-sign-service.js +57 -184
  105. package/srv/cardano-tx-service.cds +439 -370
  106. package/srv/cardano-tx-service.js +231 -190
  107. package/srv/cardano-ui.cds +16 -16
  108. package/srv/cardano-worker-service.js +7 -15
  109. package/srv/cbor/index.d.ts +1 -1
  110. package/srv/cbor/parse.d.ts +27 -0
  111. package/srv/cbor/parse.js +63 -2
  112. package/srv/server.d.ts +28 -86
  113. package/srv/server.js +132 -135
  114. package/srv/utils/agent-grants-config.d.ts +37 -0
  115. package/srv/utils/agent-grants-config.js +138 -0
  116. package/srv/utils/agent-grants.d.ts +262 -0
  117. package/srv/utils/agent-grants.js +922 -0
  118. package/srv/utils/agent-token-auth.d.ts +16 -0
  119. package/srv/utils/agent-token-auth.js +78 -0
  120. package/srv/utils/backend-request-handler.d.ts +2 -16
  121. package/srv/utils/backend-request-handler.js +3 -18
  122. package/srv/utils/collections.d.ts +4 -8
  123. package/srv/utils/collections.js +4 -8
  124. package/srv/utils/const.d.ts +30 -67
  125. package/srv/utils/const.js +32 -72
  126. package/srv/utils/crypto.d.ts +3 -12
  127. package/srv/utils/crypto.js +5 -18
  128. package/srv/utils/db-indexes.d.ts +25 -0
  129. package/srv/utils/db-indexes.js +94 -0
  130. package/srv/utils/db-sanitize.d.ts +27 -0
  131. package/srv/utils/db-sanitize.js +85 -0
  132. package/srv/utils/epoch-slots.d.ts +20 -0
  133. package/srv/utils/epoch-slots.js +43 -0
  134. package/srv/utils/error-codes.d.ts +20 -73
  135. package/srv/utils/error-codes.js +19 -70
  136. package/srv/utils/errors.d.ts +50 -177
  137. package/srv/utils/errors.js +94 -218
  138. package/srv/utils/legacy-service-paths.d.ts +11 -0
  139. package/srv/utils/legacy-service-paths.js +58 -0
  140. package/srv/utils/liveness.d.ts +16 -0
  141. package/srv/utils/liveness.js +40 -0
  142. package/srv/utils/mappers.d.ts +128 -214
  143. package/srv/utils/mappers.js +354 -299
  144. package/srv/utils/network-context.js +2 -11
  145. package/srv/utils/pg-inline-json.d.ts +8 -0
  146. package/srv/utils/pg-inline-json.js +62 -0
  147. package/srv/utils/pg-order-nulls.d.ts +14 -0
  148. package/srv/utils/pg-order-nulls.js +56 -0
  149. package/srv/utils/plutus-placeholders.d.ts +23 -16
  150. package/srv/utils/plutus-placeholders.js +63 -27
  151. package/srv/utils/rate-limiter.d.ts +46 -0
  152. package/srv/utils/rate-limiter.js +116 -0
  153. package/srv/utils/service-events.d.ts +2 -22
  154. package/srv/utils/service-events.js +3 -23
  155. package/srv/utils/signing-helper.d.ts +6 -16
  156. package/srv/utils/signing-helper.js +36 -60
  157. package/srv/utils/tx-build-helper.d.ts +28 -93
  158. package/srv/utils/tx-build-helper.js +75 -124
  159. package/srv/utils/tx-request-parsers.d.ts +101 -28
  160. package/srv/utils/tx-request-parsers.js +410 -43
  161. package/srv/utils/tx-utils.d.ts +4 -23
  162. package/srv/utils/tx-utils.js +12 -41
  163. package/srv/utils/types.d.ts +252 -179
  164. package/srv/utils/types.js +2 -6
  165. package/srv/utils/validators.d.ts +24 -90
  166. package/srv/utils/validators.js +50 -147
package/db/types.cds CHANGED
@@ -16,6 +16,8 @@ type HexBytes : String(5000);
16
16
  @title : 'Lovelace'
17
17
  @description: 'Amount of ADA in lovelace (1 ADA = 1_000_000 lovelace)'
18
18
  type Lovelace : Decimal(20, 0);
19
+ // Sum of asset quantities: one output holds at most 2^64-1, a sum over an address's outputs does not
20
+ type AssetAmount : Decimal(38, 0);
19
21
 
20
22
  @title : 'Asset Unit'
21
23
  @description: 'Concatenation of policyId and assetNameHex representing a unique asset'
@@ -57,6 +59,31 @@ type AssetSlice {
57
59
  fingerprint : String(44);
58
60
  }
59
61
 
62
+ @title : 'Asset Sum Slice'
63
+ @description: 'Asset details with the quantity summed over several outputs (per address)'
64
+ type AssetSumSlice {
65
+
66
+ @title : 'Asset Quantity'
67
+ @description: 'Quantity of the Asset summed over the outputs of the address'
68
+ quantity : AssetAmount;
69
+
70
+ @title : 'Asset Policy Id'
71
+ @description: 'Policy Id of the Asset'
72
+ policyId : Blake2b224;
73
+
74
+ @title : 'Asset Name Hex'
75
+ @description: 'Asset Name as Hex String'
76
+ assetNameHex : HexBytes;
77
+
78
+ @title : 'Asset Name'
79
+ @description: 'Asset Name as UTF-8 String'
80
+ assetName : String(128);
81
+
82
+ @title : 'Asset Fingerprint'
83
+ @description: 'CIP-14 Asset Fingerprint'
84
+ fingerprint : String(44);
85
+ }
86
+
60
87
  @title : 'Metadata Slice'
61
88
  @description: 'Structural slice for metadata details'
62
89
  type MetadataSlice {
@@ -159,6 +186,29 @@ type WorkerSignerType : String(10) enum {
159
186
  software = 'software'; // operator-configured Ed25519 key (dev/test)
160
187
  }
161
188
 
189
+ // -----------------------------------------------------
190
+ // Transaction confirmations (GetTransactionConfirmations action result)
191
+ // -----------------------------------------------------
192
+ @title : 'Transaction Confirmations'
193
+ @description: 'Depth of a transaction in the chain. Depth 1 means it sits in the tip block.'
194
+ type TransactionConfirmations {
195
+ @title : 'Transaction Hash'
196
+ @description: 'The transaction asked for'
197
+ txHash : Blake2b256;
198
+
199
+ @title : 'Block Height'
200
+ @description: 'Height of the block holding the transaction; null while it is not on chain'
201
+ blockHeight : Integer64;
202
+
203
+ @title : 'Tip Height'
204
+ @description: 'Height of the chain tip used for the count; null while the transaction is not on chain'
205
+ tipHeight : Integer64;
206
+
207
+ @title : 'Confirmations'
208
+ @description: 'Tip height minus block height plus one; 0 while the transaction is not on chain'
209
+ confirmations : Integer;
210
+ }
211
+
162
212
  // -----------------------------------------------------
163
213
  // Parsed Transaction (ParseTransactionCbor action result)
164
214
  // -----------------------------------------------------
@@ -212,6 +262,34 @@ type ParsedOutput {
212
262
  @title : 'Reference Script CBOR'
213
263
  @description: 'Hex-encoded CIP-33 reference script CBOR when present; null otherwise'
214
264
  referenceScriptHex : LargeString;
265
+
266
+ @title : 'Output CBOR Size'
267
+ @description: 'Byte length of the output as it stands in the transaction (input for the min-UTxO check)'
268
+ cborSize : Integer;
269
+ }
270
+
271
+ @title : 'Parsed Withdrawal'
272
+ @description: 'A reward withdrawal of a parsed transaction'
273
+ type ParsedWithdrawal {
274
+ @title : 'Reward Address'
275
+ @description: 'Bech32 reward address the lovelace is withdrawn from'
276
+ rewardAddress : Bech32;
277
+
278
+ @title : 'Withdrawn Lovelace'
279
+ @description: 'Withdrawn amount in lovelace (decimal string)'
280
+ lovelace : Lovelace;
281
+ }
282
+
283
+ @title : 'Parsed Certificate'
284
+ @description: 'A certificate of a parsed transaction'
285
+ type ParsedCertificate {
286
+ @title : 'Certificate Index'
287
+ @description: 'Position in the body certificate list'
288
+ index : Integer;
289
+
290
+ @title : 'Certificate Type'
291
+ @description: 'Ledger certificate name, e.g. StakeDelegation or RegistrationDrep'
292
+ type : String(40);
215
293
  }
216
294
 
217
295
  @title : 'Parsed Witness Counts'
@@ -249,6 +327,10 @@ type ParsedTransaction {
249
327
  @description: '"mainnet" or "testnet" from the tx body network ID byte; null if absent. preview vs preprod cannot be distinguished from CBOR alone.'
250
328
  network : String(10);
251
329
 
330
+ @title : 'Network ID'
331
+ @description: 'Body field 15: 1 = mainnet, 0 = testnet; null if absent'
332
+ networkId : Integer;
333
+
252
334
  @title : 'Inputs'
253
335
  @description: 'UTxOs consumed by the transaction'
254
336
  inputs : many ParsedInput;
@@ -281,6 +363,34 @@ type ParsedTransaction {
281
363
  @description: 'Collateral UTxOs for phase-2 validation (empty when no Plutus scripts run)'
282
364
  collateral : many ParsedInput;
283
365
 
366
+ @title : 'Reference Inputs'
367
+ @description: 'UTxOs the transaction reads without spending them'
368
+ referenceInputs : many ParsedInput;
369
+
370
+ @title : 'Withdrawals'
371
+ @description: 'Reward withdrawals; empty array if none'
372
+ withdrawals : many ParsedWithdrawal;
373
+
374
+ @title : 'Certificates'
375
+ @description: 'Certificates in body order; empty array if none'
376
+ certificates : many ParsedCertificate;
377
+
378
+ @title : 'Vote Count'
379
+ @description: 'Number of votes over all voters; 0 if the body has no voting procedures'
380
+ votingProcedures : Integer;
381
+
382
+ @title : 'Proposal Count'
383
+ @description: 'Number of governance proposals'
384
+ proposalProcedures : Integer;
385
+
386
+ @title : 'Treasury Donation'
387
+ @description: 'Lovelace donated to the treasury; null if absent'
388
+ treasuryDonation : Lovelace;
389
+
390
+ @title : 'Current Treasury Value'
391
+ @description: 'Treasury value the transaction asserts; null if absent'
392
+ currentTreasuryValue : Lovelace;
393
+
284
394
  @title : 'Required Signers'
285
395
  @description: '28-byte Ed25519 key hashes listed in the tx body required_signers field'
286
396
  requiredSigners : many Blake2b224;
@@ -289,6 +399,10 @@ type ParsedTransaction {
289
399
  @description: 'Blake2b-256 hash over datum/redeemer/costmodels section; null if no Plutus data is present'
290
400
  scriptDataHash : Blake2b256;
291
401
 
402
+ @title : 'Validity Flag'
403
+ @description: 'false when the transaction is flagged as failing its scripts; on chain it then spends only the collateral and creates no outputs'
404
+ isValid : Boolean;
405
+
292
406
  @title : 'Witness Counts'
293
407
  @description: 'Shape summary of the witness set (no secret material exposed)'
294
408
  witnesses : ParsedWitnesses;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatano/core",
3
- "version": "2.0.0-rc.4",
3
+ "version": "2.0.0-rc.41",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
@@ -15,7 +15,9 @@
15
15
  "srv/**/*.d.ts",
16
16
  "srv/**/*.cds",
17
17
  "db/**/*.cds",
18
- "@cds-models/"
18
+ "@cds-models/",
19
+ "scripts/migrate-txseq.mjs",
20
+ "scripts/migrate-slot-leader.mjs"
19
21
  ],
20
22
  "engines": {
21
23
  "node": ">=22.5"
@@ -24,15 +26,16 @@
24
26
  "@sap/cds": ">=10"
25
27
  },
26
28
  "dependencies": {
27
- "@blockfrost/blockfrost-js": "~6.0.0",
29
+ "@blockfrost/blockfrost-js": "~6.2.0",
28
30
  "@cap-js/hana": "^3",
29
- "@cardano-ogmios/client": "^6.14.0",
31
+ "@cardano-ogmios/client": "^7.0.0",
30
32
  "@harmoniclabs/buildooor": "0.2.9",
31
33
  "@harmoniclabs/cardano-costmodels-ts": "~1.6.1",
32
34
  "@harmoniclabs/cardano-ledger-ts": "^0.5.6",
33
35
  "@harmoniclabs/cbor": "^2.0.1",
34
36
  "@harmoniclabs/crypto": "^0.3.0",
35
37
  "@harmoniclabs/uint8array-utils": "^1.0.4",
38
+ "@odatano/cap-auth": "^0.1.0",
36
39
  "@sap/xssec": "^4",
37
40
  "axios": "^1.18.0",
38
41
  "bech32": "^2.0.0",
@@ -45,7 +48,7 @@
45
48
  "axios": "^1.18.0",
46
49
  "esbuild": "0.28.1",
47
50
  "form-data": "^4.0.6",
48
- "fast-uri": "^3.1.5",
51
+ "fast-uri": "^3.1.7",
49
52
  "ws": "7.5.11",
50
53
  "@sap/approuter": {
51
54
  "body-parser": "^2.2.3"
@@ -55,6 +58,7 @@
55
58
  "@cap-js/cds-test": "^0.4.1",
56
59
  "@cap-js/cds-typer": "^0.40.0",
57
60
  "@cap-js/cds-types": "^0.18.0",
61
+ "@cap-js/postgres": "^3.1.1",
58
62
  "@cap-js/sqlite": "^3",
59
63
  "@sap/cds": "^10",
60
64
  "@sap/cds-dk": "^10",
@@ -73,6 +77,18 @@
73
77
  "vitest": "^4.1.10"
74
78
  },
75
79
  "cds": {
80
+ "log": {
81
+ "mask_headers": [
82
+ "/authorization/i",
83
+ "/cookie/i",
84
+ "/cert/i",
85
+ "/ssl/i",
86
+ "/token/i",
87
+ "/key/i",
88
+ "/secret/i",
89
+ "/project_id/i"
90
+ ]
91
+ },
76
92
  "typer": {
77
93
  "ieee754compatible": true
78
94
  },
@@ -95,6 +111,9 @@
95
111
  "kind": "sqlite",
96
112
  "credentials": {
97
113
  "url": "db.sqlite"
114
+ },
115
+ "client": {
116
+ "timeout": 5000
98
117
  }
99
118
  },
100
119
  "[production]": {
@@ -141,7 +160,9 @@
141
160
  "pretest:unit": "npm run cds:types",
142
161
  "test:unit": "vitest run --project unit",
143
162
  "watch-odatano": "cds watch --open odatano/index.html?sap-ui-xx-viewCache=false --livereload false",
144
- "watch-wallet": "cds watch --open wallet/webapp/index.html"
163
+ "watch-wallet": "cds watch --open wallet/webapp/index.html",
164
+ "release:check": "node scripts/release-check.mjs",
165
+ "prepublishOnly": "node scripts/publish-guard.mjs"
145
166
  },
146
167
  "sapux": [
147
168
  "app/odatano"
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ // Rewrite Blocks.slotLeader values written before it became the bech32 pool id: an Ogmios
3
+ // issuer key (64 hex chars) becomes bech32('pool', blake2b-224(key)); a Koios VRF key
4
+ // (vrf_vk1…) is matched on blake2b-256 against the pools' registered VRF key hashes, taken
5
+ // from an Ogmios `queryLedgerState/stakePools` response. Prints SQL; the database is not touched.
6
+ //
7
+ // psql -Atc "SELECT DISTINCT slotLeader FROM odatano_cardano_Blocks WHERE slotLeader NOT LIKE 'pool1%'" \
8
+ // | node scripts/migrate-slot-leader.mjs [--stake-pools stake-pools.json] [--extra-map extra.txt] > slot-leader.sql
9
+ //
10
+ // The SQL fills a mapping table and runs one UPDATE (PostgreSQL and SQLite). Values that cannot
11
+ // be mapped (a VRF key of a pool no longer registered, unknown formats) are listed on stderr
12
+ // and left unchanged; `--extra-map` supplies them as "<old value> <pool id>" lines.
13
+ import fs from 'node:fs';
14
+ import { pathToFileURL } from 'node:url';
15
+ import { bech32 } from 'bech32';
16
+ import { blake2b_224, blake2b_256 } from '@harmoniclabs/crypto';
17
+
18
+ const toHex = (bytes) => Buffer.from(bytes).toString('hex');
19
+ const lines = (text) => text.split(/\r?\n/).map(l => l.trim()).filter(Boolean);
20
+
21
+ /** VRF key hash (hex) -> pool id, from an Ogmios stakePools response (whole JSON-RPC reply or its result). */
22
+ export function vrfMapFromStakePools(response) {
23
+ const pools = response?.result ?? response ?? {};
24
+ const map = new Map();
25
+ for (const [id, pool] of Object.entries(pools)) {
26
+ const vrf = pool?.vrfVerificationKeyHash;
27
+ if (typeof vrf === 'string') map.set(vrf.toLowerCase(), pool.id ?? id);
28
+ }
29
+ return map;
30
+ }
31
+
32
+ /** "<old value> <pool id>" lines to a Map; lines starting with # are skipped. */
33
+ export function parseExtraMap(text) {
34
+ const map = new Map();
35
+ for (const line of lines(text)) {
36
+ if (line.startsWith('#')) continue;
37
+ const [from, to] = line.split(/\s+/);
38
+ if (!to?.startsWith('pool1')) throw new Error(`extra map: no pool id for ${from}`);
39
+ map.set(from, to);
40
+ }
41
+ return map;
42
+ }
43
+
44
+ /** Bech32 pool id for an old slotLeader value, or null when it cannot be derived. */
45
+ export function slotLeaderToPoolId(value, vrfMap = new Map()) {
46
+ if (typeof value !== 'string') return null;
47
+ const v = value.trim();
48
+ if (/^[0-9a-f]{64}$/i.test(v)) {
49
+ return bech32.encode('pool', bech32.toWords(blake2b_224(Uint8Array.from(Buffer.from(v, 'hex')))));
50
+ }
51
+ if (v.startsWith('vrf_vk1')) {
52
+ const { words } = bech32.decode(v, 120);
53
+ const vrfHash = toHex(blake2b_256(Uint8Array.from(bech32.fromWords(words))));
54
+ return vrfMap.get(vrfHash) ?? null;
55
+ }
56
+ return null;
57
+ }
58
+
59
+ const sqlString = (s) => `'${s.replace(/'/g, "''")}'`;
60
+
61
+ /** SQL that rewrites every mapped value in one UPDATE; empty string when nothing maps. */
62
+ export function migrationSql(mapping) {
63
+ if (mapping.size === 0) return '';
64
+ const rows = [...mapping].map(([from, to]) => ` (${sqlString(from)}, ${sqlString(to)})`);
65
+ return [
66
+ 'BEGIN;',
67
+ 'CREATE TEMPORARY TABLE slot_leader_map (old_value VARCHAR(200) PRIMARY KEY, new_value VARCHAR(120) NOT NULL);',
68
+ `INSERT INTO slot_leader_map (old_value, new_value) VALUES\n${rows.join(',\n')};`,
69
+ 'UPDATE odatano_cardano_Blocks',
70
+ ' SET slotLeader = (SELECT m.new_value FROM slot_leader_map m WHERE m.old_value = odatano_cardano_Blocks.slotLeader)',
71
+ ' WHERE slotLeader IN (SELECT old_value FROM slot_leader_map);',
72
+ 'DROP TABLE slot_leader_map;',
73
+ 'COMMIT;',
74
+ '',
75
+ ].join('\n');
76
+ }
77
+
78
+ function argValue(name) {
79
+ const i = process.argv.indexOf(name);
80
+ return i >= 0 ? process.argv[i + 1] : undefined;
81
+ }
82
+
83
+ function main() {
84
+ const stakePoolsFile = argValue('--stake-pools');
85
+ const extraMapFile = argValue('--extra-map');
86
+ const vrfMap = stakePoolsFile ? vrfMapFromStakePools(JSON.parse(fs.readFileSync(stakePoolsFile, 'utf8'))) : new Map();
87
+ const extraMap = extraMapFile ? parseExtraMap(fs.readFileSync(extraMapFile, 'utf8')) : new Map();
88
+
89
+ const values = [...new Set(lines(fs.readFileSync(0, 'utf8')))];
90
+ const mapping = new Map();
91
+ const unmapped = [];
92
+ for (const v of values) {
93
+ if (v.startsWith('pool1')) continue;
94
+ const poolId = extraMap.get(v) ?? slotLeaderToPoolId(v, vrfMap);
95
+ if (poolId) mapping.set(v, poolId);
96
+ else unmapped.push(v);
97
+ }
98
+
99
+ process.stdout.write(migrationSql(mapping));
100
+ console.error(`slotLeader values: ${values.length} read, ${mapping.size} mapped, ${unmapped.length} left unchanged`);
101
+ for (const v of unmapped) console.error(` unmapped: ${v}`);
102
+ }
103
+
104
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main();
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env node
2
+ // Move a database written before the txSeq schema onto it: TransactionInputs / TransactionOutputs
3
+ // and their asset tables are keyed by Transactions.txSeq (slot * 65536 + txIndex) instead of the
4
+ // transaction hash. Runs against the configured `db` (PostgreSQL or SQLite) with ODATANO stopped:
5
+ //
6
+ // node scripts/migrate-txseq.mjs # image: docker compose run --rm --no-deps odatano migrate-txseq
7
+ // node scripts/migrate-txseq.mjs --dry-run # report what would change, touch nothing
8
+ //
9
+ // One transaction: fill Transactions.txSeq, rebuild the four tables in the new layout (rows copied
10
+ // in key order, row counts checked), recreate the service views, refresh the planner statistics
11
+ // and store the new model in `cds_model` so the next schema deployment sees no difference. A
12
+ // database already on the new layout is left alone. The table indexes are recreated by the server
13
+ // on its next start.
14
+ import cds from '@sap/cds';
15
+
16
+ const DRY = process.argv.includes('--dry-run');
17
+ const T = (name) => `odatano_cardano_${name}`;
18
+ const TX_SEQ_SLOT_FACTOR = 65536;
19
+
20
+ /** Old key column -> new key column, and the column the copy is ordered by after the key. */
21
+ const TABLES = [
22
+ { name: 'TransactionInputs', hashKey: 'tx_hash', seqKey: 'txSeq', order: 'inputIndex' },
23
+ { name: 'TransactionOutputs', hashKey: 'tx_hash', seqKey: 'txSeq', order: 'outputIndex' },
24
+ { name: 'TransactionInputAssets', hashKey: 'input_tx_hash', seqKey: 'input_txSeq', order: 'input_inputIndex, unit' },
25
+ { name: 'TransactionOutputAssets', hashKey: 'output_tx_hash', seqKey: 'output_txSeq', order: 'output_outputIndex, unit' },
26
+ ];
27
+
28
+ /** Column names of a table, lower-cased (PostgreSQL folds unquoted identifiers). */
29
+ export async function tableColumns(db, table) {
30
+ const rows = db.kind === 'postgres'
31
+ ? await db.run(`SELECT column_name AS name FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = '${table.toLowerCase()}'`)
32
+ : await db.run(`SELECT name FROM pragma_table_info('${table}')`);
33
+ return rows.map(r => String(r.name).toLowerCase());
34
+ }
35
+
36
+ /** CREATE statements of the compiled model for one table (renamed) and for every view. */
37
+ export function modelStatements(model, options) {
38
+ const sql = cds.compile.to.sql(model, options);
39
+ const views = sql.filter(s => /^CREATE VIEW/i.test(s.trim()));
40
+ const tableDdl = (name) => {
41
+ const stmt = sql.find(s => new RegExp(`^CREATE TABLE ${T(name)} \\(`, 'i').test(s.trim()));
42
+ if (!stmt) throw new Error(`model has no table ${T(name)}`);
43
+ return stmt;
44
+ };
45
+ return { views, tableDdl };
46
+ }
47
+
48
+ const viewName = (stmt) => stmt.trim().match(/^CREATE VIEW\s+("?[\w.]+"?)/i)[1];
49
+
50
+ /** Copy statement: every column of the old table except the hash key, the new key from Transactions. */
51
+ export function copySql(spec, oldColumns) {
52
+ const others = oldColumns.filter(c => c !== spec.hashKey.toLowerCase());
53
+ const target = [spec.seqKey, ...others].join(', ');
54
+ const source = ['t.txSeq', ...others.map(c => `x.${c}`)].join(', ');
55
+ const order = ['t.txSeq', ...spec.order.split(',').map(c => `x.${c.trim()}`)].join(', ');
56
+ return `INSERT INTO ${T(spec.name)}_txseq_new (${target}) SELECT ${source} FROM ${T(spec.name)} x `
57
+ + `JOIN ${T('Transactions')} t ON t.hash = x.${spec.hashKey} ORDER BY ${order}`;
58
+ }
59
+
60
+ async function count(tx, table) {
61
+ const [row] = await tx.run(`SELECT count(*) AS n FROM ${table}`);
62
+ return Number(row.n);
63
+ }
64
+
65
+ async function main() {
66
+ const db = await cds.connect.to('db');
67
+ if (db.kind !== 'postgres' && db.kind !== 'sqlite') throw new Error(`unsupported database kind ${db.kind}: re-crawl instead`);
68
+
69
+ const inputColumns = await tableColumns(db, T('TransactionInputs'));
70
+ if (!inputColumns.includes('tx_hash')) {
71
+ console.log('Already on the txSeq layout; nothing to do.');
72
+ return;
73
+ }
74
+
75
+ const [lease] = await db.run(`SELECT leaseUntil FROM ${T('CardanoSyncState')}`).catch(() => []);
76
+ const leaseUntil = lease?.leaseUntil ?? lease?.leaseuntil;
77
+ if (leaseUntil && Date.parse(leaseUntil) > Date.now()) {
78
+ throw new Error(`the crawler lease is held until ${leaseUntil}: stop ODATANO first`);
79
+ }
80
+
81
+ // the model exactly as `cds deploy` compiles it
82
+ const model = await cds.load('*').then(cds.minify);
83
+ cds.deploy.exclude_external_entities_in(model);
84
+ const options = { ...db.options };
85
+ const { views, tableDdl } = modelStatements(model, options);
86
+ const [hasModelTable] = await db.run(db.kind === 'postgres'
87
+ ? `SELECT 1 AS x FROM pg_tables WHERE tablename = 'cds_model' AND schemaname = current_schema()`
88
+ : `SELECT 1 AS x FROM sqlite_schema WHERE name = 'cds_model'`);
89
+
90
+ const txNull = Number((await db.run(`SELECT count(*) AS n FROM ${T('Transactions')} WHERE slot IS NULL OR txIndex IS NULL`))[0].n);
91
+ if (txNull > 0) throw new Error(`${txNull} transactions have no slot or txIndex; their txSeq cannot be derived`);
92
+
93
+ const plan = [];
94
+ for (const spec of TABLES) plan.push({ spec, columns: await tableColumns(db, T(spec.name)), rows: await count(db, T(spec.name)) });
95
+ for (const p of plan) console.log(`${T(p.spec.name)}: ${p.rows} rows, key ${p.spec.hashKey} -> ${p.spec.seqKey}`);
96
+ console.log(`${views.length} views recreated${hasModelTable ? ', cds_model updated' : ''}`);
97
+ if (DRY) { console.log('dry run: nothing changed'); return; }
98
+
99
+ await db.tx(async (tx) => {
100
+ const started = Date.now();
101
+ const step = (msg) => console.log(`[${Math.round((Date.now() - started) / 1000)}s] ${msg}`);
102
+
103
+ for (const stmt of [...views].reverse()) {
104
+ await tx.run(`DROP VIEW IF EXISTS ${viewName(stmt)}${db.kind === 'postgres' ? ' CASCADE' : ''}`);
105
+ }
106
+ step('views dropped');
107
+
108
+ const txColumns = await tableColumns(tx, T('Transactions'));
109
+ if (!txColumns.includes('txseq')) await tx.run(`ALTER TABLE ${T('Transactions')} ADD COLUMN txSeq BIGINT`);
110
+ await tx.run(`UPDATE ${T('Transactions')} SET txSeq = slot * ${TX_SEQ_SLOT_FACTOR} + txIndex`);
111
+ await tx.run(`CREATE INDEX IF NOT EXISTS odatano_cardano_transactions_txseq ON ${T('Transactions')} (txSeq)`);
112
+ step('Transactions.txSeq filled');
113
+
114
+ for (const { spec, columns, rows } of plan) {
115
+ const table = T(spec.name);
116
+ const newTable = `${table}_txseq_new`;
117
+ await tx.run(tableDdl(spec.name).replace(new RegExp(`^(\\s*CREATE TABLE )${table}\\b`, 'i'), `$1${newTable}`));
118
+ await tx.run(copySql(spec, columns));
119
+ const copied = await count(tx, newTable);
120
+ if (copied !== rows) throw new Error(`${table}: ${rows} rows, ${copied} copied (rows without a Transactions row?)`);
121
+ await tx.run(`DROP TABLE ${table}`);
122
+ await tx.run(`ALTER TABLE ${newTable} RENAME TO ${table}`);
123
+ if (db.kind === 'postgres') {
124
+ await tx.run(`ALTER TABLE ${table} RENAME CONSTRAINT ${newTable.toLowerCase()}_pkey TO ${table.toLowerCase()}_pkey`);
125
+ }
126
+ step(`${table}: ${copied} rows`);
127
+ }
128
+
129
+ for (const stmt of views) await tx.run(stmt);
130
+ step('views recreated');
131
+
132
+ // fresh planner statistics: without them the rebuilt tables are read by sequential scans
133
+ for (const name of ['Transactions', ...TABLES.map(t => t.name)]) await tx.run(`ANALYZE ${T(name)}`);
134
+ step('statistics updated');
135
+
136
+ if (hasModelTable) {
137
+ const { afterImage } = cds.compile.to.sql.delta(model, options);
138
+ await tx.run(db.kind === 'postgres' ? 'UPDATE cds_model SET csn = $1' : 'UPDATE cds_model SET csn = ?', [JSON.stringify(afterImage)]);
139
+ step('cds_model updated');
140
+ }
141
+ });
142
+ console.log('Migration to the txSeq layout done. Start ODATANO; it recreates the table indexes.');
143
+ }
144
+
145
+ if (process.argv[1] && import.meta.url === (await import('node:url')).pathToFileURL(process.argv[1]).href) {
146
+ main().then(() => process.exit(0), (err) => { console.error(`FAILED: ${err.message}`); process.exit(1); });
147
+ }
package/src/index.d.ts CHANGED
@@ -1,26 +1,33 @@
1
+ import type { TransactionConfirmations } from '../srv/utils/types';
1
2
  export { CardanoClient } from '../srv/blockchain/cardano-client';
2
3
  export type { CardanoClientConfig, Network, BackendName, TransactionBuilderName } from '../srv/blockchain/cardano-client';
3
4
  export { CardanoIndexer } from '../srv/blockchain/cardano-indexer';
4
5
  export { CardanoTransactionBuilder } from '../srv/blockchain/cardano-tx-builder';
5
6
  export { getAppContext, getCardanoIndexer, getCardanoClient, getCardanoTxBuilder, loadConfigFromEnv, loadHsmConfigFromEnv, loadCrawlerConfigFromEnv, startCrawlerIfConfigured, loadWalletWorkerConfigFromEnv, startWalletWorkerIfConfigured, shutdownAppContext, } from '../srv/server';
6
7
  export { getHsmSigner } from '../srv/blockchain/signing/hsm-signer';
8
+ export { issueAgentGrant, updateAgentGrant, rotateAgentGrantToken, revokeAgentGrantById, getGrantUsage, resolveUsageWindow, hashAgentToken, AGENT_TOKEN_HEADER, AGENT_TOKEN_PREFIX, AGENT_ROLE, AGENT_ALLOWLISTABLE_ACTIONS, AGENT_ALWAYS_ALLOWED_EVENTS, } from '../srv/utils/agent-grants';
9
+ export type { IssueAgentGrantInput, IssuedAgentGrant, AgentGrantStatus, UpdateAgentGrantInput, UpdateAgentGrantResult, RotatedAgentGrant, AgentGrantUsage, GrantUsageCall, UsageWindow, } from '../srv/utils/agent-grants';
10
+ export { registerTransportLane } from '@odatano/cap-auth';
11
+ export type { TransportLane, LaneOutcome } from '@odatano/cap-auth';
12
+ export { loadAgentGrantsConfig } from '../srv/utils/agent-grants-config';
13
+ export type { AgentGrantsConfig } from '../srv/utils/agent-grants-config';
7
14
  export type { HsmConfig, HsmSignResult } from '../srv/utils/types';
8
15
  export { parseTransaction } from '../srv/cbor';
9
- export type { ParsedTransaction, ParsedInput, ParsedOutput, ParsedAsset, ParsedWitnesses, } from '../srv/cbor';
16
+ export type { ParsedTransaction, ParsedInput, ParsedOutput, ParsedAsset, ParsedWitnesses, ParsedWithdrawal, ParsedCertificate, } from '../srv/cbor';
17
+ export { verifyTxWitnesses } from '../srv/blockchain/signing/signature-verifier';
18
+ export { posixToSlot, slotToPosixMs } from '../srv/utils/epoch-slots';
19
+ export type { TxWitnessVerification, TransactionConfirmations } from '../srv/utils/types';
20
+ export { applyScriptParameters, plutusScriptHash } from '../srv/utils/tx-build-helper';
10
21
  /**
11
- * Initialize the ODATANO plugin.
12
- * Loads configuration from cds.env.requires["odatano-core"] OR environment variables,
13
- * then initializes all blockchain components.
22
+ * Initialize the plugin: config from cds.env.requires["odatano-core"] or env vars,
23
+ * then all blockchain components plus the optional crawler and wallet worker.
14
24
  */
15
25
  export declare function initialize(): Promise<void>;
16
- /**
17
- * Shutdown the ODATANO plugin.
18
- * Cleans up all backend connections (especially Ogmios WebSocket).
19
- */
26
+ /** Shut down the plugin and close all backend connections. */
20
27
  export declare function shutdown(): Promise<void>;
21
- /**
22
- * Get the current status of the plugin.
23
- */
28
+ /** Confirmations of a transaction; needs initialize(). See CardanoIndexer.resolveTransactionConfirmations. */
29
+ export declare function getTransactionConfirmations(txHash: string): Promise<TransactionConfirmations>;
30
+ /** Current plugin status. */
24
31
  export declare function getStatus(): {
25
32
  initialized: boolean;
26
33
  network?: string;
package/src/index.js CHANGED
@@ -36,11 +36,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.parseTransaction = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
39
+ exports.plutusScriptHash = exports.applyScriptParameters = exports.slotToPosixMs = exports.posixToSlot = exports.verifyTxWitnesses = exports.parseTransaction = exports.loadAgentGrantsConfig = exports.registerTransportLane = exports.AGENT_ALWAYS_ALLOWED_EVENTS = exports.AGENT_ALLOWLISTABLE_ACTIONS = exports.AGENT_ROLE = exports.AGENT_TOKEN_PREFIX = exports.AGENT_TOKEN_HEADER = exports.hashAgentToken = exports.resolveUsageWindow = exports.getGrantUsage = exports.revokeAgentGrantById = exports.rotateAgentGrantToken = exports.updateAgentGrant = exports.issueAgentGrant = exports.getHsmSigner = exports.shutdownAppContext = exports.startWalletWorkerIfConfigured = exports.loadWalletWorkerConfigFromEnv = exports.startCrawlerIfConfigured = exports.loadCrawlerConfigFromEnv = exports.loadHsmConfigFromEnv = exports.loadConfigFromEnv = exports.getCardanoTxBuilder = exports.getCardanoClient = exports.getCardanoIndexer = exports.getAppContext = exports.CardanoTransactionBuilder = exports.CardanoIndexer = exports.CardanoClient = void 0;
40
40
  exports.initialize = initialize;
41
41
  exports.shutdown = shutdown;
42
+ exports.getTransactionConfirmations = getTransactionConfirmations;
42
43
  exports.getStatus = getStatus;
43
44
  const cds_1 = __importDefault(require("@sap/cds"));
45
+ const validators_1 = require("../srv/utils/validators");
46
+ const errors_1 = require("../srv/utils/errors");
47
+ const error_codes_1 = require("../srv/utils/error-codes");
44
48
  const logger = cds_1.default.log('ODATANO');
45
49
  // Re-export key types and classes for programmatic consumers
46
50
  var cardano_client_1 = require("../srv/blockchain/cardano-client");
@@ -65,13 +69,39 @@ Object.defineProperty(exports, "shutdownAppContext", { enumerable: true, get: fu
65
69
  // Re-export HSM signer for programmatic access
66
70
  var hsm_signer_1 = require("../srv/blockchain/signing/hsm-signer");
67
71
  Object.defineProperty(exports, "getHsmSigner", { enumerable: true, get: function () { return hsm_signer_1.getHsmSigner; } });
72
+ // Agent grants: programmatic seams for packages that issue grants or add transport lanes.
73
+ var agent_grants_1 = require("../srv/utils/agent-grants");
74
+ Object.defineProperty(exports, "issueAgentGrant", { enumerable: true, get: function () { return agent_grants_1.issueAgentGrant; } });
75
+ Object.defineProperty(exports, "updateAgentGrant", { enumerable: true, get: function () { return agent_grants_1.updateAgentGrant; } });
76
+ Object.defineProperty(exports, "rotateAgentGrantToken", { enumerable: true, get: function () { return agent_grants_1.rotateAgentGrantToken; } });
77
+ Object.defineProperty(exports, "revokeAgentGrantById", { enumerable: true, get: function () { return agent_grants_1.revokeAgentGrantById; } });
78
+ Object.defineProperty(exports, "getGrantUsage", { enumerable: true, get: function () { return agent_grants_1.getGrantUsage; } });
79
+ Object.defineProperty(exports, "resolveUsageWindow", { enumerable: true, get: function () { return agent_grants_1.resolveUsageWindow; } });
80
+ Object.defineProperty(exports, "hashAgentToken", { enumerable: true, get: function () { return agent_grants_1.hashAgentToken; } });
81
+ Object.defineProperty(exports, "AGENT_TOKEN_HEADER", { enumerable: true, get: function () { return agent_grants_1.AGENT_TOKEN_HEADER; } });
82
+ Object.defineProperty(exports, "AGENT_TOKEN_PREFIX", { enumerable: true, get: function () { return agent_grants_1.AGENT_TOKEN_PREFIX; } });
83
+ Object.defineProperty(exports, "AGENT_ROLE", { enumerable: true, get: function () { return agent_grants_1.AGENT_ROLE; } });
84
+ Object.defineProperty(exports, "AGENT_ALLOWLISTABLE_ACTIONS", { enumerable: true, get: function () { return agent_grants_1.AGENT_ALLOWLISTABLE_ACTIONS; } });
85
+ Object.defineProperty(exports, "AGENT_ALWAYS_ALLOWED_EVENTS", { enumerable: true, get: function () { return agent_grants_1.AGENT_ALWAYS_ALLOWED_EVENTS; } });
86
+ var cap_auth_1 = require("@odatano/cap-auth");
87
+ Object.defineProperty(exports, "registerTransportLane", { enumerable: true, get: function () { return cap_auth_1.registerTransportLane; } });
88
+ var agent_grants_config_1 = require("../srv/utils/agent-grants-config");
89
+ Object.defineProperty(exports, "loadAgentGrantsConfig", { enumerable: true, get: function () { return agent_grants_config_1.loadAgentGrantsConfig; } });
68
90
  // Re-export pure CBOR utilities (no CAP round-trip needed)
69
91
  var cbor_1 = require("../srv/cbor");
70
92
  Object.defineProperty(exports, "parseTransaction", { enumerable: true, get: function () { return cbor_1.parseTransaction; } });
93
+ var signature_verifier_1 = require("../srv/blockchain/signing/signature-verifier");
94
+ Object.defineProperty(exports, "verifyTxWitnesses", { enumerable: true, get: function () { return signature_verifier_1.verifyTxWitnesses; } });
95
+ var epoch_slots_1 = require("../srv/utils/epoch-slots");
96
+ Object.defineProperty(exports, "posixToSlot", { enumerable: true, get: function () { return epoch_slots_1.posixToSlot; } });
97
+ Object.defineProperty(exports, "slotToPosixMs", { enumerable: true, get: function () { return epoch_slots_1.slotToPosixMs; } });
98
+ // Pure script helpers (no initialize() needed)
99
+ var tx_build_helper_1 = require("../srv/utils/tx-build-helper");
100
+ Object.defineProperty(exports, "applyScriptParameters", { enumerable: true, get: function () { return tx_build_helper_1.applyScriptParameters; } });
101
+ Object.defineProperty(exports, "plutusScriptHash", { enumerable: true, get: function () { return tx_build_helper_1.plutusScriptHash; } });
71
102
  /**
72
- * Initialize the ODATANO plugin.
73
- * Loads configuration from cds.env.requires["odatano-core"] OR environment variables,
74
- * then initializes all blockchain components.
103
+ * Initialize the plugin: config from cds.env.requires["odatano-core"] or env vars,
104
+ * then all blockchain components plus the optional crawler and wallet worker.
75
105
  */
76
106
  async function initialize() {
77
107
  const { loadConfigFromEnv, loadHsmConfigFromEnv, initializeFromConfig, getAppContext } = await Promise.resolve().then(() => __importStar(require('../srv/server')));
@@ -89,26 +119,26 @@ async function initialize() {
89
119
  if (!alreadyInitialized) {
90
120
  logger.info('ODATANO core initialized');
91
121
  }
92
- // Start the pre-sync crawler if configured (plugin mode). Non-fatal.
122
+ // Optional subsystems; each is non-fatal.
93
123
  const { startCrawlerIfConfigured, startWalletWorkerIfConfigured, redriveInterruptedSubmissionsIfConfigured } = await Promise.resolve().then(() => __importStar(require('../srv/server')));
94
124
  await startCrawlerIfConfigured();
95
- // Start the wallet worker if configured (plugin mode). Non-fatal.
96
125
  await startWalletWorkerIfConfigured();
97
- // Re-drive deferred submissions interrupted by a restart (plugin mode). Non-fatal.
98
126
  await redriveInterruptedSubmissionsIfConfigured();
99
127
  }
100
- /**
101
- * Shutdown the ODATANO plugin.
102
- * Cleans up all backend connections (especially Ogmios WebSocket).
103
- */
128
+ /** Shut down the plugin and close all backend connections. */
104
129
  async function shutdown() {
105
130
  const { shutdownAppContext } = await Promise.resolve().then(() => __importStar(require('../srv/server')));
106
131
  await shutdownAppContext();
107
132
  logger.info('ODATANO core shutdown');
108
133
  }
109
- /**
110
- * Get the current status of the plugin.
111
- */
134
+ /** Confirmations of a transaction; needs initialize(). See CardanoIndexer.resolveTransactionConfirmations. */
135
+ async function getTransactionConfirmations(txHash) {
136
+ if (!(0, validators_1.isTxHash)(txHash))
137
+ throw new errors_1.TransactionValidationError(`Invalid transaction hash: ${txHash}`, undefined, error_codes_1.ERROR_CODES.INVALID_INPUT);
138
+ const { getCardanoIndexer } = await Promise.resolve().then(() => __importStar(require('../srv/server')));
139
+ return cds_1.default.tx((tx) => getCardanoIndexer().resolveTransactionConfirmations(tx, txHash));
140
+ }
141
+ /** Current plugin status. */
112
142
  function getStatus() {
113
143
  try {
114
144
  const { getAppContext } = require('../srv/server');