@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51

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 (239) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +99 -51
  2. package/@cds-models/CardanoAgentService/index.js +15 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +358 -0
  4. package/@cds-models/CardanoBackendService/index.js +41 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
  6. package/@cds-models/CardanoIndexerService/index.js +74 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +417 -57
  8. package/@cds-models/CardanoODataService/index.js +42 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +45 -19
  10. package/@cds-models/CardanoSignService/index.js +4 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
  12. package/@cds-models/CardanoTransactionService/index.js +5 -0
  13. package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
  14. package/@cds-models/CardanoWorkerService/index.js +2 -0
  15. package/@cds-models/index.d.ts +114 -4
  16. package/@cds-models/index.js +20 -4
  17. package/@cds-models/odatano/cardano/index.d.ts +451 -32
  18. package/@cds-models/odatano/cardano/index.js +48 -0
  19. package/README.md +103 -167
  20. package/db/schema.cds +2455 -1705
  21. package/db/types.cds +456 -295
  22. package/package.json +41 -53
  23. package/scripts/deploy-schema.mjs +113 -0
  24. package/scripts/migrate-schema.mjs +528 -0
  25. package/scripts/migrate-slot-leader.mjs +96 -0
  26. package/src/index.d.ts +20 -21
  27. package/src/index.js +45 -31
  28. package/src/plugin.js +17 -35
  29. package/srv/blockchain/asset-decimals.d.ts +7 -0
  30. package/srv/blockchain/asset-decimals.js +91 -0
  31. package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
  32. package/srv/blockchain/backends/blockfrost-backend.js +125 -215
  33. package/srv/blockchain/backends/call-signal.d.ts +7 -0
  34. package/srv/blockchain/backends/call-signal.js +22 -0
  35. package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
  36. package/srv/blockchain/backends/cardano-backend.js +29 -5
  37. package/srv/blockchain/backends/koios-backend.d.ts +108 -170
  38. package/srv/blockchain/backends/koios-backend.js +488 -482
  39. package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
  40. package/srv/blockchain/backends/odatano-backend.js +211 -0
  41. package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
  42. package/srv/blockchain/backends/ogmios-backend.js +683 -327
  43. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
  44. package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
  45. package/srv/blockchain/cardano-client.d.ts +71 -241
  46. package/srv/blockchain/cardano-client.js +354 -322
  47. package/srv/blockchain/cardano-indexer.d.ts +295 -283
  48. package/srv/blockchain/cardano-indexer.js +1690 -502
  49. package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
  50. package/srv/blockchain/cardano-tx-builder.js +164 -140
  51. package/srv/blockchain/circuit-breaker.d.ts +2 -13
  52. package/srv/blockchain/circuit-breaker.js +11 -15
  53. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  54. package/srv/blockchain/crawler/account-snapshots.js +173 -0
  55. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
  56. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  57. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
  58. package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
  59. package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
  60. package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
  61. package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
  62. package/srv/blockchain/crawler/certificate-backfill.js +174 -0
  63. package/srv/blockchain/crawler/crawler.d.ts +125 -81
  64. package/srv/blockchain/crawler/crawler.js +738 -167
  65. package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
  66. package/srv/blockchain/crawler/credential-backfill.js +101 -0
  67. package/srv/blockchain/crawler/hooks.d.ts +2 -17
  68. package/srv/blockchain/crawler/index.d.ts +1 -8
  69. package/srv/blockchain/crawler/index.js +31 -17
  70. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  71. package/srv/blockchain/crawler/input-asset-copies.js +161 -0
  72. package/srv/blockchain/crawler/key-pages.d.ts +12 -0
  73. package/srv/blockchain/crawler/key-pages.js +48 -0
  74. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
  75. package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
  76. package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
  77. package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
  78. package/srv/blockchain/crawler/sync-state.d.ts +31 -47
  79. package/srv/blockchain/crawler/sync-state.js +135 -128
  80. package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
  81. package/srv/blockchain/crawler/transaction-backfill.js +271 -0
  82. package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
  83. package/srv/blockchain/crawler/utxo-set-import.js +399 -0
  84. package/srv/blockchain/crawler/window-plan.d.ts +31 -0
  85. package/srv/blockchain/crawler/window-plan.js +59 -0
  86. package/srv/blockchain/ledger-state.d.ts +62 -0
  87. package/srv/blockchain/ledger-state.js +521 -0
  88. package/srv/blockchain/pending-spends.d.ts +16 -0
  89. package/srv/blockchain/pending-spends.js +81 -0
  90. package/srv/blockchain/pool-metadata.d.ts +15 -0
  91. package/srv/blockchain/pool-metadata.js +132 -0
  92. package/srv/blockchain/request-coalescer.d.ts +2 -16
  93. package/srv/blockchain/request-coalescer.js +2 -16
  94. package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
  95. package/srv/blockchain/signing/cose-verifier.js +146 -70
  96. package/srv/blockchain/signing/external-signer.d.ts +15 -115
  97. package/srv/blockchain/signing/external-signer.js +22 -131
  98. package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
  99. package/srv/blockchain/signing/failed-recheck.js +135 -0
  100. package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
  101. package/srv/blockchain/signing/hsm-signer.js +28 -79
  102. package/srv/blockchain/signing/landing-proof.d.ts +60 -0
  103. package/srv/blockchain/signing/landing-proof.js +224 -0
  104. package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
  105. package/srv/blockchain/signing/signature-verifier.js +71 -87
  106. package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
  107. package/srv/blockchain/signing/submission-finalizer.js +280 -86
  108. package/srv/blockchain/stored-chain.d.ts +19 -0
  109. package/srv/blockchain/stored-chain.js +258 -0
  110. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
  111. package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
  112. package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
  113. package/srv/blockchain/transaction-presence.d.ts +12 -0
  114. package/srv/blockchain/transaction-presence.js +29 -0
  115. package/srv/blockchain/transaction-rows.d.ts +12 -0
  116. package/srv/blockchain/transaction-rows.js +44 -0
  117. package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
  118. package/srv/blockchain/wallet-worker/build-request.js +40 -353
  119. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
  120. package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
  121. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  122. package/srv/blockchain/wallet-worker/index.js +3 -11
  123. package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
  124. package/srv/blockchain/wallet-worker/invalidation.js +128 -0
  125. package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
  126. package/srv/blockchain/wallet-worker/job-store.js +200 -273
  127. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
  128. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
  129. package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
  130. package/srv/blockchain/wallet-worker/signers.js +4 -12
  131. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
  132. package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
  133. package/srv/cardano-agent-service.cds +122 -84
  134. package/srv/cardano-agent-service.js +12 -9
  135. package/srv/cardano-backend-service.cds +81 -0
  136. package/srv/cardano-backend-service.d.ts +2 -0
  137. package/srv/cardano-backend-service.js +259 -0
  138. package/srv/cardano-indexer-service.cds +393 -18
  139. package/srv/cardano-indexer-service.d.ts +5 -1
  140. package/srv/cardano-indexer-service.js +477 -16
  141. package/srv/cardano-service.cds +426 -269
  142. package/srv/cardano-service.js +640 -217
  143. package/srv/cardano-sign-service.cds +211 -180
  144. package/srv/cardano-sign-service.js +210 -287
  145. package/srv/cardano-tx-service.cds +462 -370
  146. package/srv/cardano-tx-service.js +283 -800
  147. package/srv/cardano-ui.cds +16 -16
  148. package/srv/cardano-worker-service.cds +141 -125
  149. package/srv/cardano-worker-service.js +104 -61
  150. package/srv/cbor/cip68.d.ts +13 -0
  151. package/srv/cbor/cip68.js +56 -0
  152. package/srv/cbor/index.d.ts +3 -1
  153. package/srv/cbor/index.js +9 -1
  154. package/srv/cbor/parse.d.ts +30 -18
  155. package/srv/cbor/parse.js +44 -9
  156. package/srv/cbor/plutus-data-json.d.ts +20 -0
  157. package/srv/cbor/plutus-data-json.js +32 -0
  158. package/srv/config.d.ts +117 -0
  159. package/srv/config.js +419 -0
  160. package/srv/server.d.ts +15 -110
  161. package/srv/server.js +83 -405
  162. package/srv/utils/agent-access.d.ts +11 -0
  163. package/srv/utils/agent-access.js +86 -0
  164. package/srv/utils/agent-grants-config.d.ts +0 -46
  165. package/srv/utils/agent-grants-config.js +17 -85
  166. package/srv/utils/agent-grants.d.ts +106 -122
  167. package/srv/utils/agent-grants.js +538 -237
  168. package/srv/utils/agent-token-auth.d.ts +4 -99
  169. package/srv/utils/agent-token-auth.js +62 -186
  170. package/srv/utils/backend-request-handler.d.ts +3 -17
  171. package/srv/utils/backend-request-handler.js +3 -18
  172. package/srv/utils/build-request.d.ts +52 -0
  173. package/srv/utils/build-request.js +487 -0
  174. package/srv/utils/collections.d.ts +4 -10
  175. package/srv/utils/collections.js +14 -10
  176. package/srv/utils/const.d.ts +32 -75
  177. package/srv/utils/const.js +40 -80
  178. package/srv/utils/crypto.d.ts +3 -12
  179. package/srv/utils/crypto.js +11 -25
  180. package/srv/utils/db-indexes.d.ts +31 -0
  181. package/srv/utils/db-indexes.js +185 -0
  182. package/srv/utils/db-kind.d.ts +23 -0
  183. package/srv/utils/db-kind.js +42 -0
  184. package/srv/utils/db-sanitize.d.ts +20 -0
  185. package/srv/utils/db-sanitize.js +80 -0
  186. package/srv/utils/deep-json.d.ts +6 -0
  187. package/srv/utils/deep-json.js +240 -0
  188. package/srv/utils/detached-run.d.ts +41 -0
  189. package/srv/utils/detached-run.js +101 -0
  190. package/srv/utils/epoch-slots.d.ts +14 -0
  191. package/srv/utils/epoch-slots.js +45 -0
  192. package/srv/utils/error-codes.d.ts +26 -75
  193. package/srv/utils/error-codes.js +27 -72
  194. package/srv/utils/errors.d.ts +55 -187
  195. package/srv/utils/errors.js +161 -235
  196. package/srv/utils/lease.d.ts +20 -0
  197. package/srv/utils/lease.js +62 -0
  198. package/srv/utils/liveness.d.ts +12 -0
  199. package/srv/utils/liveness.js +35 -0
  200. package/srv/utils/mappers.d.ts +111 -223
  201. package/srv/utils/mappers.js +432 -371
  202. package/srv/utils/navigation.d.ts +17 -0
  203. package/srv/utils/navigation.js +52 -0
  204. package/srv/utils/network-context.d.ts +0 -1
  205. package/srv/utils/network-context.js +9 -15
  206. package/srv/utils/paging.d.ts +31 -0
  207. package/srv/utils/paging.js +43 -0
  208. package/srv/utils/pg-inline-json.d.ts +8 -0
  209. package/srv/utils/pg-inline-json.js +58 -0
  210. package/srv/utils/pg-order-nulls.d.ts +14 -0
  211. package/srv/utils/pg-order-nulls.js +54 -0
  212. package/srv/utils/plutus-placeholders.d.ts +16 -22
  213. package/srv/utils/plutus-placeholders.js +62 -33
  214. package/srv/utils/rate-limiter.d.ts +2 -21
  215. package/srv/utils/rate-limiter.js +5 -17
  216. package/srv/utils/readiness.d.ts +12 -0
  217. package/srv/utils/readiness.js +29 -0
  218. package/srv/utils/reference-script.d.ts +19 -0
  219. package/srv/utils/reference-script.js +84 -0
  220. package/srv/utils/resolution.d.ts +13 -0
  221. package/srv/utils/resolution.js +47 -0
  222. package/srv/utils/result-numbers.d.ts +15 -0
  223. package/srv/utils/result-numbers.js +61 -0
  224. package/srv/utils/row-values.d.ts +7 -0
  225. package/srv/utils/row-values.js +27 -0
  226. package/srv/utils/service-events.d.ts +0 -24
  227. package/srv/utils/service-events.js +3 -25
  228. package/srv/utils/signing-helper.d.ts +3 -20
  229. package/srv/utils/signing-helper.js +35 -64
  230. package/srv/utils/tx-build-helper.d.ts +25 -105
  231. package/srv/utils/tx-build-helper.js +108 -156
  232. package/srv/utils/tx-request-parsers.d.ts +82 -33
  233. package/srv/utils/tx-request-parsers.js +401 -49
  234. package/srv/utils/tx-utils.d.ts +3 -27
  235. package/srv/utils/tx-utils.js +32 -50
  236. package/srv/utils/types.d.ts +294 -232
  237. package/srv/utils/types.js +2 -22
  238. package/srv/utils/validators.d.ts +22 -92
  239. package/srv/utils/validators.js +60 -170
