@odatano/core 2.0.0-rc.49 → 2.0.0-rc.50

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 (120) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +6 -12
  2. package/@cds-models/CardanoIndexerService/index.d.ts +200 -2
  3. package/@cds-models/CardanoIndexerService/index.js +24 -0
  4. package/@cds-models/CardanoODataService/index.d.ts +49 -6
  5. package/@cds-models/CardanoODataService/index.js +4 -0
  6. package/@cds-models/CardanoSignService/index.d.ts +3 -3
  7. package/@cds-models/CardanoWorkerService/index.d.ts +4 -3
  8. package/@cds-models/index.d.ts +9 -1
  9. package/@cds-models/index.js +2 -1
  10. package/@cds-models/odatano/cardano/index.d.ts +59 -5
  11. package/@cds-models/odatano/cardano/index.js +6 -0
  12. package/README.md +29 -17
  13. package/db/schema.cds +117 -24
  14. package/db/types.cds +8 -0
  15. package/package.json +17 -15
  16. package/scripts/migrate-schema.mjs +334 -0
  17. package/src/index.d.ts +7 -5
  18. package/src/index.js +12 -10
  19. package/src/plugin.js +6 -7
  20. package/srv/blockchain/backends/blockfrost-backend.js +9 -1
  21. package/srv/blockchain/backends/cardano-backend.d.ts +15 -0
  22. package/srv/blockchain/backends/cardano-backend.js +5 -0
  23. package/srv/blockchain/backends/koios-backend.js +16 -10
  24. package/srv/blockchain/backends/ogmios-backend.d.ts +9 -3
  25. package/srv/blockchain/backends/ogmios-backend.js +60 -18
  26. package/srv/blockchain/cardano-client.d.ts +5 -4
  27. package/srv/blockchain/cardano-client.js +46 -13
  28. package/srv/blockchain/cardano-indexer.d.ts +116 -9
  29. package/srv/blockchain/cardano-indexer.js +436 -189
  30. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  31. package/srv/blockchain/crawler/account-snapshots.js +153 -0
  32. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +23 -1
  33. package/srv/blockchain/crawler/asset-registry-backfill.js +91 -1
  34. package/srv/blockchain/crawler/certificate-backfill.d.ts +2 -0
  35. package/srv/blockchain/crawler/certificate-backfill.js +10 -3
  36. package/srv/blockchain/crawler/crawler.d.ts +15 -0
  37. package/srv/blockchain/crawler/crawler.js +68 -3
  38. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  39. package/srv/blockchain/crawler/input-asset-copies.js +171 -0
  40. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
  41. package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
  42. package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
  43. package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
  44. package/srv/blockchain/crawler/transaction-backfill.d.ts +2 -0
  45. package/srv/blockchain/crawler/transaction-backfill.js +12 -8
  46. package/srv/blockchain/pool-metadata.d.ts +15 -0
  47. package/srv/blockchain/pool-metadata.js +132 -0
  48. package/srv/blockchain/signing/cose-verifier.d.ts +3 -1
  49. package/srv/blockchain/signing/cose-verifier.js +144 -56
  50. package/srv/blockchain/signing/hsm-signer.js +2 -1
  51. package/srv/blockchain/signing/submission-finalizer.d.ts +15 -4
  52. package/srv/blockchain/signing/submission-finalizer.js +201 -69
  53. package/srv/blockchain/stored-chain.js +1 -1
  54. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +1 -3
  55. package/srv/blockchain/transaction-building/buildooor-tx.js +34 -54
  56. package/srv/blockchain/transaction-presence.d.ts +5 -0
  57. package/srv/blockchain/transaction-presence.js +29 -0
  58. package/srv/blockchain/transaction-rows.js +1 -1
  59. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -1
  60. package/srv/blockchain/wallet-worker/build-request.js +25 -0
  61. package/srv/blockchain/wallet-worker/confirmation-tracker.js +1 -1
  62. package/srv/blockchain/wallet-worker/job-store.d.ts +17 -7
  63. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  64. package/srv/blockchain/wallet-worker/signers.d.ts +2 -0
  65. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +2 -0
  66. package/srv/blockchain/wallet-worker/wallet-worker.js +42 -32
  67. package/srv/cardano-agent-service.cds +11 -12
  68. package/srv/cardano-agent-service.js +2 -0
  69. package/srv/cardano-backend-service.cds +34 -1
  70. package/srv/cardano-backend-service.js +20 -17
  71. package/srv/cardano-indexer-service.cds +153 -12
  72. package/srv/cardano-indexer-service.js +175 -29
  73. package/srv/cardano-service.cds +67 -3
  74. package/srv/cardano-service.js +132 -67
  75. package/srv/cardano-sign-service.cds +30 -20
  76. package/srv/cardano-sign-service.js +13 -10
  77. package/srv/cardano-tx-service.cds +15 -1
  78. package/srv/cardano-tx-service.js +4 -1
  79. package/srv/cardano-worker-service.cds +16 -7
  80. package/srv/cardano-worker-service.js +31 -22
  81. package/srv/cbor/parse.js +11 -34
  82. package/srv/config.d.ts +113 -0
  83. package/srv/config.js +409 -0
  84. package/srv/server.d.ts +9 -14
  85. package/srv/server.js +32 -316
  86. package/srv/utils/agent-access.d.ts +9 -0
  87. package/srv/utils/agent-access.js +67 -0
  88. package/srv/utils/agent-grants-config.d.ts +0 -17
  89. package/srv/utils/agent-grants-config.js +6 -81
  90. package/srv/utils/agent-grants.d.ts +6 -19
  91. package/srv/utils/agent-grants.js +69 -130
  92. package/srv/utils/const.d.ts +4 -0
  93. package/srv/utils/const.js +5 -1
  94. package/srv/utils/db-indexes.js +11 -3
  95. package/srv/utils/error-codes.d.ts +4 -0
  96. package/srv/utils/error-codes.js +4 -0
  97. package/srv/utils/errors.d.ts +6 -0
  98. package/srv/utils/errors.js +23 -1
  99. package/srv/utils/liveness.js +2 -5
  100. package/srv/utils/mappers.d.ts +5 -7
  101. package/srv/utils/mappers.js +22 -9
  102. package/srv/utils/pg-order-nulls.js +4 -3
  103. package/srv/utils/readiness.d.ts +12 -0
  104. package/srv/utils/readiness.js +29 -0
  105. package/srv/utils/result-numbers.d.ts +15 -0
  106. package/srv/utils/result-numbers.js +61 -0
  107. package/srv/utils/tx-request-parsers.d.ts +1 -1
  108. package/srv/utils/tx-request-parsers.js +3 -3
  109. package/srv/utils/tx-utils.d.ts +3 -0
  110. package/srv/utils/tx-utils.js +17 -3
  111. package/srv/utils/types.d.ts +16 -3
  112. package/scripts/migrate-txseq.mjs +0 -138
  113. package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -13
  114. package/srv/blockchain/transaction-building/buildooor-fee-patch.js +0 -71
  115. package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -15
  116. package/srv/blockchain/transaction-building/caller-datums.js +0 -133
  117. package/srv/cbor/redeemer-tag-patch.d.ts +0 -3
  118. package/srv/cbor/redeemer-tag-patch.js +0 -61
  119. package/srv/utils/legacy-service-paths.d.ts +0 -11
  120. package/srv/utils/legacy-service-paths.js +0 -58
