@odatano/core 2.0.0-rc.43 → 2.0.0-rc.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +0 -46
- package/@cds-models/CardanoBackendService/index.d.ts +0 -10
- package/@cds-models/CardanoIndexerService/index.d.ts +36 -20
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoODataService/index.d.ts +19 -47
- package/@cds-models/CardanoSignService/index.d.ts +3 -18
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -31
- package/@cds-models/CardanoWorkerService/index.d.ts +3 -19
- package/@cds-models/index.d.ts +17 -0
- package/@cds-models/index.js +2 -0
- package/@cds-models/odatano/cardano/index.d.ts +1 -34
- package/README.md +6 -6
- package/db/schema.cds +29 -44
- package/db/types.cds +22 -5
- package/package.json +3 -1
- package/scripts/migrate-slot-leader.mjs +3 -11
- package/scripts/migrate-txseq.mjs +3 -12
- package/src/index.d.ts +0 -4
- package/src/index.js +3 -5
- package/src/plugin.js +4 -8
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +2 -10
- package/srv/blockchain/backends/blockfrost-backend.js +15 -21
- package/srv/blockchain/backends/cardano-backend.d.ts +12 -71
- package/srv/blockchain/backends/koios-backend.d.ts +14 -147
- package/srv/blockchain/backends/koios-backend.js +40 -164
- package/srv/blockchain/backends/odatano-backend.d.ts +1 -11
- package/srv/blockchain/backends/odatano-backend.js +11 -12
- package/srv/blockchain/backends/ogmios-backend.d.ts +13 -160
- package/srv/blockchain/backends/ogmios-backend.js +48 -175
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +2 -18
- package/srv/blockchain/backends/ogmios-frame-guard.js +8 -20
- package/srv/blockchain/cardano-client.d.ts +12 -80
- package/srv/blockchain/cardano-client.js +36 -88
- package/srv/blockchain/cardano-indexer.d.ts +12 -192
- package/srv/blockchain/cardano-indexer.js +132 -222
- package/srv/blockchain/cardano-tx-builder.d.ts +1 -28
- package/srv/blockchain/cardano-tx-builder.js +17 -34
- package/srv/blockchain/circuit-breaker.d.ts +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +0 -17
- package/srv/blockchain/crawler/certificate-backfill.js +8 -22
- package/srv/blockchain/crawler/crawler.d.ts +16 -93
- package/srv/blockchain/crawler/crawler.js +85 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +0 -9
- package/srv/blockchain/crawler/credential-backfill.js +6 -6
- package/srv/blockchain/crawler/hooks.d.ts +1 -5
- package/srv/blockchain/crawler/index.d.ts +0 -12
- package/srv/blockchain/crawler/index.js +6 -20
- package/srv/blockchain/crawler/sync-state.d.ts +6 -44
- package/srv/blockchain/crawler/sync-state.js +18 -53
- package/srv/blockchain/crawler/transaction-backfill.d.ts +0 -11
- package/srv/blockchain/crawler/transaction-backfill.js +11 -30
- package/srv/blockchain/crawler/utxo-set-import.d.ts +1 -30
- package/srv/blockchain/crawler/utxo-set-import.js +27 -53
- package/srv/blockchain/ledger-state.d.ts +10 -54
- package/srv/blockchain/ledger-state.js +11 -27
- package/srv/blockchain/pending-spends.d.ts +0 -12
- package/srv/blockchain/pending-spends.js +4 -12
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +0 -9
- package/srv/blockchain/signing/cose-verifier.js +4 -10
- package/srv/blockchain/signing/external-signer.d.ts +1 -4
- package/srv/blockchain/signing/external-signer.js +2 -8
- package/srv/blockchain/signing/hsm-signer.d.ts +6 -18
- package/srv/blockchain/signing/hsm-signer.js +16 -28
- package/srv/blockchain/signing/signature-verifier.d.ts +1 -8
- package/srv/blockchain/signing/signature-verifier.js +9 -19
- package/srv/blockchain/signing/submission-finalizer.d.ts +10 -16
- package/srv/blockchain/signing/submission-finalizer.js +48 -19
- package/srv/blockchain/stored-chain.d.ts +1 -14
- package/srv/blockchain/stored-chain.js +3 -8
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -4
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +4 -9
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -150
- package/srv/blockchain/transaction-building/buildooor-tx.js +91 -196
- package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -14
- package/srv/blockchain/transaction-building/caller-datums.js +3 -9
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +1 -4
- package/srv/blockchain/wallet-worker/build-request.d.ts +0 -5
- package/srv/blockchain/wallet-worker/build-request.js +6 -9
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -20
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -5
- package/srv/blockchain/wallet-worker/job-store.d.ts +15 -65
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -10
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -12
- package/srv/blockchain/wallet-worker/signers.d.ts +3 -11
- package/srv/blockchain/wallet-worker/signers.js +3 -6
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +3 -21
- package/srv/blockchain/wallet-worker/wallet-worker.js +47 -54
- package/srv/cardano-agent-service.cds +123 -146
- package/srv/cardano-agent-service.js +2 -5
- package/srv/cardano-backend-service.cds +10 -17
- package/srv/cardano-backend-service.js +7 -12
- package/srv/cardano-indexer-service.cds +35 -37
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +64 -33
- package/srv/cardano-service.cds +56 -40
- package/srv/cardano-service.js +42 -69
- package/srv/cardano-sign-service.cds +14 -23
- package/srv/cardano-sign-service.js +18 -24
- package/srv/cardano-tx-service.cds +27 -29
- package/srv/cardano-tx-service.js +60 -122
- package/srv/cardano-worker-service.cds +109 -125
- package/srv/cardano-worker-service.js +21 -31
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +1 -0
- package/srv/cbor/index.js +6 -1
- package/srv/cbor/parse.d.ts +3 -18
- package/srv/cbor/parse.js +2 -7
- package/srv/cbor/plutus-data-json.d.ts +0 -4
- package/srv/server.d.ts +5 -36
- package/srv/server.js +30 -51
- package/srv/utils/agent-grants-config.d.ts +0 -18
- package/srv/utils/agent-grants-config.js +6 -13
- package/srv/utils/agent-grants.d.ts +14 -68
- package/srv/utils/agent-grants.js +42 -60
- package/srv/utils/agent-token-auth.d.ts +0 -5
- package/srv/utils/agent-token-auth.js +2 -5
- package/srv/utils/backend-request-handler.d.ts +1 -1
- package/srv/utils/collections.d.ts +1 -4
- package/srv/utils/collections.js +1 -4
- package/srv/utils/const.d.ts +0 -18
- package/srv/utils/const.js +7 -18
- package/srv/utils/crypto.js +3 -5
- package/srv/utils/db-indexes.d.ts +2 -0
- package/srv/utils/db-indexes.js +22 -9
- package/srv/utils/db-sanitize.d.ts +1 -8
- package/srv/utils/db-sanitize.js +3 -8
- package/srv/utils/epoch-slots.d.ts +1 -8
- package/srv/utils/epoch-slots.js +3 -8
- package/srv/utils/error-codes.d.ts +0 -4
- package/srv/utils/error-codes.js +2 -4
- package/srv/utils/errors.d.ts +2 -22
- package/srv/utils/errors.js +13 -27
- package/srv/utils/liveness.d.ts +0 -4
- package/srv/utils/liveness.js +2 -4
- package/srv/utils/mappers.d.ts +0 -37
- package/srv/utils/mappers.js +22 -39
- package/srv/utils/network-context.js +2 -4
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.js +3 -7
- package/srv/utils/pg-order-nulls.js +2 -5
- package/srv/utils/plutus-placeholders.d.ts +0 -13
- package/srv/utils/plutus-placeholders.js +6 -13
- package/srv/utils/rate-limiter.d.ts +0 -8
- package/srv/utils/rate-limiter.js +2 -4
- package/srv/utils/reference-script.d.ts +0 -18
- package/srv/utils/reference-script.js +8 -19
- package/srv/utils/service-events.d.ts +0 -4
- package/srv/utils/service-events.js +2 -4
- package/srv/utils/signing-helper.d.ts +1 -8
- package/srv/utils/signing-helper.js +3 -8
- package/srv/utils/tx-build-helper.d.ts +2 -32
- package/srv/utils/tx-build-helper.js +26 -40
- package/srv/utils/tx-request-parsers.d.ts +1 -25
- package/srv/utils/tx-request-parsers.js +10 -25
- package/srv/utils/tx-utils.d.ts +0 -8
- package/srv/utils/tx-utils.js +10 -13
- package/srv/utils/types.d.ts +2 -37
- package/srv/utils/validators.d.ts +0 -4
- package/srv/utils/validators.js +2 -4
|
@@ -79,12 +79,8 @@ function ogmiosValueToLovelaceString(value) {
|
|
|
79
79
|
function ratio(a, b) {
|
|
80
80
|
return b === 0n ? 0 : Number((a * 1000000n) / b) / 1_000_000;
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* (max supply - reserves) / nOpt. Figures the ledger view does not carry stay 0 / null: active
|
|
85
|
-
* stake (the indexer derives it from the previous snapshot), block counts, delegator counts,
|
|
86
|
-
* DRep last activity.
|
|
87
|
-
*/
|
|
82
|
+
// Saturation is live stake over ((max supply - reserves) / nOpt), as in the ledger.
|
|
83
|
+
// Figures the ledger does not carry stay 0 or null, such as active stake and block counts.
|
|
88
84
|
function mapOgmiosEpochState(raw) {
|
|
89
85
|
const lovelace = (v) => BigInt(ogmiosValueToLovelaceString(v));
|
|
90
86
|
const reserves = raw.pots?.reserves ? lovelace(raw.pots.reserves) : null;
|
|
@@ -151,10 +147,8 @@ function mapOgmiosEpochState(raw) {
|
|
|
151
147
|
drepNoConfidenceStake: noConfidence == null ? null : noConfidence.toString(),
|
|
152
148
|
};
|
|
153
149
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
* high nibble 0x2 = DRep, low nibble 0x2 = key hash / 0x3 = script hash.
|
|
157
|
-
*/
|
|
150
|
+
// Decode a CIP-129 DRep ID into credential hash and type. In the header byte the high
|
|
151
|
+
// nibble 0x2 means DRep. The low nibble is 0x2 for a key hash and 0x3 for a script hash.
|
|
158
152
|
function decodeDrepId(drepId) {
|
|
159
153
|
const decoded = bech32_1.bech32.decode(drepId, const_1.BECH32_MAX_LENGTH);
|
|
160
154
|
const bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
|
|
@@ -174,10 +168,8 @@ function resolveOgmiosTip(tip) {
|
|
|
174
168
|
function resolveOgmiosHeight(height) {
|
|
175
169
|
return height === 'origin' ? 0 : height;
|
|
176
170
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
* (txHash, index), a mint index into the sorted policy ids; both are resolved here.
|
|
180
|
-
*/
|
|
171
|
+
// Redeemers of a chain-sync tx. A spend index points into the inputs sorted by txHash and index.
|
|
172
|
+
// A mint index points into the sorted policy ids. Both are resolved here.
|
|
181
173
|
function mapOgmiosRedeemers(tx) {
|
|
182
174
|
const sortedInputs = [...(tx.inputs ?? [])].sort((a, b) => (0, mappers_1.compareOutRef)({ txHash: a.transaction.id, outputIndex: a.index }, { txHash: b.transaction.id, outputIndex: b.index }));
|
|
183
175
|
const sortedPolicies = Object.keys(tx.mint ?? {}).sort();
|
|
@@ -199,13 +191,10 @@ function mapOgmiosRedeemers(tx) {
|
|
|
199
191
|
/** CardanoBackend implementation over an Ogmios WebSocket (local node). */
|
|
200
192
|
class OgmiosBackend {
|
|
201
193
|
name = 'ogmios';
|
|
202
|
-
/**
|
|
203
|
-
* Capability declaration — the orchestrator skips Ogmios for these without counting
|
|
204
|
-
* circuit failures. Historic queries are out of protocol scope.
|
|
205
|
-
*/
|
|
194
|
+
/** Ogmios cannot answer historic queries. The orchestrator skips it for these. */
|
|
206
195
|
unsupportedMethods = new Set([
|
|
207
|
-
// getEpoch is
|
|
208
|
-
//
|
|
196
|
+
// getEpoch is not listed, because Ogmios serves the current epoch.
|
|
197
|
+
// Routing prefers historical backends for it anyway.
|
|
209
198
|
'getBlock',
|
|
210
199
|
'getTransaction',
|
|
211
200
|
'getTransactionMetadata',
|
|
@@ -234,11 +223,8 @@ class OgmiosBackend {
|
|
|
234
223
|
this.timeoutMs = timeoutMs;
|
|
235
224
|
this.ogmiosUrl = ogmiosUrl;
|
|
236
225
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
* whose pooled sockets (kept alive since Node 19) fail with "Premature close" once Ogmios' Warp server
|
|
240
|
-
* half-closes them. No agent hook exists, so keep-alive is disabled process-wide for `http://` only.
|
|
241
|
-
*/
|
|
226
|
+
// The `/health` probe uses node-fetch v2 on `http.globalAgent`. Its kept-alive sockets fail with
|
|
227
|
+
// "Premature close" once Ogmios half-closes them. There is no agent hook, so keep-alive is off for http.
|
|
242
228
|
static keepAliveDisabled = false;
|
|
243
229
|
static disableHttpKeepAlive() {
|
|
244
230
|
if (OgmiosBackend.keepAliveDisabled)
|
|
@@ -251,7 +237,7 @@ class OgmiosBackend {
|
|
|
251
237
|
const url = new URL(rawUrl);
|
|
252
238
|
// Only allow WebSocket schemes (block file://, http://, etc.)
|
|
253
239
|
if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {
|
|
254
|
-
throw new errors_1.BackendInitError('ogmios', new Error(`Invalid Ogmios URL scheme "${url.protocol}"
|
|
240
|
+
throw new errors_1.BackendInitError('ogmios', new Error(`Invalid Ogmios URL scheme "${url.protocol}": only ws:// and wss:// are allowed`));
|
|
255
241
|
}
|
|
256
242
|
// In production, block link-local / metadata IPs (SSRF prevention).
|
|
257
243
|
// Private/loopback IPs are allowed since Ogmios typically runs on the local node.
|
|
@@ -264,11 +250,8 @@ class OgmiosBackend {
|
|
|
264
250
|
throw new errors_1.BackendInitError('ogmios', new Error('Ogmios URL must not point to a link-local or metadata address'));
|
|
265
251
|
}
|
|
266
252
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
* can hang when the node is busy. The rejection message contains "timeout" so the
|
|
270
|
-
* orchestrator's transient-error retry picks it up.
|
|
271
|
-
*/
|
|
253
|
+
// The WebSocket handshake has no timeout and can hang on a busy node. The rejection says
|
|
254
|
+
// "timeout" so the orchestrator retries it as a transient error.
|
|
272
255
|
withInitTimeout(p, label) {
|
|
273
256
|
// Short on purpose: the orchestrator retries init several times within a bounded bootstrap window.
|
|
274
257
|
const ms = Math.max(1, Math.min(this.timeoutMs, 4000));
|
|
@@ -279,10 +262,7 @@ class OgmiosBackend {
|
|
|
279
262
|
});
|
|
280
263
|
return Promise.race([p, timeout]).finally(() => clearTimeout(timer));
|
|
281
264
|
}
|
|
282
|
-
/**
|
|
283
|
-
* Force-release an interaction socket after a failed/expired open or close. The runtime
|
|
284
|
-
* socket is `ws` (has `terminate`); the `close` fallback keeps test doubles working.
|
|
285
|
-
*/
|
|
265
|
+
/** Force-release a socket after a failed open or close. Test doubles without `terminate` get `close`. */
|
|
286
266
|
forceCloseContext(context) {
|
|
287
267
|
const socket = context.socket;
|
|
288
268
|
try {
|
|
@@ -313,7 +293,7 @@ class OgmiosBackend {
|
|
|
313
293
|
// Socket closed: clear the clients so the next request reconnects via ensureConnected.
|
|
314
294
|
if (this.isShutdown)
|
|
315
295
|
return;
|
|
316
|
-
logger.warn('[OgmiosBackend] WebSocket closed
|
|
296
|
+
logger.warn('[OgmiosBackend] WebSocket closed, will reconnect on next request');
|
|
317
297
|
this.stateQueryClient = null;
|
|
318
298
|
this.txSubmissionClient = null;
|
|
319
299
|
}, { connection }), 'createInteractionContext');
|
|
@@ -333,11 +313,8 @@ class OgmiosBackend {
|
|
|
333
313
|
this.context = context;
|
|
334
314
|
return true;
|
|
335
315
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
* each), and Ogmios serves the queries of one connection in order; on their own connection they no
|
|
339
|
-
* longer hold up tip, epoch and protocol parameters. Opened on first use, reopened after a close.
|
|
340
|
-
*/
|
|
316
|
+
// Address queries scan the whole UTxO set and take seconds. Ogmios answers one connection in order,
|
|
317
|
+
// so they get their own connection and do not hold up tip and epoch queries.
|
|
341
318
|
async scanQueryClient() {
|
|
342
319
|
this.ensureNotShutdown();
|
|
343
320
|
// never initialized (test-injected clients): the shared client
|
|
@@ -365,10 +342,7 @@ class OgmiosBackend {
|
|
|
365
342
|
}
|
|
366
343
|
return this.scanConnecting;
|
|
367
344
|
}
|
|
368
|
-
/**
|
|
369
|
-
* Reconnect when the WebSocket died since the last init. No-op when never initialized
|
|
370
|
-
* (test-injected clients); concurrent callers share one reconnect attempt.
|
|
371
|
-
*/
|
|
345
|
+
/** Reconnect a dead WebSocket. Concurrent callers share one attempt. No-op before the first init. */
|
|
372
346
|
async ensureConnected() {
|
|
373
347
|
this.ensureNotShutdown();
|
|
374
348
|
if (!this.context)
|
|
@@ -378,28 +352,19 @@ class OgmiosBackend {
|
|
|
378
352
|
if (this.stateQueryClient && socketOpen)
|
|
379
353
|
return;
|
|
380
354
|
if (!this.reconnectPromise) {
|
|
381
|
-
logger.warn('[OgmiosBackend] WebSocket not connected
|
|
355
|
+
logger.warn('[OgmiosBackend] WebSocket not connected, reconnecting');
|
|
382
356
|
this.reconnectPromise = this.init()
|
|
383
357
|
.then(() => undefined)
|
|
384
358
|
.finally(() => { this.reconnectPromise = null; });
|
|
385
359
|
}
|
|
386
360
|
await this.reconnectPromise;
|
|
387
361
|
}
|
|
388
|
-
/**
|
|
389
|
-
* Get specific Block Data (not supported)
|
|
390
|
-
* @param _hash block hash (hex)
|
|
391
|
-
* @returns {Promise<BlockData>} block data
|
|
392
|
-
*/
|
|
393
362
|
async getBlock(_hash) {
|
|
394
363
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
395
364
|
throw new errors_1.NotFoundError('Historic Block queries not supported', this.name);
|
|
396
365
|
}, this.name);
|
|
397
366
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Get specific Epoch Data (not supported)
|
|
400
|
-
* @param _epochNumber epoch number
|
|
401
|
-
* @returns {Promise<EpochData>} epoch data
|
|
402
|
-
*/
|
|
367
|
+
/** Only the current epoch. */
|
|
403
368
|
async getEpoch(epochNumber) {
|
|
404
369
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
405
370
|
await this.ensureConnected();
|
|
@@ -411,32 +376,18 @@ class OgmiosBackend {
|
|
|
411
376
|
return this.getLatestEpoch();
|
|
412
377
|
}, this.name);
|
|
413
378
|
}
|
|
414
|
-
/**
|
|
415
|
-
* Get specific Transaction Data (not supported)
|
|
416
|
-
* @param _hash transaction hash (hex)
|
|
417
|
-
* @returns {Promise<Transaction>} transaction data
|
|
418
|
-
*/
|
|
419
379
|
async getTransaction(_hash) {
|
|
420
380
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
421
381
|
throw new errors_1.NotFoundError('Historic Transaction queries not supported', this.name);
|
|
422
382
|
}, this.name);
|
|
423
383
|
}
|
|
424
|
-
/**
|
|
425
|
-
* Get specific Transaction Metadata (not supported)
|
|
426
|
-
* @param _tx_hash transaction hash (hex)
|
|
427
|
-
* @returns {Promise<MetadataLabelTx[]>} transaction metadata list
|
|
428
|
-
*/
|
|
429
384
|
async getTransactionMetadata(_tx_hash) {
|
|
430
385
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
431
386
|
throw new errors_1.NotFoundError('Historic Transaction metadata not supported', this.name);
|
|
432
387
|
}, this.name);
|
|
433
388
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
* raw `Method()` primitive, since the client ships no wrapper. Ogmios lists only REGISTERED
|
|
437
|
-
* DReps: retired/unknown → NotFoundError; `expired` is derived from the mandate epoch.
|
|
438
|
-
* @param drepId CIP-129 bech32 DRep ID (`drep1…`)
|
|
439
|
-
*/
|
|
389
|
+
// DRep from `queryLedgerState/delegateRepresentatives` via raw `Method()`, as the client has no wrapper.
|
|
390
|
+
// Ogmios lists only registered DReps, so others are NotFoundError.
|
|
440
391
|
async getDrep(drepId) {
|
|
441
392
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
442
393
|
await this.ensureConnected();
|
|
@@ -471,27 +422,20 @@ class OgmiosBackend {
|
|
|
471
422
|
hex: hashHex,
|
|
472
423
|
amount: ogmiosValueToLovelaceString(drep.stake),
|
|
473
424
|
hasScript: isScript || drep.from === 'script',
|
|
474
|
-
// Ogmios reports the mandate
|
|
425
|
+
// Ogmios reports the mandate expiry epoch, not the last activity.
|
|
475
426
|
lastActiveEpoch: 0,
|
|
476
427
|
expired: typeof mandateEpoch === 'number' && mandateEpoch < Number(currentEpoch),
|
|
477
428
|
retired: false,
|
|
478
429
|
};
|
|
479
430
|
}, this.name);
|
|
480
431
|
}
|
|
481
|
-
/**
|
|
482
|
-
* Get Asset Info (not supported for Ogmios — no aggregate-supply query in the protocol)
|
|
483
|
-
* @param _unit asset unit (policyId + assetNameHex)
|
|
484
|
-
* @returns {Promise<AssetInfo>} asset info
|
|
485
|
-
*/
|
|
432
|
+
/** Not supported. The protocol has no aggregate-supply query. */
|
|
486
433
|
async getAssetInfo(_unit) {
|
|
487
434
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
488
435
|
throw new errors_1.ProviderUnavailableError('Asset info queries not supported by Ogmios backend', this.name);
|
|
489
436
|
}, this.name);
|
|
490
437
|
}
|
|
491
|
-
/**
|
|
492
|
-
* Supply figures from `queryLedgerState/treasuryAndReserves`: total = max − reserves.
|
|
493
|
-
* Circulating, locked and stake totals are not in the ledger state and stay '0'.
|
|
494
|
-
*/
|
|
438
|
+
/** Total supply is max supply minus reserves. Circulating, locked and stake totals stay '0'. */
|
|
495
439
|
async getNetworkInformation() {
|
|
496
440
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
497
441
|
await this.ensureConnected();
|
|
@@ -523,10 +467,7 @@ class OgmiosBackend {
|
|
|
523
467
|
};
|
|
524
468
|
}, this.name);
|
|
525
469
|
}
|
|
526
|
-
/**
|
|
527
|
-
* Address at the tip: type, script flag and stake address decoded from the address itself,
|
|
528
|
-
* UTxOs from the ledger, balance summed over them. No transaction history (getAddressTransactions).
|
|
529
|
-
*/
|
|
470
|
+
/** Address at the tip, decoded locally, with UTxOs and balance from the ledger. No tx history. */
|
|
530
471
|
async getAddress(address) {
|
|
531
472
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
532
473
|
await this.ensureConnected();
|
|
@@ -543,10 +484,6 @@ class OgmiosBackend {
|
|
|
543
484
|
};
|
|
544
485
|
}, this.name);
|
|
545
486
|
}
|
|
546
|
-
/** get current specific Address UTxOs
|
|
547
|
-
* @param address bech32 address
|
|
548
|
-
* @returns {Promise<UTxO[]>} address UTxOs
|
|
549
|
-
*/
|
|
550
487
|
async getAddressUtxos(address) {
|
|
551
488
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
552
489
|
await this.ensureConnected();
|
|
@@ -572,11 +509,8 @@ class OgmiosBackend {
|
|
|
572
509
|
scriptRefType: ref?.type ?? null,
|
|
573
510
|
};
|
|
574
511
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
* holds one acquired point per connection, so the shared socket would pin live queries to the past.
|
|
578
|
-
* The point must be inside the node's volatile window (k blocks) or acquisition is refused.
|
|
579
|
-
*/
|
|
512
|
+
// Runs `fn` on the ledger state at `point` over a separate WebSocket. A connection holds one acquired
|
|
513
|
+
// point, so the shared socket would pin live queries to the past. `point` must be within k blocks.
|
|
580
514
|
async withLedgerStateAt(point, label, fn) {
|
|
581
515
|
const url = new URL(this.ogmiosUrl);
|
|
582
516
|
const connection = { host: url.hostname, port: Number(url.port) || (url.protocol === 'wss:' ? 443 : 80), tls: url.protocol === 'wss:' };
|
|
@@ -605,10 +539,7 @@ class OgmiosBackend {
|
|
|
605
539
|
return utxos.map((u) => this.mapOgmiosUtxo(u));
|
|
606
540
|
}), this.name);
|
|
607
541
|
}
|
|
608
|
-
/**
|
|
609
|
-
* Pools, DReps and pots as of `point` (crawler epoch snapshot), all read from one acquired
|
|
610
|
-
* ledger state. Performances are optional: without them (no nOpt) saturation stays 0.
|
|
611
|
-
*/
|
|
542
|
+
/** Pools, DReps and pots at `point` from one ledger state. Without nOpt saturation stays 0. */
|
|
612
543
|
async epochStateAt(point) {
|
|
613
544
|
return (0, backend_request_handler_1.handleBackendRequest)(() => this.withLedgerStateAt(point, 'epoch snapshot', async (client) => {
|
|
614
545
|
const ctx = client.context;
|
|
@@ -631,15 +562,10 @@ class OgmiosBackend {
|
|
|
631
562
|
});
|
|
632
563
|
}), this.name);
|
|
633
564
|
}
|
|
634
|
-
/** Not supported
|
|
565
|
+
/** Not supported. Ogmios only queries live state. */
|
|
635
566
|
async getAddressTransactions(_address) {
|
|
636
567
|
throw new errors_1.NotFoundError('Address transactions not available via Ogmios - use historical backend (Blockfrost/Koios)', this.name);
|
|
637
568
|
}
|
|
638
|
-
/**
|
|
639
|
-
* Get current specific Pool Data
|
|
640
|
-
* @param poolId pool id
|
|
641
|
-
* @returns {Promise<PoolData>} pool data
|
|
642
|
-
*/
|
|
643
569
|
async getPool(poolId) {
|
|
644
570
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
645
571
|
await this.ensureConnected();
|
|
@@ -661,8 +587,7 @@ class OgmiosBackend {
|
|
|
661
587
|
// not in the ledger state; null = unavailable
|
|
662
588
|
liveDelegators: null,
|
|
663
589
|
liveSaturation: 0,
|
|
664
|
-
//
|
|
665
|
-
// of fabricating it from the pledge
|
|
590
|
+
// Ogmios pool params have no active stake
|
|
666
591
|
activeStake: '0',
|
|
667
592
|
activeSize: 0,
|
|
668
593
|
// pledge/cost are ValueAdaOnly objects in Ogmios v6; margin is a Ratio string ("1/10")
|
|
@@ -673,11 +598,6 @@ class OgmiosBackend {
|
|
|
673
598
|
};
|
|
674
599
|
}, this.name);
|
|
675
600
|
}
|
|
676
|
-
/**
|
|
677
|
-
* Get Account Data for specified stake address
|
|
678
|
-
* @param stakeAddress stake address
|
|
679
|
-
* @returns {Promise<AccountData>} account data
|
|
680
|
-
*/
|
|
681
601
|
async getAccount(stakeAddress) {
|
|
682
602
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
683
603
|
await this.ensureConnected();
|
|
@@ -712,11 +632,6 @@ class OgmiosBackend {
|
|
|
712
632
|
};
|
|
713
633
|
}, this.name);
|
|
714
634
|
}
|
|
715
|
-
/**
|
|
716
|
-
* Submit Transaction to the network
|
|
717
|
-
* @param signedTxCbor signed transaction in CBOR hex format
|
|
718
|
-
* @returns {Promise<string>} transaction hash
|
|
719
|
-
*/
|
|
720
635
|
async submitTransaction(signedTxCbor) {
|
|
721
636
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
722
637
|
await this.ensureConnected();
|
|
@@ -738,11 +653,6 @@ class OgmiosBackend {
|
|
|
738
653
|
}
|
|
739
654
|
}, this.name);
|
|
740
655
|
}
|
|
741
|
-
/**
|
|
742
|
-
* Evaluate transaction script execution units
|
|
743
|
-
* @param unsignedTxCbor unsigned transaction in CBOR hex format
|
|
744
|
-
* @returns {Promise<ScriptEvaluationResult[]>} evaluation results
|
|
745
|
-
*/
|
|
746
656
|
async evaluateTransaction(unsignedTxCbor) {
|
|
747
657
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
748
658
|
await this.ensureConnected();
|
|
@@ -765,10 +675,6 @@ class OgmiosBackend {
|
|
|
765
675
|
}
|
|
766
676
|
}, this.name);
|
|
767
677
|
}
|
|
768
|
-
/**
|
|
769
|
-
* Get current Protocol Parameters
|
|
770
|
-
* @returns {Promise<LedgerProtocolParameters>} protocol parameters
|
|
771
|
-
*/
|
|
772
678
|
async getProtocolParameters() {
|
|
773
679
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
774
680
|
await this.ensureConnected();
|
|
@@ -817,10 +723,6 @@ class OgmiosBackend {
|
|
|
817
723
|
};
|
|
818
724
|
}, this.name);
|
|
819
725
|
}
|
|
820
|
-
/**
|
|
821
|
-
* Get Latest Epoch Data
|
|
822
|
-
* @returns {Promise<EpochData>} latest epoch data
|
|
823
|
-
*/
|
|
824
726
|
async getLatestEpoch() {
|
|
825
727
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
826
728
|
await this.ensureConnected();
|
|
@@ -846,10 +748,6 @@ class OgmiosBackend {
|
|
|
846
748
|
};
|
|
847
749
|
}, this.name);
|
|
848
750
|
}
|
|
849
|
-
/**
|
|
850
|
-
* Get current Latest Block Data
|
|
851
|
-
* @returns {Promise<BlockData>} latest block data
|
|
852
|
-
*/
|
|
853
751
|
async getLatestBlock() {
|
|
854
752
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
855
753
|
await this.ensureConnected();
|
|
@@ -878,10 +776,6 @@ class OgmiosBackend {
|
|
|
878
776
|
};
|
|
879
777
|
}, this.name);
|
|
880
778
|
}
|
|
881
|
-
/**
|
|
882
|
-
* Get the latest chain tip slot.
|
|
883
|
-
* @returns {Promise<number>} current chain slot
|
|
884
|
-
*/
|
|
885
779
|
async getCurrentSlot() {
|
|
886
780
|
const block = await this.getLatestBlock();
|
|
887
781
|
if (block.slot == null) {
|
|
@@ -889,11 +783,7 @@ class OgmiosBackend {
|
|
|
889
783
|
}
|
|
890
784
|
return block.slot;
|
|
891
785
|
}
|
|
892
|
-
/**
|
|
893
|
-
* Unspent check via `queryLedgerState/utxo` with an outputReferences filter; empty = spent or nonexistent.
|
|
894
|
-
* @param txHash 64-char lowercase hex
|
|
895
|
-
* @param outputIndex non-negative integer
|
|
896
|
-
*/
|
|
786
|
+
/** Unspent check via `queryLedgerState/utxo`. An empty answer means spent or unknown. */
|
|
897
787
|
async isUtxoUnspent(txHash, outputIndex) {
|
|
898
788
|
if (!Number.isInteger(outputIndex) || outputIndex < 0)
|
|
899
789
|
return false;
|
|
@@ -959,10 +849,7 @@ class OgmiosBackend {
|
|
|
959
849
|
throw new errors_1.ProviderUnavailableError('Ogmios client has been shutdown', this.name);
|
|
960
850
|
}
|
|
961
851
|
}
|
|
962
|
-
/**
|
|
963
|
-
* Ogmios value `{ ada: { lovelace }, policyId: { assetName: qty } }` →
|
|
964
|
-
* `[{ unit: 'lovelace', quantity }, { unit: policyId+assetName, quantity }]`.
|
|
965
|
-
*/
|
|
852
|
+
/** Ogmios value `{ ada: { lovelace }, policyId: { assetName: qty } }` to a list of units and quantities. */
|
|
966
853
|
convertOgmiosValue(value) {
|
|
967
854
|
const amounts = [];
|
|
968
855
|
if (value.ada?.lovelace) {
|
|
@@ -984,13 +871,10 @@ class OgmiosBackend {
|
|
|
984
871
|
return amounts;
|
|
985
872
|
}
|
|
986
873
|
// ---------------------------------------------------------------------------
|
|
987
|
-
// ChainSyncBackend
|
|
874
|
+
// ChainSyncBackend: streamed forward sync for the chain crawler
|
|
988
875
|
// ---------------------------------------------------------------------------
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
* deliver blocks strictly in order (required by reorg detection and serial persist). Inputs arrive
|
|
992
|
-
* as bare references (resolved by the indexer from indexed outputs); per-tx size/deposit are not surfaced.
|
|
993
|
-
*/
|
|
876
|
+
// Opens a chain-sync stream on its own WebSocket. One block in flight keeps blocks strictly
|
|
877
|
+
// in order, which reorg detection needs. Inputs arrive as bare references the indexer resolves.
|
|
994
878
|
async openChainSync(from, callbacks) {
|
|
995
879
|
OgmiosBackend.validateOgmiosUrl(this.ogmiosUrl);
|
|
996
880
|
const url = new URL(this.ogmiosUrl);
|
|
@@ -1051,7 +935,7 @@ class OgmiosBackend {
|
|
|
1051
935
|
rollForward: async ({ block, tip }, nextBlock) => {
|
|
1052
936
|
try {
|
|
1053
937
|
const b = block;
|
|
1054
|
-
// Byron
|
|
938
|
+
// Byron boundary and bft blocks carry no indexable txs
|
|
1055
939
|
if (b.type !== 'praos') {
|
|
1056
940
|
nextBlock();
|
|
1057
941
|
return;
|
|
@@ -1065,7 +949,7 @@ class OgmiosBackend {
|
|
|
1065
949
|
nextBlock();
|
|
1066
950
|
}
|
|
1067
951
|
catch (err) {
|
|
1068
|
-
logger.error('[OgmiosBackend] chain-sync rollForward failed
|
|
952
|
+
logger.error('[OgmiosBackend] chain-sync rollForward failed, stream halted:', err);
|
|
1069
953
|
await reportStreamError(err);
|
|
1070
954
|
}
|
|
1071
955
|
},
|
|
@@ -1076,7 +960,7 @@ class OgmiosBackend {
|
|
|
1076
960
|
nextBlock();
|
|
1077
961
|
}
|
|
1078
962
|
catch (err) {
|
|
1079
|
-
logger.error('[OgmiosBackend] chain-sync rollBackward failed
|
|
963
|
+
logger.error('[OgmiosBackend] chain-sync rollBackward failed, stream halted:', err);
|
|
1080
964
|
await reportStreamError(err);
|
|
1081
965
|
}
|
|
1082
966
|
},
|
|
@@ -1124,11 +1008,8 @@ class OgmiosBackend {
|
|
|
1124
1008
|
}
|
|
1125
1009
|
};
|
|
1126
1010
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
* fees; epoch/epochSlot derive from the slot via the Shelley anchor. A phase-2 failure without
|
|
1130
|
-
* `total_collateral` still carries its declared fee here; applyCollateralFees() corrects it.
|
|
1131
|
-
*/
|
|
1011
|
+
// Block fees are the sum of tx fees. A phase-2 failure without `total_collateral` keeps
|
|
1012
|
+
// its declared fee here, and applyCollateralFees() corrects it later.
|
|
1132
1013
|
mapOgmiosBlock(block) {
|
|
1133
1014
|
const txs = (block.transactions ?? []).map((t, i) => this.mapOgmiosTx(t, block, i));
|
|
1134
1015
|
const totalFees = txs.reduce((sum, t) => sum + BigInt(t.fee || 0), 0n);
|
|
@@ -1149,11 +1030,8 @@ class OgmiosBackend {
|
|
|
1149
1030
|
};
|
|
1150
1031
|
return { block: blockData, txs };
|
|
1151
1032
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
* `spends` selects the ledger-applied partition: a phase-2-invalid tx consumes collaterals
|
|
1155
|
-
* and creates only its collateral-return output; the fee follows that partition too.
|
|
1156
|
-
*/
|
|
1033
|
+
// A phase-2 invalid tx consumes its collaterals and creates only the collateral-return output.
|
|
1034
|
+
// `spends` selects which side the ledger applied, and the fee follows it.
|
|
1157
1035
|
mapOgmiosTx(tx, block, index) {
|
|
1158
1036
|
const mapInput = (input, flags = {}) => ({
|
|
1159
1037
|
address: '',
|
|
@@ -1210,14 +1088,12 @@ class OgmiosBackend {
|
|
|
1210
1088
|
// The ledger applies no mint when the script phase failed: the body's mint field is
|
|
1211
1089
|
// declared but never enacted, so a phase-2 failure must report none at all.
|
|
1212
1090
|
mint: spendsCollaterals ? undefined : this.convertOgmiosValue(tx.mint ?? {}),
|
|
1213
|
-
//
|
|
1214
|
-
// lazy path's `size ?? null` convention; 0 would masquerade as a real size
|
|
1091
|
+
// chain-sync has no serialized size, and 0 would look like a real size
|
|
1215
1092
|
size: null,
|
|
1216
1093
|
blockTime: (0, epoch_slots_1.slotToPosixSeconds)(this.network, block.slot),
|
|
1217
1094
|
inputs,
|
|
1218
1095
|
outputs,
|
|
1219
|
-
// undefined
|
|
1220
|
-
// mapTransaction's hasMetadata flag stays false for metadata-less txs
|
|
1096
|
+
// undefined, not [], so hasMetadata stays false as on the Blockfrost path
|
|
1221
1097
|
metadata: metadataEntries.length ? metadataEntries : undefined,
|
|
1222
1098
|
certificates: this.mapOgmiosCertificates(tx.certificates ?? []),
|
|
1223
1099
|
withdrawals: Object.entries(tx.withdrawals ?? {}).map(([stakeAddress, value]) => ({
|
|
@@ -1228,11 +1104,8 @@ class OgmiosBackend {
|
|
|
1228
1104
|
datums: Object.entries(tx.datums ?? {}).map(([hash, cbor]) => ({ hash, cbor })),
|
|
1229
1105
|
});
|
|
1230
1106
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
* with both pool and DRep target is split into two entries with the same index (as db-sync
|
|
1234
|
-
* reports it); bare credential hashes are re-encoded as bech32 to match the other tables.
|
|
1235
|
-
*/
|
|
1107
|
+
// Maps Ogmios certificates to `CertificateKind`. A delegation to both pool and DRep becomes two
|
|
1108
|
+
// entries with one index, as db-sync reports it. Credential hashes are re-encoded as bech32.
|
|
1236
1109
|
mapOgmiosCertificates(certs) {
|
|
1237
1110
|
const out = [];
|
|
1238
1111
|
const lovelace = (v) => v?.ada?.lovelace != null ? v.ada.lovelace.toString() : null;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Guard for Ogmios chain-sync frames the client's `safeJSON.parse` cannot handle: it recurses per
|
|
3
|
-
* nesting level, so a deeply nested native script overflows the stack inside an un-awaited socket
|
|
4
|
-
* handler and ends the process. On RangeError fall back to iterative `JSON.parse` (big ints as strings).
|
|
5
|
-
*/
|
|
6
1
|
import { safeJSON } from '@cardano-ogmios/client';
|
|
7
2
|
/** A frame the guard could not turn into an object at all. */
|
|
8
3
|
export interface UnparseableFrame {
|
|
@@ -13,20 +8,9 @@ export interface UnparseableFrame {
|
|
|
13
8
|
reason: string;
|
|
14
9
|
bytes: number;
|
|
15
10
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Wrap integers outside the safe double range in JSON strings so plain `JSON.parse` cannot
|
|
18
|
-
* round them. One linear pass, no recursion; digits inside strings, floats and exponents
|
|
19
|
-
* are left alone.
|
|
20
|
-
*/
|
|
11
|
+
/** Quote integers beyond 2^53 so `JSON.parse` cannot round them. One pass, no recursion. */
|
|
21
12
|
export declare function widenBigIntegers(text: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* Wrap `safeJSON.parse` once per process and register a report callback; returns its
|
|
24
|
-
* unregister function. The parser is shared by every open chain-sync socket and cannot tell
|
|
25
|
-
* which one a frame came from, so an unusable frame goes to every registered callback.
|
|
26
|
-
* After a reported frame the stream stalls (the client drops non-nextBlock responses),
|
|
27
|
-
* so the caller decides what happens next.
|
|
28
|
-
*/
|
|
29
13
|
export declare function installOgmiosFrameGuard(onUnparseableFrame: (frame: UnparseableFrame) => void): () => void;
|
|
30
|
-
/** Tests only
|
|
14
|
+
/** Tests only: drop the wrapper so each case starts from the untouched client. */
|
|
31
15
|
export declare function resetOgmiosFrameGuardForTests(originalParse?: typeof safeJSON.parse): void;
|
|
32
16
|
//# sourceMappingURL=ogmios-frame-guard.d.ts.map
|
|
@@ -6,19 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.widenBigIntegers = widenBigIntegers;
|
|
7
7
|
exports.installOgmiosFrameGuard = installOgmiosFrameGuard;
|
|
8
8
|
exports.resetOgmiosFrameGuardForTests = resetOgmiosFrameGuardForTests;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* nesting level, so a deeply nested native script overflows the stack inside an un-awaited socket
|
|
12
|
-
* handler and ends the process. On RangeError fall back to iterative `JSON.parse` (big ints as strings).
|
|
13
|
-
*/
|
|
9
|
+
// The Ogmios client's `safeJSON.parse` recurses per nesting level. A deeply nested native script
|
|
10
|
+
// overflows the stack in a socket handler and ends the process, so on RangeError we use `JSON.parse`.
|
|
14
11
|
const client_1 = require("@cardano-ogmios/client");
|
|
15
12
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
16
13
|
const logger = cds_1.default.log('OgmiosFrameGuard');
|
|
17
|
-
/**
|
|
18
|
-
* Wrap integers outside the safe double range in JSON strings so plain `JSON.parse` cannot
|
|
19
|
-
* round them. One linear pass, no recursion; digits inside strings, floats and exponents
|
|
20
|
-
* are left alone.
|
|
21
|
-
*/
|
|
14
|
+
/** Quote integers beyond 2^53 so `JSON.parse` cannot round them. One pass, no recursion. */
|
|
22
15
|
function widenBigIntegers(text) {
|
|
23
16
|
const SAFE_DIGITS = String(Number.MAX_SAFE_INTEGER).length; // 16
|
|
24
17
|
let out = '';
|
|
@@ -55,7 +48,7 @@ function widenBigIntegers(text) {
|
|
|
55
48
|
const digits = j - digitsFrom;
|
|
56
49
|
if (digits === 0)
|
|
57
50
|
continue;
|
|
58
|
-
// a fraction or exponent means it was never an exact integer
|
|
51
|
+
// a fraction or exponent means it was never an exact integer
|
|
59
52
|
const after = text[j];
|
|
60
53
|
if (after === '.' || after === 'e' || after === 'E') {
|
|
61
54
|
i = j;
|
|
@@ -81,13 +74,8 @@ function readBlockHeader(text) {
|
|
|
81
74
|
}
|
|
82
75
|
let installed = false;
|
|
83
76
|
const reporters = new Set();
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
* unregister function. The parser is shared by every open chain-sync socket and cannot tell
|
|
87
|
-
* which one a frame came from, so an unusable frame goes to every registered callback.
|
|
88
|
-
* After a reported frame the stream stalls (the client drops non-nextBlock responses),
|
|
89
|
-
* so the caller decides what happens next.
|
|
90
|
-
*/
|
|
77
|
+
// Wraps `safeJSON.parse` once per process and returns an unregister function. The parser is shared
|
|
78
|
+
// by all chain-sync sockets, so an unusable frame goes to every callback. That stream then stalls.
|
|
91
79
|
function installOgmiosFrameGuard(onUnparseableFrame) {
|
|
92
80
|
reporters.add(onUnparseableFrame);
|
|
93
81
|
const unregister = () => { reporters.delete(onUnparseableFrame); };
|
|
@@ -107,7 +95,7 @@ function installOgmiosFrameGuard(onUnparseableFrame) {
|
|
|
107
95
|
try {
|
|
108
96
|
const parsed = JSON.parse(widenBigIntegers(text));
|
|
109
97
|
logger.warn(`chain-sync frame too deeply nested for the client's parser (block ${where.height ?? '?'} ` +
|
|
110
|
-
`${where.id ?? ''}, ${text.length} bytes)
|
|
98
|
+
`${where.id ?? ''}, ${text.length} bytes), parsed without it. Integers beyond 2^53 are ` +
|
|
111
99
|
`strings on this path; the chain-sync mapper stringifies them anyway.`);
|
|
112
100
|
return parsed;
|
|
113
101
|
}
|
|
@@ -132,7 +120,7 @@ function installOgmiosFrameGuard(onUnparseableFrame) {
|
|
|
132
120
|
};
|
|
133
121
|
return unregister;
|
|
134
122
|
}
|
|
135
|
-
/** Tests only
|
|
123
|
+
/** Tests only: drop the wrapper so each case starts from the untouched client. */
|
|
136
124
|
function resetOgmiosFrameGuardForTests(originalParse) {
|
|
137
125
|
if (originalParse)
|
|
138
126
|
client_1.safeJSON.parse = originalParse;
|