@odatano/core 2.0.0-rc.2 → 2.0.0-rc.21
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.
- package/@cds-models/CardanoAgentService/index.d.ts +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +139 -2
- package/@cds-models/CardanoIndexerService/index.js +18 -0
- package/@cds-models/CardanoODataService/index.d.ts +231 -6
- package/@cds-models/CardanoODataService/index.js +27 -0
- package/@cds-models/CardanoSignService/index.d.ts +5 -2
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -9
- package/@cds-models/odatano/cardano/index.d.ts +323 -6
- package/@cds-models/odatano/cardano/index.js +33 -0
- package/README.md +195 -136
- package/db/schema.cds +2133 -1633
- package/package.json +181 -173
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +10 -10
- package/src/index.js +24 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +45 -158
- package/srv/blockchain/backends/cardano-backend.d.ts +83 -158
- package/srv/blockchain/backends/cardano-backend.js +14 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +293 -203
- package/srv/blockchain/backends/ogmios-backend.d.ts +69 -94
- package/srv/blockchain/backends/ogmios-backend.js +319 -185
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +57 -204
- package/srv/blockchain/cardano-client.js +94 -226
- package/srv/blockchain/cardano-indexer.d.ts +176 -240
- package/srv/blockchain/cardano-indexer.js +615 -338
- package/srv/blockchain/cardano-tx-builder.d.ts +29 -82
- package/srv/blockchain/cardano-tx-builder.js +88 -128
- package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
- package/srv/blockchain/crawler/certificate-backfill.js +150 -0
- package/srv/blockchain/crawler/crawler.d.ts +121 -53
- package/srv/blockchain/crawler/crawler.js +403 -89
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +44 -28
- package/srv/blockchain/crawler/sync-state.js +115 -43
- package/srv/blockchain/crawler/utxo-set-import.d.ts +69 -0
- package/srv/blockchain/crawler/utxo-set-import.js +269 -0
- package/srv/blockchain/ledger-state.d.ts +80 -0
- package/srv/blockchain/ledger-state.js +383 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -48
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +71 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +185 -260
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +42 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +39 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-indexer-service.cds +164 -73
- package/srv/cardano-indexer-service.js +156 -11
- package/srv/cardano-service.cds +45 -0
- package/srv/cardano-service.js +38 -96
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.js +136 -196
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +28 -86
- package/srv/server.js +95 -128
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +914 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +19 -68
- package/srv/utils/const.js +20 -69
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +93 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +25 -0
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +36 -179
- package/srv/utils/errors.js +62 -220
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +41 -0
- package/srv/utils/mappers.d.ts +89 -214
- package/srv/utils/mappers.js +289 -301
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +57 -0
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +18 -92
- package/srv/utils/tx-build-helper.js +32 -123
- package/srv/utils/tx-request-parsers.d.ts +14 -20
- package/srv/utils/tx-request-parsers.js +33 -20
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +114 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -13,15 +13,14 @@ 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 },
|
|
22
20
|
getAddressUtxos: { preferLive: false },
|
|
23
21
|
getAddressTransactions: { preferLive: false },
|
|
24
|
-
|
|
22
|
+
// providers first: they report circulation; Ogmios only has treasury and reserves
|
|
23
|
+
getNetworkInformation: { preferLive: false },
|
|
25
24
|
getTransactionMetadata: { preferLive: false },
|
|
26
25
|
getBlock: { preferLive: false },
|
|
27
26
|
getEpoch: { preferLive: false },
|
|
@@ -37,12 +36,8 @@ const METHOD_ROUTING = {
|
|
|
37
36
|
submitTransaction: { preferLive: true },
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
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
|
|
39
|
+
* Multi-backend Cardano client: live/state queries prefer Ogmios, historical queries prefer
|
|
40
|
+
* Blockfrost/Koios, with automatic fallback between them.
|
|
46
41
|
*/
|
|
47
42
|
class CardanoClient {
|
|
48
43
|
config;
|
|
@@ -62,11 +57,7 @@ class CardanoClient {
|
|
|
62
57
|
txCoalescer = new request_coalescer_1.RequestCoalescer();
|
|
63
58
|
addrCoalescer = new request_coalescer_1.RequestCoalescer();
|
|
64
59
|
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
|
-
*/
|
|
60
|
+
/** Builds the configured backends; throws ConfigError when none is configured. */
|
|
70
61
|
constructor(clientConfig) {
|
|
71
62
|
this.network = clientConfig.network;
|
|
72
63
|
const backends = clientConfig.backends;
|
|
@@ -83,9 +74,7 @@ class CardanoClient {
|
|
|
83
74
|
throw new errors_1.ConfigError('No valid backends configured for CardanoClient');
|
|
84
75
|
}
|
|
85
76
|
this.circuitBreaker = new circuit_breaker_1.CircuitBreakerManager(clientConfig.circuitBreaker);
|
|
86
|
-
//
|
|
87
|
-
// Previously max_age_ms stayed hardcoded at 60s and indexTtlMs was dead — the
|
|
88
|
-
// documented/configurable 1h default never took effect.
|
|
77
|
+
// indexTtlMs is the cache TTL the indexer reads via max_age_ms
|
|
89
78
|
if (Number.isFinite(clientConfig.indexTtlMs) && clientConfig.indexTtlMs > 0) {
|
|
90
79
|
this.max_age_ms = clientConfig.indexTtlMs;
|
|
91
80
|
}
|
|
@@ -101,16 +90,13 @@ class CardanoClient {
|
|
|
101
90
|
return names;
|
|
102
91
|
}
|
|
103
92
|
/**
|
|
104
|
-
* Ensure backends are initialized.
|
|
105
|
-
*
|
|
106
|
-
* a transient startup failure (e.g. Ogmios briefly down) left the client
|
|
107
|
-
* permanently broken until process restart.
|
|
108
|
-
* @returns {Promise<void>}
|
|
93
|
+
* Ensure backends are initialized. A rejected init promise is cleared so the next request
|
|
94
|
+
* retries instead of leaving the client permanently broken.
|
|
109
95
|
*/
|
|
110
96
|
async ensureInitialized() {
|
|
111
97
|
if (this.initialized)
|
|
112
98
|
return;
|
|
113
|
-
//
|
|
99
|
+
// ??= keeps concurrent callers on one init promise
|
|
114
100
|
this.initPromise ??= this.initBackends().catch((err) => {
|
|
115
101
|
this.initPromise = null;
|
|
116
102
|
throw err;
|
|
@@ -118,10 +104,8 @@ class CardanoClient {
|
|
|
118
104
|
await this.initPromise;
|
|
119
105
|
}
|
|
120
106
|
/**
|
|
121
|
-
* Transient (retryable) init failures: a backend momentarily unreachable at
|
|
122
|
-
*
|
|
123
|
-
* a freshly-arrived block ("Premature close"), or the socket still coming up
|
|
124
|
-
* (ECONNREFUSED). Config/validation errors are NOT transient.
|
|
107
|
+
* Transient (retryable) init failures: a backend momentarily unreachable at startup
|
|
108
|
+
* (connection refused/reset, a cut-short health response). Config/validation errors are not.
|
|
125
109
|
*/
|
|
126
110
|
static isTransientInitError(err) {
|
|
127
111
|
const e = err;
|
|
@@ -132,12 +116,8 @@ class CardanoClient {
|
|
|
132
116
|
return /premature close|socket hang up|econnreset|econnrefused|etimedout|timeout|fetch failed|terminated|other side closed/.test(msg);
|
|
133
117
|
}
|
|
134
118
|
/**
|
|
135
|
-
* Init a backend, retrying brief transient failures.
|
|
136
|
-
*
|
|
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.
|
|
119
|
+
* Init a backend, retrying brief transient failures. Kept small (3 attempts, 1 s backoff) so
|
|
120
|
+
* a sustained outage still fails fast and the total stays under the test bootstrap hook.
|
|
141
121
|
*/
|
|
142
122
|
async initBackendWithRetry(backend) {
|
|
143
123
|
const maxAttempts = 3;
|
|
@@ -155,12 +135,8 @@ class CardanoClient {
|
|
|
155
135
|
}
|
|
156
136
|
}
|
|
157
137
|
/**
|
|
158
|
-
* Initialize all backends
|
|
159
|
-
*
|
|
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>}
|
|
138
|
+
* Initialize all backends. Backends whose init fails stay in rotation, tracked in
|
|
139
|
+
* `uninitializedBackends`, and are retried lazily per request (bounded by the circuit breaker).
|
|
164
140
|
*/
|
|
165
141
|
async initBackends() {
|
|
166
142
|
const initErrors = [];
|
|
@@ -220,13 +196,7 @@ class CardanoClient {
|
|
|
220
196
|
return false;
|
|
221
197
|
}
|
|
222
198
|
}
|
|
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
|
-
*/
|
|
199
|
+
/** Wrap a promise with a timeout that rejects with ProviderUnavailableError. */
|
|
230
200
|
withTimeout(promise, ms, backendName) {
|
|
231
201
|
let timeoutId;
|
|
232
202
|
const timeoutPromise = new Promise((_, reject) => {
|
|
@@ -236,22 +206,15 @@ class CardanoClient {
|
|
|
236
206
|
clearTimeout(timeoutId);
|
|
237
207
|
});
|
|
238
208
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Get timeout for specific backend
|
|
241
|
-
* @param backend CardanoBackend instance
|
|
242
|
-
* @returns {number} timeout in milliseconds
|
|
243
|
-
*/
|
|
209
|
+
/** Per-backend timeout: Koios gets the fallback timeout, everything else the primary one. */
|
|
244
210
|
getTimeoutForBackend(backend) {
|
|
245
211
|
if (backend.name === 'koios')
|
|
246
212
|
return this.config.fallbackTimeoutMs;
|
|
247
213
|
return this.config.primaryTimeoutMs;
|
|
248
214
|
}
|
|
249
215
|
/**
|
|
250
|
-
*
|
|
251
|
-
*
|
|
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.
|
|
216
|
+
* Single-backend call with the executeWithPriority resilience contract (breaker gate, timeout,
|
|
217
|
+
* success/failure recording, 4xx exempt) for paths that cannot fail over.
|
|
255
218
|
*/
|
|
256
219
|
async callWithResilience(backend, fn) {
|
|
257
220
|
if (!this.circuitBreaker.shouldAttempt(backend.name)) {
|
|
@@ -275,15 +238,11 @@ class CardanoClient {
|
|
|
275
238
|
throw backendError;
|
|
276
239
|
}
|
|
277
240
|
}
|
|
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
|
-
*/
|
|
241
|
+
/** Execute on backends in preference order (live vs historical) with automatic fallback. */
|
|
284
242
|
async executeWithPriority(fn, preferLive, methodName) {
|
|
285
243
|
await this.ensureInitialized();
|
|
286
244
|
const errors = [];
|
|
245
|
+
const skipped = [];
|
|
287
246
|
// Determine backend order based on preference
|
|
288
247
|
const primaryBackends = preferLive
|
|
289
248
|
? (this.liveBackend ? [this.liveBackend] : [])
|
|
@@ -297,10 +256,12 @@ class CardanoClient {
|
|
|
297
256
|
// capability routing: declared non-support is a skip, not a failure
|
|
298
257
|
if (methodName && backend.unsupportedMethods?.has(methodName)) {
|
|
299
258
|
logger.debug(`${backend.name} does not support ${methodName}, skipping`);
|
|
259
|
+
skipped.push(`${backend.name}: does not support ${methodName}`);
|
|
300
260
|
continue;
|
|
301
261
|
}
|
|
302
262
|
if (!this.circuitBreaker.shouldAttempt(backend.name)) {
|
|
303
263
|
logger.debug(`Circuit open for ${backend.name}, skipping`);
|
|
264
|
+
skipped.push(`${backend.name}: circuit open`);
|
|
304
265
|
continue;
|
|
305
266
|
}
|
|
306
267
|
// fast-path sync check — only await the init retry in the rare failure case
|
|
@@ -317,10 +278,8 @@ class CardanoClient {
|
|
|
317
278
|
catch (err) {
|
|
318
279
|
const backendError = (0, errors_1.normalizeBackendError)(err, backend.name);
|
|
319
280
|
errors.push(backendError);
|
|
320
|
-
// 4xx are definitive verdicts from a
|
|
321
|
-
//
|
|
322
|
-
// health and may open the circuit. Counting client errors opened the breaker
|
|
323
|
-
// on user mistakes and took working backends out of rotation.
|
|
281
|
+
// 4xx are definitive verdicts from a healthy backend and must not open the circuit;
|
|
282
|
+
// only 5xx/timeouts/transport errors indicate backend health.
|
|
324
283
|
const isClientError = backendError.statusCode >= 400 && backendError.statusCode < 500;
|
|
325
284
|
if (!isClientError) {
|
|
326
285
|
this.circuitBreaker.recordFailure(backend.name);
|
|
@@ -329,48 +288,27 @@ class CardanoClient {
|
|
|
329
288
|
logger[logLevel](`Backend failed${backendError.statusCode === 404 ? ': resource not found' : ''}: ${backend.name} - ${backendError.message}`);
|
|
330
289
|
}
|
|
331
290
|
}
|
|
332
|
-
throw new errors_1.AllBackendsFailedError(errors);
|
|
291
|
+
throw new errors_1.AllBackendsFailedError(errors, undefined, skipped);
|
|
333
292
|
}
|
|
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
|
-
*/
|
|
293
|
+
/** Route a call by METHOD_ROUTING (default: historical first). */
|
|
340
294
|
route(methodName, fn) {
|
|
341
295
|
const config = METHOD_ROUTING[methodName] ?? { preferLive: false };
|
|
342
296
|
return this.executeWithPriority(fn, config.preferLive, methodName);
|
|
343
297
|
}
|
|
344
|
-
/**
|
|
345
|
-
* Get transaction by hash with fallback between backends
|
|
346
|
-
* @param txHash transaction hash (hex)
|
|
347
|
-
* @returns {Promise<Transaction>} transaction data
|
|
348
|
-
*/
|
|
298
|
+
/** Transaction by hash (coalesced across concurrent callers). */
|
|
349
299
|
getTransaction(txHash) {
|
|
350
300
|
return this.txCoalescer.get(txHash, () => this.route('getTransaction', b => b.getTransaction(txHash)));
|
|
351
301
|
}
|
|
352
|
-
/**
|
|
353
|
-
* Get address by bech32 address with fallback between backends
|
|
354
|
-
* @param address bech32 address
|
|
355
|
-
* @returns {Promise<Address>} address data
|
|
356
|
-
*/
|
|
302
|
+
/** Address data (coalesced across concurrent callers). */
|
|
357
303
|
getAddress(address) {
|
|
358
304
|
return this.addrCoalescer.get(address, () => this.route('getAddress', b => b.getAddress(address)));
|
|
359
305
|
}
|
|
360
|
-
/**
|
|
361
|
-
* Get address UTxOs with fallback between backends
|
|
362
|
-
* @param address bech32 address
|
|
363
|
-
* @returns {Promise<UTxO[]>} list of UTxOs
|
|
364
|
-
*/
|
|
365
306
|
getAddressUtxos(address) {
|
|
366
307
|
return this.route('getAddressUtxos', b => b.getAddressUtxos(address));
|
|
367
308
|
}
|
|
368
309
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
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
|
|
310
|
+
* UTxOs by 28-byte payment credential (56-char hex), across all bech32 forms sharing it.
|
|
311
|
+
* Koios-only: no other backend has a credential-keyed endpoint, so this throws without Koios.
|
|
374
312
|
*/
|
|
375
313
|
getCredentialUtxos(credHash) {
|
|
376
314
|
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
@@ -380,85 +318,37 @@ class CardanoClient {
|
|
|
380
318
|
}
|
|
381
319
|
return this.credCoalescer.get(credHash, () => this.callWithResilience(koios, () => koios.getCredentialUtxos(credHash)));
|
|
382
320
|
}
|
|
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
321
|
getAddressTransactions(address, limit) {
|
|
389
322
|
return this.route('getAddressTransactions', b => b.getAddressTransactions(address, limit));
|
|
390
323
|
}
|
|
391
|
-
/**
|
|
392
|
-
* Get network information with fallback between backends
|
|
393
|
-
* @returns {Promise<Network>} network information
|
|
394
|
-
*/
|
|
395
324
|
getNetworkInformation() {
|
|
396
325
|
return this.route('getNetworkInformation', b => b.getNetworkInformation());
|
|
397
326
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Get transaction metadata with fallback between backends
|
|
400
|
-
* @param tx_hash transaction hash (hex)
|
|
401
|
-
* @returns {Promise<MetadataLabelTx[]>} transaction metadata
|
|
402
|
-
*/
|
|
403
327
|
getTransactionMetadata(tx_hash) {
|
|
404
328
|
return this.route('getTransactionMetadata', b => b.getTransactionMetadata(tx_hash));
|
|
405
329
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Get block data with fallback between backends
|
|
408
|
-
* @param block_hash block hash (hex)
|
|
409
|
-
* @returns {Promise<BlockData>} block data
|
|
410
|
-
*/
|
|
411
330
|
getBlock(block_hash) {
|
|
412
331
|
return this.route('getBlock', b => b.getBlock(block_hash));
|
|
413
332
|
}
|
|
414
|
-
/**
|
|
415
|
-
* Get epoch data with fallback between backends
|
|
416
|
-
* @param epochNumber epoch number
|
|
417
|
-
* @returns {Promise<EpochData>} epoch data
|
|
418
|
-
*/
|
|
419
333
|
getEpoch(epochNumber) {
|
|
420
334
|
return this.route('getEpoch', b => b.getEpoch(epochNumber));
|
|
421
335
|
}
|
|
422
|
-
/**
|
|
423
|
-
* Get Pool data with fallback between backends
|
|
424
|
-
* @param poolId pool id
|
|
425
|
-
* @returns {Promise<PoolData>} pool data
|
|
426
|
-
*/
|
|
427
336
|
getPool(poolId) {
|
|
428
337
|
return this.route('getPool', b => b.getPool(poolId));
|
|
429
338
|
}
|
|
430
|
-
/**
|
|
431
|
-
* Get drep data with fallback between backends
|
|
432
|
-
* @param drepId drep id
|
|
433
|
-
* @returns {Promise<DrepData>} drep data
|
|
434
|
-
*/
|
|
435
339
|
getDrep(drepId) {
|
|
436
340
|
return this.route('getDrep', b => b.getDrep(drepId));
|
|
437
341
|
}
|
|
438
|
-
/**
|
|
439
|
-
* Get account data with fallback between backends
|
|
440
|
-
* @param stakeAddress stake address
|
|
441
|
-
* @returns {Promise<AccountData>} account data
|
|
442
|
-
*/
|
|
443
342
|
getAccount(stakeAddress) {
|
|
444
343
|
return this.route('getAccount', b => b.getAccount(stakeAddress));
|
|
445
344
|
}
|
|
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
|
-
*/
|
|
345
|
+
/** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
|
|
452
346
|
getAssetInfo(unit) {
|
|
453
347
|
return this.route('getAssetInfo', b => b.getAssetInfo(unit));
|
|
454
348
|
}
|
|
455
349
|
/**
|
|
456
|
-
*
|
|
457
|
-
*
|
|
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)
|
|
350
|
+
* Latest mint/burn events for an asset, most recent first. Prefers Koios (block timestamps);
|
|
351
|
+
* Blockfrost is the fallback with timestamps left null.
|
|
462
352
|
*/
|
|
463
353
|
getAssetHistory(unit, limit = 100) {
|
|
464
354
|
const candidates = [...this.historicalBackends, this.liveBackend];
|
|
@@ -475,15 +365,10 @@ class CardanoClient {
|
|
|
475
365
|
// Batch Methods (N+1 Optimization)
|
|
476
366
|
//-----------------------------------------------------------------------------
|
|
477
367
|
/**
|
|
478
|
-
*
|
|
479
|
-
*
|
|
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
|
|
368
|
+
* Transaction hashes for an address; falls back to a full getAddressTransactions when no
|
|
369
|
+
* backend supports the lightweight listing.
|
|
484
370
|
*/
|
|
485
371
|
async getAddressTransactionHashes(address, limit) {
|
|
486
|
-
// Try backends with getAddressTransactionHashes support
|
|
487
372
|
const allBackends = this.getOrderedBackends();
|
|
488
373
|
for (const backend of allBackends) {
|
|
489
374
|
if (backend.getAddressTransactionHashes) {
|
|
@@ -499,15 +384,8 @@ class CardanoClient {
|
|
|
499
384
|
const txs = await this.getAddressTransactions(address, limit);
|
|
500
385
|
return txs.map(tx => tx.hash);
|
|
501
386
|
}
|
|
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
|
-
*/
|
|
387
|
+
/** Batch fetch transactions by hash; falls back to individual coalesced getTransaction calls. */
|
|
509
388
|
async getTransactionsBatch(txHashes) {
|
|
510
|
-
// Try backends with batch support
|
|
511
389
|
const allBackends = this.getOrderedBackends();
|
|
512
390
|
for (const backend of allBackends) {
|
|
513
391
|
if (backend.getTransactionsBatch) {
|
|
@@ -523,11 +401,7 @@ class CardanoClient {
|
|
|
523
401
|
const entries = await Promise.all(txHashes.map(h => this.getTransaction(h).then(tx => [h, tx])));
|
|
524
402
|
return new Map(entries);
|
|
525
403
|
}
|
|
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
|
-
*/
|
|
404
|
+
/** Backends in historical-first order, for the batch methods. */
|
|
531
405
|
getOrderedBackends() {
|
|
532
406
|
const backends = [...this.historicalBackends];
|
|
533
407
|
if (this.liveBackend)
|
|
@@ -535,11 +409,8 @@ class CardanoClient {
|
|
|
535
409
|
return backends;
|
|
536
410
|
}
|
|
537
411
|
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
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.
|
|
412
|
+
* A backend that supports streamed chain-sync (Ogmios), or null. Backends whose init failed
|
|
413
|
+
* are skipped: the crawler uses these instances directly, outside the lazy-retry/breaker path.
|
|
543
414
|
*/
|
|
544
415
|
getChainSyncBackend() {
|
|
545
416
|
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
@@ -550,13 +421,51 @@ class CardanoClient {
|
|
|
550
421
|
return null;
|
|
551
422
|
}
|
|
552
423
|
/**
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
424
|
+
* getChainSyncBackend(), retrying a failed startup init. Polled by the crawler while it runs
|
|
425
|
+
* on pagination because no chain-sync source was usable when it started.
|
|
426
|
+
*/
|
|
427
|
+
async recoverChainSyncBackend() {
|
|
428
|
+
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
429
|
+
for (const b of candidates) {
|
|
430
|
+
if (!b || !(0, cardano_backend_1.isChainSyncBackend)(b))
|
|
431
|
+
continue;
|
|
432
|
+
if (await this.ensureBackendInitialized(b))
|
|
433
|
+
return b;
|
|
434
|
+
}
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
/** The first usable backend that can dump the UTxO set at a point (Ogmios) — crawler.utxoSet import. */
|
|
438
|
+
getLedgerStateBackend() {
|
|
439
|
+
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
440
|
+
for (const b of candidates) {
|
|
441
|
+
if (b && !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isLedgerStateBackend)(b))
|
|
442
|
+
return b;
|
|
443
|
+
}
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Outputs among `refs` that are unspent at the tip, read from the node's ledger; null when no
|
|
448
|
+
* ledger-state backend is usable (the caller then resolves via the producing transaction).
|
|
449
|
+
*/
|
|
450
|
+
async getUnspentOutputs(refs) {
|
|
451
|
+
const backend = this.getLedgerStateBackend();
|
|
452
|
+
return backend ? backend.getUnspentOutputs(refs) : null;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
|
|
456
|
+
* snapshots stay off instead of degrading into thousands of single requests.
|
|
457
|
+
*/
|
|
458
|
+
getEnumeratingBackend() {
|
|
459
|
+
const candidates = [...this.historicalBackends, this.liveBackend];
|
|
460
|
+
for (const b of candidates) {
|
|
461
|
+
if (b && !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isEnumeratingBackend)(b))
|
|
462
|
+
return b;
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* A backend that can be walked forward by pagination (Blockfrost/Koios), or null. Koios is
|
|
468
|
+
* preferred: it batches 100 txs per call, Blockfrost needs ~3 calls per tx.
|
|
560
469
|
*/
|
|
561
470
|
getPaginatingBackend() {
|
|
562
471
|
const usable = this.historicalBackends.filter((b) => !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isPaginatingBackend)(b));
|
|
@@ -570,18 +479,13 @@ class CardanoClient {
|
|
|
570
479
|
}
|
|
571
480
|
return null;
|
|
572
481
|
}
|
|
573
|
-
/**
|
|
574
|
-
* Get protocol parameters with caching (5 minute TTL)
|
|
575
|
-
* Protocol parameters rarely change (once per epoch at most), so caching improves performance
|
|
576
|
-
* @returns {Promise<LedgerProtocolParameters>} protocol parameters
|
|
577
|
-
*/
|
|
482
|
+
/** Protocol parameters with a 5-minute in-memory cache and coalesced refresh. */
|
|
578
483
|
async getProtocolParameters() {
|
|
579
484
|
const now = Date.now();
|
|
580
485
|
if (this.protocolParamsCache && (now - this.protocolParamsCache.fetchedAt) < CardanoClient.PROTOCOL_PARAMS_TTL_MS) {
|
|
581
486
|
logger.debug('Returning cached protocol parameters');
|
|
582
487
|
return this.protocolParamsCache.data;
|
|
583
488
|
}
|
|
584
|
-
// Promise coalescing: deduplicate concurrent requests during cache miss
|
|
585
489
|
if (!this.protocolParamsFetchPromise) {
|
|
586
490
|
logger.debug('Fetching fresh protocol parameters');
|
|
587
491
|
this.protocolParamsFetchPromise = this.route('getProtocolParameters', b => b.getProtocolParameters())
|
|
@@ -597,12 +501,9 @@ class CardanoClient {
|
|
|
597
501
|
}
|
|
598
502
|
return this.protocolParamsFetchPromise;
|
|
599
503
|
}
|
|
600
|
-
/**
|
|
601
|
-
* Shutdown all backends (for cleanup in tests)
|
|
602
|
-
*/
|
|
504
|
+
/** Shut down all backends. */
|
|
603
505
|
async shutdown() {
|
|
604
506
|
logger.info('Shutting down CardanoClient backends...');
|
|
605
|
-
// Shutdown live backend if it has a shutdown method
|
|
606
507
|
if (this.liveBackend && 'shutdown' in this.liveBackend && typeof this.liveBackend.shutdown === 'function') {
|
|
607
508
|
try {
|
|
608
509
|
await this.liveBackend.shutdown();
|
|
@@ -612,7 +513,6 @@ class CardanoClient {
|
|
|
612
513
|
logger.error(`Error shutting down live backend ${this.liveBackend.name}: ${err}`);
|
|
613
514
|
}
|
|
614
515
|
}
|
|
615
|
-
// Shutdown historical backends
|
|
616
516
|
for (const backend of this.historicalBackends) {
|
|
617
517
|
if ('shutdown' in backend && typeof backend.shutdown === 'function') {
|
|
618
518
|
try {
|
|
@@ -628,69 +528,37 @@ class CardanoClient {
|
|
|
628
528
|
this.initPromise = null;
|
|
629
529
|
logger.info('CardanoClient shutdown complete');
|
|
630
530
|
}
|
|
631
|
-
/**
|
|
632
|
-
* Get latest block data with fallback between backends
|
|
633
|
-
* @returns {Promise<BlockData>} latest block data
|
|
634
|
-
*/
|
|
635
531
|
getLatestBlock() {
|
|
636
532
|
return this.route('getLatestBlock', b => b.getLatestBlock());
|
|
637
533
|
}
|
|
638
|
-
/**
|
|
639
|
-
* Get latest epoch data with fallback between backends
|
|
640
|
-
* @returns {Promise<EpochData>} latest epoch data
|
|
641
|
-
*/
|
|
642
534
|
getLatestEpoch() {
|
|
643
535
|
return this.route('getLatestEpoch', b => b.getLatestEpoch());
|
|
644
536
|
}
|
|
645
|
-
/**
|
|
646
|
-
* Get the current chain slot with fallback between backends.
|
|
647
|
-
* @returns {Promise<number>} current chain slot
|
|
648
|
-
*/
|
|
649
537
|
getCurrentSlot() {
|
|
650
538
|
return this.route('getCurrentSlot', b => b.getCurrentSlot());
|
|
651
539
|
}
|
|
652
|
-
/**
|
|
653
|
-
* Check whether a UTxO is still unspent with fallback between backends.
|
|
654
|
-
* @param txHash 64-char lowercase hex transaction hash
|
|
655
|
-
* @param outputIndex non-negative integer output index
|
|
656
|
-
* @returns {Promise<boolean>} true iff the UTxO exists and is unspent
|
|
657
|
-
*/
|
|
540
|
+
/** True iff the UTxO exists and is unspent. */
|
|
658
541
|
isUtxoUnspent(txHash, outputIndex) {
|
|
659
542
|
return this.route('isUtxoUnspent', b => b.isUtxoUnspent(txHash, outputIndex));
|
|
660
543
|
}
|
|
661
544
|
/**
|
|
662
|
-
* Submit transaction
|
|
663
|
-
*
|
|
664
|
-
* @returns {Promise<string>} transaction hash
|
|
665
|
-
*
|
|
666
|
-
* NOTE on failover semantics: when the preferred backend ACCEPTS the tx but
|
|
667
|
-
* its response is lost (timeout), the failover resubmits on the next backend,
|
|
668
|
-
* which may answer 409 "already submitted". Callers should treat a
|
|
669
|
-
* TransactionAlreadySubmittedError after a submit attempt as success — the
|
|
670
|
-
* transaction IS in the mempool.
|
|
545
|
+
* Submit a signed transaction (CBOR hex); returns its hash. On failover after a lost response
|
|
546
|
+
* the next backend may answer 409 "already submitted" — callers treat that as success.
|
|
671
547
|
*/
|
|
672
548
|
submitTransaction(signedTxCbor) {
|
|
673
549
|
return this.route('submitTransaction', b => b.submitTransaction(signedTxCbor));
|
|
674
550
|
}
|
|
675
|
-
/**
|
|
676
|
-
* Check if Ogmios backend is available for transaction evaluation
|
|
677
|
-
* @returns {boolean} true if Ogmios is the live backend
|
|
678
|
-
*/
|
|
551
|
+
/** True when Ogmios is the live backend (script evaluation available). */
|
|
679
552
|
hasOgmiosBackend() {
|
|
680
553
|
return this.liveBackend?.name === 'ogmios';
|
|
681
554
|
}
|
|
682
|
-
/**
|
|
683
|
-
* Evaluate transaction script execution units (Ogmios only)
|
|
684
|
-
* @param unsignedTxCbor unsigned transaction in CBOR hex format
|
|
685
|
-
* @returns {Promise<ScriptEvaluationResult[]>} evaluation results
|
|
686
|
-
*/
|
|
555
|
+
/** Evaluate script execution units of an unsigned transaction (Ogmios only). */
|
|
687
556
|
async evaluateTransaction(unsignedTxCbor) {
|
|
688
557
|
await this.ensureInitialized();
|
|
689
|
-
// Evaluation requires an EvaluatingBackend (typically Ogmios)
|
|
690
558
|
if (!this.liveBackend || !(0, cardano_backend_1.isEvaluatingBackend)(this.liveBackend)) {
|
|
691
559
|
throw new errors_1.ProviderUnavailableError('Transaction evaluation requires an evaluating backend (e.g., Ogmios)');
|
|
692
560
|
}
|
|
693
|
-
// timeout + breaker
|
|
561
|
+
// timeout + breaker, so a hanging socket cannot block Plutus builds
|
|
694
562
|
const backend = this.liveBackend;
|
|
695
563
|
return this.callWithResilience(backend, () => backend.evaluateTransaction(unsignedTxCbor));
|
|
696
564
|
}
|