@odatano/core 2.0.0-rc.44 → 2.0.0-rc.46
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 +5 -20
- package/@cds-models/CardanoODataService/index.d.ts +18 -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 +0 -34
- package/README.md +20 -20
- package/db/schema.cds +25 -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 +0 -9
- package/srv/blockchain/asset-decimals.js +21 -16
- 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 +43 -166
- 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 +19 -160
- package/srv/blockchain/backends/ogmios-backend.js +96 -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 +14 -192
- package/srv/blockchain/cardano-indexer.js +136 -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 +0 -5
- package/srv/blockchain/crawler/asset-decimals-backfill.js +2 -5
- 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 -10
- package/srv/blockchain/crawler/credential-backfill.js +2 -4
- 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 +53 -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 +16 -37
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +44 -35
- 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 +0 -4
- package/srv/cbor/cip68.js +2 -4
- 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 +19 -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
|
@@ -19,11 +19,14 @@ const crypto_1 = require("@harmoniclabs/crypto");
|
|
|
19
19
|
const reference_script_1 = require("../../utils/reference-script");
|
|
20
20
|
const backend_request_handler_1 = require("../../utils/backend-request-handler");
|
|
21
21
|
const errors_1 = require("../../utils/errors");
|
|
22
|
+
const tx_build_helper_1 = require("../../utils/tx-build-helper");
|
|
22
23
|
const ogmios_frame_guard_1 = require("./ogmios-frame-guard");
|
|
23
24
|
const epoch_slots_1 = require("../../utils/epoch-slots");
|
|
24
25
|
const mappers_1 = require("../../utils/mappers");
|
|
25
26
|
const const_1 = require("../../utils/const");
|
|
26
27
|
const logger = cds_1.default.log('OgmiosBackend');
|
|
28
|
+
/** Node rejection text for inputs that are no longer unspent. */
|
|
29
|
+
const SPENT_INPUTS = /inputs are spent|unknown output reference|already been included/i;
|
|
27
30
|
/** Parse an Ogmios `Ratio` ("num/den", e.g. "3/1000") into a number; `Number("3/1000")` is NaN. */
|
|
28
31
|
function parseOgmiosRatio(ratio) {
|
|
29
32
|
if (ratio === null || ratio === undefined)
|
|
@@ -79,12 +82,8 @@ function ogmiosValueToLovelaceString(value) {
|
|
|
79
82
|
function ratio(a, b) {
|
|
80
83
|
return b === 0n ? 0 : Number((a * 1000000n) / b) / 1_000_000;
|
|
81
84
|
}
|
|
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
|
-
*/
|
|
85
|
+
// Saturation is live stake over ((max supply - reserves) / nOpt), as in the ledger.
|
|
86
|
+
// Figures the ledger does not carry stay 0 or null, such as active stake and block counts.
|
|
88
87
|
function mapOgmiosEpochState(raw) {
|
|
89
88
|
const lovelace = (v) => BigInt(ogmiosValueToLovelaceString(v));
|
|
90
89
|
const reserves = raw.pots?.reserves ? lovelace(raw.pots.reserves) : null;
|
|
@@ -151,10 +150,8 @@ function mapOgmiosEpochState(raw) {
|
|
|
151
150
|
drepNoConfidenceStake: noConfidence == null ? null : noConfidence.toString(),
|
|
152
151
|
};
|
|
153
152
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
* high nibble 0x2 = DRep, low nibble 0x2 = key hash / 0x3 = script hash.
|
|
157
|
-
*/
|
|
153
|
+
// Decode a CIP-129 DRep ID into credential hash and type. In the header byte the high
|
|
154
|
+
// nibble 0x2 means DRep. The low nibble is 0x2 for a key hash and 0x3 for a script hash.
|
|
158
155
|
function decodeDrepId(drepId) {
|
|
159
156
|
const decoded = bech32_1.bech32.decode(drepId, const_1.BECH32_MAX_LENGTH);
|
|
160
157
|
const bytes = Buffer.from(bech32_1.bech32.fromWords(decoded.words));
|
|
@@ -174,10 +171,8 @@ function resolveOgmiosTip(tip) {
|
|
|
174
171
|
function resolveOgmiosHeight(height) {
|
|
175
172
|
return height === 'origin' ? 0 : height;
|
|
176
173
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
* (txHash, index), a mint index into the sorted policy ids; both are resolved here.
|
|
180
|
-
*/
|
|
174
|
+
// Redeemers of a chain-sync tx. A spend index points into the inputs sorted by txHash and index.
|
|
175
|
+
// A mint index points into the sorted policy ids. Both are resolved here.
|
|
181
176
|
function mapOgmiosRedeemers(tx) {
|
|
182
177
|
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
178
|
const sortedPolicies = Object.keys(tx.mint ?? {}).sort();
|
|
@@ -199,13 +194,10 @@ function mapOgmiosRedeemers(tx) {
|
|
|
199
194
|
/** CardanoBackend implementation over an Ogmios WebSocket (local node). */
|
|
200
195
|
class OgmiosBackend {
|
|
201
196
|
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
|
-
*/
|
|
197
|
+
/** Ogmios cannot answer historic queries. The orchestrator skips it for these. */
|
|
206
198
|
unsupportedMethods = new Set([
|
|
207
|
-
// getEpoch is
|
|
208
|
-
//
|
|
199
|
+
// getEpoch is not listed, because Ogmios serves the current epoch.
|
|
200
|
+
// Routing prefers historical backends for it anyway.
|
|
209
201
|
'getBlock',
|
|
210
202
|
'getTransaction',
|
|
211
203
|
'getTransactionMetadata',
|
|
@@ -234,11 +226,8 @@ class OgmiosBackend {
|
|
|
234
226
|
this.timeoutMs = timeoutMs;
|
|
235
227
|
this.ogmiosUrl = ogmiosUrl;
|
|
236
228
|
}
|
|
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
|
-
*/
|
|
229
|
+
// The `/health` probe uses node-fetch v2 on `http.globalAgent`. Its kept-alive sockets fail with
|
|
230
|
+
// "Premature close" once Ogmios half-closes them. There is no agent hook, so keep-alive is off for http.
|
|
242
231
|
static keepAliveDisabled = false;
|
|
243
232
|
static disableHttpKeepAlive() {
|
|
244
233
|
if (OgmiosBackend.keepAliveDisabled)
|
|
@@ -251,7 +240,7 @@ class OgmiosBackend {
|
|
|
251
240
|
const url = new URL(rawUrl);
|
|
252
241
|
// Only allow WebSocket schemes (block file://, http://, etc.)
|
|
253
242
|
if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {
|
|
254
|
-
throw new errors_1.BackendInitError('ogmios', new Error(`Invalid Ogmios URL scheme "${url.protocol}"
|
|
243
|
+
throw new errors_1.BackendInitError('ogmios', new Error(`Invalid Ogmios URL scheme "${url.protocol}": only ws:// and wss:// are allowed`));
|
|
255
244
|
}
|
|
256
245
|
// In production, block link-local / metadata IPs (SSRF prevention).
|
|
257
246
|
// Private/loopback IPs are allowed since Ogmios typically runs on the local node.
|
|
@@ -264,11 +253,8 @@ class OgmiosBackend {
|
|
|
264
253
|
throw new errors_1.BackendInitError('ogmios', new Error('Ogmios URL must not point to a link-local or metadata address'));
|
|
265
254
|
}
|
|
266
255
|
}
|
|
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
|
-
*/
|
|
256
|
+
// The WebSocket handshake has no timeout and can hang on a busy node. The rejection says
|
|
257
|
+
// "timeout" so the orchestrator retries it as a transient error.
|
|
272
258
|
withInitTimeout(p, label) {
|
|
273
259
|
// Short on purpose: the orchestrator retries init several times within a bounded bootstrap window.
|
|
274
260
|
const ms = Math.max(1, Math.min(this.timeoutMs, 4000));
|
|
@@ -279,10 +265,7 @@ class OgmiosBackend {
|
|
|
279
265
|
});
|
|
280
266
|
return Promise.race([p, timeout]).finally(() => clearTimeout(timer));
|
|
281
267
|
}
|
|
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
|
-
*/
|
|
268
|
+
/** Force-release a socket after a failed open or close. Test doubles without `terminate` get `close`. */
|
|
286
269
|
forceCloseContext(context) {
|
|
287
270
|
const socket = context.socket;
|
|
288
271
|
try {
|
|
@@ -313,7 +296,7 @@ class OgmiosBackend {
|
|
|
313
296
|
// Socket closed: clear the clients so the next request reconnects via ensureConnected.
|
|
314
297
|
if (this.isShutdown)
|
|
315
298
|
return;
|
|
316
|
-
logger.warn('[OgmiosBackend] WebSocket closed
|
|
299
|
+
logger.warn('[OgmiosBackend] WebSocket closed, will reconnect on next request');
|
|
317
300
|
this.stateQueryClient = null;
|
|
318
301
|
this.txSubmissionClient = null;
|
|
319
302
|
}, { connection }), 'createInteractionContext');
|
|
@@ -333,11 +316,8 @@ class OgmiosBackend {
|
|
|
333
316
|
this.context = context;
|
|
334
317
|
return true;
|
|
335
318
|
}
|
|
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
|
-
*/
|
|
319
|
+
// Address queries scan the whole UTxO set and take seconds. Ogmios answers one connection in order,
|
|
320
|
+
// so they get their own connection and do not hold up tip and epoch queries.
|
|
341
321
|
async scanQueryClient() {
|
|
342
322
|
this.ensureNotShutdown();
|
|
343
323
|
// never initialized (test-injected clients): the shared client
|
|
@@ -365,10 +345,7 @@ class OgmiosBackend {
|
|
|
365
345
|
}
|
|
366
346
|
return this.scanConnecting;
|
|
367
347
|
}
|
|
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
|
-
*/
|
|
348
|
+
/** Reconnect a dead WebSocket. Concurrent callers share one attempt. No-op before the first init. */
|
|
372
349
|
async ensureConnected() {
|
|
373
350
|
this.ensureNotShutdown();
|
|
374
351
|
if (!this.context)
|
|
@@ -378,28 +355,19 @@ class OgmiosBackend {
|
|
|
378
355
|
if (this.stateQueryClient && socketOpen)
|
|
379
356
|
return;
|
|
380
357
|
if (!this.reconnectPromise) {
|
|
381
|
-
logger.warn('[OgmiosBackend] WebSocket not connected
|
|
358
|
+
logger.warn('[OgmiosBackend] WebSocket not connected, reconnecting');
|
|
382
359
|
this.reconnectPromise = this.init()
|
|
383
360
|
.then(() => undefined)
|
|
384
361
|
.finally(() => { this.reconnectPromise = null; });
|
|
385
362
|
}
|
|
386
363
|
await this.reconnectPromise;
|
|
387
364
|
}
|
|
388
|
-
/**
|
|
389
|
-
* Get specific Block Data (not supported)
|
|
390
|
-
* @param _hash block hash (hex)
|
|
391
|
-
* @returns {Promise<BlockData>} block data
|
|
392
|
-
*/
|
|
393
365
|
async getBlock(_hash) {
|
|
394
366
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
395
367
|
throw new errors_1.NotFoundError('Historic Block queries not supported', this.name);
|
|
396
368
|
}, this.name);
|
|
397
369
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Get specific Epoch Data (not supported)
|
|
400
|
-
* @param _epochNumber epoch number
|
|
401
|
-
* @returns {Promise<EpochData>} epoch data
|
|
402
|
-
*/
|
|
370
|
+
/** Only the current epoch. */
|
|
403
371
|
async getEpoch(epochNumber) {
|
|
404
372
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
405
373
|
await this.ensureConnected();
|
|
@@ -411,32 +379,18 @@ class OgmiosBackend {
|
|
|
411
379
|
return this.getLatestEpoch();
|
|
412
380
|
}, this.name);
|
|
413
381
|
}
|
|
414
|
-
/**
|
|
415
|
-
* Get specific Transaction Data (not supported)
|
|
416
|
-
* @param _hash transaction hash (hex)
|
|
417
|
-
* @returns {Promise<Transaction>} transaction data
|
|
418
|
-
*/
|
|
419
382
|
async getTransaction(_hash) {
|
|
420
383
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
421
384
|
throw new errors_1.NotFoundError('Historic Transaction queries not supported', this.name);
|
|
422
385
|
}, this.name);
|
|
423
386
|
}
|
|
424
|
-
/**
|
|
425
|
-
* Get specific Transaction Metadata (not supported)
|
|
426
|
-
* @param _tx_hash transaction hash (hex)
|
|
427
|
-
* @returns {Promise<MetadataLabelTx[]>} transaction metadata list
|
|
428
|
-
*/
|
|
429
387
|
async getTransactionMetadata(_tx_hash) {
|
|
430
388
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
431
389
|
throw new errors_1.NotFoundError('Historic Transaction metadata not supported', this.name);
|
|
432
390
|
}, this.name);
|
|
433
391
|
}
|
|
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
|
-
*/
|
|
392
|
+
// DRep from `queryLedgerState/delegateRepresentatives` via raw `Method()`, as the client has no wrapper.
|
|
393
|
+
// Ogmios lists only registered DReps, so others are NotFoundError.
|
|
440
394
|
async getDrep(drepId) {
|
|
441
395
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
442
396
|
await this.ensureConnected();
|
|
@@ -471,27 +425,20 @@ class OgmiosBackend {
|
|
|
471
425
|
hex: hashHex,
|
|
472
426
|
amount: ogmiosValueToLovelaceString(drep.stake),
|
|
473
427
|
hasScript: isScript || drep.from === 'script',
|
|
474
|
-
// Ogmios reports the mandate
|
|
428
|
+
// Ogmios reports the mandate expiry epoch, not the last activity.
|
|
475
429
|
lastActiveEpoch: 0,
|
|
476
430
|
expired: typeof mandateEpoch === 'number' && mandateEpoch < Number(currentEpoch),
|
|
477
431
|
retired: false,
|
|
478
432
|
};
|
|
479
433
|
}, this.name);
|
|
480
434
|
}
|
|
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
|
-
*/
|
|
435
|
+
/** Not supported. The protocol has no aggregate-supply query. */
|
|
486
436
|
async getAssetInfo(_unit) {
|
|
487
437
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
488
438
|
throw new errors_1.ProviderUnavailableError('Asset info queries not supported by Ogmios backend', this.name);
|
|
489
439
|
}, this.name);
|
|
490
440
|
}
|
|
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
|
-
*/
|
|
441
|
+
/** Total supply is max supply minus reserves. Circulating, locked and stake totals stay '0'. */
|
|
495
442
|
async getNetworkInformation() {
|
|
496
443
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
497
444
|
await this.ensureConnected();
|
|
@@ -523,10 +470,7 @@ class OgmiosBackend {
|
|
|
523
470
|
};
|
|
524
471
|
}, this.name);
|
|
525
472
|
}
|
|
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
|
-
*/
|
|
473
|
+
/** Address at the tip, decoded locally, with UTxOs and balance from the ledger. No tx history. */
|
|
530
474
|
async getAddress(address) {
|
|
531
475
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
532
476
|
await this.ensureConnected();
|
|
@@ -543,10 +487,6 @@ class OgmiosBackend {
|
|
|
543
487
|
};
|
|
544
488
|
}, this.name);
|
|
545
489
|
}
|
|
546
|
-
/** get current specific Address UTxOs
|
|
547
|
-
* @param address bech32 address
|
|
548
|
-
* @returns {Promise<UTxO[]>} address UTxOs
|
|
549
|
-
*/
|
|
550
490
|
async getAddressUtxos(address) {
|
|
551
491
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
552
492
|
await this.ensureConnected();
|
|
@@ -572,11 +512,8 @@ class OgmiosBackend {
|
|
|
572
512
|
scriptRefType: ref?.type ?? null,
|
|
573
513
|
};
|
|
574
514
|
}
|
|
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
|
-
*/
|
|
515
|
+
// Runs `fn` on the ledger state at `point` over a separate WebSocket. A connection holds one acquired
|
|
516
|
+
// point, so the shared socket would pin live queries to the past. `point` must be within k blocks.
|
|
580
517
|
async withLedgerStateAt(point, label, fn) {
|
|
581
518
|
const url = new URL(this.ogmiosUrl);
|
|
582
519
|
const connection = { host: url.hostname, port: Number(url.port) || (url.protocol === 'wss:' ? 443 : 80), tls: url.protocol === 'wss:' };
|
|
@@ -605,10 +542,7 @@ class OgmiosBackend {
|
|
|
605
542
|
return utxos.map((u) => this.mapOgmiosUtxo(u));
|
|
606
543
|
}), this.name);
|
|
607
544
|
}
|
|
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
|
-
*/
|
|
545
|
+
/** Pools, DReps and pots at `point` from one ledger state. Without nOpt saturation stays 0. */
|
|
612
546
|
async epochStateAt(point) {
|
|
613
547
|
return (0, backend_request_handler_1.handleBackendRequest)(() => this.withLedgerStateAt(point, 'epoch snapshot', async (client) => {
|
|
614
548
|
const ctx = client.context;
|
|
@@ -631,15 +565,10 @@ class OgmiosBackend {
|
|
|
631
565
|
});
|
|
632
566
|
}), this.name);
|
|
633
567
|
}
|
|
634
|
-
/** Not supported
|
|
568
|
+
/** Not supported. Ogmios only queries live state. */
|
|
635
569
|
async getAddressTransactions(_address) {
|
|
636
570
|
throw new errors_1.NotFoundError('Address transactions not available via Ogmios - use historical backend (Blockfrost/Koios)', this.name);
|
|
637
571
|
}
|
|
638
|
-
/**
|
|
639
|
-
* Get current specific Pool Data
|
|
640
|
-
* @param poolId pool id
|
|
641
|
-
* @returns {Promise<PoolData>} pool data
|
|
642
|
-
*/
|
|
643
572
|
async getPool(poolId) {
|
|
644
573
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
645
574
|
await this.ensureConnected();
|
|
@@ -661,8 +590,7 @@ class OgmiosBackend {
|
|
|
661
590
|
// not in the ledger state; null = unavailable
|
|
662
591
|
liveDelegators: null,
|
|
663
592
|
liveSaturation: 0,
|
|
664
|
-
//
|
|
665
|
-
// of fabricating it from the pledge
|
|
593
|
+
// Ogmios pool params have no active stake
|
|
666
594
|
activeStake: '0',
|
|
667
595
|
activeSize: 0,
|
|
668
596
|
// pledge/cost are ValueAdaOnly objects in Ogmios v6; margin is a Ratio string ("1/10")
|
|
@@ -673,11 +601,6 @@ class OgmiosBackend {
|
|
|
673
601
|
};
|
|
674
602
|
}, this.name);
|
|
675
603
|
}
|
|
676
|
-
/**
|
|
677
|
-
* Get Account Data for specified stake address
|
|
678
|
-
* @param stakeAddress stake address
|
|
679
|
-
* @returns {Promise<AccountData>} account data
|
|
680
|
-
*/
|
|
681
604
|
async getAccount(stakeAddress) {
|
|
682
605
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
683
606
|
await this.ensureConnected();
|
|
@@ -712,11 +635,6 @@ class OgmiosBackend {
|
|
|
712
635
|
};
|
|
713
636
|
}, this.name);
|
|
714
637
|
}
|
|
715
|
-
/**
|
|
716
|
-
* Submit Transaction to the network
|
|
717
|
-
* @param signedTxCbor signed transaction in CBOR hex format
|
|
718
|
-
* @returns {Promise<string>} transaction hash
|
|
719
|
-
*/
|
|
720
638
|
async submitTransaction(signedTxCbor) {
|
|
721
639
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
722
640
|
await this.ensureConnected();
|
|
@@ -732,17 +650,57 @@ class OgmiosBackend {
|
|
|
732
650
|
const e = err;
|
|
733
651
|
if (typeof e?.code === 'number' && e.code >= 3000 && e.code < 4000) {
|
|
734
652
|
const detail = e.data === undefined ? '' : ` ${JSON.stringify(e.data).slice(0, 800)}`;
|
|
653
|
+
// spent inputs are also what a resubmit of a transaction the node already holds reports
|
|
654
|
+
if (SPENT_INPUTS.test(`${String(e.message ?? '')}${detail}`)) {
|
|
655
|
+
const txHash = this.txHashOrNull(signedTxCbor);
|
|
656
|
+
if (txHash && await this.isKnownTransaction(txHash))
|
|
657
|
+
throw new errors_1.TransactionAlreadySubmittedError(txHash, err);
|
|
658
|
+
}
|
|
735
659
|
throw new errors_1.TransactionValidationError(`node rejected the transaction (${e.code}): ${String(e.message ?? '')}${detail}`, err);
|
|
736
660
|
}
|
|
737
661
|
throw err;
|
|
738
662
|
}
|
|
739
663
|
}, this.name);
|
|
740
664
|
}
|
|
741
|
-
/**
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
665
|
+
/** Hash of a signed transaction, or null when the CBOR does not parse. */
|
|
666
|
+
txHashOrNull(signedTxCbor) {
|
|
667
|
+
try {
|
|
668
|
+
return (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
669
|
+
}
|
|
670
|
+
catch {
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
/** Whether the node holds the transaction: in its mempool, or on chain with its first output unspent. */
|
|
675
|
+
async isKnownTransaction(txHash) {
|
|
676
|
+
try {
|
|
677
|
+
if (await this.mempoolHas(txHash))
|
|
678
|
+
return true;
|
|
679
|
+
const query = await this.scanQueryClient();
|
|
680
|
+
const onChain = await this.withInitTimeout(query.utxo({ outputReferences: [{ transaction: { id: txHash }, index: 0 }] }), 'utxo/known-transaction');
|
|
681
|
+
return onChain.length > 0;
|
|
682
|
+
}
|
|
683
|
+
catch (err) {
|
|
684
|
+
logger.warn(`[OgmiosBackend] could not check whether ${txHash} is known: ${err instanceof Error ? err.message : String(err)}`);
|
|
685
|
+
return false;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
/** Mempool lookup on its own short connection, since an acquired mempool snapshot blocks the session. */
|
|
689
|
+
async mempoolHas(txHash) {
|
|
690
|
+
const url = new URL(this.ogmiosUrl);
|
|
691
|
+
const connection = { host: url.hostname, port: Number(url.port) || (url.protocol === 'wss:' ? 443 : 80), tls: url.protocol === 'wss:' };
|
|
692
|
+
const context = await this.withInitTimeout((0, client_1.createInteractionContext)((err) => logger.debug(`[OgmiosBackend] mempool context error: ${err.message}`), () => undefined, { connection }), 'mempool/createInteractionContext');
|
|
693
|
+
try {
|
|
694
|
+
const mempool = await this.withInitTimeout((0, client_1.createMempoolMonitoringClient)(context), 'mempool/client');
|
|
695
|
+
await this.withInitTimeout(mempool.acquireMempool(), 'mempool/acquire');
|
|
696
|
+
const has = await this.withInitTimeout(mempool.hasTransaction(txHash), 'mempool/hasTransaction');
|
|
697
|
+
await mempool.shutdown().catch(() => undefined);
|
|
698
|
+
return has;
|
|
699
|
+
}
|
|
700
|
+
finally {
|
|
701
|
+
this.forceCloseContext(context);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
746
704
|
async evaluateTransaction(unsignedTxCbor) {
|
|
747
705
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
748
706
|
await this.ensureConnected();
|
|
@@ -765,10 +723,6 @@ class OgmiosBackend {
|
|
|
765
723
|
}
|
|
766
724
|
}, this.name);
|
|
767
725
|
}
|
|
768
|
-
/**
|
|
769
|
-
* Get current Protocol Parameters
|
|
770
|
-
* @returns {Promise<LedgerProtocolParameters>} protocol parameters
|
|
771
|
-
*/
|
|
772
726
|
async getProtocolParameters() {
|
|
773
727
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
774
728
|
await this.ensureConnected();
|
|
@@ -817,10 +771,6 @@ class OgmiosBackend {
|
|
|
817
771
|
};
|
|
818
772
|
}, this.name);
|
|
819
773
|
}
|
|
820
|
-
/**
|
|
821
|
-
* Get Latest Epoch Data
|
|
822
|
-
* @returns {Promise<EpochData>} latest epoch data
|
|
823
|
-
*/
|
|
824
774
|
async getLatestEpoch() {
|
|
825
775
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
826
776
|
await this.ensureConnected();
|
|
@@ -846,10 +796,6 @@ class OgmiosBackend {
|
|
|
846
796
|
};
|
|
847
797
|
}, this.name);
|
|
848
798
|
}
|
|
849
|
-
/**
|
|
850
|
-
* Get current Latest Block Data
|
|
851
|
-
* @returns {Promise<BlockData>} latest block data
|
|
852
|
-
*/
|
|
853
799
|
async getLatestBlock() {
|
|
854
800
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
855
801
|
await this.ensureConnected();
|
|
@@ -878,10 +824,6 @@ class OgmiosBackend {
|
|
|
878
824
|
};
|
|
879
825
|
}, this.name);
|
|
880
826
|
}
|
|
881
|
-
/**
|
|
882
|
-
* Get the latest chain tip slot.
|
|
883
|
-
* @returns {Promise<number>} current chain slot
|
|
884
|
-
*/
|
|
885
827
|
async getCurrentSlot() {
|
|
886
828
|
const block = await this.getLatestBlock();
|
|
887
829
|
if (block.slot == null) {
|
|
@@ -889,11 +831,7 @@ class OgmiosBackend {
|
|
|
889
831
|
}
|
|
890
832
|
return block.slot;
|
|
891
833
|
}
|
|
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
|
-
*/
|
|
834
|
+
/** Unspent check via `queryLedgerState/utxo`. An empty answer means spent or unknown. */
|
|
897
835
|
async isUtxoUnspent(txHash, outputIndex) {
|
|
898
836
|
if (!Number.isInteger(outputIndex) || outputIndex < 0)
|
|
899
837
|
return false;
|
|
@@ -959,10 +897,7 @@ class OgmiosBackend {
|
|
|
959
897
|
throw new errors_1.ProviderUnavailableError('Ogmios client has been shutdown', this.name);
|
|
960
898
|
}
|
|
961
899
|
}
|
|
962
|
-
/**
|
|
963
|
-
* Ogmios value `{ ada: { lovelace }, policyId: { assetName: qty } }` →
|
|
964
|
-
* `[{ unit: 'lovelace', quantity }, { unit: policyId+assetName, quantity }]`.
|
|
965
|
-
*/
|
|
900
|
+
/** Ogmios value `{ ada: { lovelace }, policyId: { assetName: qty } }` to a list of units and quantities. */
|
|
966
901
|
convertOgmiosValue(value) {
|
|
967
902
|
const amounts = [];
|
|
968
903
|
if (value.ada?.lovelace) {
|
|
@@ -984,13 +919,10 @@ class OgmiosBackend {
|
|
|
984
919
|
return amounts;
|
|
985
920
|
}
|
|
986
921
|
// ---------------------------------------------------------------------------
|
|
987
|
-
// ChainSyncBackend
|
|
922
|
+
// ChainSyncBackend: streamed forward sync for the chain crawler
|
|
988
923
|
// ---------------------------------------------------------------------------
|
|
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
|
-
*/
|
|
924
|
+
// Opens a chain-sync stream on its own WebSocket. One block in flight keeps blocks strictly
|
|
925
|
+
// in order, which reorg detection needs. Inputs arrive as bare references the indexer resolves.
|
|
994
926
|
async openChainSync(from, callbacks) {
|
|
995
927
|
OgmiosBackend.validateOgmiosUrl(this.ogmiosUrl);
|
|
996
928
|
const url = new URL(this.ogmiosUrl);
|
|
@@ -1051,7 +983,7 @@ class OgmiosBackend {
|
|
|
1051
983
|
rollForward: async ({ block, tip }, nextBlock) => {
|
|
1052
984
|
try {
|
|
1053
985
|
const b = block;
|
|
1054
|
-
// Byron
|
|
986
|
+
// Byron boundary and bft blocks carry no indexable txs
|
|
1055
987
|
if (b.type !== 'praos') {
|
|
1056
988
|
nextBlock();
|
|
1057
989
|
return;
|
|
@@ -1065,7 +997,7 @@ class OgmiosBackend {
|
|
|
1065
997
|
nextBlock();
|
|
1066
998
|
}
|
|
1067
999
|
catch (err) {
|
|
1068
|
-
logger.error('[OgmiosBackend] chain-sync rollForward failed
|
|
1000
|
+
logger.error('[OgmiosBackend] chain-sync rollForward failed, stream halted:', err);
|
|
1069
1001
|
await reportStreamError(err);
|
|
1070
1002
|
}
|
|
1071
1003
|
},
|
|
@@ -1076,7 +1008,7 @@ class OgmiosBackend {
|
|
|
1076
1008
|
nextBlock();
|
|
1077
1009
|
}
|
|
1078
1010
|
catch (err) {
|
|
1079
|
-
logger.error('[OgmiosBackend] chain-sync rollBackward failed
|
|
1011
|
+
logger.error('[OgmiosBackend] chain-sync rollBackward failed, stream halted:', err);
|
|
1080
1012
|
await reportStreamError(err);
|
|
1081
1013
|
}
|
|
1082
1014
|
},
|
|
@@ -1124,11 +1056,8 @@ class OgmiosBackend {
|
|
|
1124
1056
|
}
|
|
1125
1057
|
};
|
|
1126
1058
|
}
|
|
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
|
-
*/
|
|
1059
|
+
// Block fees are the sum of tx fees. A phase-2 failure without `total_collateral` keeps
|
|
1060
|
+
// its declared fee here, and applyCollateralFees() corrects it later.
|
|
1132
1061
|
mapOgmiosBlock(block) {
|
|
1133
1062
|
const txs = (block.transactions ?? []).map((t, i) => this.mapOgmiosTx(t, block, i));
|
|
1134
1063
|
const totalFees = txs.reduce((sum, t) => sum + BigInt(t.fee || 0), 0n);
|
|
@@ -1149,11 +1078,8 @@ class OgmiosBackend {
|
|
|
1149
1078
|
};
|
|
1150
1079
|
return { block: blockData, txs };
|
|
1151
1080
|
}
|
|
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
|
-
*/
|
|
1081
|
+
// A phase-2 invalid tx consumes its collaterals and creates only the collateral-return output.
|
|
1082
|
+
// `spends` selects which side the ledger applied, and the fee follows it.
|
|
1157
1083
|
mapOgmiosTx(tx, block, index) {
|
|
1158
1084
|
const mapInput = (input, flags = {}) => ({
|
|
1159
1085
|
address: '',
|
|
@@ -1210,14 +1136,12 @@ class OgmiosBackend {
|
|
|
1210
1136
|
// The ledger applies no mint when the script phase failed: the body's mint field is
|
|
1211
1137
|
// declared but never enacted, so a phase-2 failure must report none at all.
|
|
1212
1138
|
mint: spendsCollaterals ? undefined : this.convertOgmiosValue(tx.mint ?? {}),
|
|
1213
|
-
//
|
|
1214
|
-
// lazy path's `size ?? null` convention; 0 would masquerade as a real size
|
|
1139
|
+
// chain-sync has no serialized size, and 0 would look like a real size
|
|
1215
1140
|
size: null,
|
|
1216
1141
|
blockTime: (0, epoch_slots_1.slotToPosixSeconds)(this.network, block.slot),
|
|
1217
1142
|
inputs,
|
|
1218
1143
|
outputs,
|
|
1219
|
-
// undefined
|
|
1220
|
-
// mapTransaction's hasMetadata flag stays false for metadata-less txs
|
|
1144
|
+
// undefined, not [], so hasMetadata stays false as on the Blockfrost path
|
|
1221
1145
|
metadata: metadataEntries.length ? metadataEntries : undefined,
|
|
1222
1146
|
certificates: this.mapOgmiosCertificates(tx.certificates ?? []),
|
|
1223
1147
|
withdrawals: Object.entries(tx.withdrawals ?? {}).map(([stakeAddress, value]) => ({
|
|
@@ -1228,11 +1152,8 @@ class OgmiosBackend {
|
|
|
1228
1152
|
datums: Object.entries(tx.datums ?? {}).map(([hash, cbor]) => ({ hash, cbor })),
|
|
1229
1153
|
});
|
|
1230
1154
|
}
|
|
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
|
-
*/
|
|
1155
|
+
// Maps Ogmios certificates to `CertificateKind`. A delegation to both pool and DRep becomes two
|
|
1156
|
+
// entries with one index, as db-sync reports it. Credential hashes are re-encoded as bech32.
|
|
1236
1157
|
mapOgmiosCertificates(certs) {
|
|
1237
1158
|
const out = [];
|
|
1238
1159
|
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
|