@odatano/core 2.0.0-rc.19 → 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 +1 -5
- package/@cds-models/CardanoIndexerService/index.d.ts +51 -2
- package/@cds-models/CardanoIndexerService/index.js +7 -0
- package/package.json +1 -1
- package/src/index.d.ts +4 -10
- package/src/index.js +6 -16
- package/src/plugin.js +11 -27
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +39 -150
- package/srv/blockchain/backends/cardano-backend.d.ts +53 -171
- package/srv/blockchain/backends/cardano-backend.js +1 -5
- package/srv/blockchain/backends/koios-backend.d.ts +26 -71
- package/srv/blockchain/backends/koios-backend.js +50 -132
- package/srv/blockchain/backends/ogmios-backend.d.ts +43 -124
- package/srv/blockchain/backends/ogmios-backend.js +71 -179
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +12 -57
- package/srv/blockchain/backends/ogmios-frame-guard.js +27 -66
- package/srv/blockchain/cardano-client.d.ts +43 -216
- package/srv/blockchain/cardano-client.js +49 -234
- package/srv/blockchain/cardano-indexer.d.ts +79 -357
- package/srv/blockchain/cardano-indexer.js +98 -406
- 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 +41 -145
- package/srv/blockchain/crawler/crawler.js +57 -172
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +2 -6
- package/srv/blockchain/crawler/index.js +4 -9
- package/srv/blockchain/crawler/sync-state.d.ts +17 -39
- package/srv/blockchain/crawler/sync-state.js +23 -55
- package/srv/blockchain/crawler/utxo-set-import.d.ts +5 -22
- package/srv/blockchain/crawler/utxo-set-import.js +8 -28
- package/srv/blockchain/ledger-state.d.ts +3 -12
- 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 +65 -174
- package/srv/blockchain/transaction-building/buildooor-tx.js +107 -266
- 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 +9 -22
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +12 -35
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -32
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +33 -111
- 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 +1 -5
- package/srv/cardano-agent-service.js +3 -7
- package/srv/cardano-indexer-service.cds +32 -4
- package/srv/cardano-indexer-service.js +83 -15
- package/srv/cardano-service.js +36 -98
- package/srv/cardano-sign-service.cds +1 -1
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +1 -1
- package/srv/cardano-tx-service.js +54 -174
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +27 -86
- package/srv/server.js +52 -148
- package/srv/utils/agent-grants-config.d.ts +11 -50
- package/srv/utils/agent-grants-config.js +12 -45
- package/srv/utils/agent-grants.d.ts +34 -123
- package/srv/utils/agent-grants.js +57 -156
- package/srv/utils/agent-token-auth.d.ts +2 -5
- package/srv/utils/agent-token-auth.js +2 -5
- 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 +2 -7
- package/srv/utils/db-indexes.js +7 -34
- package/srv/utils/db-sanitize.d.ts +5 -18
- package/srv/utils/db-sanitize.js +6 -19
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +29 -191
- package/srv/utils/errors.js +44 -229
- package/srv/utils/liveness.d.ts +2 -9
- package/srv/utils/liveness.js +3 -11
- package/srv/utils/mappers.d.ts +50 -298
- package/srv/utils/mappers.js +80 -386
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.js +4 -23
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +6 -17
- package/srv/utils/rate-limiter.js +5 -15
- 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 +7 -26
- package/srv/utils/tx-request-parsers.js +7 -26
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +67 -206
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -22,11 +22,8 @@ const KOIOS_URLS = {
|
|
|
22
22
|
preprod: 'https://preprod.koios.rest/api/v1',
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
|
-
* Koios `reference_script` (
|
|
26
|
-
*
|
|
27
|
-
* that object downstream and broke the v1.6.1 input-side refScript feature.
|
|
28
|
-
* Returns the full script CBOR bytes when present (what the local Plutus eval
|
|
29
|
-
* needs), falling back to the hash (resolved on-chain only).
|
|
25
|
+
* Koios `reference_script` (`_extended: true`) is an object `{ hash, size, type, bytes, value }`.
|
|
26
|
+
* Returns the full script CBOR when present (needed for local Plutus eval), else the hash.
|
|
30
27
|
*/
|
|
31
28
|
function koiosRefScriptBytes(ref) {
|
|
32
29
|
if (!ref)
|
|
@@ -45,28 +42,17 @@ function koiosRefScriptHash(ref) {
|
|
|
45
42
|
const obj = ref;
|
|
46
43
|
return obj.hash || null;
|
|
47
44
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Sort Koios /address_txs rows newest-first. Koios gives no ordering guarantee —
|
|
50
|
-
* a bare `slice(0, limit)` returned ARBITRARY rather than recent transactions
|
|
51
|
-
* (Blockfrost requests `order: 'desc'` for the same data).
|
|
52
|
-
*/
|
|
45
|
+
/** Sort Koios /address_txs rows newest-first — Koios gives no ordering guarantee. */
|
|
53
46
|
function sortAddressTxsDesc(rows) {
|
|
54
47
|
return [...rows].sort((a, b) => Number(b.block_height ?? b.block_time ?? 0) - Number(a.block_height ?? a.block_time ?? 0));
|
|
55
48
|
}
|
|
56
|
-
/**
|
|
57
|
-
* KoiosBackend Implementation for CardanoBackend Interface
|
|
58
|
-
* Implements the CardanoBackend interface using Koios API with Axios
|
|
59
|
-
*/
|
|
49
|
+
/** CardanoBackend implementation on the Koios REST API (Axios). */
|
|
60
50
|
class KoiosBackend {
|
|
61
51
|
name = 'koios';
|
|
62
52
|
api;
|
|
63
53
|
network;
|
|
64
|
-
/**
|
|
65
|
-
* Constructor
|
|
66
|
-
*/
|
|
67
54
|
constructor(network, timeoutMs, apiKey) {
|
|
68
55
|
const headers = {};
|
|
69
|
-
// Add Authorization header if API key is configured
|
|
70
56
|
if (apiKey) {
|
|
71
57
|
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
72
58
|
}
|
|
@@ -76,12 +62,9 @@ class KoiosBackend {
|
|
|
76
62
|
headers,
|
|
77
63
|
});
|
|
78
64
|
this.network = network;
|
|
79
|
-
// Koios
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
// (57014) while the rest are healthy. Such failures are instance-specific,
|
|
83
|
-
// so a short bounded retry usually lands on a healthy instance. Genuine
|
|
84
|
-
// client-input errors (PG class 22 etc.) are not retried.
|
|
65
|
+
// Koios is load-balanced; single instances serve broken SQL functions (PostgREST 400,
|
|
66
|
+
// e.g. 42703) or statement timeouts (57014) while others are healthy, so a short
|
|
67
|
+
// bounded retry usually lands on a healthy instance. Client-input errors are not retried.
|
|
85
68
|
this.api.interceptors.response.use(undefined, async (error) => {
|
|
86
69
|
const config = error.config;
|
|
87
70
|
const pgCode = error.response?.data?.code;
|
|
@@ -96,11 +79,8 @@ class KoiosBackend {
|
|
|
96
79
|
return this.api.request(config);
|
|
97
80
|
});
|
|
98
81
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Initialize the backend
|
|
101
|
-
*/
|
|
82
|
+
/** Probe /tip to verify connectivity. */
|
|
102
83
|
async init() {
|
|
103
|
-
// Test connection by fetching latest block
|
|
104
84
|
try {
|
|
105
85
|
await this.api.get('/tip');
|
|
106
86
|
}
|
|
@@ -110,16 +90,9 @@ class KoiosBackend {
|
|
|
110
90
|
return true;
|
|
111
91
|
}
|
|
112
92
|
/**
|
|
113
|
-
* Retry
|
|
114
|
-
*
|
|
115
|
-
* valid queries — a single retry is not always sufficient for historical
|
|
116
|
-
* epoch lookups, so we retry with increasing delays (500 → 1000 → 2000 ms).
|
|
93
|
+
* Retry (500 → 1000 → 2000 ms) when Koios transiently returns [] for a valid query.
|
|
94
|
+
* Element type is `any` on purpose: only non-emptiness is checked; rows are narrowed at use sites.
|
|
117
95
|
*/
|
|
118
|
-
// Type-agnostic retry helper: it only checks that `.data` is a non-empty
|
|
119
|
-
// array, so the element type is intentionally `any` to avoid forcing every
|
|
120
|
-
// Koios endpoint call site (block_info, epoch_info, account_info, …) to
|
|
121
|
-
// declare a row shape just for the empty-array retry path. Row narrowing
|
|
122
|
-
// happens at the use sites.
|
|
123
96
|
async fetchWithRetryOnEmpty(fn, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
124
97
|
label) {
|
|
125
98
|
const maxRetries = 3;
|
|
@@ -140,13 +113,9 @@ class KoiosBackend {
|
|
|
140
113
|
return [];
|
|
141
114
|
}
|
|
142
115
|
/**
|
|
143
|
-
*
|
|
144
|
-
* version-skewed
|
|
145
|
-
*
|
|
146
|
-
* word128 vs numeric on /epoch_info) while healthy instances serve the
|
|
147
|
-
* IDENTICAL request fine. The same request therefore flips 200/400 between
|
|
148
|
-
* calls. Retrying a few times lands on a healthy instance. Scoped strictly to
|
|
149
|
-
* the 42804 type-skew error so genuine 400s (bad params) still fail fast.
|
|
116
|
+
* Retry on Postgres 42804 ("structure of query does not match function result type"):
|
|
117
|
+
* version-skewed Koios instances behind the load balancer return it for a request that
|
|
118
|
+
* healthy instances serve fine. Other 400s still fail fast.
|
|
150
119
|
*/
|
|
151
120
|
async getWithRetryOn42804(url, config, label) {
|
|
152
121
|
const maxRetries = 8;
|
|
@@ -246,8 +215,7 @@ class KoiosBackend {
|
|
|
246
215
|
}
|
|
247
216
|
const addressData = data[0];
|
|
248
217
|
const addressUtxos = await this.getAddressUtxos(address);
|
|
249
|
-
// Sum balances from the
|
|
250
|
-
// address_info's utxo_set (whose asset_list can be null → crashed here).
|
|
218
|
+
// Sum balances from the mapped UTxOs; address_info's utxo_set may carry a null asset_list.
|
|
251
219
|
const totals = new Map();
|
|
252
220
|
for (const u of addressUtxos) {
|
|
253
221
|
for (const a of u.amount) {
|
|
@@ -323,11 +291,8 @@ class KoiosBackend {
|
|
|
323
291
|
}, this.name);
|
|
324
292
|
}
|
|
325
293
|
/**
|
|
326
|
-
*
|
|
327
|
-
* sharing the given 28-byte payment credential (key hash or script hash).
|
|
328
|
-
* Native Koios endpoint — single round-trip with inline-datum hydration.
|
|
294
|
+
* UTxOs across all bech32 addresses sharing a payment credential (native Koios endpoint).
|
|
329
295
|
* @param credHash 28-byte payment credential as 56-char lowercase hex
|
|
330
|
-
* @returns {Promise<UTxO[]>} list of UTxOs across all bech32 forms
|
|
331
296
|
*/
|
|
332
297
|
async getCredentialUtxos(credHash) {
|
|
333
298
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
@@ -366,7 +331,7 @@ class KoiosBackend {
|
|
|
366
331
|
*/
|
|
367
332
|
async getNetworkInformation() {
|
|
368
333
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
369
|
-
//
|
|
334
|
+
// /totals works on mainnet but returns [] on preview/preprod
|
|
370
335
|
const { data: totalsData } = await this.api.get('/totals', {
|
|
371
336
|
params: { order: 'epoch_no.desc', limit: 1 }
|
|
372
337
|
});
|
|
@@ -387,8 +352,7 @@ class KoiosBackend {
|
|
|
387
352
|
},
|
|
388
353
|
};
|
|
389
354
|
}
|
|
390
|
-
//
|
|
391
|
-
// Use genesis endpoint to get max supply; remaining fields default to '0'
|
|
355
|
+
// Testnet fallback: max supply from /genesis, remaining fields '0'
|
|
392
356
|
const { data: genesisData } = await this.api.get('/genesis');
|
|
393
357
|
if (!genesisData || !Array.isArray(genesisData) || genesisData.length === 0) {
|
|
394
358
|
throw new errors_1.NotFoundError('Genesis', this.name);
|
|
@@ -460,20 +424,14 @@ class KoiosBackend {
|
|
|
460
424
|
poolId: poolData.pool_id_bech32 || poolData.pool_id_hex || fallbackId,
|
|
461
425
|
vrfKeyHash: poolData.vrf_key_hash,
|
|
462
426
|
blocksMinted: poolData.block_count,
|
|
463
|
-
// Koios pool_info has no blocks-in-current-epoch figure
|
|
464
|
-
//
|
|
465
|
-
// semantic than Blockfrost's blocks_epoch. null = not available: a 0
|
|
466
|
-
// here read as "minted nothing this epoch" and produced leaderboards
|
|
467
|
-
// full of zeros downstream, indistinguishable from a real zero.
|
|
427
|
+
// Koios pool_info has no blocks-in-current-epoch figure. null = not available;
|
|
428
|
+
// a 0 would be indistinguishable from a real zero downstream.
|
|
468
429
|
blocksEpoch: null,
|
|
469
430
|
liveStake: poolData.live_stake || '0',
|
|
470
431
|
liveSize: poolData.live_size || 0,
|
|
471
432
|
liveDelegators: poolData.live_delegators || 0,
|
|
472
|
-
// Koios reports saturation in PERCENT (75.42
|
|
473
|
-
//
|
|
474
|
-
// behind it are Decimal(9, 4) — so convert here. Passing the percent value
|
|
475
|
-
// through would overflow the column for a saturated pool and take the
|
|
476
|
-
// whole epoch snapshot down with it.
|
|
433
|
+
// Koios reports saturation in PERCENT (75.42); PoolData holds a fraction (0.7542)
|
|
434
|
+
// stored in Decimal(9, 4) — the percent value would overflow the column.
|
|
477
435
|
liveSaturation: (Number(poolData.live_saturation) || 0) / 100,
|
|
478
436
|
activeStake: poolData.active_stake || '0',
|
|
479
437
|
activeSize: poolData.active_size || 0,
|
|
@@ -484,11 +442,8 @@ class KoiosBackend {
|
|
|
484
442
|
};
|
|
485
443
|
}
|
|
486
444
|
/**
|
|
487
|
-
*
|
|
488
|
-
* Koios's `asset_info` returns total_supply, mint/burn counts split,
|
|
489
|
-
* minting tx + creation_time, and both on-chain and registry metadata.
|
|
445
|
+
* Asset info from Koios `asset_info`: supply, mint/burn counts, minting tx, CIP-25 + CIP-26 metadata.
|
|
490
446
|
* @param unit policyId + assetNameHex (concatenated hex)
|
|
491
|
-
* @returns {Promise<AssetInfo>} canonical asset info
|
|
492
447
|
*/
|
|
493
448
|
async getAssetInfo(unit) {
|
|
494
449
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
@@ -554,14 +509,9 @@ class KoiosBackend {
|
|
|
554
509
|
}, this.name);
|
|
555
510
|
}
|
|
556
511
|
/**
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
* the canonical `quantity` field stores absolute value.
|
|
561
|
-
* @param unit policyId + assetNameHex (concatenated hex)
|
|
562
|
-
* @param limit max number of events (default 100). Note: Koios returns ALL events;
|
|
563
|
-
* limit is applied client-side after sort-by-block_time desc.
|
|
564
|
-
* @returns {Promise<AssetHistoryEntry[]>} list of mint/burn events (most recent first)
|
|
512
|
+
* Latest mint/burn events. Koios `asset_history` returns ALL events with `quantity` SIGNED
|
|
513
|
+
* (negative = burn): action derives from the sign, `quantity` stores the absolute value,
|
|
514
|
+
* `limit` is applied client-side after sorting by block_time desc.
|
|
565
515
|
*/
|
|
566
516
|
async getAssetHistory(unit, limit = 100) {
|
|
567
517
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
@@ -612,11 +562,8 @@ class KoiosBackend {
|
|
|
612
562
|
}
|
|
613
563
|
/** Map one Koios /drep_info row to the canonical DrepData. */
|
|
614
564
|
_mapKoiosDrep(drepData) {
|
|
615
|
-
// Koios
|
|
616
|
-
// `
|
|
617
|
-
// `drep_status` ('registered' | 'retired'), `active` (boolean) and
|
|
618
|
-
// `expires_epoch_no`. Read the old fields first (mainnet/preprod may
|
|
619
|
-
// lag the migration), then derive from the new ones.
|
|
565
|
+
// Koios /drep_info exposes either `expired`/`retired`/`last_active_epoch` (older schema)
|
|
566
|
+
// or `drep_status` ('registered' | 'retired'), `active` and `expires_epoch_no`; read both.
|
|
620
567
|
const retired = drepData.retired ?? drepData.drep_status === 'retired';
|
|
621
568
|
const expired = drepData.expired ?? (drepData.active === false && !retired);
|
|
622
569
|
return {
|
|
@@ -624,8 +571,7 @@ class KoiosBackend {
|
|
|
624
571
|
hex: drepData.hex,
|
|
625
572
|
amount: drepData.amount,
|
|
626
573
|
hasScript: drepData.has_script,
|
|
627
|
-
// The
|
|
628
|
-
// `expires_epoch_no`, which has different semantics) — keep 0 there.
|
|
574
|
+
// The newer schema has no last-activity epoch (`expires_epoch_no` differs in meaning) — 0 then.
|
|
629
575
|
lastActiveEpoch: drepData.last_active_epoch ?? 0,
|
|
630
576
|
expired,
|
|
631
577
|
retired,
|
|
@@ -645,7 +591,6 @@ class KoiosBackend {
|
|
|
645
591
|
if (!Array.isArray(data) || data.length === 0) {
|
|
646
592
|
throw new errors_1.NotFoundError('Account', this.name);
|
|
647
593
|
}
|
|
648
|
-
// Fetch associated addresses
|
|
649
594
|
const addressDataResponse = await this.api.post('/account_addresses', body);
|
|
650
595
|
// Koios returns [{ stake_address, addresses: [...] }], flatten to get all addresses
|
|
651
596
|
const addressesFlat = addressDataResponse.data.flatMap((item) => item.addresses);
|
|
@@ -833,12 +778,7 @@ class KoiosBackend {
|
|
|
833
778
|
configureCrawl(options) {
|
|
834
779
|
this.crawlCertificates = Boolean(options.certificates);
|
|
835
780
|
}
|
|
836
|
-
/**
|
|
837
|
-
* Batch fetch multiple transactions by hash using Koios POST /tx_info.
|
|
838
|
-
* Sends all hashes in one request (chunked at 100 per Koios limit).
|
|
839
|
-
* @param txHashes array of transaction hashes
|
|
840
|
-
* @returns {Promise<Map<string, Transaction>>} map of hash -> Transaction
|
|
841
|
-
*/
|
|
781
|
+
/** Batch fetch transactions via POST /tx_info, chunked at 100 hashes (Koios limit). */
|
|
842
782
|
async getTransactionsBatch(txHashes) {
|
|
843
783
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
844
784
|
const BATCH_SIZE = 100;
|
|
@@ -850,8 +790,7 @@ class KoiosBackend {
|
|
|
850
790
|
_inputs: true,
|
|
851
791
|
_metadata: true,
|
|
852
792
|
_assets: true,
|
|
853
|
-
//
|
|
854
|
-
// only asked for when the crawl will write them
|
|
793
|
+
// certificates + withdrawals only when the crawl will write them (larger payload)
|
|
855
794
|
_withdrawals: this.crawlCertificates,
|
|
856
795
|
_certs: this.crawlCertificates,
|
|
857
796
|
_scripts: false,
|
|
@@ -872,12 +811,9 @@ class KoiosBackend {
|
|
|
872
811
|
}, this.name);
|
|
873
812
|
}
|
|
874
813
|
// ---------------------------------------------------------------------------
|
|
875
|
-
// PaginatingBackend — forward iteration for the chain crawler
|
|
814
|
+
// PaginatingBackend — forward iteration for the chain crawler
|
|
876
815
|
// ---------------------------------------------------------------------------
|
|
877
|
-
/**
|
|
878
|
-
* Map a Koios /block_info response object to our BlockData (same shape getBlock
|
|
879
|
-
* maps inline; kept private to avoid touching getBlock).
|
|
880
|
-
*/
|
|
816
|
+
/** Map a Koios /block_info row to BlockData. */
|
|
881
817
|
mapKoiosBlockInfo(data) {
|
|
882
818
|
return {
|
|
883
819
|
time: data.block_time,
|
|
@@ -905,21 +841,17 @@ class KoiosBackend {
|
|
|
905
841
|
}, this.name);
|
|
906
842
|
}
|
|
907
843
|
/**
|
|
908
|
-
*
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
* knows the anchor height (the crawler's cursor), the hash→height resolution
|
|
912
|
-
* round-trip is skipped entirely.
|
|
844
|
+
* Up to `count` blocks after `afterHash`, ascending. Koios has no "next after hash" endpoint:
|
|
845
|
+
* list blocks above the anchor height (PostgREST gt + order + limit), then batch /block_info.
|
|
846
|
+
* A known `afterHeight` skips the hash→height round-trip.
|
|
913
847
|
*/
|
|
914
848
|
async getNextBlocks(afterHash, count, afterHeight) {
|
|
915
849
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
916
850
|
let anchorHeight = afterHeight;
|
|
917
851
|
if (anchorHeight != null && anchorHeight > 0) {
|
|
918
|
-
// A height hint
|
|
919
|
-
//
|
|
920
|
-
//
|
|
921
|
-
// even though `afterHash` is the now-orphaned block at H. Validate the
|
|
922
|
-
// canonical hash first so the crawler enters its reorg-recovery path.
|
|
852
|
+
// A height hint is not proof the cursor is still canonical: after a rollback Koios
|
|
853
|
+
// keeps listing blocks above H while `afterHash` is orphaned. Validate the hash first
|
|
854
|
+
// so the crawler enters reorg recovery.
|
|
923
855
|
const canonical = await this.fetchWithRetryOnEmpty(() => this.api.get(`/blocks?block_height=eq.${anchorHeight}&limit=1`), `getNextBlocks/anchor(${anchorHeight})`);
|
|
924
856
|
const canonicalHash = canonical[0]?.hash;
|
|
925
857
|
if (!canonicalHash) {
|
|
@@ -940,12 +872,9 @@ class KoiosBackend {
|
|
|
940
872
|
return [];
|
|
941
873
|
const requestedHashes = rows.map((r) => r.hash);
|
|
942
874
|
const infos = await this.fetchWithRetryOnEmpty(() => this.api.post('/block_info', { _block_hashes: requestedHashes }), `getNextBlocks/info(${afterHash})`);
|
|
943
|
-
//
|
|
944
|
-
//
|
|
945
|
-
//
|
|
946
|
-
// past the missing block, leaving a permanent hole in the pre-synced range
|
|
947
|
-
// (crawled entities are non-temporal — nothing re-fetches them). Fail the
|
|
948
|
-
// round as transient instead; the next round retries the same anchor.
|
|
875
|
+
// Load-balanced instances can return a PARTIAL /block_info batch. Returning the subset
|
|
876
|
+
// would advance the cursor past the missing block and leave a permanent hole (crawled
|
|
877
|
+
// entities are never re-fetched), so fail the round as transient instead.
|
|
949
878
|
if (infos.length < requestedHashes.length) {
|
|
950
879
|
const returned = new Set(infos.map((d) => d.hash));
|
|
951
880
|
const missing = requestedHashes.filter((h) => !returned.has(h));
|
|
@@ -963,10 +892,7 @@ class KoiosBackend {
|
|
|
963
892
|
static LIST_PAGE_SIZE = 1000;
|
|
964
893
|
/** Ids resolved per /pool_info / /drep_info request. */
|
|
965
894
|
static INFO_BATCH_SIZE = 50;
|
|
966
|
-
/**
|
|
967
|
-
* Refuse to page forever if an endpoint keeps returning full pages — 500 pages is
|
|
968
|
-
* 500 000 ids, far beyond any real pool or DRep set.
|
|
969
|
-
*/
|
|
895
|
+
/** Page cap — 500 pages is 500 000 ids, far beyond any real pool or DRep set. */
|
|
970
896
|
static LIST_MAX_PAGES = 500;
|
|
971
897
|
/**
|
|
972
898
|
* Page through a PostgREST list endpoint and collect one id column. Stops on the first
|
|
@@ -1035,9 +961,8 @@ class KoiosBackend {
|
|
|
1035
961
|
}, this.name);
|
|
1036
962
|
}
|
|
1037
963
|
/**
|
|
1038
|
-
*
|
|
1039
|
-
*
|
|
1040
|
-
* {tx_hashes:[...]} shape defensively.
|
|
964
|
+
* Full transaction list of a block in block order via /block_txs → /tx_info batch.
|
|
965
|
+
* Accepts both the flattened ({tx_hash} per row) and the {tx_hashes:[...]} shape.
|
|
1041
966
|
*/
|
|
1042
967
|
async getBlockTransactions(blockHash) {
|
|
1043
968
|
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
@@ -1054,9 +979,8 @@ class KoiosBackend {
|
|
|
1054
979
|
const byHash = await this.getTransactionsBatch(hashes);
|
|
1055
980
|
const missing = hashes.filter(h => !byHash.has(h));
|
|
1056
981
|
if (missing.length > 0) {
|
|
1057
|
-
//
|
|
1058
|
-
//
|
|
1059
|
-
// retries the whole block without persisting it.
|
|
982
|
+
// A partial /tx_info would make the omitted transactions permanent — 503 so the
|
|
983
|
+
// crawler retries the whole block without persisting it.
|
|
1060
984
|
throw new errors_1.ProviderUnavailableError(`Incomplete transaction data for block ${blockHash}: ${missing.length}/${hashes.length} transaction(s) missing`, this.name);
|
|
1061
985
|
}
|
|
1062
986
|
return hashes.map(h => byHash.get(h));
|
|
@@ -1065,9 +989,7 @@ class KoiosBackend {
|
|
|
1065
989
|
//-----------------------------------------------------------------------------
|
|
1066
990
|
// Private Helpers
|
|
1067
991
|
//-----------------------------------------------------------------------------
|
|
1068
|
-
/**
|
|
1069
|
-
* Map a Koios /tx_info response object to the normalized Transaction type.
|
|
1070
|
-
*/
|
|
992
|
+
/** Map a Koios /tx_info row to the normalized Transaction. */
|
|
1071
993
|
_mapKoiosTx(tx) {
|
|
1072
994
|
let labels = [];
|
|
1073
995
|
if (tx.metadata) {
|
|
@@ -1083,9 +1005,7 @@ class KoiosBackend {
|
|
|
1083
1005
|
blockHeight: Number(tx.block_height),
|
|
1084
1006
|
blockTime: tx.tx_timestamp ?? tx.block_time ?? 0,
|
|
1085
1007
|
slot: tx.absolute_slot ?? tx.slot_no ?? 0,
|
|
1086
|
-
// Koios
|
|
1087
|
-
// the live OpenAPI spec) — `tx_index`/`tx_fee` never existed, so the fee
|
|
1088
|
-
// was always reported as '0'
|
|
1008
|
+
// Koios spells these `tx_block_index` and `fee` (not `tx_index` / `tx_fee`)
|
|
1089
1009
|
index: tx.tx_block_index ?? 0,
|
|
1090
1010
|
fee: tx.fee || '0',
|
|
1091
1011
|
deposit: tx.deposit || '0',
|
|
@@ -1197,10 +1117,8 @@ const KOIOS_CERT_KINDS = {
|
|
|
1197
1117
|
param_proposal: 'param_proposal',
|
|
1198
1118
|
};
|
|
1199
1119
|
/**
|
|
1200
|
-
* Normalize Koios `/tx_info` certificates (`_certs: true`). Field names inside `info`
|
|
1201
|
-
*
|
|
1202
|
-
* `retiring_epoch` — spelled `retiring epoch` with a space in current Koios), so every
|
|
1203
|
-
* alias is read. Exported for the unit tests.
|
|
1120
|
+
* Normalize Koios `/tx_info` certificates (`_certs: true`). Field names inside `info` differ
|
|
1121
|
+
* per type (`retiring_epoch` is spelled `retiring epoch` in current Koios), so every alias is read.
|
|
1204
1122
|
*/
|
|
1205
1123
|
function mapKoiosCertificates(certs) {
|
|
1206
1124
|
const str = (v) => (typeof v === 'string' && v.length ? v : null);
|