@@ -0,0 +1,14 @@
1
+ import { safeJSON } from '@cardano-ogmios/client';
2
+ /** A frame the guard could not turn into an object at all. */
3
+ export interface UnparseableFrame {
4
+ /** Block height, when it could be read off the raw text; null when even that failed. */
5
+ height: number | null;
6
+ /** Block id (hash), when readable. */
7
+ id: string | null;
8
+ reason: string;
9
+ bytes: number;
10
+ }
11
+ export declare function installOgmiosFrameGuard(onUnparseableFrame: (frame: UnparseableFrame) => void): () => void;
12
+ /** Tests only: drop the wrapper so each case starts from the untouched client. */
13
+ export declare function resetOgmiosFrameGuardForTests(originalParse?: typeof safeJSON.parse): void;
14
+ //# sourceMappingURL=ogmios-frame-guard.d.ts.map
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.installOgmiosFrameGuard = installOgmiosFrameGuard;
7
+ exports.resetOgmiosFrameGuardForTests = resetOgmiosFrameGuardForTests;
8
+ // The Ogmios client's `safeJSON.parse` recurses per nesting level and refuses a "__proto__" key.
9
+ // Either throw lands in a socket handler and ends the process, so such frames are parsed here.
10
+ const client_1 = require("@cardano-ogmios/client");
11
+ const cds_1 = __importDefault(require("@sap/cds"));
12
+ const deep_json_1 = require("../../utils/deep-json");
13
+ const logger = cds_1.default.log('OgmiosFrameGuard');
14
+ /** Block height/id from the front of an unparseable frame, to name the block in logs and `lastError`. */
15
+ function readBlockHeader(text) {
16
+ const head = text.slice(0, 4096);
17
+ const id = /"id"\s*:\s*"([0-9a-fA-F]{64})"/.exec(head);
18
+ const height = /"height"\s*:\s*(\d{1,15})/.exec(head);
19
+ return { height: height ? Number(height[1]) : null, id: id ? id[1] : null };
20
+ }
21
+ let installed = false;
22
+ const reporters = new Set();
23
+ // Why the client's parser gave up, or null for a genuine syntax error. json-bigint throws a plain
24
+ // object named SyntaxError for a "__proto__" key; the client only rewrites the "constructor" case.
25
+ function fallbackReason(err) {
26
+ if (err instanceof RangeError)
27
+ return "too deeply nested for the client's parser";
28
+ const e = err;
29
+ if (e?.name === 'SyntaxError' && typeof e.message === 'string' && e.message.includes('forbidden prototype')) {
30
+ return 'carries a "__proto__" key the client\'s parser refuses';
31
+ }
32
+ return null;
33
+ }
34
+ // Wraps `safeJSON.parse` once per process and returns an unregister function. The parser is shared
35
+ // by all chain-sync sockets, so an unusable frame goes to every callback. That stream then stalls.
36
+ function installOgmiosFrameGuard(onUnparseableFrame) {
37
+ reporters.add(onUnparseableFrame);
38
+ const unregister = () => { reporters.delete(onUnparseableFrame); };
39
+ if (installed)
40
+ return unregister;
41
+ const original = client_1.safeJSON.parse.bind(client_1.safeJSON);
42
+ installed = true; // only once the original is safely in hand
43
+ client_1.safeJSON.parse = (raw) => {
44
+ try {
45
+ return original(raw);
46
+ }
47
+ catch (err) {
48
+ const why = fallbackReason(err);
49
+ if (why === null)
50
+ throw err; // a genuine syntax error stays a syntax error
51
+ const text = String(raw);
52
+ const where = readBlockHeader(text);
53
+ try {
54
+ // Without the client's bigint pass (it recurses too), so short integers stay numbers here.
55
+ // Every reader of a quantity stringifies it, so the two shapes are read the same way.
56
+ const parsed = (0, deep_json_1.parseJson)(text);
57
+ logger.warn(`chain-sync frame ${why} (block ${where.height ?? '?'} ${where.id ?? ''}, ${text.length} bytes), ` +
58
+ 'parsed without it.');
59
+ return parsed;
60
+ }
61
+ catch (fallbackErr) {
62
+ const reason = fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr);
63
+ logger.error(`chain-sync frame unparseable (block ${where.height ?? '?'} ${where.id ?? ''}, ` +
64
+ `${text.length} bytes): ${reason}`);
65
+ const frame = { ...where, reason, bytes: text.length };
66
+ for (const r of [...reporters]) {
67
+ try {
68
+ r(frame);
69
+ }
70
+ catch (cbErr) {
71
+ logger.error('frame guard report callback failed:', cbErr);
72
+ }
73
+ }
74
+ // Never throw: this runs in an async socket handler nobody awaits, so a throw
75
+ // becomes an unhandled rejection and ends the process.
76
+ return {};
77
+ }
78
+ }
79
+ };
80
+ return unregister;
81
+ }
82
+ /** Tests only: drop the wrapper so each case starts from the untouched client. */
83
+ function resetOgmiosFrameGuardForTests(originalParse) {
84
+ if (originalParse)
85
+ client_1.safeJSON.parse = originalParse;
86
+ installed = false;
87
+ reporters.clear();
88
+ }
89
+ //# sourceMappingURL=ogmios-frame-guard.js.map
@@ -1,9 +1,9 @@
1
- import { ChainSyncBackend, PaginatingBackend } from './backends/cardano-backend';
1
+ import { ChainSyncBackend, PaginatingBackend, EnumeratingBackend, LedgerStateBackend, EpochStateBackend, TokenRegistryBackend, RewardAccountStateBackend } from './backends/cardano-backend';
2
+ import { PendingSpends } from './pending-spends';
2
3
  import { type CircuitBreakerConfig } from './circuit-breaker';
