@odatano/core 2.0.0-rc.43 → 2.0.0-rc.45

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 (171) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +0 -46
  2. package/@cds-models/CardanoBackendService/index.d.ts +0 -10
  3. package/@cds-models/CardanoIndexerService/index.d.ts +36 -20
  4. package/@cds-models/CardanoIndexerService/index.js +4 -0
  5. package/@cds-models/CardanoODataService/index.d.ts +19 -47
  6. package/@cds-models/CardanoSignService/index.d.ts +3 -18
  7. package/@cds-models/CardanoTransactionService/index.d.ts +9 -31
  8. package/@cds-models/CardanoWorkerService/index.d.ts +3 -19
  9. package/@cds-models/index.d.ts +17 -0
  10. package/@cds-models/index.js +2 -0
  11. package/@cds-models/odatano/cardano/index.d.ts +1 -34
  12. package/README.md +6 -6
  13. package/db/schema.cds +29 -44
  14. package/db/types.cds +22 -5
  15. package/package.json +3 -1
  16. package/scripts/migrate-slot-leader.mjs +3 -11
  17. package/scripts/migrate-txseq.mjs +3 -12
  18. package/src/index.d.ts +0 -4
  19. package/src/index.js +3 -5
  20. package/src/plugin.js +4 -8
  21. package/srv/blockchain/asset-decimals.d.ts +7 -0
  22. package/srv/blockchain/asset-decimals.js +91 -0
  23. package/srv/blockchain/backends/blockfrost-backend.d.ts +2 -10
  24. package/srv/blockchain/backends/blockfrost-backend.js +15 -21
  25. package/srv/blockchain/backends/cardano-backend.d.ts +12 -71
  26. package/srv/blockchain/backends/koios-backend.d.ts +14 -147
  27. package/srv/blockchain/backends/koios-backend.js +40 -164
  28. package/srv/blockchain/backends/odatano-backend.d.ts +1 -11
  29. package/srv/blockchain/backends/odatano-backend.js +11 -12
  30. package/srv/blockchain/backends/ogmios-backend.d.ts +13 -160
  31. package/srv/blockchain/backends/ogmios-backend.js +48 -175
  32. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +2 -18
  33. package/srv/blockchain/backends/ogmios-frame-guard.js +8 -20
  34. package/srv/blockchain/cardano-client.d.ts +12 -80
  35. package/srv/blockchain/cardano-client.js +36 -88
  36. package/srv/blockchain/cardano-indexer.d.ts +12 -192
  37. package/srv/blockchain/cardano-indexer.js +132 -222
  38. package/srv/blockchain/cardano-tx-builder.d.ts +1 -28
  39. package/srv/blockchain/cardano-tx-builder.js +17 -34
  40. package/srv/blockchain/circuit-breaker.d.ts +1 -13
  41. package/srv/blockchain/circuit-breaker.js +5 -15
  42. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
  43. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  44. package/srv/blockchain/crawler/certificate-backfill.d.ts +0 -17
  45. package/srv/blockchain/crawler/certificate-backfill.js +8 -22
  46. package/srv/blockchain/crawler/crawler.d.ts +16 -93
  47. package/srv/blockchain/crawler/crawler.js +85 -160
  48. package/srv/blockchain/crawler/credential-backfill.d.ts +0 -9
  49. package/srv/blockchain/crawler/credential-backfill.js +6 -6
  50. package/srv/blockchain/crawler/hooks.d.ts +1 -5
  51. package/srv/blockchain/crawler/index.d.ts +0 -12
  52. package/srv/blockchain/crawler/index.js +6 -20
  53. package/srv/blockchain/crawler/sync-state.d.ts +6 -44
  54. package/srv/blockchain/crawler/sync-state.js +18 -53
  55. package/srv/blockchain/crawler/transaction-backfill.d.ts +0 -11
  56. package/srv/blockchain/crawler/transaction-backfill.js +11 -30
  57. package/srv/blockchain/crawler/utxo-set-import.d.ts +1 -30
  58. package/srv/blockchain/crawler/utxo-set-import.js +27 -53
  59. package/srv/blockchain/ledger-state.d.ts +10 -54
  60. package/srv/blockchain/ledger-state.js +11 -27
  61. package/srv/blockchain/pending-spends.d.ts +0 -12
  62. package/srv/blockchain/pending-spends.js +4 -12
  63. package/srv/blockchain/request-coalescer.d.ts +2 -16
  64. package/srv/blockchain/request-coalescer.js +2 -16
  65. package/srv/blockchain/signing/cose-verifier.d.ts +0 -9
  66. package/srv/blockchain/signing/cose-verifier.js +4 -10
  67. package/srv/blockchain/signing/external-signer.d.ts +1 -4
  68. package/srv/blockchain/signing/external-signer.js +2 -8
  69. package/srv/blockchain/signing/hsm-signer.d.ts +6 -18
  70. package/srv/blockchain/signing/hsm-signer.js +16 -28
  71. package/srv/blockchain/signing/signature-verifier.d.ts +1 -8
  72. package/srv/blockchain/signing/signature-verifier.js +9 -19
  73. package/srv/blockchain/signing/submission-finalizer.d.ts +10 -16
  74. package/srv/blockchain/signing/submission-finalizer.js +48 -19
  75. package/srv/blockchain/stored-chain.d.ts +1 -14
  76. package/srv/blockchain/stored-chain.js +3 -8
  77. package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -4
  78. package/srv/blockchain/transaction-building/buildooor-fee-patch.js +4 -9
  79. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -150
  80. package/srv/blockchain/transaction-building/buildooor-tx.js +91 -196
  81. package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -14
  82. package/srv/blockchain/transaction-building/caller-datums.js +3 -9
  83. package/srv/blockchain/transaction-building/cardano-tx.d.ts +1 -4
  84. package/srv/blockchain/wallet-worker/build-request.d.ts +0 -5
  85. package/srv/blockchain/wallet-worker/build-request.js +6 -9
  86. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -23
  87. package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -20
  88. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  89. package/srv/blockchain/wallet-worker/index.js +3 -5
  90. package/srv/blockchain/wallet-worker/job-store.d.ts +15 -65
  91. package/srv/blockchain/wallet-worker/job-store.js +0 -0
  92. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -10
  93. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -12
  94. package/srv/blockchain/wallet-worker/signers.d.ts +3 -11
  95. package/srv/blockchain/wallet-worker/signers.js +3 -6
  96. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +3 -21
  97. package/srv/blockchain/wallet-worker/wallet-worker.js +47 -54
  98. package/srv/cardano-agent-service.cds +123 -146
  99. package/srv/cardano-agent-service.js +2 -5
  100. package/srv/cardano-backend-service.cds +10 -17
  101. package/srv/cardano-backend-service.js +7 -12
  102. package/srv/cardano-indexer-service.cds +35 -37
  103. package/srv/cardano-indexer-service.d.ts +5 -1
  104. package/srv/cardano-indexer-service.js +64 -33
  105. package/srv/cardano-service.cds +56 -40
  106. package/srv/cardano-service.js +42 -69
  107. package/srv/cardano-sign-service.cds +14 -23
  108. package/srv/cardano-sign-service.js +18 -24
  109. package/srv/cardano-tx-service.cds +27 -29
  110. package/srv/cardano-tx-service.js +60 -122
  111. package/srv/cardano-worker-service.cds +109 -125
  112. package/srv/cardano-worker-service.js +21 -31
  113. package/srv/cbor/cip68.d.ts +13 -0
  114. package/srv/cbor/cip68.js +56 -0
  115. package/srv/cbor/index.d.ts +1 -0
  116. package/srv/cbor/index.js +6 -1
  117. package/srv/cbor/parse.d.ts +3 -18
  118. package/srv/cbor/parse.js +2 -7
  119. package/srv/cbor/plutus-data-json.d.ts +0 -4
  120. package/srv/server.d.ts +5 -36
  121. package/srv/server.js +30 -51
  122. package/srv/utils/agent-grants-config.d.ts +0 -18
  123. package/srv/utils/agent-grants-config.js +6 -13
  124. package/srv/utils/agent-grants.d.ts +14 -68
  125. package/srv/utils/agent-grants.js +42 -60
  126. package/srv/utils/agent-token-auth.d.ts +0 -5
  127. package/srv/utils/agent-token-auth.js +2 -5
  128. package/srv/utils/backend-request-handler.d.ts +1 -1
  129. package/srv/utils/collections.d.ts +1 -4
  130. package/srv/utils/collections.js +1 -4
  131. package/srv/utils/const.d.ts +0 -18
  132. package/srv/utils/const.js +7 -18
  133. package/srv/utils/crypto.js +3 -5
  134. package/srv/utils/db-indexes.d.ts +2 -0
  135. package/srv/utils/db-indexes.js +22 -9
  136. package/srv/utils/db-sanitize.d.ts +1 -8
  137. package/srv/utils/db-sanitize.js +3 -8
  138. package/srv/utils/epoch-slots.d.ts +1 -8
  139. package/srv/utils/epoch-slots.js +3 -8
  140. package/srv/utils/error-codes.d.ts +0 -4
  141. package/srv/utils/error-codes.js +2 -4
  142. package/srv/utils/errors.d.ts +2 -22
  143. package/srv/utils/errors.js +13 -27
  144. package/srv/utils/liveness.d.ts +0 -4
  145. package/srv/utils/liveness.js +2 -4
  146. package/srv/utils/mappers.d.ts +0 -37
  147. package/srv/utils/mappers.js +22 -39
  148. package/srv/utils/network-context.js +2 -4
  149. package/srv/utils/paging.d.ts +31 -0
  150. package/srv/utils/paging.js +43 -0
  151. package/srv/utils/pg-inline-json.js +3 -7
  152. package/srv/utils/pg-order-nulls.js +2 -5
  153. package/srv/utils/plutus-placeholders.d.ts +0 -13
  154. package/srv/utils/plutus-placeholders.js +6 -13
  155. package/srv/utils/rate-limiter.d.ts +0 -8
  156. package/srv/utils/rate-limiter.js +2 -4
  157. package/srv/utils/reference-script.d.ts +0 -18
  158. package/srv/utils/reference-script.js +8 -19
  159. package/srv/utils/service-events.d.ts +0 -4
  160. package/srv/utils/service-events.js +2 -4
  161. package/srv/utils/signing-helper.d.ts +1 -8
  162. package/srv/utils/signing-helper.js +3 -8
  163. package/srv/utils/tx-build-helper.d.ts +2 -32
  164. package/srv/utils/tx-build-helper.js +26 -40
  165. package/srv/utils/tx-request-parsers.d.ts +1 -25
  166. package/srv/utils/tx-request-parsers.js +10 -25
  167. package/srv/utils/tx-utils.d.ts +0 -8
  168. package/srv/utils/tx-utils.js +10 -13
  169. package/srv/utils/types.d.ts +2 -37
  170. package/srv/utils/validators.d.ts +0 -4
  171. package/srv/utils/validators.js +2 -4
