@odatano/core 2.0.0-rc.19 → 2.0.0-rc.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +1 -5
  2. package/@cds-models/CardanoIndexerService/index.d.ts +51 -2
  3. package/@cds-models/CardanoIndexerService/index.js +7 -0
  4. package/package.json +1 -1
  5. package/src/index.d.ts +4 -10
  6. package/src/index.js +6 -16
  7. package/src/plugin.js +11 -27
  8. package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
  9. package/srv/blockchain/backends/blockfrost-backend.js +39 -150
  10. package/srv/blockchain/backends/cardano-backend.d.ts +53 -171
  11. package/srv/blockchain/backends/cardano-backend.js +1 -5
  12. package/srv/blockchain/backends/koios-backend.d.ts +26 -71
  13. package/srv/blockchain/backends/koios-backend.js +50 -132
  14. package/srv/blockchain/backends/ogmios-backend.d.ts +43 -124
  15. package/srv/blockchain/backends/ogmios-backend.js +71 -179
  16. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +12 -57
  17. package/srv/blockchain/backends/ogmios-frame-guard.js +27 -66
  18. package/srv/blockchain/cardano-client.d.ts +43 -216
  19. package/srv/blockchain/cardano-client.js +49 -234
  20. package/srv/blockchain/cardano-indexer.d.ts +79 -357
  21. package/srv/blockchain/cardano-indexer.js +98 -406
  22. package/srv/blockchain/cardano-tx-builder.d.ts +19 -84
  23. package/srv/blockchain/cardano-tx-builder.js +21 -107
  24. package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
  25. package/srv/blockchain/crawler/certificate-backfill.js +150 -0
  26. package/srv/blockchain/crawler/crawler.d.ts +41 -145
  27. package/srv/blockchain/crawler/crawler.js +57 -172
  28. package/srv/blockchain/crawler/hooks.d.ts +3 -14
  29. package/srv/blockchain/crawler/index.d.ts +2 -6
  30. package/srv/blockchain/crawler/index.js +4 -9
  31. package/srv/blockchain/crawler/sync-state.d.ts +17 -39
  32. package/srv/blockchain/crawler/sync-state.js +23 -55
  33. package/srv/blockchain/crawler/utxo-set-import.d.ts +5 -22
  34. package/srv/blockchain/crawler/utxo-set-import.js +8 -28
  35. package/srv/blockchain/ledger-state.d.ts +3 -12
  36. package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
  37. package/srv/blockchain/signing/cose-verifier.js +6 -12
  38. package/srv/blockchain/signing/external-signer.d.ts +16 -113
  39. package/srv/blockchain/signing/external-signer.js +19 -122
  40. package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
  41. package/srv/blockchain/signing/hsm-signer.js +23 -63
  42. package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
  43. package/srv/blockchain/signing/signature-verifier.js +13 -54
  44. package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
  45. package/srv/blockchain/signing/submission-finalizer.js +16 -48
  46. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +65 -174
  47. package/srv/blockchain/transaction-building/buildooor-tx.js +107 -266
  48. package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
  49. package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
  50. package/srv/blockchain/wallet-worker/build-request.js +9 -22
  51. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +12 -35
  52. package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -32
  53. package/srv/blockchain/wallet-worker/index.js +2 -8
  54. package/srv/blockchain/wallet-worker/job-store.d.ts +33 -111
  55. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  56. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
  57. package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
  58. package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
  59. package/srv/blockchain/wallet-worker/signers.js +3 -8
  60. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
  61. package/srv/blockchain/wallet-worker/wallet-worker.js +34 -90
  62. package/srv/cardano-agent-service.cds +1 -5
  63. package/srv/cardano-agent-service.js +3 -7
  64. package/srv/cardano-indexer-service.cds +32 -4
  65. package/srv/cardano-indexer-service.js +83 -15
  66. package/srv/cardano-service.js +36 -98
  67. package/srv/cardano-sign-service.cds +1 -1
  68. package/srv/cardano-sign-service.js +55 -173
  69. package/srv/cardano-tx-service.cds +1 -1
  70. package/srv/cardano-tx-service.js +54 -174
  71. package/srv/cardano-worker-service.js +7 -15
  72. package/srv/server.d.ts +27 -86
  73. package/srv/server.js +52 -148
  74. package/srv/utils/agent-grants-config.d.ts +11 -50
  75. package/srv/utils/agent-grants-config.js +12 -45
  76. package/srv/utils/agent-grants.d.ts +34 -123
  77. package/srv/utils/agent-grants.js +57 -156
  78. package/srv/utils/agent-token-auth.d.ts +2 -5
  79. package/srv/utils/agent-token-auth.js +2 -5
  80. package/srv/utils/backend-request-handler.d.ts +2 -16
  81. package/srv/utils/backend-request-handler.js +3 -18
  82. package/srv/utils/collections.d.ts +4 -8
  83. package/srv/utils/collections.js +4 -8
  84. package/srv/utils/const.d.ts +19 -68
  85. package/srv/utils/const.js +20 -69
  86. package/srv/utils/crypto.d.ts +3 -12
  87. package/srv/utils/crypto.js +5 -18
  88. package/srv/utils/db-indexes.d.ts +2 -7
  89. package/srv/utils/db-indexes.js +7 -34
  90. package/srv/utils/db-sanitize.d.ts +5 -18
  91. package/srv/utils/db-sanitize.js +6 -19
  92. package/srv/utils/error-codes.d.ts +18 -73
  93. package/srv/utils/error-codes.js +17 -70
  94. package/srv/utils/errors.d.ts +29 -191
  95. package/srv/utils/errors.js +44 -229
  96. package/srv/utils/liveness.d.ts +2 -9
  97. package/srv/utils/liveness.js +3 -11
  98. package/srv/utils/mappers.d.ts +50 -298
  99. package/srv/utils/mappers.js +80 -386
  100. package/srv/utils/network-context.js +2 -11
  101. package/srv/utils/pg-order-nulls.js +4 -23
  102. package/srv/utils/plutus-placeholders.d.ts +6 -18
  103. package/srv/utils/plutus-placeholders.js +6 -20
  104. package/srv/utils/rate-limiter.d.ts +6 -17
  105. package/srv/utils/rate-limiter.js +5 -15
  106. package/srv/utils/service-events.d.ts +2 -22
  107. package/srv/utils/service-events.js +3 -23
  108. package/srv/utils/signing-helper.d.ts +3 -18
  109. package/srv/utils/signing-helper.js +10 -32
  110. package/srv/utils/tx-build-helper.d.ts +18 -92
  111. package/srv/utils/tx-build-helper.js +32 -123
  112. package/srv/utils/tx-request-parsers.d.ts +7 -26
  113. package/srv/utils/tx-request-parsers.js +7 -26
  114. package/srv/utils/tx-utils.d.ts +4 -23
  115. package/srv/utils/tx-utils.js +12 -41
  116. package/srv/utils/types.d.ts +67 -206
  117. package/srv/utils/types.js +2 -6
  118. package/srv/utils/validators.d.ts +19 -89
  119. package/srv/utils/validators.js +31 -138
