@odatano/core 2.0.0-rc.2 → 2.0.0-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +224 -0
- 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 +316 -0
- package/@cds-models/odatano/cardano/index.js +33 -0
- package/README.md +195 -136
- package/db/schema.cds +2121 -1633
- package/package.json +179 -173
- 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 +78 -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 +292 -202
- package/srv/blockchain/backends/ogmios-backend.d.ts +59 -96
- package/srv/blockchain/backends/ogmios-backend.js +241 -153
- 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 +50 -205
- package/srv/blockchain/cardano-client.js +80 -224
- package/srv/blockchain/cardano-indexer.d.ts +146 -244
- package/srv/blockchain/cardano-indexer.js +442 -285
- package/srv/blockchain/cardano-tx-builder.d.ts +19 -84
- package/srv/blockchain/cardano-tx-builder.js +21 -107
- 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 +402 -82
- 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/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 +34 -90
- 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 +133 -195
- 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 +89 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +34 -178
- package/srv/utils/errors.js +55 -217
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +41 -0
- package/srv/utils/mappers.d.ts +82 -210
- package/srv/utils/mappers.js +272 -293
- 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 +112 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -13,9 +13,7 @@ const ogmios_backend_1 = require("./backends/ogmios-backend");
|
|
|
13
13
|
const blockfrost_backend_1 = require("./backends/blockfrost-backend");
|
|
14
14
|
const koios_backend_1 = require("./backends/koios-backend");
|
|
15
15
|
const logger = cds_1.default.log('CardanoClient');
|
|
16
|
-
/**
|
|
17
|
-
* Method routing configuration - defines which backend type to prefer for each method
|
|
18
|
-
*/
|
|
16
|
+
/** Which backend type to prefer per method. */
|
|
19
17
|
const METHOD_ROUTING = {
|
|
20
18
|
getTransaction: { preferLive: false },
|
|
21
19
|
getAddress: { preferLive: true },
|
|
@@ -37,12 +35,8 @@ const METHOD_ROUTING = {
|
|
|
37
35
|
submitTransaction: { preferLive: true },
|
|
38
36
|
};
|
|
39
37
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* Routes requests to appropriate backends:
|
|
43
|
-
* - Live/State queries → Ogmios (if available)
|
|
44
|
-
* - Historical queries → Blockfrost/Koios (if available)
|
|
45
|
-
* - Automatic fallback between backends
|
|
38
|
+
* Multi-backend Cardano client: live/state queries prefer Ogmios, historical queries prefer
|
|
39
|
+
* Blockfrost/Koios, with automatic fallback between them.
|
|
46
40
|
*/
|
|
47
41
|
class CardanoClient {
|
|
48
42
|
config;
|
|
@@ -62,11 +56,7 @@ class CardanoClient {
|
|
|
62
56
|
txCoalescer = new request_coalescer_1.RequestCoalescer();
|
|
63
57
|
addrCoalescer = new request_coalescer_1.RequestCoalescer();
|
|
64
58
|
credCoalescer = new request_coalescer_1.RequestCoalescer();
|
|
65
|
-
/**
|
|
66
|
-
* Constructor for CardanoClient
|
|
67
|
-
* @param liveBackend - Optional backend for live/state queries (typically Ogmios)
|
|
68
|
-
* @param historicalBackends - Optional backends for historical queries (typically Blockfrost/Koios)
|
|
69
|
-
*/
|
|
59
|
+
/** Builds the configured backends; throws ConfigError when none is configured. */
|
|
70
60
|
constructor(clientConfig) {
|
|
71
61
|
this.network = clientConfig.network;
|
|
72
62
|
const backends = clientConfig.backends;
|
|
@@ -83,9 +73,7 @@ class CardanoClient {
|
|
|
83
73
|
throw new errors_1.ConfigError('No valid backends configured for CardanoClient');
|
|
84
74
|
}
|
|
85
75
|
this.circuitBreaker = new circuit_breaker_1.CircuitBreakerManager(clientConfig.circuitBreaker);
|
|
86
|
-
//
|
|
87
|
-
// Previously max_age_ms stayed hardcoded at 60s and indexTtlMs was dead — the
|
|
88
|
-
// documented/configurable 1h default never took effect.
|
|
76
|
+
// indexTtlMs is the cache TTL the indexer reads via max_age_ms
|
|
89
77
|
if (Number.isFinite(clientConfig.indexTtlMs) && clientConfig.indexTtlMs > 0) {
|
|
90
78
|
this.max_age_ms = clientConfig.indexTtlMs;
|
|
91
79
|
}
|
|
@@ -101,16 +89,13 @@ class CardanoClient {
|
|
|
101
89
|
return names;
|
|
102
90
|
}
|
|
103
91
|
/**
|
|
104
|
-
* Ensure backends are initialized.
|
|
105
|
-
*
|
|
106
|
-
* a transient startup failure (e.g. Ogmios briefly down) left the client
|
|
107
|
-
* permanently broken until process restart.
|
|
108
|
-
* @returns {Promise<void>}
|
|
92
|
+
* Ensure backends are initialized. A rejected init promise is cleared so the next request
|
|
93
|
+
* retries instead of leaving the client permanently broken.
|
|
109
94
|
*/
|
|
110
95
|
async ensureInitialized() {
|
|
111
96
|
if (this.initialized)
|
|
112
97
|
return;
|
|
113
|
-
//
|
|
98
|
+
// ??= keeps concurrent callers on one init promise
|
|
114
99
|
this.initPromise ??= this.initBackends().catch((err) => {
|
|
115
100
|
this.initPromise = null;
|
|
116
101
|
throw err;
|
|
@@ -118,10 +103,8 @@ class CardanoClient {
|
|
|
118
103
|
await this.initPromise;
|
|
119
104
|
}
|
|
120
105
|
/**
|
|
121
|
-
* Transient (retryable) init failures: a backend momentarily unreachable at
|
|
122
|
-
*
|
|
123
|
-
* a freshly-arrived block ("Premature close"), or the socket still coming up
|
|
124
|
-
* (ECONNREFUSED). Config/validation errors are NOT transient.
|
|
106
|
+
* Transient (retryable) init failures: a backend momentarily unreachable at startup
|
|
107
|
+
* (connection refused/reset, a cut-short health response). Config/validation errors are not.
|
|
125
108
|
*/
|
|
126
109
|
static isTransientInitError(err) {
|
|
127
110
|
const e = err;
|
|
@@ -132,12 +115,8 @@ class CardanoClient {
|
|
|
132
115
|
return /premature close|socket hang up|econnreset|econnrefused|etimedout|timeout|fetch failed|terminated|other side closed/.test(msg);
|
|
133
116
|
}
|
|
134
117
|
/**
|
|
135
|
-
* Init a backend, retrying brief transient failures.
|
|
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.
|
|
118
|
+
* Init a backend, retrying brief transient failures. Kept small (3 attempts, 1 s backoff) so
|
|
119
|
+
* a sustained outage still fails fast and the total stays under the test bootstrap hook.
|
|
141
120
|
*/
|
|
142
121
|
async initBackendWithRetry(backend) {
|
|
143
122
|
const maxAttempts = 3;
|
|
@@ -155,12 +134,8 @@ class CardanoClient {
|
|
|
155
134
|
}
|
|
156
135
|
}
|
|
157
136
|
/**
|
|
158
|
-
* Initialize all backends
|
|
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>}
|
|
137
|
+
* Initialize all backends. Backends whose init fails stay in rotation, tracked in
|
|
138
|
+
* `uninitializedBackends`, and are retried lazily per request (bounded by the circuit breaker).
|
|
164
139
|
*/
|
|
165
140
|
async initBackends() {
|
|
166
141
|
const initErrors = [];
|
|
@@ -220,13 +195,7 @@ class CardanoClient {
|
|
|
220
195
|
return false;
|
|
221
196
|
}
|
|
222
197
|
}
|
|
223
|
-
/**
|
|
224
|
-
* Wrap a promise with a timeout
|
|
225
|
-
* @param promise - the promise to wrap
|
|
226
|
-
* @param ms - timeout in milliseconds
|
|
227
|
-
* @param backendName - name of the backend (for error context)
|
|
228
|
-
* @returns {Promise<T>} the result of the promise or a timeout error
|
|
229
|
-
*/
|
|
198
|
+
/** Wrap a promise with a timeout that rejects with ProviderUnavailableError. */
|
|
230
199
|
withTimeout(promise, ms, backendName) {
|
|
231
200
|
let timeoutId;
|
|
232
201
|
const timeoutPromise = new Promise((_, reject) => {
|
|
@@ -236,22 +205,15 @@ class CardanoClient {
|
|
|
236
205
|
clearTimeout(timeoutId);
|
|
237
206
|
});
|
|
238
207
|
}
|
|
239
|
-
/**
|
|
240
|
-
* Get timeout for specific backend
|
|
241
|
-
* @param backend CardanoBackend instance
|
|
242
|
-
* @returns {number} timeout in milliseconds
|
|
243
|
-
*/
|
|
208
|
+
/** Per-backend timeout: Koios gets the fallback timeout, everything else the primary one. */
|
|
244
209
|
getTimeoutForBackend(backend) {
|
|
245
210
|
if (backend.name === 'koios')
|
|
246
211
|
return this.config.fallbackTimeoutMs;
|
|
247
212
|
return this.config.primaryTimeoutMs;
|
|
248
213
|
}
|
|
249
214
|
/**
|
|
250
|
-
*
|
|
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.
|
|
215
|
+
* Single-backend call with the executeWithPriority resilience contract (breaker gate, timeout,
|
|
216
|
+
* success/failure recording, 4xx exempt) for paths that cannot fail over.
|
|
255
217
|
*/
|
|
256
218
|
async callWithResilience(backend, fn) {
|
|
257
219
|
if (!this.circuitBreaker.shouldAttempt(backend.name)) {
|
|
@@ -275,12 +237,7 @@ class CardanoClient {
|
|
|
275
237
|
throw backendError;
|
|
276
238
|
}
|
|
277
239
|
}
|
|
278
|
-
/**
|
|
279
|
-
* Execute with priority-based backend selection and automatic fallback
|
|
280
|
-
* @param fn function to execute on backend
|
|
281
|
-
* @param preferLive whether to prefer live backend over historical
|
|
282
|
-
* @returns {Promise<T>} result from backend
|
|
283
|
-
*/
|
|
240
|
+
/** Execute on backends in preference order (live vs historical) with automatic fallback. */
|
|
284
241
|
async executeWithPriority(fn, preferLive, methodName) {
|
|
285
242
|
await this.ensureInitialized();
|
|
286
243
|
const errors = [];
|
|
@@ -317,10 +274,8 @@ class CardanoClient {
|
|
|
317
274
|
catch (err) {
|
|
318
275
|
const backendError = (0, errors_1.normalizeBackendError)(err, backend.name);
|
|
319
276
|
errors.push(backendError);
|
|
320
|
-
// 4xx are definitive verdicts from a
|
|
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.
|
|
277
|
+
// 4xx are definitive verdicts from a healthy backend and must not open the circuit;
|
|
278
|
+
// only 5xx/timeouts/transport errors indicate backend health.
|
|
324
279
|
const isClientError = backendError.statusCode >= 400 && backendError.statusCode < 500;
|
|
325
280
|
if (!isClientError) {
|
|
326
281
|
this.circuitBreaker.recordFailure(backend.name);
|
|
@@ -331,46 +286,25 @@ class CardanoClient {
|
|
|
331
286
|
}
|
|
332
287
|
throw new errors_1.AllBackendsFailedError(errors);
|
|
333
288
|
}
|
|
334
|
-
/**
|
|
335
|
-
* Route method call to appropriate backend based on method routing configuration
|
|
336
|
-
* @param methodName name of the method being called
|
|
337
|
-
* @param fn function to execute on backend
|
|
338
|
-
* @returns {Promise<T>} result from backend
|
|
339
|
-
*/
|
|
289
|
+
/** Route a call by METHOD_ROUTING (default: historical first). */
|
|
340
290
|
route(methodName, fn) {
|
|
341
291
|
const config = METHOD_ROUTING[methodName] ?? { preferLive: false };
|
|
342
292
|
return this.executeWithPriority(fn, config.preferLive, methodName);
|
|
343
293
|
}
|
|
344
|
-
/**
|
|
345
|
-
* Get transaction by hash with fallback between backends
|
|
346
|
-
* @param txHash transaction hash (hex)
|
|
347
|
-
* @returns {Promise<Transaction>} transaction data
|
|
348
|
-
*/
|
|
294
|
+
/** Transaction by hash (coalesced across concurrent callers). */
|
|
349
295
|
getTransaction(txHash) {
|
|
350
296
|
return this.txCoalescer.get(txHash, () => this.route('getTransaction', b => b.getTransaction(txHash)));
|
|
351
297
|
}
|
|
352
|
-
/**
|
|
353
|
-
* Get address by bech32 address with fallback between backends
|
|
354
|
-
* @param address bech32 address
|
|
355
|
-
* @returns {Promise<Address>} address data
|
|
356
|
-
*/
|
|
298
|
+
/** Address data (coalesced across concurrent callers). */
|
|
357
299
|
getAddress(address) {
|
|
358
300
|
return this.addrCoalescer.get(address, () => this.route('getAddress', b => b.getAddress(address)));
|
|
359
301
|
}
|
|
360
|
-
/**
|
|
361
|
-
* Get address UTxOs with fallback between backends
|
|
362
|
-
* @param address bech32 address
|
|
363
|
-
* @returns {Promise<UTxO[]>} list of UTxOs
|
|
364
|
-
*/
|
|
365
302
|
getAddressUtxos(address) {
|
|
366
303
|
return this.route('getAddressUtxos', b => b.getAddressUtxos(address));
|
|
367
304
|
}
|
|
368
305
|
/**
|
|
369
|
-
*
|
|
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
|
|
306
|
+
* UTxOs by 28-byte payment credential (56-char hex), across all bech32 forms sharing it.
|
|
307
|
+
* Koios-only: no other backend has a credential-keyed endpoint, so this throws without Koios.
|
|
374
308
|
*/
|
|
375
309
|
getCredentialUtxos(credHash) {
|
|
376
310
|
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
@@ -380,85 +314,37 @@ class CardanoClient {
|
|
|
380
314
|
}
|
|
381
315
|
return this.credCoalescer.get(credHash, () => this.callWithResilience(koios, () => koios.getCredentialUtxos(credHash)));
|
|
382
316
|
}
|
|
383
|
-
/**
|
|
384
|
-
* Get address transactions with fallback between backends
|
|
385
|
-
* @param address bech32 address
|
|
386
|
-
* @returns {Promise<Transaction[]>} list of transactions for this address
|
|
387
|
-
*/
|
|
388
317
|
getAddressTransactions(address, limit) {
|
|
389
318
|
return this.route('getAddressTransactions', b => b.getAddressTransactions(address, limit));
|
|
390
319
|
}
|
|
391
|
-
/**
|
|
392
|
-
* Get network information with fallback between backends
|
|
393
|
-
* @returns {Promise<Network>} network information
|
|
394
|
-
*/
|
|
395
320
|
getNetworkInformation() {
|
|
396
321
|
return this.route('getNetworkInformation', b => b.getNetworkInformation());
|
|
397
322
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Get transaction metadata with fallback between backends
|
|
400
|
-
* @param tx_hash transaction hash (hex)
|
|
401
|
-
* @returns {Promise<MetadataLabelTx[]>} transaction metadata
|
|
402
|
-
*/
|
|
403
323
|
getTransactionMetadata(tx_hash) {
|
|
404
324
|
return this.route('getTransactionMetadata', b => b.getTransactionMetadata(tx_hash));
|
|
405
325
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Get block data with fallback between backends
|
|
408
|
-
* @param block_hash block hash (hex)
|
|
409
|
-
* @returns {Promise<BlockData>} block data
|
|
410
|
-
*/
|
|
411
326
|
getBlock(block_hash) {
|
|
412
327
|
return this.route('getBlock', b => b.getBlock(block_hash));
|
|
413
328
|
}
|
|
414
|
-
/**
|
|
415
|
-
* Get epoch data with fallback between backends
|
|
416
|
-
* @param epochNumber epoch number
|
|
417
|
-
* @returns {Promise<EpochData>} epoch data
|
|
418
|
-
*/
|
|
419
329
|
getEpoch(epochNumber) {
|
|
420
330
|
return this.route('getEpoch', b => b.getEpoch(epochNumber));
|
|
421
331
|
}
|
|
422
|
-
/**
|
|
423
|
-
* Get Pool data with fallback between backends
|
|
424
|
-
* @param poolId pool id
|
|
425
|
-
* @returns {Promise<PoolData>} pool data
|
|
426
|
-
*/
|
|
427
332
|
getPool(poolId) {
|
|
428
333
|
return this.route('getPool', b => b.getPool(poolId));
|
|
429
334
|
}
|
|
430
|
-
/**
|
|
431
|
-
* Get drep data with fallback between backends
|
|
432
|
-
* @param drepId drep id
|
|
433
|
-
* @returns {Promise<DrepData>} drep data
|
|
434
|
-
*/
|
|
435
335
|
getDrep(drepId) {
|
|
436
336
|
return this.route('getDrep', b => b.getDrep(drepId));
|
|
437
337
|
}
|
|
438
|
-
/**
|
|
439
|
-
* Get account data with fallback between backends
|
|
440
|
-
* @param stakeAddress stake address
|
|
441
|
-
* @returns {Promise<AccountData>} account data
|
|
442
|
-
*/
|
|
443
338
|
getAccount(stakeAddress) {
|
|
444
339
|
return this.route('getAccount', b => b.getAccount(stakeAddress));
|
|
445
340
|
}
|
|
446
|
-
/**
|
|
447
|
-
* Get asset info (supply, mint history, CIP-25 + CIP-26 metadata) with fallback.
|
|
448
|
-
* Both Blockfrost and Koios implement; Ogmios throws "not supported".
|
|
449
|
-
* @param unit policyId + assetNameHex (concatenated hex)
|
|
450
|
-
* @returns {Promise<AssetInfo>} canonical asset info
|
|
451
|
-
*/
|
|
341
|
+
/** Asset info (supply, mint history, CIP-25/CIP-26 metadata); Blockfrost and Koios only. */
|
|
452
342
|
getAssetInfo(unit) {
|
|
453
343
|
return this.route('getAssetInfo', b => b.getAssetInfo(unit));
|
|
454
344
|
}
|
|
455
345
|
/**
|
|
456
|
-
*
|
|
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)
|
|
346
|
+
* Latest mint/burn events for an asset, most recent first. Prefers Koios (block timestamps);
|
|
347
|
+
* Blockfrost is the fallback with timestamps left null.
|
|
462
348
|
*/
|
|
463
349
|
getAssetHistory(unit, limit = 100) {
|
|
464
350
|
const candidates = [...this.historicalBackends, this.liveBackend];
|
|
@@ -475,15 +361,10 @@ class CardanoClient {
|
|
|
475
361
|
// Batch Methods (N+1 Optimization)
|
|
476
362
|
//-----------------------------------------------------------------------------
|
|
477
363
|
/**
|
|
478
|
-
*
|
|
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
|
|
364
|
+
* Transaction hashes for an address; falls back to a full getAddressTransactions when no
|
|
365
|
+
* backend supports the lightweight listing.
|
|
484
366
|
*/
|
|
485
367
|
async getAddressTransactionHashes(address, limit) {
|
|
486
|
-
// Try backends with getAddressTransactionHashes support
|
|
487
368
|
const allBackends = this.getOrderedBackends();
|
|
488
369
|
for (const backend of allBackends) {
|
|
489
370
|
if (backend.getAddressTransactionHashes) {
|
|
@@ -499,15 +380,8 @@ class CardanoClient {
|
|
|
499
380
|
const txs = await this.getAddressTransactions(address, limit);
|
|
500
381
|
return txs.map(tx => tx.hash);
|
|
501
382
|
}
|
|
502
|
-
/**
|
|
503
|
-
* Batch fetch multiple transactions by hash.
|
|
504
|
-
* Uses getTransactionsBatch() if backend supports it, otherwise
|
|
505
|
-
* falls back to individual getTransaction() calls (still coalesced).
|
|
506
|
-
* @param txHashes array of transaction hashes
|
|
507
|
-
* @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
|
|
508
|
-
*/
|
|
383
|
+
/** Batch fetch transactions by hash; falls back to individual coalesced getTransaction calls. */
|
|
509
384
|
async getTransactionsBatch(txHashes) {
|
|
510
|
-
// Try backends with batch support
|
|
511
385
|
const allBackends = this.getOrderedBackends();
|
|
512
386
|
for (const backend of allBackends) {
|
|
513
387
|
if (backend.getTransactionsBatch) {
|
|
@@ -523,11 +397,7 @@ class CardanoClient {
|
|
|
523
397
|
const entries = await Promise.all(txHashes.map(h => this.getTransaction(h).then(tx => [h, tx])));
|
|
524
398
|
return new Map(entries);
|
|
525
399
|
}
|
|
526
|
-
/**
|
|
527
|
-
* Backends in historical-first order. Used by the batch methods — both
|
|
528
|
-
* always prefer historical data, so the former preferLive parameter was a
|
|
529
|
-
* dead branch.
|
|
530
|
-
*/
|
|
400
|
+
/** Backends in historical-first order, for the batch methods. */
|
|
531
401
|
getOrderedBackends() {
|
|
532
402
|
const backends = [...this.historicalBackends];
|
|
533
403
|
if (this.liveBackend)
|
|
@@ -535,11 +405,8 @@ class CardanoClient {
|
|
|
535
405
|
return backends;
|
|
536
406
|
}
|
|
537
407
|
/**
|
|
538
|
-
*
|
|
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.
|
|
408
|
+
* A backend that supports streamed chain-sync (Ogmios), or null. Backends whose init failed
|
|
409
|
+
* are skipped: the crawler uses these instances directly, outside the lazy-retry/breaker path.
|
|
543
410
|
*/
|
|
544
411
|
getChainSyncBackend() {
|
|
545
412
|
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
@@ -550,13 +417,43 @@ class CardanoClient {
|
|
|
550
417
|
return null;
|
|
551
418
|
}
|
|
552
419
|
/**
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
420
|
+
* getChainSyncBackend(), retrying a failed startup init. Polled by the crawler while it runs
|
|
421
|
+
* on pagination because no chain-sync source was usable when it started.
|
|
422
|
+
*/
|
|
423
|
+
async recoverChainSyncBackend() {
|
|
424
|
+
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
425
|
+
for (const b of candidates) {
|
|
426
|
+
if (!b || !(0, cardano_backend_1.isChainSyncBackend)(b))
|
|
427
|
+
continue;
|
|
428
|
+
if (await this.ensureBackendInitialized(b))
|
|
429
|
+
return b;
|
|
430
|
+
}
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
/** The first usable backend that can dump the UTxO set at a point (Ogmios) — crawler.utxoSet import. */
|
|
434
|
+
getLedgerStateBackend() {
|
|
435
|
+
const candidates = [this.liveBackend, ...this.historicalBackends];
|
|
436
|
+
for (const b of candidates) {
|
|
437
|
+
if (b && !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isLedgerStateBackend)(b))
|
|
438
|
+
return b;
|
|
439
|
+
}
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* A backend that can enumerate the full pool/DRep set (Koios), or null; without one the epoch
|
|
444
|
+
* snapshots stay off instead of degrading into thousands of single requests.
|
|
445
|
+
*/
|
|
446
|
+
getEnumeratingBackend() {
|
|
447
|
+
const candidates = [...this.historicalBackends, this.liveBackend];
|
|
448
|
+
for (const b of candidates) {
|
|
449
|
+
if (b && !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isEnumeratingBackend)(b))
|
|
450
|
+
return b;
|
|
451
|
+
}
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* A backend that can be walked forward by pagination (Blockfrost/Koios), or null. Koios is
|
|
456
|
+
* preferred: it batches 100 txs per call, Blockfrost needs ~3 calls per tx.
|
|
560
457
|
*/
|
|
561
458
|
getPaginatingBackend() {
|
|
562
459
|
const usable = this.historicalBackends.filter((b) => !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isPaginatingBackend)(b));
|
|
@@ -570,18 +467,13 @@ class CardanoClient {
|
|
|
570
467
|
}
|
|
571
468
|
return null;
|
|
572
469
|
}
|
|
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
|
-
*/
|
|
470
|
+
/** Protocol parameters with a 5-minute in-memory cache and coalesced refresh. */
|
|
578
471
|
async getProtocolParameters() {
|
|
579
472
|
const now = Date.now();
|
|
580
473
|
if (this.protocolParamsCache && (now - this.protocolParamsCache.fetchedAt) < CardanoClient.PROTOCOL_PARAMS_TTL_MS) {
|
|
581
474
|
logger.debug('Returning cached protocol parameters');
|
|
582
475
|
return this.protocolParamsCache.data;
|
|
583
476
|
}
|
|
584
|
-
// Promise coalescing: deduplicate concurrent requests during cache miss
|
|
585
477
|
if (!this.protocolParamsFetchPromise) {
|
|
586
478
|
logger.debug('Fetching fresh protocol parameters');
|
|
587
479
|
this.protocolParamsFetchPromise = this.route('getProtocolParameters', b => b.getProtocolParameters())
|
|
@@ -597,12 +489,9 @@ class CardanoClient {
|
|
|
597
489
|
}
|
|
598
490
|
return this.protocolParamsFetchPromise;
|
|
599
491
|
}
|
|
600
|
-
/**
|
|
601
|
-
* Shutdown all backends (for cleanup in tests)
|
|
602
|
-
*/
|
|
492
|
+
/** Shut down all backends. */
|
|
603
493
|
async shutdown() {
|
|
604
494
|
logger.info('Shutting down CardanoClient backends...');
|
|
605
|
-
// Shutdown live backend if it has a shutdown method
|
|
606
495
|
if (this.liveBackend && 'shutdown' in this.liveBackend && typeof this.liveBackend.shutdown === 'function') {
|
|
607
496
|
try {
|
|
608
497
|
await this.liveBackend.shutdown();
|
|
@@ -612,7 +501,6 @@ class CardanoClient {
|
|
|
612
501
|
logger.error(`Error shutting down live backend ${this.liveBackend.name}: ${err}`);
|
|
613
502
|
}
|
|
614
503
|
}
|
|
615
|
-
// Shutdown historical backends
|
|
616
504
|
for (const backend of this.historicalBackends) {
|
|
617
505
|
if ('shutdown' in backend && typeof backend.shutdown === 'function') {
|
|
618
506
|
try {
|
|
@@ -628,69 +516,37 @@ class CardanoClient {
|
|
|
628
516
|
this.initPromise = null;
|
|
629
517
|
logger.info('CardanoClient shutdown complete');
|
|
630
518
|
}
|
|
631
|
-
/**
|
|
632
|
-
* Get latest block data with fallback between backends
|
|
633
|
-
* @returns {Promise<BlockData>} latest block data
|
|
634
|
-
*/
|
|
635
519
|
getLatestBlock() {
|
|
636
520
|
return this.route('getLatestBlock', b => b.getLatestBlock());
|
|
637
521
|
}
|
|
638
|
-
/**
|
|
639
|
-
* Get latest epoch data with fallback between backends
|
|
640
|
-
* @returns {Promise<EpochData>} latest epoch data
|
|
641
|
-
*/
|
|
642
522
|
getLatestEpoch() {
|
|
643
523
|
return this.route('getLatestEpoch', b => b.getLatestEpoch());
|
|
644
524
|
}
|
|
645
|
-
/**
|
|
646
|
-
* Get the current chain slot with fallback between backends.
|
|
647
|
-
* @returns {Promise<number>} current chain slot
|
|
648
|
-
*/
|
|
649
525
|
getCurrentSlot() {
|
|
650
526
|
return this.route('getCurrentSlot', b => b.getCurrentSlot());
|
|
651
527
|
}
|
|
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
|
-
*/
|
|
528
|
+
/** True iff the UTxO exists and is unspent. */
|
|
658
529
|
isUtxoUnspent(txHash, outputIndex) {
|
|
659
530
|
return this.route('isUtxoUnspent', b => b.isUtxoUnspent(txHash, outputIndex));
|
|
660
531
|
}
|
|
661
532
|
/**
|
|
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.
|
|
533
|
+
* Submit a signed transaction (CBOR hex); returns its hash. On failover after a lost response
|
|
534
|
+
* the next backend may answer 409 "already submitted" — callers treat that as success.
|
|
671
535
|
*/
|
|
672
536
|
submitTransaction(signedTxCbor) {
|
|
673
537
|
return this.route('submitTransaction', b => b.submitTransaction(signedTxCbor));
|
|
674
538
|
}
|
|
675
|
-
/**
|
|
676
|
-
* Check if Ogmios backend is available for transaction evaluation
|
|
677
|
-
* @returns {boolean} true if Ogmios is the live backend
|
|
678
|
-
*/
|
|
539
|
+
/** True when Ogmios is the live backend (script evaluation available). */
|
|
679
540
|
hasOgmiosBackend() {
|
|
680
541
|
return this.liveBackend?.name === 'ogmios';
|
|
681
542
|
}
|
|
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
|
-
*/
|
|
543
|
+
/** Evaluate script execution units of an unsigned transaction (Ogmios only). */
|
|
687
544
|
async evaluateTransaction(unsignedTxCbor) {
|
|
688
545
|
await this.ensureInitialized();
|
|
689
|
-
// Evaluation requires an EvaluatingBackend (typically Ogmios)
|
|
690
546
|
if (!this.liveBackend || !(0, cardano_backend_1.isEvaluatingBackend)(this.liveBackend)) {
|
|
691
547
|
throw new errors_1.ProviderUnavailableError('Transaction evaluation requires an evaluating backend (e.g., Ogmios)');
|
|
692
548
|
}
|
|
693
|
-
// timeout + breaker
|
|
549
|
+
// timeout + breaker, so a hanging socket cannot block Plutus builds
|
|
694
550
|
const backend = this.liveBackend;
|
|
695
551
|
return this.callWithResilience(backend, () => backend.evaluateTransaction(unsignedTxCbor));
|
|
696
552
|
}
|