@@ -22,10 +22,6 @@ export type CardanoClientConfig = {
22
22
  indexTtlMs: number;
23
23
  circuitBreaker?: Partial<CircuitBreakerConfig>;
24
24
  };
25
- /**
26
- * Multi-backend Cardano client: live/state queries prefer Ogmios, historical queries prefer
27
- * Blockfrost/Koios, with automatic fallback between them.
28
- */
29
25
  export declare class CardanoClient {
30
26
  private config;
31
27
  private liveBackend?;
@@ -33,7 +29,7 @@ export declare class CardanoClient {
33
29
  private initialized;
34
30
  private initPromise;
35
31
  private circuitBreaker;
36
- /** Backends whose init failed — kept in rotation and retried lazily per request */
32
+ /** Backends whose init failed. They stay in rotation and init is retried per request. */
37
33
  private uninitializedBackends;
38
34
  network: Network;
39
35
  max_age_ms: number;
@@ -51,40 +47,19 @@ export declare class CardanoClient {
51
47
  constructor(clientConfig: CardanoClientConfig);
52
48
  /** Names of the configured backends (live + historical), for status reporting. */
53
49
  listBackends(): string[];
54
- /**
55
- * Ensure backends are initialized. A rejected init promise is cleared so the next request
56
- * retries instead of leaving the client permanently broken.
57
- */
50
+ /** A failed init promise is cleared so the next request retries instead of staying broken. */
58
51
  private ensureInitialized;
59
- /**
60
- * Transient (retryable) init failures: a backend momentarily unreachable at startup
61
- * (connection refused/reset, a cut-short health response). Config/validation errors are not.
62
- */
52
+ /** True for a backend that is briefly unreachable at startup. Config errors are not transient. */
63
53
  private static isTransientInitError;
64
- /**
65
- * Init a backend, retrying brief transient failures. Kept small (3 attempts, 1 s backoff) so
66
- * a sustained outage still fails fast and the total stays under the test bootstrap hook.
67
- */
68
54
  private initBackendWithRetry;
69
- /**
70
- * Initialize all backends. Backends whose init fails stay in rotation, tracked in
71
- * `uninitializedBackends`, and are retried lazily per request (bounded by the circuit breaker).
72
- */
55
+ /** Backends whose init fails stay in rotation and are retried per request, bounded by the breaker. */
73
56
  private initBackends;
74
- /**
75
- * Lazily retry a backend's init when it failed at startup. Returns true when
76
- * the backend is usable; false (after recording a breaker failure) when the
77
- * retry failed.
78
- */
57
+ /** Retries a failed startup init. False records a breaker failure. */
79
58
  private ensureBackendInitialized;
80
59
  /** Wrap a promise with a timeout that rejects with ProviderUnavailableError. */
81
60
  private withTimeout;
82
61
  /** Per-backend timeout: Koios and a remote ODATANO get the fallback timeout, everything else the primary one. */
83
62
  private getTimeoutForBackend;
84
- /**
85
- * Single-backend call with the executeWithPriority resilience contract (breaker gate, timeout,
86
- * success/failure recording, 4xx exempt) for paths that cannot fail over.
87
- */
88
63
  private callWithResilience;
89
64
  /** Execute on backends in preference order (live vs historical) with automatic fallback. */
90
65
  private executeWithPriority;
@@ -95,10 +70,6 @@ export declare class CardanoClient {
95
70
  /** Address data (coalesced across concurrent callers). */
96
71
  getAddress(address: string): Promise<Address>;
97
72
  getAddressUtxos(address: string): Promise<UTxO[]>;
98
- /**
99
- * UTxOs by 28-byte payment credential (56-char hex), across all bech32 forms sharing it.
100
- * Needs a credential-keyed backend (Koios, or another ODATANO); Blockfrost has none.
101
- */
102
73
  getCredentialUtxos(credHash: string): Promise<UTxO[]>;
103
74
  getAddressTransactions(address: string, limit: number): Promise<Transaction[]>;
104
75
  getNetworkInformation(): Promise<NetworkInformation>;
@@ -108,51 +79,22 @@ export declare class CardanoClient {
108
79
  getPool(poolId: string): Promise<PoolData>;
109
80
  getDrep(drepId: string): Promise<DrepData>;
110
81
  getAccount(stakeAddress: string): Promise<AccountData>;
111
- /**
112
- * Whether the reward account is registered in the ledger. Node first; the first backend that
113
- * answers decides, its "not found" means not registered. Only a backend failure falls through.
114
- */
115
- /**
116
- * Whether the stake credential is registered. The node's reward-account summary proves it, but
117
- * the summary lists only credentials delegated to a pool or a DRep, so its absence proves nothing and the
118
- * providers answer from the certificate history; one that knows the account decides, one that
119
- * knows no such account means not registered. `null`: nobody could tell (no summary on the
120
- * node, no provider configured or reachable).
121
- */
122
82
  isRewardAccountRegistered(stakeAddress: string): Promise<boolean | null>;
123
83
  /** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
124
84
  getAssetInfo(unit: string): Promise<AssetInfo>;
125
- /**
126
- * Latest mint/burn events for an asset, most recent first. Prefers Koios (block timestamps);
127
- * Blockfrost is the fallback with timestamps left null.
128
- */
85
+ /** Latest mint and burn events. Prefers Koios, because Blockfrost leaves timestamps null. */
129
86
  getAssetHistory(unit: string, limit?: number): Promise<AssetHistoryEntry[]>;
130
- /**
131
- * Transaction hashes for an address; falls back to a full getAddressTransactions when no
132
- * backend supports the lightweight listing.
133
- */
87
+ /** Falls back to a full getAddressTransactions when no backend lists hashes only. */
134
88
  getAddressTransactionHashes(address: string, limit: number): Promise<string[]>;
135
89
  /** Batch fetch transactions by hash; falls back to individual coalesced getTransaction calls. */
136
90
  getTransactionsBatch(txHashes: string[]): Promise<Map<string, Transaction>>;
137
91
  /** Backends in historical-first order, for the batch methods. */
138
92
  private getOrderedBackends;
139
- /**
140
- * A backend that supports streamed chain-sync (Ogmios), or null. Backends whose init failed
141
- * are skipped: the crawler uses these instances directly, outside the lazy-retry/breaker path.
142
- */
143
93
  getChainSyncBackend(): ChainSyncBackend | null;
144
- /**
145
- * getChainSyncBackend(), retrying a failed startup init. Polled by the crawler while it runs
146
- * on pagination because no chain-sync source was usable when it started.
147
- */
94
+ /** Like getChainSyncBackend() but retries a failed init. The crawler polls it while on pagination. */
148
95
  recoverChainSyncBackend(): Promise<ChainSyncBackend | null>;
149
- /** The first usable backend that can dump the UTxO set at a point (Ogmios) — crawler.utxoSet import. */
96
+ /** First usable backend that can dump the UTxO set at a point, for the UTxO set import. */
150
97
  getLedgerStateBackend(): LedgerStateBackend | null;
151
- /**
152
- * Outputs among `refs` that are unspent at the tip, read from the node's ledger (Ogmios, or a remote
153
- * ODATANO that asks its node); null when no backend can (the caller then resolves via the producing
154
- * transaction, which carries no reference-script bytes).
155
- */
156
98
  getUnspentOutputs(refs: Array<{
157
99
  txHash: string;
158
100
  outputIndex: number;
@@ -161,17 +103,11 @@ export declare class CardanoClient {
161
103
  private outputLookupBackend;
162
104
  /** True when an initialized backend implements `method` and does not declare it unsupported. */
163
105
  hasBackendFor(method: string): boolean;
164
- /** A backend that reads pool/DRep/pot state at a block (Ogmios) — preferred source of epoch snapshots. */
106
+ /** Backend that reads pool, DRep and pot state at a block. Preferred source of epoch snapshots. */
165
107
  getEpochStateBackend(): EpochStateBackend | null;
166
- /**
167
- * A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
168
- * snapshots stay off instead of degrading into thousands of single requests.
169
- */
108
+ /** Without one, epoch snapshots stay off instead of making thousands of single requests. */
170
109
  getEnumeratingBackend(): EnumeratingBackend | null;
171
- /**
172
- * A backend that can be walked forward by pagination (Blockfrost/Koios), or null. Koios is
173
- * preferred: it batches 100 txs per call, Blockfrost needs ~3 calls per tx.
174
- */
110
+ /** Prefers Koios, because it batches 100 txs per call and Blockfrost needs about 3 calls per tx. */
175
111
  getPaginatingBackend(): PaginatingBackend | null;
176
112
  /** Protocol parameters with a 5-minute in-memory cache and coalesced refresh. */
177
113
  getProtocolParameters(): Promise<LedgerProtocolParameters>;
@@ -182,10 +118,6 @@ export declare class CardanoClient {
182
118
  getCurrentSlot(): Promise<number>;
183
119
  /** True iff the UTxO exists and is unspent. */
184
120
  isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
185
- /**
186
- * Submit a signed transaction (CBOR hex); returns its hash. On failover after a lost response
187
- * the next backend may answer 409 "already submitted" — callers treat that as success.
188
- */
189
121
  submitTransaction(signedTxCbor: string): Promise<string>;
190
122
  /** True when Ogmios is the live backend. */
191
123
  hasOgmiosBackend(): boolean;
@@ -40,10 +40,8 @@ const METHOD_ROUTING = {
40
40
  // a node's rejection (4xx) is final: another backend submits to the same ledger
41
41
  submitTransaction: { preferLive: true, finalOnClientError: true },
42
42
  };
43
- /**
44
- * Multi-backend Cardano client: live/state queries prefer Ogmios, historical queries prefer
45
- * Blockfrost/Koios, with automatic fallback between them.
46
- */
43
+ // Multi-backend client. Live state queries prefer Ogmios, historical queries prefer Blockfrost
44
+ // or Koios, with automatic fallback between them.
47
45
  class CardanoClient {
48
46
  config;
49
47
  liveBackend;
@@ -51,7 +49,7 @@ class CardanoClient {
51
49
  initialized = false;
52
50
  initPromise = null;
53
51
  circuitBreaker;
54
- /** Backends whose init failed — kept in rotation and retried lazily per request */
52
+ /** Backends whose init failed. They stay in rotation and init is retried per request. */
55
53
  uninitializedBackends = new Set();
56
54
  network;
57
55
  max_age_ms = 60000; // default 1 minute for temporary caching
@@ -62,7 +60,7 @@ class CardanoClient {
62
60
  /** Last protocol parameters the live backend (node) answered. */
63
61
  lastLiveProtocolParams;
64
62
  static PROTOCOL_PARAMS_TTL_MS = 5 * 60 * 1000; // 5 minutes
65
- // Request coalescers — deduplicate concurrent fetches for the same resource
63
+ // Deduplicate concurrent fetches for the same resource.
66
64
  txCoalescer = new request_coalescer_1.RequestCoalescer();
67
65
  addrCoalescer = new request_coalescer_1.RequestCoalescer();
68
66
  credCoalescer = new request_coalescer_1.RequestCoalescer();
@@ -102,10 +100,7 @@ class CardanoClient {
102
100
  names.push(...this.historicalBackends.map(b => b.name));
103
101
  return names;
104
102
  }
105
- /**
106
- * Ensure backends are initialized. A rejected init promise is cleared so the next request
107
- * retries instead of leaving the client permanently broken.
108
- */
103
+ /** A failed init promise is cleared so the next request retries instead of staying broken. */
109
104
  async ensureInitialized() {
110
105
  if (this.initialized)
111
106
  return;
@@ -116,10 +111,7 @@ class CardanoClient {
116
111
  });
117
112
  await this.initPromise;
118
113
  }
119
- /**
120
- * Transient (retryable) init failures: a backend momentarily unreachable at startup
121
- * (connection refused/reset, a cut-short health response). Config/validation errors are not.
122
- */
114
+ /** True for a backend that is briefly unreachable at startup. Config errors are not transient. */
123
115
  static isTransientInitError(err) {
124
116
  const e = err;
125
117
  const code = e?.code ?? e?.cause?.code ?? '';
@@ -128,10 +120,8 @@ class CardanoClient {
128
120
  return true;
129
121
  return /premature close|socket hang up|econnreset|econnrefused|etimedout|timeout|fetch failed|terminated|other side closed/.test(msg);
130
122
  }
131
- /**
132
- * Init a backend, retrying brief transient failures. Kept small (3 attempts, 1 s backoff) so
133
- * a sustained outage still fails fast and the total stays under the test bootstrap hook.
134
- */
123
+ // Retries brief transient init failures. Few attempts with a short backoff, so a real
124
+ // outage still fails fast and stays under the test bootstrap timeout.
135
125
  async initBackendWithRetry(backend) {
136
126
  const maxAttempts = 3;
137
127
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
@@ -142,15 +132,12 @@ class CardanoClient {
142
132
  catch (err) {
143
133
  if (attempt >= maxAttempts || !CardanoClient.isTransientInitError(err))
144
134
  throw err;
145
- logger.warn(`Init of ${backend.name} failed (attempt ${attempt}/${maxAttempts}) — transient, retrying in 1s`, err);
135
+ logger.warn(`Init of ${backend.name} failed (attempt ${attempt}/${maxAttempts}), transient, retrying in 1s`, err);
146
136
  await new Promise(r => setTimeout(r, 1000));
147
137
  }
148
138
  }
149
139
  }
150
- /**
151
- * Initialize all backends. Backends whose init fails stay in rotation, tracked in
152
- * `uninitializedBackends`, and are retried lazily per request (bounded by the circuit breaker).
153
- */
140
+ /** Backends whose init fails stay in rotation and are retried per request, bounded by the breaker. */
154
141
  async initBackends() {
155
142
  const initErrors = [];
156
143
  // Initialize live backend
@@ -163,7 +150,7 @@ class CardanoClient {
163
150
  }
164
151
  catch (err) {
165
152
  initErrors.push(new errors_1.BackendInitError(this.liveBackend.name, err));
166
- logger.error(`Failed to initialize live backend: ${this.liveBackend.name} — kept for lazy retry`, err);
153
+ logger.error(`Failed to initialize live backend: ${this.liveBackend.name}, kept for lazy retry`, err);
167
154
  this.uninitializedBackends.add(this.liveBackend);
168
155
  }
169
156
  }
@@ -177,7 +164,7 @@ class CardanoClient {
177
164
  }
178
165
  catch (err) {
179
166
  initErrors.push(new errors_1.BackendInitError(backend.name, err));
180
- logger.error(`Failed to initialize historical backend: ${backend.name} — kept for lazy retry`, err);
167
+ logger.error(`Failed to initialize historical backend: ${backend.name}, kept for lazy retry`, err);
181
168
  this.uninitializedBackends.add(backend);
182
169
  }
183
170
  }
@@ -187,11 +174,7 @@ class CardanoClient {
187
174
  }
188
175
  this.initialized = true;
189
176
  }
190
- /**
191
- * Lazily retry a backend's init when it failed at startup. Returns true when
192
- * the backend is usable; false (after recording a breaker failure) when the
193
- * retry failed.
194
- */
177
+ /** Retries a failed startup init. False records a breaker failure. */
195
178
  async ensureBackendInitialized(backend, errors) {
196
179
  if (!this.uninitializedBackends.has(backend))
197
180
  return true;
@@ -225,15 +208,13 @@ class CardanoClient {
225
208
  return this.config.fallbackTimeoutMs;
226
209
  return this.config.primaryTimeoutMs;
227
210
  }
228
- /**
229
- * Single-backend call with the executeWithPriority resilience contract (breaker gate, timeout,
230
- * success/failure recording, 4xx exempt) for paths that cannot fail over.
231
- */
211
+ // One backend call with the same breaker, timeout and recording rules as executeWithPriority.
212
+ // For paths that cannot fail over.
232
213
  async callWithResilience(backend, fn) {
233
214
  if (!this.circuitBreaker.shouldAttempt(backend.name)) {
234
215
  throw new errors_1.ProviderUnavailableError(`Circuit open for ${backend.name}`, backend.name);
235
216
  }
236
- // fast-path sync check — keeps fn() synchronous for the request coalescers
217
+ // Sync check first keeps fn() synchronous for the request coalescers.
237
218
  if (this.uninitializedBackends.has(backend) && !(await this.ensureBackendInitialized(backend))) {
238
219
  throw new errors_1.ProviderUnavailableError(`Backend ${backend.name} is not initialized (lazy retry failed)`, backend.name);
239
220
  }
@@ -277,7 +258,7 @@ class CardanoClient {
277
258
  skipped.push(`${backend.name}: circuit open`);
278
259
  continue;
279
260
  }
280
- // fast-path sync check — only await the init retry in the rare failure case
261
+ // Sync check first, so only the rare failure case awaits the init retry.
281
262
  if (this.uninitializedBackends.has(backend) && !(await this.ensureBackendInitialized(backend, errors))) {
282
263
  continue;
283
264
  }
@@ -321,10 +302,8 @@ class CardanoClient {
321
302
  getAddressUtxos(address) {
322
303
  return this.route('getAddressUtxos', b => b.getAddressUtxos(address));
323
304
  }
324
- /**
325
- * UTxOs by 28-byte payment credential (56-char hex), across all bech32 forms sharing it.
326
- * Needs a credential-keyed backend (Koios, or another ODATANO); Blockfrost has none.
327
- */
305
+ // UTxOs of every address form that shares the payment credential.
306
+ // Needs Koios or another ODATANO, because Blockfrost has no credential lookup.
328
307
  getCredentialUtxos(credHash) {
329
308
  const candidates = [this.liveBackend, ...this.historicalBackends];
330
309
  const capable = candidates.filter((b) => typeof b?.getCredentialUtxos === 'function');
@@ -358,17 +337,8 @@ class CardanoClient {
358
337
  getAccount(stakeAddress) {
359
338
  return this.route('getAccount', b => b.getAccount(stakeAddress));
360
339
  }
361
- /**
362
- * Whether the reward account is registered in the ledger. Node first; the first backend that
363
- * answers decides, its "not found" means not registered. Only a backend failure falls through.
364
- */
365
- /**
366
- * Whether the stake credential is registered. The node's reward-account summary proves it, but
367
- * the summary lists only credentials delegated to a pool or a DRep, so its absence proves nothing and the
368
- * providers answer from the certificate history; one that knows the account decides, one that
369
- * knows no such account means not registered. `null`: nobody could tell (no summary on the
370
- * node, no provider configured or reachable).
371
- */
340
+ // The node lists only delegated credentials, so its absence proves nothing and providers decide.
341
+ // A provider 404 means not registered. Null when no source could tell.
372
342
  async isRewardAccountRegistered(stakeAddress) {
373
343
  try {
374
344
  return await this.executeWithPriority(async (b) => (await b.getAccount(stakeAddress)).active, true, 'getAccount');
@@ -388,10 +358,7 @@ class CardanoClient {
388
358
  getAssetInfo(unit) {
389
359
  return this.route('getAssetInfo', b => b.getAssetInfo(unit));
390
360
  }
391
- /**
392
- * Latest mint/burn events for an asset, most recent first. Prefers Koios (block timestamps);
393
- * Blockfrost is the fallback with timestamps left null.
394
- */
361
+ /** Latest mint and burn events. Prefers Koios, because Blockfrost leaves timestamps null. */
395
362
  getAssetHistory(unit, limit = 100) {
396
363
  const candidates = [...this.historicalBackends, this.liveBackend];
397
364
  const koios = candidates.find(b => b?.name === 'koios' && typeof b.getAssetHistory === 'function');
@@ -406,10 +373,7 @@ class CardanoClient {
406
373
  //-----------------------------------------------------------------------------
407
374
  // Batch Methods (N+1 Optimization)
408
375
  //-----------------------------------------------------------------------------
409
- /**
410
- * Transaction hashes for an address; falls back to a full getAddressTransactions when no
411
- * backend supports the lightweight listing.
412
- */
376
+ /** Falls back to a full getAddressTransactions when no backend lists hashes only. */
413
377
  async getAddressTransactionHashes(address, limit) {
414
378
  const allBackends = this.getOrderedBackends();
415
379
  for (const backend of allBackends) {
@@ -418,7 +382,7 @@ class CardanoClient {
418
382
  return await this.callWithResilience(backend, () => backend.getAddressTransactionHashes(address, limit));
419
383
  }
420
384
  catch (err) {
421
- logger.debug(`getAddressTransactionHashes failed on ${backend.name}: ${err instanceof Error ? err.message : String(err)} — trying next backend`);
385
+ logger.debug(`getAddressTransactionHashes failed on ${backend.name}: ${err instanceof Error ? err.message : String(err)}, trying next backend`);
422
386
  }
423
387
  }
424
388
  }
@@ -435,7 +399,7 @@ class CardanoClient {
435
399
  return await this.callWithResilience(backend, () => backend.getTransactionsBatch(txHashes));
436
400
  }
437
401
  catch (err) {
438
- logger.debug(`getTransactionsBatch failed on ${backend.name}: ${err instanceof Error ? err.message : String(err)} — trying next backend`);
402
+ logger.debug(`getTransactionsBatch failed on ${backend.name}: ${err instanceof Error ? err.message : String(err)}, trying next backend`);
439
403
  }
440
404
  }
441
405
  }
@@ -450,10 +414,8 @@ class CardanoClient {
450
414
  backends.push(this.liveBackend);
451
415
  return backends;
452
416
  }
453
- /**
454
- * A backend that supports streamed chain-sync (Ogmios), or null. Backends whose init failed
455
- * are skipped: the crawler uses these instances directly, outside the lazy-retry/breaker path.
456
- */
417
+ // Skips backends whose init failed, because the crawler uses this instance
418
+ // directly, without lazy retry or breaker.
457
419
  getChainSyncBackend() {
458
420
  const candidates = [this.liveBackend, ...this.historicalBackends];
459
421
  for (const b of candidates) {
@@ -462,10 +424,7 @@ class CardanoClient {
462
424
  }
463
425
  return null;
464
426
  }
465
- /**
466
- * getChainSyncBackend(), retrying a failed startup init. Polled by the crawler while it runs
467
- * on pagination because no chain-sync source was usable when it started.
468
- */
427
+ /** Like getChainSyncBackend() but retries a failed init. The crawler polls it while on pagination. */
469
428
  async recoverChainSyncBackend() {
470
429
  const candidates = [this.liveBackend, ...this.historicalBackends];
471
430
  for (const b of candidates) {
@@ -476,7 +435,7 @@ class CardanoClient {
476
435
  }
477
436
  return null;
478
437
  }
479
- /** The first usable backend that can dump the UTxO set at a point (Ogmios) — crawler.utxoSet import. */
438
+ /** First usable backend that can dump the UTxO set at a point, for the UTxO set import. */
480
439
  getLedgerStateBackend() {
481
440
  const candidates = [this.liveBackend, ...this.historicalBackends];
482
441
  for (const b of candidates) {
@@ -485,11 +444,8 @@ class CardanoClient {
485
444
  }
486
445
  return null;
487
446
  }
488
- /**
489
- * Outputs among `refs` that are unspent at the tip, read from the node's ledger (Ogmios, or a remote
490
- * ODATANO that asks its node); null when no backend can (the caller then resolves via the producing
491
- * transaction, which carries no reference-script bytes).
492
- */
447
+ // Outputs among refs that are unspent at the tip, read from the node's ledger.
448
+ // Null when no backend can. The caller then reads the producing tx, which lacks reference-script bytes.
493
449
  async getUnspentOutputs(refs) {
494
450
  const backend = this.getLedgerStateBackend() ?? this.outputLookupBackend();
495
451
  return backend ? backend.getUnspentOutputs(refs) : null;
@@ -513,7 +469,7 @@ class CardanoClient {
513
469
  && typeof b[method] === 'function'
514
470
  && !b.unsupportedMethods?.has(method));
515
471
  }
516
- /** A backend that reads pool/DRep/pot state at a block (Ogmios) — preferred source of epoch snapshots. */
472
+ /** Backend that reads pool, DRep and pot state at a block. Preferred source of epoch snapshots. */
517
473
  getEpochStateBackend() {
518
474
  const candidates = [this.liveBackend, ...this.historicalBackends];
519
475
  for (const b of candidates) {
@@ -522,10 +478,7 @@ class CardanoClient {
522
478
  }
523
479
  return null;
524
480
  }
525
- /**
526
- * A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
527
- * snapshots stay off instead of degrading into thousands of single requests.
528
- */
481
+ /** Without one, epoch snapshots stay off instead of making thousands of single requests. */
529
482
  getEnumeratingBackend() {
530
483
  const candidates = [...this.historicalBackends, this.liveBackend];
531
484
  for (const b of candidates) {
@@ -534,10 +487,7 @@ class CardanoClient {
534
487
  }
535
488
  return null;
536
489
  }
537
- /**
538
- * A backend that can be walked forward by pagination (Blockfrost/Koios), or null. Koios is
539
- * preferred: it batches 100 txs per call, Blockfrost needs ~3 calls per tx.
540
- */
490
+ /** Prefers Koios, because it batches 100 txs per call and Blockfrost needs about 3 calls per tx. */
541
491
  getPaginatingBackend() {
542
492
  const usable = this.historicalBackends.filter((b) => !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isPaginatingBackend)(b));
543
493
  const koios = usable.find((b) => b.name === 'koios');
@@ -621,10 +571,8 @@ class CardanoClient {
621
571
  isUtxoUnspent(txHash, outputIndex) {
622
572
  return this.route('isUtxoUnspent', b => b.isUtxoUnspent(txHash, outputIndex));
623
573
  }
624
- /**
625
- * Submit a signed transaction (CBOR hex); returns its hash. On failover after a lost response
626
- * the next backend may answer 409 "already submitted" — callers treat that as success.
627
- */
574
+ // After a lost response, the next backend may answer 409 "already submitted".
575
+ // Callers treat that as success.
628
576
  async submitTransaction(signedTxCbor) {
629
577
  try {
630
578
  const hash = await this.route('submitTransaction', b => b.submitTransaction(signedTxCbor));