3
4
  import { Transaction, Address, UTxO, NetworkInformation, BlockData, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, ScriptEvaluationResult } from '../utils/types';
4
5
  export type Network = 'mainnet' | 'preview' | 'preprod';
5
- export type BackendName = 'blockfrost' | 'koios' | 'ogmios';
6
- export type TransactionBuilderName = 'buildooor';
6
+ export type BackendName = 'blockfrost' | 'koios' | 'ogmios' | 'odatano';
7
7
  export type CardanoClientConfig = {
8
8
  network: Network;
9
9
  backends: BackendName[];
@@ -11,20 +11,15 @@ export type CardanoClientConfig = {
11
11
  blockfrostCustomBackend?: string;
12
12
  koiosApiKey: string;
13
13
  ogmiosUrl: string;
14
- transactionBuilders: TransactionBuilderName[];
14
+ /** Remote ODATANO for the `odatano` backend; defaults to the public API of the network. */
15
+ odatanoUrl?: string;
16
+ /** Key for the remote ODATANO (a gateway `oda_…` key or an agent grant token). */
17
+ odatanoApiKey?: string;
15
18
  primaryTimeoutMs: number;
16
19
  fallbackTimeoutMs: number;
17
20
  indexTtlMs: number;
18
21
  circuitBreaker?: Partial<CircuitBreakerConfig>;
19
22
  };
20
- /**
21
- * CardanoClient - Smart Multi-backend Cardano Client
22
- *
23
- * Routes requests to appropriate backends:
24
- * - Live/State queries → Ogmios (if available)
25
- * - Historical queries → Blockfrost/Koios (if available)
26
- * - Automatic fallback between backends
27
- */
28
23
  export declare class CardanoClient {
29
24
  private config;
30
25
  private liveBackend?;
@@ -32,283 +27,118 @@ export declare class CardanoClient {
32
27
  private initialized;
33
28
  private initPromise;
34
29
  private circuitBreaker;
35
- /** Backends whose init failed — kept in rotation and retried lazily per request */
30
+ /** Backends whose init failed. They stay in rotation and init is retried per request. */
36
31
  private uninitializedBackends;
32
+ /** Running init retry per backend, shared by concurrent callers. */
33
+ private initRetries;
37
34
  network: Network;
38
35
  max_age_ms: number;
36
+ /** Transactions submitted through this client that the ledger view does not show yet. */
37
+ readonly pendingSpends: PendingSpends;
39
38
  private protocolParamsCache?;
40
39
  private protocolParamsFetchPromise;
41
- private static readonly PROTOCOL_PARAMS_TTL_MS;
40
+ /** Last protocol parameters the live backend (node) answered. */
41
+ private lastLiveProtocolParams?;
42
42
  private txCoalescer;
43
43
  private addrCoalescer;
44
44
  private credCoalescer;
45
- /**
46
- * Constructor for CardanoClient
47
- * @param liveBackend - Optional backend for live/state queries (typically Ogmios)
48
- * @param historicalBackends - Optional backends for historical queries (typically Blockfrost/Koios)
49
- */
45
+ /** Builds the configured backends; throws ConfigError when none is configured. */
50
46
  constructor(clientConfig: CardanoClientConfig);
51
47
  /** Names of the configured backends (live + historical), for status reporting. */
52
48
  listBackends(): string[];
53
- /**
54
- * Ensure backends are initialized.
55
- * A REJECTED init promise is cleared so the next request retries — previously
56
- * a transient startup failure (e.g. Ogmios briefly down) left the client
57
- * permanently broken until process restart.
58
- * @returns {Promise<void>}
59
- */
49
+ /** A failed init promise is cleared so the next request retries instead of staying broken. */
60
50
  private ensureInitialized;
61
- /**
62
- * Transient (retryable) init failures: a backend momentarily unreachable at
63
- * startup — e.g. Ogmios's /health response cut short while the node processes
64
- * a freshly-arrived block ("Premature close"), or the socket still coming up
65
- * (ECONNREFUSED). Config/validation errors are NOT transient.
66
- */
51
+ /** True for a backend that is briefly unreachable at startup. Config errors are not transient. */
67
52
  private static isTransientInitError;
68
- /**
69
- * Init a backend, retrying brief transient failures. Deliberately SMALL: the
70
- * integration suites bootstrap under a 20s cds.test() hook, so total retry
71
- * time must stay well under it (≤3 attempts × 4s init-timeout + 1s backoff
72
- * ≈ 14s worst case; in practice "Premature close" returns sub-second). With
73
- * the node at tip these failures are momentary block-processing blips, so a
74
- * couple of quick retries ride over them; a sustained outage still fails fast.
75
- */
76
53
  private initBackendWithRetry;
77
- /**
78
- * Initialize all backends from configuration.
79
- * Backends that fail to initialize are KEPT (previously removed permanently)
80
- * and tracked in `uninitializedBackends` — the request loops retry their
81
- * init lazily, so a backend that comes back online recovers without a
82
- * process restart. The circuit breaker bounds the retry cost.
83
- * @returns {Promise<void>}
84
- */
54
+ /** Backends whose init fails stay in rotation and are retried per request, bounded by the breaker. */
85
55
  private initBackends;
86
- /**
87
- * Lazily retry a backend's init when it failed at startup. Returns true when
88
- * the backend is usable; false (after recording a breaker failure) when the
89
- * retry failed.
90
- */
91
56
  private ensureBackendInitialized;
92
- /**
93
- * Wrap a promise with a timeout
94
- * @param promise - the promise to wrap
95
- * @param ms - timeout in milliseconds
96
- * @param backendName - name of the backend (for error context)
97
- * @returns {Promise<T>} the result of the promise or a timeout error
98
- */
99
57
  private withTimeout;
100
- /**
101
- * Get timeout for specific backend
102
- * @param backend CardanoBackend instance
103
- * @returns {number} timeout in milliseconds
104
- */
58
+ /** Per-backend timeout: Koios and a remote ODATANO get the fallback timeout, everything else the primary one. */
105
59
  private getTimeoutForBackend;
106
- /**
107
- * Run a single-backend call with the same resilience contract as
108
- * executeWithPriority: circuit-breaker gate, timeout, success/failure
109
- * recording (4xx exempt). For the paths that cannot fail over (Koios-only,
110
- * Ogmios-only, batch-capable loops) — these previously bypassed timeout AND
111
- * breaker entirely, so a hanging socket blocked the caller indefinitely.
112
- */
113
60
  private callWithResilience;
114
- /**
115
- * Execute with priority-based backend selection and automatic fallback
116
- * @param fn function to execute on backend
117
- * @param preferLive whether to prefer live backend over historical
118
- * @returns {Promise<T>} result from backend
119
- */
61
+ private recordOutcome;
62
+ /** Execute on backends in preference order (live vs historical) with automatic fallback. */
120
63
  private executeWithPriority;
121
- /**
122
- * Route method call to appropriate backend based on method routing configuration
123
- * @param methodName name of the method being called
124
- * @param fn function to execute on backend
125
- * @returns {Promise<T>} result from backend
126
- */
64
+ /** Route a call by METHOD_ROUTING (default: historical first). */
127
65
  private route;
128
- /**
129
- * Get transaction by hash with fallback between backends
130
- * @param txHash transaction hash (hex)
131
- * @returns {Promise<Transaction>} transaction data
132
- */
66
+ /** Transaction by hash (coalesced across concurrent callers). */
133
67
  getTransaction(txHash: string): Promise<Transaction>;
134
- /**
135
- * Get address by bech32 address with fallback between backends
136
- * @param address bech32 address
137
- * @returns {Promise<Address>} address data
138
- */
68
+ /** Address data (coalesced across concurrent callers). */
139
69
  getAddress(address: string): Promise<Address>;
140
- /**
141
- * Get address UTxOs with fallback between backends
142
- * @param address bech32 address
143
- * @returns {Promise<UTxO[]>} list of UTxOs
144
- */
145
70
  getAddressUtxos(address: string): Promise<UTxO[]>;
146
- /**
147
- * Get UTxOs by 28-byte payment credential. Koios-only — bypasses generic
148
- * failover because no other backend exposes a credential-keyed UTxO endpoint.
149
- * Throws ProviderUnavailableError if Koios is not configured.
150
- * @param credHash 28-byte payment credential as 56-char lowercase hex
151
- * @returns {Promise<UTxO[]>} list of UTxOs across all bech32 forms sharing the credential
152
- */
153
71
  getCredentialUtxos(credHash: string): Promise<UTxO[]>;
154
- /**
155
- * Get address transactions with fallback between backends
156
- * @param address bech32 address
157
- * @returns {Promise<Transaction[]>} list of transactions for this address
158
- */
72
+ /** Backends that pass `can`, the one named `preferred` first. */
73
+ private capableBackends;
74
+ private firstAnswer;
159
75
  getAddressTransactions(address: string, limit: number): Promise<Transaction[]>;
160
- /**
161
- * Get network information with fallback between backends
162
- * @returns {Promise<Network>} network information
163
- */
164
76
  getNetworkInformation(): Promise<NetworkInformation>;
165
- /**
166
- * Get transaction metadata with fallback between backends
167
- * @param tx_hash transaction hash (hex)
168
- * @returns {Promise<MetadataLabelTx[]>} transaction metadata
169
- */
170
77
  getTransactionMetadata(tx_hash: string): Promise<MetadataLabelTx[]>;
171
- /**
172
- * Get block data with fallback between backends
173
- * @param block_hash block hash (hex)
174
- * @returns {Promise<BlockData>} block data
175
- */
176
78
  getBlock(block_hash: string): Promise<BlockData>;
177
- /**
178
- * Get epoch data with fallback between backends
179
- * @param epochNumber epoch number
180
- * @returns {Promise<EpochData>} epoch data
181
- */
182
79
  getEpoch(epochNumber: number): Promise<EpochData>;
183
- /**
184
- * Get Pool data with fallback between backends
185
- * @param poolId pool id
186
- * @returns {Promise<PoolData>} pool data
187
- */
188
80
  getPool(poolId: string): Promise<PoolData>;
189
- /**
190
- * Get drep data with fallback between backends
191
- * @param drepId drep id
192
- * @returns {Promise<DrepData>} drep data
193
- */
194
81
  getDrep(drepId: string): Promise<DrepData>;
195
- /**
196
- * Get account data with fallback between backends
197
- * @param stakeAddress stake address
198
- * @returns {Promise<AccountData>} account data
199
- */
200
82
  getAccount(stakeAddress: string): Promise<AccountData>;
201
- /**
202
- * Get asset info (supply, mint history, CIP-25 + CIP-26 metadata) with fallback.
203
- * Both Blockfrost and Koios implement; Ogmios throws "not supported".
204
- * @param unit policyId + assetNameHex (concatenated hex)
205
- * @returns {Promise<AssetInfo>} canonical asset info
206
- */
83
+ isRewardAccountRegistered(stakeAddress: string): Promise<boolean | null>;
84
+ /** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
207
85
  getAssetInfo(unit: string): Promise<AssetInfo>;
208
- /**
209
- * Get latest mint/burn events for an asset. Prefers Koios because it provides
210
- * block timestamps; Blockfrost is the fallback (timestamps left null).
211
- * Ogmios doesn't implement — fallback skips it via the optional method check.
212
- * @param unit policyId + assetNameHex (concatenated hex)
213
- * @param limit max number of events (default 100)
214
- * @returns {Promise<AssetHistoryEntry[]>} list of mint/burn events (most recent first)
215
- */
86
+ /** Latest mint and burn events. Koios first, because Blockfrost leaves timestamps null. */
216
87
  getAssetHistory(unit: string, limit?: number): Promise<AssetHistoryEntry[]>;
217
- /**
218
- * Get transaction hashes for an address (lightweight — no full tx details).
219
- * Uses getAddressTransactionHashes() if backend supports it, otherwise
220
- * falls back to getAddressTransactions() and extracts hashes.
221
- * @param address bech32 address
222
- * @param limit maximum number of hashes
223
- * @returns {Promise<string[]>} list of transaction hashes
224
- */
88
+ /** Falls back to a full getAddressTransactions when no backend lists hashes only. */
225
89
  getAddressTransactionHashes(address: string, limit: number): Promise<string[]>;
226
- /**
227
- * Batch fetch multiple transactions by hash.
228
- * Uses getTransactionsBatch() if backend supports it, otherwise
229
- * falls back to individual getTransaction() calls (still coalesced).
230
- * @param txHashes array of transaction hashes
231
- * @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
232
- */
90
+ /** Batch fetch transactions by hash; falls back to individual coalesced getTransaction calls. */
233
91
  getTransactionsBatch(txHashes: string[]): Promise<Map<string, Transaction>>;
234
- /**
235
- * Backends in historical-first order. Used by the batch methods — both
236
- * always prefer historical data, so the former preferLive parameter was a
237
- * dead branch.
238
- */
92
+ /** Backends in historical-first order, for the batch methods. */
239
93
  private getOrderedBackends;
240
- /**
241
- * Get a backend that supports streamed chain-synchronization (Ogmios), or null.
242
- * The crawler's primary, reorg-aware source. Checks the live backend first.
243
- * Backends whose init() failed are skipped — the crawler uses these instances
244
- * DIRECTLY (outside executeWithPriority's lazy-retry/breaker), so handing out an
245
- * uninitialized backend would wedge it.
246
- */
247
94
  getChainSyncBackend(): ChainSyncBackend | null;
248
- /**
249
- * Get a backend that can be walked forward by pagination (Blockfrost/Koios), or null.
250
- * The crawler's fallback source when no Ogmios chain-sync is available.
251
- * Skips backends whose init() failed (see getChainSyncBackend).
252
- *
253
- * Koios is preferred over Blockfrost for bulk block-crawling: Koios batches 100 txs
254
- * per POST /tx_info, while Blockfrost has no batch endpoint (~3 HTTP calls per tx) —
255
- * roughly a 40x difference in request volume per crawled block.
256
- */
95
+ /** Like getChainSyncBackend() but retries a failed init. The crawler polls it while on pagination. */
96
+ recoverChainSyncBackend(): Promise<ChainSyncBackend | null>;
97
+ /** First usable backend that can dump the UTxO set at a point, for the UTxO set import. */
98
+ getLedgerStateBackend(): LedgerStateBackend | null;
99
+ readLedger(refs: Array<{
100
+ txHash: string;
101
+ outputIndex: number;
102
+ }>): Promise<{
103
+ live: boolean;
104
+ tip: number;
105
+ unspent: boolean[];
106
+ }>;
107
+ getUnspentOutputs(refs: Array<{
108
+ txHash: string;
109
+ outputIndex: number;
110
+ }>): Promise<UTxO[] | null>;
111
+ /** True when an initialized backend implements `method` and does not declare it unsupported. */
112
+ hasBackendFor(method: string): boolean;
113
+ /** Backend that reads pool, DRep and pot state at a block. Preferred source of epoch snapshots. */
114
+ getEpochStateBackend(): EpochStateBackend | null;
115
+ /** Backend that reads reward accounts at a block, for account snapshots. */
116
+ getRewardAccountStateBackend(): RewardAccountStateBackend | null;
117
+ /** Without one, epoch snapshots stay off instead of making thousands of single requests. */
118
+ getEnumeratingBackend(): EnumeratingBackend | null;
119
+ /** Backend that lists the CIP-26 token registry (Koios). Null when none is configured. */
120
+ getTokenRegistryBackend(): TokenRegistryBackend | null;
121
+ /** Prefers Koios, because it batches 100 txs per call and Blockfrost needs about 3 calls per tx. */
257
122
  getPaginatingBackend(): PaginatingBackend | null;
258
- /**
259
- * Get protocol parameters with caching (5 minute TTL)
260
- * Protocol parameters rarely change (once per epoch at most), so caching improves performance
261
- * @returns {Promise<LedgerProtocolParameters>} protocol parameters
262
- */
123
+ /** Protocol parameters with a 5-minute in-memory cache and coalesced refresh. */
263
124
  getProtocolParameters(): Promise<LedgerProtocolParameters>;
264
- /**
265
- * Shutdown all backends (for cleanup in tests)
266
- */
125
+ /** Shut down all backends. */
267
126
  shutdown(): Promise<void>;
268
- /**
269
- * Get latest block data with fallback between backends
270
- * @returns {Promise<BlockData>} latest block data
271
- */
272
127
  getLatestBlock(): Promise<BlockData>;
273
- /**
274
- * Get latest epoch data with fallback between backends
275
- * @returns {Promise<EpochData>} latest epoch data
276
- */
277
128
  getLatestEpoch(): Promise<EpochData>;
278
- /**
279
- * Get the current chain slot with fallback between backends.
280
- * @returns {Promise<number>} current chain slot
281
- */
282
129
  getCurrentSlot(): Promise<number>;
283
- /**
284
- * Check whether a UTxO is still unspent with fallback between backends.
285
- * @param txHash 64-char lowercase hex transaction hash
286
- * @param outputIndex non-negative integer output index
287
- * @returns {Promise<boolean>} true iff the UTxO exists and is unspent
288
- */
130
+ /** True iff the UTxO exists and is unspent. */
289
131
  isUtxoUnspent(txHash: string, outputIndex: number): Promise<boolean>;
290
- /**
291
- * Submit transaction with fallback between backends
292
- * @param signedTxCbor signed transaction in CBOR hex format
293
- * @returns {Promise<string>} transaction hash
294
- *
295
- * NOTE on failover semantics: when the preferred backend ACCEPTS the tx but
296
- * its response is lost (timeout), the failover resubmits on the next backend,
297
- * which may answer 409 "already submitted". Callers should treat a
298
- * TransactionAlreadySubmittedError after a submit attempt as success — the
299
- * transaction IS in the mempool.
300
- */
301
132
  submitTransaction(signedTxCbor: string): Promise<string>;
302
- /**
303
- * Check if Ogmios backend is available for transaction evaluation
304
- * @returns {boolean} true if Ogmios is the live backend
305
- */
133
+ /** True when a configured backend can serve the method. */
134
+ supports(methodName: string): boolean;
135
+ /** True when Ogmios is the live backend. */
306
136
  hasOgmiosBackend(): boolean;
307
- /**
308
- * Evaluate transaction script execution units (Ogmios only)
309
- * @param unsignedTxCbor unsigned transaction in CBOR hex format
310
- * @returns {Promise<ScriptEvaluationResult[]>} evaluation results
311
- */
137
+ /** The backend that evaluates scripts: the live one (Ogmios), else an evaluating historical one (odatano). */
138
+ private evaluatingBackend;
139
+ /** True when some backend can evaluate script execution units. */
140
+ hasEvaluatingBackend(): boolean;
141
+ /** Evaluate script execution units of an unsigned transaction. */
312
142
  evaluateTransaction(unsignedTxCbor: string): Promise<ScriptEvaluationResult[]>;
313
143
  }
314
144
  //# sourceMappingURL=cardano-client.d.ts.map