@@ -13,9 +13,7 @@ const ogmios_backend_1 = require("./backends/ogmios-backend");
13
13
  const blockfrost_backend_1 = require("./backends/blockfrost-backend");
14
14
  const koios_backend_1 = require("./backends/koios-backend");
15
15
  const logger = cds_1.default.log('CardanoClient');
16
- /**
17
- * Method routing configuration - defines which backend type to prefer for each method
18
- */
16
+ /** Which backend type to prefer per method. */
19
17
  const METHOD_ROUTING = {
20
18
  getTransaction: { preferLive: false },
21
19
  getAddress: { preferLive: true },
@@ -37,12 +35,8 @@ const METHOD_ROUTING = {
37
35
  submitTransaction: { preferLive: true },
38
36
  };
39
37
  /**
40
- * CardanoClient - Smart Multi-backend Cardano Client
41
- *
42
- * Routes requests to appropriate backends:
43
- * - Live/State queries → Ogmios (if available)
44
- * - Historical queries → Blockfrost/Koios (if available)
45
- * - Automatic fallback between backends
38
+ * Multi-backend Cardano client: live/state queries prefer Ogmios, historical queries prefer
39
+ * Blockfrost/Koios, with automatic fallback between them.
46
40
  */
47
41
  class CardanoClient {
48
42
  config;
@@ -62,11 +56,7 @@ class CardanoClient {
62
56
  txCoalescer = new request_coalescer_1.RequestCoalescer();
63
57
  addrCoalescer = new request_coalescer_1.RequestCoalescer();
64
58
  credCoalescer = new request_coalescer_1.RequestCoalescer();
65
- /**
66
- * Constructor for CardanoClient
67
- * @param liveBackend - Optional backend for live/state queries (typically Ogmios)
68
- * @param historicalBackends - Optional backends for historical queries (typically Blockfrost/Koios)
69
- */
59
+ /** Builds the configured backends; throws ConfigError when none is configured. */
70
60
  constructor(clientConfig) {
71
61
  this.network = clientConfig.network;
72
62
  const backends = clientConfig.backends;
@@ -83,9 +73,7 @@ class CardanoClient {
83
73
  throw new errors_1.ConfigError('No valid backends configured for CardanoClient');
84
74
  }
85
75
  this.circuitBreaker = new circuit_breaker_1.CircuitBreakerManager(clientConfig.circuitBreaker);
86
- // Wire the configured cache TTL into the field the indexer actually reads.
87
- // Previously max_age_ms stayed hardcoded at 60s and indexTtlMs was dead — the
88
- // documented/configurable 1h default never took effect.
76
+ // indexTtlMs is the cache TTL the indexer reads via max_age_ms
89
77
  if (Number.isFinite(clientConfig.indexTtlMs) && clientConfig.indexTtlMs > 0) {
90
78
  this.max_age_ms = clientConfig.indexTtlMs;
91
79
  }
@@ -101,16 +89,13 @@ class CardanoClient {
101
89
  return names;
102
90
  }
103
91
  /**
104
- * Ensure backends are initialized.
105
- * A REJECTED init promise is cleared so the next request retries — previously
106
- * a transient startup failure (e.g. Ogmios briefly down) left the client
107
- * permanently broken until process restart.
108
- * @returns {Promise<void>}
92
+ * Ensure backends are initialized. A rejected init promise is cleared so the next request
93
+ * retries instead of leaving the client permanently broken.
109
94
  */
110
95
  async ensureInitialized() {
111
96
  if (this.initialized)
112
97
  return;
113
- // Use nullish coalescing assignment for atomic operation to prevent race conditions
98
+ // ??= keeps concurrent callers on one init promise
114
99
  this.initPromise ??= this.initBackends().catch((err) => {
115
100
  this.initPromise = null;
116
101
  throw err;
@@ -118,10 +103,8 @@ class CardanoClient {
118
103
  await this.initPromise;
119
104
  }
120
105
  /**
121
- * Transient (retryable) init failures: a backend momentarily unreachable at
122
- * startup — e.g. Ogmios's /health response cut short while the node processes
123
- * a freshly-arrived block ("Premature close"), or the socket still coming up
124
- * (ECONNREFUSED). Config/validation errors are NOT transient.
106
+ * Transient (retryable) init failures: a backend momentarily unreachable at startup
107
+ * (connection refused/reset, a cut-short health response). Config/validation errors are not.
125
108
  */
126
109
  static isTransientInitError(err) {
127
110
  const e = err;
@@ -132,12 +115,8 @@ class CardanoClient {
132
115
  return /premature close|socket hang up|econnreset|econnrefused|etimedout|timeout|fetch failed|terminated|other side closed/.test(msg);
133
116
  }
134
117
  /**
135
- * Init a backend, retrying brief transient failures. Deliberately SMALL: the
136
- * integration suites bootstrap under a 20s cds.test() hook, so total retry
137
- * time must stay well under it (≤3 attempts × 4s init-timeout + 1s backoff
138
- * ≈ 14s worst case; in practice "Premature close" returns sub-second). With
139
- * the node at tip these failures are momentary block-processing blips, so a
140
- * couple of quick retries ride over them; a sustained outage still fails fast.
118
+ * Init a backend, retrying brief transient failures. Kept small (3 attempts, 1 s backoff) so
119
+ * a sustained outage still fails fast and the total stays under the test bootstrap hook.
141
120
  */
142
121
  async initBackendWithRetry(backend) {
143
122
  const maxAttempts = 3;
@@ -155,12 +134,8 @@ class CardanoClient {
155
134
  }
156
135
  }
157
136
  /**
158
- * Initialize all backends from configuration.
159
- * Backends that fail to initialize are KEPT (previously removed permanently)
160
- * and tracked in `uninitializedBackends` — the request loops retry their
161
- * init lazily, so a backend that comes back online recovers without a
162
- * process restart. The circuit breaker bounds the retry cost.
163
- * @returns {Promise<void>}
137
+ * Initialize all backends. Backends whose init fails stay in rotation, tracked in
138
+ * `uninitializedBackends`, and are retried lazily per request (bounded by the circuit breaker).
164
139
  */
165
140
  async initBackends() {
166
141
  const initErrors = [];
@@ -220,13 +195,7 @@ class CardanoClient {
220
195
  return false;
221
196
  }
222
197
  }
223
- /**
224
- * Wrap a promise with a timeout
225
- * @param promise - the promise to wrap
226
- * @param ms - timeout in milliseconds
227
- * @param backendName - name of the backend (for error context)
228
- * @returns {Promise<T>} the result of the promise or a timeout error
229
- */
198
+ /** Wrap a promise with a timeout that rejects with ProviderUnavailableError. */
230
199
  withTimeout(promise, ms, backendName) {
231
200
  let timeoutId;
232
201
  const timeoutPromise = new Promise((_, reject) => {
@@ -236,22 +205,15 @@ class CardanoClient {
236
205
  clearTimeout(timeoutId);
237
206
  });
238
207
  }
239
- /**
240
- * Get timeout for specific backend
241
- * @param backend CardanoBackend instance
242
- * @returns {number} timeout in milliseconds
243
- */
208
+ /** Per-backend timeout: Koios gets the fallback timeout, everything else the primary one. */
244
209
  getTimeoutForBackend(backend) {
245
210
  if (backend.name === 'koios')
246
211
  return this.config.fallbackTimeoutMs;
247
212
  return this.config.primaryTimeoutMs;
248
213
  }
249
214
  /**
250
- * Run a single-backend call with the same resilience contract as
251
- * executeWithPriority: circuit-breaker gate, timeout, success/failure
252
- * recording (4xx exempt). For the paths that cannot fail over (Koios-only,
253
- * Ogmios-only, batch-capable loops) — these previously bypassed timeout AND
254
- * breaker entirely, so a hanging socket blocked the caller indefinitely.
215
+ * Single-backend call with the executeWithPriority resilience contract (breaker gate, timeout,
216
+ * success/failure recording, 4xx exempt) for paths that cannot fail over.
255
217
  */
256
218
  async callWithResilience(backend, fn) {
257
219
  if (!this.circuitBreaker.shouldAttempt(backend.name)) {
@@ -275,12 +237,7 @@ class CardanoClient {
275
237
  throw backendError;
276
238
  }
277
239
  }
278
- /**
279
- * Execute with priority-based backend selection and automatic fallback
280
- * @param fn function to execute on backend
281
- * @param preferLive whether to prefer live backend over historical
282
- * @returns {Promise<T>} result from backend
283
- */
240
+ /** Execute on backends in preference order (live vs historical) with automatic fallback. */
284
241
  async executeWithPriority(fn, preferLive, methodName) {
285
242
  await this.ensureInitialized();
286
243
  const errors = [];
@@ -317,10 +274,8 @@ class CardanoClient {
317
274
  catch (err) {
318
275
  const backendError = (0, errors_1.normalizeBackendError)(err, backend.name);
319
276
  errors.push(backendError);
320
- // 4xx are definitive verdicts from a HEALTHY backend (bad input, not found,
321
- // conflict, rate limit) — only 5xx/timeouts/transport errors indicate backend
322
- // health and may open the circuit. Counting client errors opened the breaker
323
- // on user mistakes and took working backends out of rotation.
277
+ // 4xx are definitive verdicts from a healthy backend and must not open the circuit;
278
+ // only 5xx/timeouts/transport errors indicate backend health.
324
279
  const isClientError = backendError.statusCode >= 400 && backendError.statusCode < 500;
325
280
  if (!isClientError) {
326
281
  this.circuitBreaker.recordFailure(backend.name);
@@ -331,46 +286,25 @@ class CardanoClient {
331
286
  }
332
287
  throw new errors_1.AllBackendsFailedError(errors);
333
288
  }
334
- /**
335
- * Route method call to appropriate backend based on method routing configuration
336
- * @param methodName name of the method being called
337
- * @param fn function to execute on backend
338
- * @returns {Promise<T>} result from backend
339
- */
289
+ /** Route a call by METHOD_ROUTING (default: historical first). */
340
290
  route(methodName, fn) {
341
291
  const config = METHOD_ROUTING[methodName] ?? { preferLive: false };
342
292
  return this.executeWithPriority(fn, config.preferLive, methodName);
343
293
  }
344
- /**
345
- * Get transaction by hash with fallback between backends
346
- * @param txHash transaction hash (hex)
347
- * @returns {Promise<Transaction>} transaction data
348
- */
294
+ /** Transaction by hash (coalesced across concurrent callers). */
349
295
  getTransaction(txHash) {
350
296
  return this.txCoalescer.get(txHash, () => this.route('getTransaction', b => b.getTransaction(txHash)));
351
297
  }
352
- /**
353
- * Get address by bech32 address with fallback between backends
354
- * @param address bech32 address
355
- * @returns {Promise<Address>} address data
356
- */
298
+ /** Address data (coalesced across concurrent callers). */
357
299
  getAddress(address) {
358
300
  return this.addrCoalescer.get(address, () => this.route('getAddress', b => b.getAddress(address)));
359
301
  }
360
- /**
361
- * Get address UTxOs with fallback between backends
362
- * @param address bech32 address
363
- * @returns {Promise<UTxO[]>} list of UTxOs
364
- */
365
302
  getAddressUtxos(address) {
366
303
  return this.route('getAddressUtxos', b => b.getAddressUtxos(address));
367
304
  }
368
305
  /**
369
- * Get UTxOs by 28-byte payment credential. Koios-only — bypasses generic
370
- * failover because no other backend exposes a credential-keyed UTxO endpoint.
371
- * Throws ProviderUnavailableError if Koios is not configured.
372
- * @param credHash 28-byte payment credential as 56-char lowercase hex
373
- * @returns {Promise<UTxO[]>} list of UTxOs across all bech32 forms sharing the credential
306
+ * UTxOs by 28-byte payment credential (56-char hex), across all bech32 forms sharing it.
307
+ * Koios-only: no other backend has a credential-keyed endpoint, so this throws without Koios.
374
308
  */
375
309
  getCredentialUtxos(credHash) {
376
310
  const candidates = [this.liveBackend, ...this.historicalBackends];
@@ -380,85 +314,37 @@ class CardanoClient {
380
314
  }
381
315
  return this.credCoalescer.get(credHash, () => this.callWithResilience(koios, () => koios.getCredentialUtxos(credHash)));
382
316
  }
383
- /**
384
- * Get address transactions with fallback between backends
385
- * @param address bech32 address
386
- * @returns {Promise<Transaction[]>} list of transactions for this address
387
- */
388
317
  getAddressTransactions(address, limit) {
389
318
  return this.route('getAddressTransactions', b => b.getAddressTransactions(address, limit));
390
319
  }
391
- /**
392
- * Get network information with fallback between backends
393
- * @returns {Promise<Network>} network information
394
- */
395
320
  getNetworkInformation() {
396
321
  return this.route('getNetworkInformation', b => b.getNetworkInformation());
397
322
  }
398
- /**
399
- * Get transaction metadata with fallback between backends
400
- * @param tx_hash transaction hash (hex)
401
- * @returns {Promise<MetadataLabelTx[]>} transaction metadata
402
- */
403
323
  getTransactionMetadata(tx_hash) {
404
324
  return this.route('getTransactionMetadata', b => b.getTransactionMetadata(tx_hash));
405
325
  }
406
- /**
407
- * Get block data with fallback between backends
408
- * @param block_hash block hash (hex)
409
- * @returns {Promise<BlockData>} block data
410
- */
411
326
  getBlock(block_hash) {
412
327
  return this.route('getBlock', b => b.getBlock(block_hash));
413
328
  }
414
- /**
415
- * Get epoch data with fallback between backends
416
- * @param epochNumber epoch number
417
- * @returns {Promise<EpochData>} epoch data
418
- */
419
329
  getEpoch(epochNumber) {
420
330
  return this.route('getEpoch', b => b.getEpoch(epochNumber));
421
331
  }
422
- /**
423
- * Get Pool data with fallback between backends
424
- * @param poolId pool id
425
- * @returns {Promise<PoolData>} pool data
426
- */
427
332
  getPool(poolId) {
428
333
  return this.route('getPool', b => b.getPool(poolId));
429
334
  }
430
- /**
431
- * Get drep data with fallback between backends
432
- * @param drepId drep id
433
- * @returns {Promise<DrepData>} drep data
434
- */
435
335
  getDrep(drepId) {
436
336
  return this.route('getDrep', b => b.getDrep(drepId));
437
337
  }
438
- /**
439
- * Get account data with fallback between backends
440
- * @param stakeAddress stake address
441
- * @returns {Promise<AccountData>} account data
442
- */
443
338
  getAccount(stakeAddress) {
444
339
  return this.route('getAccount', b => b.getAccount(stakeAddress));
445
340
  }
446
- /**
447
- * Get asset info (supply, mint history, CIP-25 + CIP-26 metadata) with fallback.
448
- * Both Blockfrost and Koios implement; Ogmios throws "not supported".
449
- * @param unit policyId + assetNameHex (concatenated hex)
450
- * @returns {Promise<AssetInfo>} canonical asset info
451
- */
341
+ /** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
452
342
  getAssetInfo(unit) {
453
343
  return this.route('getAssetInfo', b => b.getAssetInfo(unit));
454
344
  }
455
345
  /**
456
- * Get latest mint/burn events for an asset. Prefers Koios because it provides
457
- * block timestamps; Blockfrost is the fallback (timestamps left null).
458
- * Ogmios doesn't implement — fallback skips it via the optional method check.
459
- * @param unit policyId + assetNameHex (concatenated hex)
460
- * @param limit max number of events (default 100)
461
- * @returns {Promise<AssetHistoryEntry[]>} list of mint/burn events (most recent first)
346
+ * Latest mint/burn events for an asset, most recent first. Prefers Koios (block timestamps);
347
+ * Blockfrost is the fallback with timestamps left null.
462
348
  */
463
349
  getAssetHistory(unit, limit = 100) {
464
350
  const candidates = [...this.historicalBackends, this.liveBackend];
@@ -475,15 +361,10 @@ class CardanoClient {
475
361
  // Batch Methods (N+1 Optimization)
476
362
  //-----------------------------------------------------------------------------
477
363
  /**
478
- * Get transaction hashes for an address (lightweight — no full tx details).
479
- * Uses getAddressTransactionHashes() if backend supports it, otherwise
480
- * falls back to getAddressTransactions() and extracts hashes.
481
- * @param address bech32 address
482
- * @param limit maximum number of hashes
483
- * @returns {Promise<string[]>} list of transaction hashes
364
+ * Transaction hashes for an address; falls back to a full getAddressTransactions when no
365
+ * backend supports the lightweight listing.
484
366
  */
485
367
  async getAddressTransactionHashes(address, limit) {
486
- // Try backends with getAddressTransactionHashes support
487
368
  const allBackends = this.getOrderedBackends();
488
369
  for (const backend of allBackends) {
489
370
  if (backend.getAddressTransactionHashes) {
@@ -499,15 +380,8 @@ class CardanoClient {
499
380
  const txs = await this.getAddressTransactions(address, limit);
500
381
  return txs.map(tx => tx.hash);
501
382
  }
502
- /**
503
- * Batch fetch multiple transactions by hash.
504
- * Uses getTransactionsBatch() if backend supports it, otherwise
505
- * falls back to individual getTransaction() calls (still coalesced).
506
- * @param txHashes array of transaction hashes
507
- * @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
508
- */
383
+ /** Batch fetch transactions by hash; falls back to individual coalesced getTransaction calls. */
509
384
  async getTransactionsBatch(txHashes) {
510
- // Try backends with batch support
511
385
  const allBackends = this.getOrderedBackends();
512
386
  for (const backend of allBackends) {
513
387
  if (backend.getTransactionsBatch) {
@@ -523,11 +397,7 @@ class CardanoClient {
523
397
  const entries = await Promise.all(txHashes.map(h => this.getTransaction(h).then(tx => [h, tx])));
524
398
  return new Map(entries);
525
399
  }
526
- /**
527
- * Backends in historical-first order. Used by the batch methods — both
528
- * always prefer historical data, so the former preferLive parameter was a
529
- * dead branch.
530
- */
400
+ /** Backends in historical-first order, for the batch methods. */
531
401
  getOrderedBackends() {
532
402
  const backends = [...this.historicalBackends];
533
403
  if (this.liveBackend)
@@ -535,11 +405,8 @@ class CardanoClient {
535
405
  return backends;
536
406
  }
537
407
  /**
538
- * Get a backend that supports streamed chain-synchronization (Ogmios), or null.
539
- * The crawler's primary, reorg-aware source. Checks the live backend first.
540
- * Backends whose init() failed are skipped — the crawler uses these instances
541
- * DIRECTLY (outside executeWithPriority's lazy-retry/breaker), so handing out an
542
- * uninitialized backend would wedge it.
408
+ * A backend that supports streamed chain-sync (Ogmios), or null. Backends whose init failed
409
+ * are skipped: the crawler uses these instances directly, outside the lazy-retry/breaker path.
543
410
  */
544
411
  getChainSyncBackend() {
545
412
  const candidates = [this.liveBackend, ...this.historicalBackends];
@@ -550,12 +417,8 @@ class CardanoClient {
550
417
  return null;
551
418
  }
552
419
  /**
553
- * getChainSyncBackend(), but retrying the startup init of a chain-sync-capable backend
554
- * that failed it. The crawler polls this while it crawls on pagination only because no
555
- * chain-sync source was usable when it started: on a box where the node and ODATANO
556
- * restart together, the node's chunk validation and ledger replay routinely outlast
557
- * ODATANO's startup, so Ogmios refuses the init once and is healthy minutes later.
558
- * Without this the crawler would stay on pagination for the rest of the process.
420
+ * getChainSyncBackend(), retrying a failed startup init. Polled by the crawler while it runs
421
+ * on pagination because no chain-sync source was usable when it started.
559
422
  */
560
423
  async recoverChainSyncBackend() {
561
424
  const candidates = [this.liveBackend, ...this.historicalBackends];
@@ -577,10 +440,8 @@ class CardanoClient {
577
440
  return null;
578
441
  }
579
442
  /**
580
- * Get a backend that can enumerate the full pool/DRep set (Koios), or null. Used by the
581
- * crawler's epoch-boundary snapshots; without one they stay off rather than degrade into
582
- * thousands of single requests (see EnumeratingBackend).
583
- * Skips backends whose init() failed (see getChainSyncBackend).
443
+ * A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
444
+ * snapshots stay off instead of degrading into thousands of single requests.
584
445
  */
585
446
  getEnumeratingBackend() {
586
447
  const candidates = [...this.historicalBackends, this.liveBackend];
@@ -591,13 +452,8 @@ class CardanoClient {
591
452
  return null;
592
453
  }
593
454
  /**
594
- * Get a backend that can be walked forward by pagination (Blockfrost/Koios), or null.
595
- * The crawler's fallback source when no Ogmios chain-sync is available.
596
- * Skips backends whose init() failed (see getChainSyncBackend).
597
- *
598
- * Koios is preferred over Blockfrost for bulk block-crawling: Koios batches 100 txs
599
- * per POST /tx_info, while Blockfrost has no batch endpoint (~3 HTTP calls per tx) —
600
- * roughly a 40x difference in request volume per crawled block.
455
+ * A backend that can be walked forward by pagination (Blockfrost/Koios), or null. Koios is
456
+ * preferred: it batches 100 txs per call, Blockfrost needs ~3 calls per tx.
601
457
  */
602
458
  getPaginatingBackend() {
603
459
  const usable = this.historicalBackends.filter((b) => !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isPaginatingBackend)(b));
@@ -611,18 +467,13 @@ class CardanoClient {
611
467
  }
612
468
  return null;
613
469
  }
614
- /**
615
- * Get protocol parameters with caching (5 minute TTL)
616
- * Protocol parameters rarely change (once per epoch at most), so caching improves performance
617
- * @returns {Promise<LedgerProtocolParameters>} protocol parameters
618
- */
470
+ /** Protocol parameters with a 5-minute in-memory cache and coalesced refresh. */
619
471
  async getProtocolParameters() {
620
472
  const now = Date.now();
621
473
  if (this.protocolParamsCache && (now - this.protocolParamsCache.fetchedAt) < CardanoClient.PROTOCOL_PARAMS_TTL_MS) {
622
474
  logger.debug('Returning cached protocol parameters');
623
475
  return this.protocolParamsCache.data;
624
476
  }
625
- // Promise coalescing: deduplicate concurrent requests during cache miss
626
477
  if (!this.protocolParamsFetchPromise) {
627
478
  logger.debug('Fetching fresh protocol parameters');
628
479
  this.protocolParamsFetchPromise = this.route('getProtocolParameters', b => b.getProtocolParameters())
@@ -638,12 +489,9 @@ class CardanoClient {
638
489
  }
639
490
  return this.protocolParamsFetchPromise;
640
491
  }
641
- /**
642
- * Shutdown all backends (for cleanup in tests)
643
- */
492
+ /** Shut down all backends. */
644
493
  async shutdown() {
645
494
  logger.info('Shutting down CardanoClient backends...');
646
- // Shutdown live backend if it has a shutdown method
647
495
  if (this.liveBackend && 'shutdown' in this.liveBackend && typeof this.liveBackend.shutdown === 'function') {
648
496
  try {
649
497
  await this.liveBackend.shutdown();
@@ -653,7 +501,6 @@ class CardanoClient {
653
501
  logger.error(`Error shutting down live backend ${this.liveBackend.name}: ${err}`);
654
502
  }
655
503
  }
656
- // Shutdown historical backends
657
504
  for (const backend of this.historicalBackends) {
658
505
  if ('shutdown' in backend && typeof backend.shutdown === 'function') {
659
506
  try {
@@ -669,69 +516,37 @@ class CardanoClient {
669
516
  this.initPromise = null;
670
517
  logger.info('CardanoClient shutdown complete');
671
518
  }
672
- /**
673
- * Get latest block data with fallback between backends
674
- * @returns {Promise<BlockData>} latest block data
675
- */
676
519
  getLatestBlock() {
677
520
  return this.route('getLatestBlock', b => b.getLatestBlock());
678
521
  }
679
- /**
680
- * Get latest epoch data with fallback between backends
681
- * @returns {Promise<EpochData>} latest epoch data
682
- */
683
522
  getLatestEpoch() {
684
523
  return this.route('getLatestEpoch', b => b.getLatestEpoch());
685
524
  }
686
- /**
687
- * Get the current chain slot with fallback between backends.
688
- * @returns {Promise<number>} current chain slot
689
- */
690
525
  getCurrentSlot() {
691
526
  return this.route('getCurrentSlot', b => b.getCurrentSlot());
692
527
  }
693
- /**
694
- * Check whether a UTxO is still unspent with fallback between backends.
695
- * @param txHash 64-char lowercase hex transaction hash
696
- * @param outputIndex non-negative integer output index
697
- * @returns {Promise<boolean>} true iff the UTxO exists and is unspent
698
- */
528
+ /** True iff the UTxO exists and is unspent. */
699
529
  isUtxoUnspent(txHash, outputIndex) {
700
530
  return this.route('isUtxoUnspent', b => b.isUtxoUnspent(txHash, outputIndex));
701
531
  }
702
532
  /**
703
- * Submit transaction with fallback between backends
704
- * @param signedTxCbor signed transaction in CBOR hex format
705
- * @returns {Promise<string>} transaction hash
706
- *
707
- * NOTE on failover semantics: when the preferred backend ACCEPTS the tx but
708
- * its response is lost (timeout), the failover resubmits on the next backend,
709
- * which may answer 409 "already submitted". Callers should treat a
710
- * TransactionAlreadySubmittedError after a submit attempt as success — the
711
- * transaction IS in the mempool.
533
+ * Submit a signed transaction (CBOR hex); returns its hash. On failover after a lost response
534
+ * the next backend may answer 409 "already submitted" — callers treat that as success.
712
535
  */
713
536
  submitTransaction(signedTxCbor) {
714
537
  return this.route('submitTransaction', b => b.submitTransaction(signedTxCbor));
715
538
  }
716
- /**
717
- * Check if Ogmios backend is available for transaction evaluation
718
- * @returns {boolean} true if Ogmios is the live backend
719
- */
539
+ /** True when Ogmios is the live backend (script evaluation available). */
720
540
  hasOgmiosBackend() {
721
541
  return this.liveBackend?.name === 'ogmios';
722
542
  }
723
- /**
724
- * Evaluate transaction script execution units (Ogmios only)
725
- * @param unsignedTxCbor unsigned transaction in CBOR hex format
726
- * @returns {Promise<ScriptEvaluationResult[]>} evaluation results
727
- */
543
+ /** Evaluate script execution units of an unsigned transaction (Ogmios only). */
728
544
  async evaluateTransaction(unsignedTxCbor) {
729
545
  await this.ensureInitialized();
730
- // Evaluation requires an EvaluatingBackend (typically Ogmios)
731
546
  if (!this.liveBackend || !(0, cardano_backend_1.isEvaluatingBackend)(this.liveBackend)) {
732
547
  throw new errors_1.ProviderUnavailableError('Transaction evaluation requires an evaluating backend (e.g., Ogmios)');
733
548
  }
734
- // timeout + breaker — a hanging Ogmios socket previously blocked Plutus builds indefinitely
549
+ // timeout + breaker, so a hanging socket cannot block Plutus builds
735
550
  const backend = this.liveBackend;
736
551
  return this.callWithResilience(backend, () => backend.evaluateTransaction(unsignedTxCbor));
737
552
  }