@@ -16,9 +16,15 @@ const transaction_backfill_1 = require("./blockchain/crawler/transaction-backfil
16
16
  const credential_backfill_1 = require("./blockchain/crawler/credential-backfill");
17
17
  const asset_decimals_backfill_1 = require("./blockchain/crawler/asset-decimals-backfill");
18
18
  const asset_registry_backfill_1 = require("./blockchain/crawler/asset-registry-backfill");
19
+ const output_datum_backfill_1 = require("./blockchain/crawler/output-datum-backfill");
20
+ const metadata_position_backfill_1 = require("./blockchain/crawler/metadata-position-backfill");
21
+ const input_asset_copies_1 = require("./blockchain/crawler/input-asset-copies");
19
22
  const validators_1 = require("./utils/validators");
20
23
  const server_1 = require("./server");
24
+ const config_1 = require("./config");
21
25
  const liveness_1 = require("./utils/liveness");
26
+ const readiness_1 = require("./utils/readiness");
27
+ const result_numbers_1 = require("./utils/result-numbers");
22
28
  const cardano_1 = require("#cds-models/odatano/cardano");
23
29
  const { SELECT } = cds_1.default.ql;
24
30
  const logger = cds_1.default.log('CardanoIndexerService');
@@ -27,23 +33,29 @@ let utxoSetImportInFlight = null;
27
33
  /** Set while a start request is validated, so a second request cannot start a parallel run. */
28
34
  let certificateBackfillStarting = false;
29
35
  let certificateBackfill = {
30
- status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0,
36
+ status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0, removed: 0,
31
37
  startedAt: null, finishedAt: null, error: null,
32
38
  };
33
39
  let transactionBackfillStarting = false;
34
40
  let transactionBackfill = {
35
- status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, datums: 0, rewritten: 0, skipped: 0,
41
+ status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, inputs: 0, outputs: 0, redeemers: 0, datums: 0, rewritten: 0, skipped: 0,
36
42
  startedAt: null, finishedAt: null, error: null,
37
43
  };
44
+ const NO_DATUM_PROGRESS = { scanned: 0, candidates: 0, transactions: 0, missing: 0, outputs: 0, inputs: 0, ledgerUtxos: 0 };
45
+ let datumBackfill = { status: 'none', ...NO_DATUM_PROGRESS, startedAt: null, finishedAt: null, error: null };
46
+ let metadataBackfill = { status: 'none', atSlot: 0, toSlot: 0, rows: 0, startedAt: null, finishedAt: null, error: null };
47
+ const IDLE = { status: 'none', startedAt: null, finishedAt: null, error: null };
48
+ let epochBackfill = { ...IDLE, atEpoch: 0, toEpoch: 0, updated: 0, created: 0 };
49
+ let copyPrune = { ...IDLE, atSlot: 0, toSlot: 0, referenced: 0, kept: 0, deleted: 0 };
50
+ let copyRestore = { ...IDLE, atSlot: 0, toSlot: 0, restored: 0, rows: 0 };
38
51
  let credentialBackfill = {
39
52
  status: 'none', table: null, outputs: 0, inputs: 0, ledgerUtxos: 0, startedAt: null, finishedAt: null, error: null,
40
53
  };
41
54
  let decimalsBackfill = {
42
55
  status: 'none', scanned: 0, candidates: 0, filled: 0, startedAt: null, finishedAt: null, error: null,
43
56
  };
44
- let registryBackfill = {
45
- status: 'none', units: 0, processed: 0, filled: 0, failed: 0, startedAt: null, finishedAt: null, error: null,
46
- };
57
+ const REGISTRY_IDLE = { units: 0, processed: 0, filled: 0, failed: 0, absent: 0, skipped: 0 };
58
+ let registryBackfill = { ...REGISTRY_IDLE, status: 'none', startedAt: null, finishedAt: null, error: null };
47
59
  /** Slot range of a backfill: defaults to crawl start .. cursor, never past the cursor. */
48
60
  async function backfillRange(db, data) {
49
61
  const cursor = await (0, sync_state_1.readCursor)(db);
@@ -57,17 +69,10 @@ async function backfillRange(db, data) {
57
69
  throw new errors_1.TransactionValidationError(`toSlot ${toSlot} is past the crawler cursor (slot ${cursor.lastSlot}). Only crawled blocks can be backfilled.`);
58
70
  return { fromSlot, toSlot };
59
71
  }
60
- function utxoSetConfigured() {
72
+ /** A crawler switch as configured; false when the configuration is invalid. */
73
+ function crawlerOption(name) {
61
74
  try {
62
- return Boolean((0, server_1.loadCrawlerConfigFromEnv)()?.utxoSet);
63
- }
64
- catch {
65
- return false;
66
- }
67
- }
68
- function epochSnapshotsConfigured() {
69
- try {
70
- return Boolean((0, server_1.loadCrawlerConfigFromEnv)()?.epochSnapshots);
75
+ return Boolean((0, config_1.loadCrawlerConfigFromEnv)()?.[name]);
71
76
  }
72
77
  catch {
73
78
  return false;
@@ -95,13 +100,22 @@ function isCrawlerStalled(cursor, now = Date.now()) {
95
100
  }
96
101
  /** CardanoIndexerService handlers. They read the crawler cursor and start or stop the crawler. */
97
102
  module.exports = (srv) => {
103
+ (0, result_numbers_1.answerNumbersAsText)(srv);
98
104
  // getLiveness: unauthenticated probe. No handleRequest and no app context.
99
105
  srv.on('getLiveness', async () => (0, liveness_1.buildLiveness)());
106
+ // getReadiness: unauthenticated probe. A missing part answers 503 with the same body.
107
+ srv.on('getReadiness', async (req) => {
108
+ const readiness = await (0, readiness_1.buildReadiness)((0, server_1.readinessParts)());
109
+ if (readiness.status !== 'ready')
110
+ req.http?.res.status(503);
111
+ return readiness;
112
+ });
100
113
  // getStatus: run state and sync progress. Numeric fields are strings, as CAP 10 serializes them.
101
114
  srv.on('getStatus', async (req) => {
102
115
  return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
103
116
  const cursor = await (0, sync_state_1.readCursor)(db);
104
117
  const lastSnapshot = await db.run(SELECT.one.from(cardano_1.EpochLedgerSnapshots).columns('epoch', 'source', 'snapshotSlot').orderBy('epoch desc'));
118
+ const lastAccounts = await db.run(SELECT.one.from(cardano_1.EpochLedgerSnapshots).columns('epoch', 'accountCount').where({ accountCount: { '!=': null } }).orderBy('epoch desc'));
105
119
  const lastHeight = cursor?.lastHeight ?? 0;
106
120
  const tipHeight = cursor?.tipHeight ?? 0;
107
121
  const progress = tipHeight > 0 ? Math.min(100, (lastHeight / tipHeight) * 100) : 0;
@@ -118,7 +132,7 @@ module.exports = (srv) => {
118
132
  lastIndexedAt: cursor?.lastIndexedAt ?? null,
119
133
  stalled: isCrawlerStalled(cursor),
120
134
  utxoSet: {
121
- enabled: utxoSetConfigured(),
135
+ enabled: crawlerOption('utxoSet'),
122
136
  status: utxoSetImportInFlight ? 'importing' : (cursor?.utxoSet?.status ?? 'none'),
123
137
  anchorSlot: cursor?.utxoSet?.anchorSlot == null ? null : String(cursor.utxoSet.anchorSlot),
124
138
  anchorHash: cursor?.utxoSet?.anchorHash ?? null,
@@ -133,6 +147,7 @@ module.exports = (srv) => {
133
147
  blocks: certificateBackfill.blocks,
134
148
  certificates: certificateBackfill.certificates,
135
149
  withdrawals: certificateBackfill.withdrawals,
150
+ removed: certificateBackfill.removed,
136
151
  startedAt: certificateBackfill.startedAt,
137
152
  finishedAt: certificateBackfill.finishedAt,
138
153
  error: certificateBackfill.error,
@@ -145,6 +160,7 @@ module.exports = (srv) => {
145
160
  blocks: transactionBackfill.blocks,
146
161
  transactions: transactionBackfill.transactions,
147
162
  inputs: transactionBackfill.inputs,
163
+ outputs: transactionBackfill.outputs,
148
164
  redeemers: transactionBackfill.redeemers,
149
165
  datums: transactionBackfill.datums,
150
166
  rewritten: transactionBackfill.rewritten,
@@ -156,12 +172,20 @@ module.exports = (srv) => {
156
172
  credentialBackfill: { ...credentialBackfill },
157
173
  decimalsBackfill: { ...decimalsBackfill },
158
174
  registryBackfill: { ...registryBackfill },
175
+ datumBackfill: { ...datumBackfill },
176
+ metadataBackfill: { ...metadataBackfill, atSlot: String(metadataBackfill.atSlot), toSlot: String(metadataBackfill.toSlot) },
177
+ epochBackfill: { ...epochBackfill },
178
+ copyPrune: { ...copyPrune, atSlot: String(copyPrune.atSlot), toSlot: String(copyPrune.toSlot) },
179
+ copyRestore: { ...copyRestore, atSlot: String(copyRestore.atSlot), toSlot: String(copyRestore.toSlot) },
159
180
  epochSnapshots: {
160
- enabled: epochSnapshotsConfigured(),
181
+ enabled: crawlerOption('epochSnapshots'),
161
182
  source: epochSnapshotSource(),
162
183
  lastEpoch: lastSnapshot?.epoch ?? null,
163
184
  lastSource: lastSnapshot?.source ?? null,
164
185
  lastSlot: lastSnapshot?.snapshotSlot == null ? null : String(lastSnapshot.snapshotSlot),
186
+ accounts: crawlerOption('accountSnapshots'),
187
+ lastAccountEpoch: lastAccounts?.epoch ?? null,
188
+ lastAccountCount: lastAccounts?.accountCount ?? null,
165
189
  },
166
190
  };
167
191
  });
@@ -183,7 +207,7 @@ module.exports = (srv) => {
183
207
  return await (0, backend_request_handler_1.handleRequest)(req, async (db) => {
184
208
  const { fromSlot, toSlot } = await backfillRange(db, data);
185
209
  certificateBackfill = {
186
- status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0,
210
+ status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0, removed: 0,
187
211
  startedAt: new Date().toISOString(), finishedAt: null, error: null,
188
212
  };
189
213
  void (0, certificate_backfill_1.backfillCertificates)({
@@ -229,7 +253,7 @@ module.exports = (srv) => {
229
253
  return await (0, backend_request_handler_1.handleRequest)(req, async (db) => {
230
254
  const { fromSlot, toSlot } = await backfillRange(db, data);
231
255
  transactionBackfill = {
232
- status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, datums: 0, rewritten: 0, skipped: 0,
256
+ status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, inputs: 0, outputs: 0, redeemers: 0, datums: 0, rewritten: 0, skipped: 0,
233
257
  startedAt: new Date().toISOString(), finishedAt: null, error: null,
234
258
  };
235
259
  void (0, transaction_backfill_1.backfillTransactions)({
@@ -292,18 +316,32 @@ module.exports = (srv) => {
292
316
  });
293
317
  return { accepted: true, message: 'Asset-decimals backfill started; poll getStatus().decimalsBackfill.' };
294
318
  });
295
- // backfillAssetRegistry: writes the CIP-26 registry fields of every registered unit. The registry
296
- // is off-chain, so this needs a backend that lists it. Progress is in getStatus().registryBackfill.
319
+ // backfillAssetRegistry: writes the CIP-26 registry fields of every registered unit. The registry is
320
+ // off-chain: it comes from a backend that lists it, or from the entry files of its repository.
297
321
  srv.on('backfillAssetRegistry', async (req) => {
322
+ const data = (req.data ?? {});
323
+ const source = data.source ?? 'koios';
298
324
  if (registryBackfill.status === 'running')
299
325
  return (0, errors_1.rejectInvalid)(req, 'backfillAssetRegistry', 'An asset-registry backfill is already running');
300
- if (!(0, server_1.getCardanoClient)().getTokenRegistryBackend())
301
- return (0, errors_1.rejectInvalid)(req, 'backfillAssetRegistry', 'No backend lists the token registry (needs Koios)');
302
- registryBackfill = { status: 'running', units: 0, processed: 0, filled: 0, failed: 0, startedAt: new Date().toISOString(), finishedAt: null, error: null };
303
- void (0, asset_registry_backfill_1.backfillAssetRegistry)({
304
- client: (0, server_1.getCardanoClient)(), indexer: (0, server_1.getCardanoIndexer)(),
305
- onProgress: (p) => { Object.assign(registryBackfill, p); },
306
- })
326
+ if (source === 'file') {
327
+ if (!data.path)
328
+ return (0, errors_1.rejectMissing)(req, 'backfillAssetRegistry', 'path');
329
+ try {
330
+ await (0, asset_registry_backfill_1.registryEntryFiles)(data.path);
331
+ }
332
+ catch (err) {
333
+ return (0, errors_1.rejectInvalid)(req, 'backfillAssetRegistry', err instanceof Error ? err.message : String(err), 'path');
334
+ }
335
+ }
336
+ else if (!(0, server_1.getCardanoClient)().getTokenRegistryBackend()) {
337
+ return (0, errors_1.rejectInvalid)(req, 'backfillAssetRegistry', 'No backend lists the token registry (needs Koios, or source file)');
338
+ }
339
+ registryBackfill = { ...REGISTRY_IDLE, status: 'running', startedAt: new Date().toISOString(), finishedAt: null, error: null };
340
+ const onProgress = (p) => { Object.assign(registryBackfill, p); };
341
+ const run = source === 'file' && data.path
342
+ ? (0, asset_registry_backfill_1.backfillAssetRegistryFromFiles)({ directory: data.path, onProgress })
343
+ : (0, asset_registry_backfill_1.backfillAssetRegistry)({ client: (0, server_1.getCardanoClient)(), indexer: (0, server_1.getCardanoIndexer)(), onProgress });
344
+ void run
307
345
  .then((r) => { Object.assign(registryBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
308
346
  .catch((err) => {
309
347
  const message = err instanceof Error ? err.message : String(err);
@@ -312,6 +350,114 @@ module.exports = (srv) => {
312
350
  });
313
351
  return { accepted: true, message: 'Asset-registry backfill started; poll getStatus().registryBackfill.' };
314
352
  });
353
+ // backfillOutputDatums: reads transactions again whose outputs hold a datum hash and no inline
354
+ // datum. Needs a backend that serves transactions. Progress is in getStatus().datumBackfill.
355
+ srv.on('backfillOutputDatums', async (req) => {
356
+ if (datumBackfill.status === 'running')
357
+ return (0, errors_1.rejectInvalid)(req, 'backfillOutputDatums', 'An output-datum backfill is already running');
358
+ if (!(0, server_1.getCardanoClient)().supports('getTransaction')) {
359
+ return (0, errors_1.rejectInvalid)(req, 'backfillOutputDatums', 'No configured backend serves transactions. With Ogmios only, run backfillTransactions over the crawled range');
360
+ }
361
+ datumBackfill = { status: 'running', ...NO_DATUM_PROGRESS, startedAt: new Date().toISOString(), finishedAt: null, error: null };
362
+ void (0, output_datum_backfill_1.backfillOutputDatums)({
363
+ client: (0, server_1.getCardanoClient)(),
364
+ onProgress: (p) => { Object.assign(datumBackfill, p); },
365
+ })
366
+ .then((r) => { Object.assign(datumBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
367
+ .catch((err) => {
368
+ const message = err instanceof Error ? err.message : String(err);
369
+ Object.assign(datumBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
370
+ logger.error(`Output-datum backfill failed: ${message}`);
371
+ });
372
+ return { accepted: true, message: 'Output-datum backfill started; poll getStatus().datumBackfill.' };
373
+ });
374
+ // backfillMetadataPositions: writes the chain position to metadata rows that lack it.
375
+ // Needs no backend and runs detached. Progress is in getStatus().metadataBackfill.
376
+ srv.on('backfillMetadataPositions', async (req) => {
377
+ if (metadataBackfill.status === 'running')
378
+ return (0, errors_1.rejectInvalid)(req, 'backfillMetadataPositions', 'A metadata-position backfill is already running');
379
+ metadataBackfill = { status: 'running', atSlot: 0, toSlot: 0, rows: 0, startedAt: new Date().toISOString(), finishedAt: null, error: null };
380
+ void (0, metadata_position_backfill_1.backfillMetadataPositions)({
381
+ onProgress: (p) => { Object.assign(metadataBackfill, p); },
382
+ })
383
+ .then((r) => { Object.assign(metadataBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
384
+ .catch((err) => {
385
+ const message = err instanceof Error ? err.message : String(err);
386
+ Object.assign(metadataBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
387
+ logger.error(`Metadata-position backfill failed: ${message}`);
388
+ });
389
+ return { accepted: true, message: 'Metadata-position backfill started; poll getStatus().metadataBackfill.' };
390
+ });
391
+ // backfillEpochs: rebuilds the epoch rows of the crawled range from the stored blocks.
392
+ // Needs no backend and runs detached.
393
+ srv.on('backfillEpochs', async (req) => {
394
+ if (epochBackfill.status === 'running')
395
+ return (0, errors_1.rejectInvalid)(req, 'backfillEpochs', 'An epoch backfill is already running');
396
+ epochBackfill = { ...IDLE, status: 'running', startedAt: new Date().toISOString(), atEpoch: 0, toEpoch: 0, updated: 0, created: 0 };
397
+ void (0, server_1.getCardanoIndexer)().backfillEpochs((p) => { Object.assign(epochBackfill, p); })
398
+ .then((r) => { Object.assign(epochBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
399
+ .catch((err) => {
400
+ const message = err instanceof Error ? err.message : String(err);
401
+ Object.assign(epochBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
402
+ logger.error(`Epoch backfill failed: ${message}`);
403
+ });
404
+ return { accepted: true, message: 'Epoch backfill started; poll getStatus().epochBackfill.' };
405
+ });
406
+ // Slot range of a walk over input asset copies. Both bounds are required: the caller names what
407
+ // moves. Null after the request was rejected.
408
+ const copyRange = (req, action) => {
409
+ const data = (req.data ?? {});
410
+ if (data.fromSlot == null) {
411
+ (0, errors_1.rejectMissing)(req, action, 'fromSlot');
412
+ return null;
413
+ }
414
+ if (data.toSlot == null) {
415
+ (0, errors_1.rejectMissing)(req, action, 'toSlot');
416
+ return null;
417
+ }
418
+ const range = { fromSlot: Number(data.fromSlot), toSlot: Number(data.toSlot) };
419
+ if (range.fromSlot > range.toSlot) {
420
+ (0, errors_1.rejectInvalid)(req, action, 'fromSlot must not be after toSlot', 'fromSlot');
421
+ return null;
422
+ }
423
+ return data.slotWindow == null ? range : { ...range, slotWindow: Number(data.slotWindow) };
424
+ };
425
+ const copyWalkRunning = () => copyPrune.status === 'running' || copyRestore.status === 'running';
426
+ // pruneInputAssetCopies: moves the inputs of a slot range from asset copies to the output they
427
+ // spent and deletes those copies. Needs no backend and runs detached.
428
+ srv.on('pruneInputAssetCopies', async (req) => {
429
+ const range = copyRange(req, 'pruneInputAssetCopies');
430
+ if (!range)
431
+ return;
432
+ if (copyWalkRunning())
433
+ return (0, errors_1.rejectInvalid)(req, 'pruneInputAssetCopies', 'A prune or restore of input asset copies is already running');
434
+ copyPrune = { ...IDLE, status: 'running', startedAt: new Date().toISOString(), atSlot: 0, toSlot: 0, referenced: 0, kept: 0, deleted: 0 };
435
+ void (0, input_asset_copies_1.pruneInputAssetCopies)({ ...range, onProgress: (p) => { Object.assign(copyPrune, p); } })
436
+ .then((r) => { Object.assign(copyPrune, r, { status: 'done', finishedAt: new Date().toISOString() }); })
437
+ .catch((err) => {
438
+ const message = err instanceof Error ? err.message : String(err);
439
+ Object.assign(copyPrune, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
440
+ logger.error(`Prune of input asset copies failed: ${message}`);
441
+ });
442
+ return { accepted: true, message: 'Prune of input asset copies started; poll getStatus().copyPrune.' };
443
+ });
444
+ // restoreInputAssetCopies: the way back, copies written from the outputs.
445
+ srv.on('restoreInputAssetCopies', async (req) => {
446
+ const range = copyRange(req, 'restoreInputAssetCopies');
447
+ if (!range)
448
+ return;
449
+ if (copyWalkRunning())
450
+ return (0, errors_1.rejectInvalid)(req, 'restoreInputAssetCopies', 'A prune or restore of input asset copies is already running');
451
+ copyRestore = { ...IDLE, status: 'running', startedAt: new Date().toISOString(), atSlot: 0, toSlot: 0, restored: 0, rows: 0 };
452
+ void (0, input_asset_copies_1.restoreInputAssetCopies)({ ...range, onProgress: (p) => { Object.assign(copyRestore, p); } })
453
+ .then((r) => { Object.assign(copyRestore, r, { status: 'done', finishedAt: new Date().toISOString() }); })
454
+ .catch((err) => {
455
+ const message = err instanceof Error ? err.message : String(err);
456
+ Object.assign(copyRestore, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
457
+ logger.error(`Restore of input asset copies failed: ${message}`);
458
+ });
459
+ return { accepted: true, message: 'Restore of input asset copies started; poll getStatus().copyRestore.' };
460
+ });
315
461
  // importUtxoSet: one-off snapshot import that anchors crawler.utxoSet.
316
462
  // Runs detached. Progress is in getStatus().utxoSet.
317
463
  srv.on('importUtxoSet', async (req) => {
@@ -421,7 +567,7 @@ module.exports = (srv) => {
421
567
  srv.on('resumeCrawler', async (req) => {
422
568
  let config;
423
569
  try {
424
- config = (0, server_1.loadCrawlerConfigFromEnv)();
570
+ config = (0, config_1.loadCrawlerConfigFromEnv)();
425
571
  }
426
572
  catch (err) {
427
573
  // A config problem (e.g. enabled without a start block) is the caller's 400.
@@ -3,7 +3,7 @@ using { Blake2b256, Bech32, AssetUnit, ParsedTransaction, TransactionConfirmatio
3
3
 
4
4
  // Read queries for Cardano chain data. Every operation needs an authenticated user;
5
5
  // per-address ownership is not checked (docs/guides/SECURITY_GUIDE.md).
6
- @requires: 'authenticated-user'
6
+ @requires: 'Read'
7
7
  @path: '/odata/v4/cardano'
8
8
  service CardanoODataService @(impl: './cardano-service') {
9
9
 
@@ -51,6 +51,11 @@ service CardanoODataService @(impl: './cardano-service') {
51
51
  @description: 'Projection for per-epoch network ledger figures written by the chain crawler'
52
52
  entity EpochLedgerSnapshots as projection on db.EpochLedgerSnapshots;
53
53
 
54
+ @readonly
55
+ @title : 'Account Epoch Snapshots'
56
+ @description: 'Projection for per-epoch reward account snapshots written by the chain crawler'
57
+ entity AccountEpochSnapshots as projection on db.AccountEpochSnapshots;
58
+
54
59
  @readonly
55
60
  @title : 'Assets'
56
61
  @description: 'Projection for Native-Asset Information'
@@ -79,7 +84,17 @@ service CardanoODataService @(impl: './cardano-service') {
79
84
  @readonly
80
85
  @title : 'Transaction Input Assets'
81
86
  @description: 'Projection for Transaction Input Assets'
82
- entity TransactionInputAssets as projection on db.TransactionInputAssets;
87
+ entity TransactionInputAssets as
88
+ select from db.TransactionInputAssets
89
+ mixin {
90
+ input : Association to TransactionInputs
91
+ on input.txSeq = $projection.input_txSeq
92
+ and input.inputIndex = $projection.input_inputIndex;
93
+ }
94
+ into {
95
+ *,
96
+ input
97
+ };
83
98
 
84
99
  @readonly
85
100
  @title : 'Transaction Output Assets'
@@ -176,10 +191,12 @@ service CardanoODataService @(impl: './cardano-service') {
176
191
  // ---------------------------------------------------------------------------
177
192
  @title : 'Get Network Information'
178
193
  @description: 'Retrieve current network information including network type and genesis hash'
194
+ @odatano.agent: 'read'
179
195
  action GetNetworkInformation() returns NetworkInformation;
180
196
 
181
197
  @title : 'Get Blocks by Block Hash'
182
198
  @description: 'Retrieve block information using the Block Hash'
199
+ @odatano.agent: 'read'
183
200
  action GetBlockByHash(
184
201
  @title: 'Block Hash'
185
202
  @description: 'The unique identifier of the block'
@@ -187,6 +204,7 @@ service CardanoODataService @(impl: './cardano-service') {
187
204
 
188
205
  @title : 'Get Epochs by Epoch Number'
189
206
  @description: 'Retrieve epoch information using the Epoch Number'
207
+ @odatano.agent: 'read'
190
208
  action GetEpochByNumber(
191
209
  @title: 'Epoch Number'
192
210
  @description: 'The sequential number of the epoch'
@@ -195,6 +213,7 @@ service CardanoODataService @(impl: './cardano-service') {
195
213
 
196
214
  @title : 'Get Pools by Pool Id'
197
215
  @description: 'Retrieve pool information using the Pool Id'
216
+ @odatano.agent: 'read'
198
217
  action GetPoolById(
199
218
  @title: 'Pool Id'
200
219
  @description: 'The unique identifier of the stake pool'
@@ -202,6 +221,7 @@ service CardanoODataService @(impl: './cardano-service') {
202
221
 
203
222
  @title : 'Get Dreps by Drep Id'
204
223
  @description: 'Retrieve drep information using the Drep Id'
224
+ @odatano.agent: 'read'
205
225
  action GetDrepById(
206
226
  @title: 'Drep Id'
207
227
  @description: 'The unique identifier of the drep'
@@ -209,6 +229,7 @@ service CardanoODataService @(impl: './cardano-service') {
209
229
 
210
230
  @title : 'Get Asset Info'
211
231
  @description: 'Retrieve native-asset information (supply, mint history, CIP-25 + CIP-26 metadata) by unit. Multi-backend (Blockfrost, Koios). Field availability differs slightly per backend; see entity description.'
232
+ @odatano.agent: 'read'
212
233
  action GetAssetInfo(
213
234
  @title: 'Asset Unit'
214
235
  @description: 'Concatenation of policyId (56 hex) and assetNameHex (0-64 hex; ledger caps asset names at 32 bytes)'
@@ -216,6 +237,7 @@ service CardanoODataService @(impl: './cardano-service') {
216
237
 
217
238
  @title : 'Get Asset Mint/Burn History'
218
239
  @description: 'Retrieve recent mint/burn events for a native asset, newest first. Koios is preferred (provides block timestamps); Blockfrost is the fallback (timestamps null). Always-fresh fetch, UPSERTs entries by (unit, txHash). skip + limit covers at most the newest 100 events; older events are read from the AssetHistory entity with $top/$skip.'
240
+ @odatano.agent: 'read'
219
241
  action GetAssetHistory(
220
242
  @title: 'Asset Unit'
221
243
  @description: 'Concatenation of policyId (56 hex) and assetNameHex (0-64 hex; ledger caps asset names at 32 bytes)'
@@ -231,6 +253,7 @@ service CardanoODataService @(impl: './cardano-service') {
231
253
 
232
254
  @title : 'Get Accounts by Stake Address'
233
255
  @description: 'Retrieve account information using the Bech32 Stake Address'
256
+ @odatano.agent: 'read'
234
257
  action GetAccountByStakeAddress(
235
258
  @title: 'Stake Address'
236
259
  @description: 'The Bech32 encoded stake address'
@@ -238,6 +261,7 @@ service CardanoODataService @(impl: './cardano-service') {
238
261
 
239
262
  @title : 'Get Transactions by Tx Hash'
240
263
  @description: 'Retrieve transaction information using the Transaction Hash'
264
+ @odatano.agent: 'read'
241
265
  action GetTransactionByHash(
242
266
  @title: 'Transaction Hash'
243
267
  @description: 'The unique identifier of the transaction'
@@ -245,6 +269,7 @@ service CardanoODataService @(impl: './cardano-service') {
245
269
 
246
270
  @title : 'Get Transaction Confirmations'
247
271
  @description: 'Number of blocks on top of a transaction, its own block included; 0 while it is not on chain. Uses the crawled chain when the crawler is synced, else the backends.'
272
+ @odatano.agent: 'read'
248
273
  action GetTransactionConfirmations(
249
274
  @title: 'Transaction Hash'
250
275
  @description: 'The unique identifier of the transaction'
@@ -252,6 +277,7 @@ service CardanoODataService @(impl: './cardano-service') {
252
277
 
253
278
  @title : 'Get Transaction Metadata by Tx Hash'
254
279
  @description: 'Retrieve transaction metadata using the Transaction Hash'
280
+ @odatano.agent: 'read'
255
281
  action GetMetadataByTxHash(
256
282
  @title: 'Transaction Hash'
257
283
  @description: 'The unique identifier of the transaction'
@@ -265,8 +291,29 @@ service CardanoODataService @(impl: './cardano-service') {
265
291
  @assert.range: [0, _]
266
292
  skip: Integer) returns many TransactionMetadata;
267
293
 
294
+ @title : 'Get Transaction Metadata by Label'
295
+ @description: 'Stored transaction metadata of one label in chain order, oldest first: the metadata of crawled transactions and of transactions read earlier. No backend is asked. Each row carries txSeq (slot * 65536 + txIndex); read on from a slot with fromSlot, or page with skip.'
296
+ @odatano.agent: 'read'
297
+ action GetMetadataByLabel(
298
+ @title: 'Label'
299
+ @description: 'The metadata label, an unsigned 64-bit integer as string'
300
+ label: String(20),
301
+ @title: 'From Slot'
302
+ @description: 'Only transactions in this slot or later (default 0)'
303
+ @assert.range: [0, _]
304
+ fromSlot: Integer64,
305
+ @title: 'Limit'
306
+ @description: 'Maximum number of rows (default 100, at most 1000)'
307
+ @assert.range: [1, 1000]
308
+ limit: Integer,
309
+ @title: 'Skip'
310
+ @description: 'Number of rows to skip (default 0)'
311
+ @assert.range: [0, _]
312
+ skip: Integer) returns many TransactionMetadata;
313
+
268
314
  @title : 'Get Addresses by Bech32 Address'
269
315
  @description: 'Retrieve address information using the Bech32 Address'
316
+ @odatano.agent: 'read'
270
317
  action GetAddressByBech32(
271
318
  @title: 'Bech32 Address'
272
319
  @description: 'The Bech32 encoded address'
@@ -274,6 +321,7 @@ service CardanoODataService @(impl: './cardano-service') {
274
321
 
275
322
  @title : 'Get UTxOs by Bech32 Address'
276
323
  @description: 'Retrieve UTxO information using the Bech32 Address'
324
+ @odatano.agent: 'read'
277
325
  action GetUTxOsByAddress(
278
326
  @title: 'Bech32 Address'
279
327
  @description: 'The Bech32 encoded address'
@@ -289,6 +337,7 @@ service CardanoODataService @(impl: './cardano-service') {
289
337
 
290
338
  @title : 'Get UTxOs by Payment Credential'
291
339
  @description: 'Retrieve UTxOs across all bech32 addresses sharing the given 28-byte payment credential (key hash or script hash). Useful for protocols that write to multiple bech32 forms of the same script (e.g. Indigo CDPs, Liqwid positions). Served from the crawled UTxO set (crawler.utxoSet active and synced) with outputs read from the node at the tip, else from Koios; throws ProviderUnavailableError when neither is available. Always fresh, no cache check.'
340
+ @odatano.agent: 'read'
292
341
  action GetUTxOsByCredential(
293
342
  @title: 'Payment Credential'
294
343
  @description: '28-byte payment credential hash as 56-char lowercase hex string'
@@ -304,6 +353,7 @@ service CardanoODataService @(impl: './cardano-service') {
304
353
 
305
354
  @title : 'Get Assets by Bech32 Address'
306
355
  @description: 'Retrieve asset information using the Bech32 Address'
356
+ @odatano.agent: 'read'
307
357
  action GetAssetsByAddress(
308
358
  @title: 'Bech32 Address'
309
359
  @description: 'The Bech32 encoded address'
@@ -319,6 +369,7 @@ service CardanoODataService @(impl: './cardano-service') {
319
369
 
320
370
  @title : 'Get latest Transactions by Bech32 Address'
321
371
  @description: 'Retrieve the latest transactions of the Bech32 Address, newest first. skip + limit covers at most the newest 100 transactions.'
372
+ @odatano.agent: 'read'
322
373
  action GetLatestTransactionsByAddress(
323
374
  @title: 'Bech32 Address'
324
375
  @description: 'The Bech32 encoded address'
@@ -330,22 +381,34 @@ service CardanoODataService @(impl: './cardano-service') {
330
381
  @title: 'Skip'
331
382
  @description: 'Number of rows to skip (default 0)'
332
383
  @assert.range: [0, 99]
333
- skip: Integer) returns many AddressTransactions;
384
+ skip: Integer,
385
+ @title: 'Since Time'
386
+ @description: 'Only transactions with a block time after this unix time in seconds'
387
+ @assert.range: [0, _]
388
+ sinceTime: Integer64,
389
+ @title: 'Wait (ms)'
390
+ @description: 'With sinceTime: when no newer transaction is known, read again every 5 seconds until one appears or this time is up (at most 30000)'
391
+ @assert.range: [0, 30000]
392
+ waitMs: Integer) returns many AddressTransactions;
334
393
 
335
394
  @title : 'Get Latest Block'
336
395
  @description: 'Retrieve the latest block information'
396
+ @odatano.agent: 'read'
337
397
  action GetLatestBlock() returns Blocks;
338
398
 
339
399
  @title : 'Get Latest Epoch'
340
400
  @description: 'Retrieve the latest epoch information'
401
+ @odatano.agent: 'read'
341
402
  action GetLatestEpoch() returns Epochs;
342
403
 
343
404
  @title : 'Get Ledger Protocol Parameters'
344
405
  @description: 'Retrieve the current ledger protocol parameters'
406
+ @odatano.agent: 'read'
345
407
  action GetLedgerProtocolParameters() returns LedgerProtocolParameters;
346
408
 
347
409
  @title : 'Parse Transaction CBOR'
348
410
  @description: 'Parse hex-encoded transaction CBOR (signed or unsigned) into structured fields. Pure function, no network call, no DB write.'
411
+ @odatano.agent: 'read'
349
412
  action ParseTransactionCbor(
350
413
  @title: 'Transaction CBOR'
351
414
  @description: 'Hex-encoded transaction CBOR; signed or unsigned. Capped at 128 KiB of hex.'
@@ -353,6 +416,7 @@ service CardanoODataService @(impl: './cardano-service') {
353
416
 
354
417
  @title : 'Decode Plutus Data'
355
418
  @description: 'Decode PlutusData CBOR hex (an inline datum, a witness datum, a redeemer) into the JSON the build actions accept as outputDatumJson (DetailedSchema: constructor/fields, int, bytes, list, map). Integers beyond 2^53 are decimal strings. Pure function, no network call, no DB write.'
419
+ @odatano.agent: 'read'
356
420
  action DecodePlutusData(
357
421
  @title: 'PlutusData CBOR'
358
422
  @description: 'Hex-encoded PlutusData CBOR. Capped at 128 KiB of hex.'