@odatano/core 2.0.0-rc.11 → 2.0.0-rc.12
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/CardanoODataService/index.d.ts +54 -0
- package/@cds-models/CardanoODataService/index.js +6 -0
- package/@cds-models/odatano/cardano/index.d.ts +54 -0
- package/@cds-models/odatano/cardano/index.js +6 -0
- package/db/schema.cds +1844 -1738
- package/package.json +1 -1
- package/srv/blockchain/backends/blockfrost-backend.js +7 -2
- package/srv/blockchain/backends/cardano-backend.d.ts +22 -0
- package/srv/blockchain/backends/cardano-backend.js +9 -0
- package/srv/blockchain/backends/koios-backend.d.ts +34 -2
- package/srv/blockchain/backends/koios-backend.js +133 -39
- package/srv/blockchain/backends/ogmios-backend.js +3 -0
- package/srv/blockchain/cardano-client.d.ts +8 -1
- package/srv/blockchain/cardano-client.js +14 -0
- package/srv/blockchain/cardano-indexer.d.ts +111 -2
- package/srv/blockchain/cardano-indexer.js +292 -3
- package/srv/blockchain/crawler/crawler.d.ts +58 -0
- package/srv/blockchain/crawler/crawler.js +95 -0
- package/srv/cardano-service.cds +10 -0
- package/srv/server.js +26 -1
- package/srv/utils/const.d.ts +1 -1
- package/srv/utils/const.js +1 -1
- package/srv/utils/mappers.d.ts +54 -1
- package/srv/utils/mappers.js +111 -0
- package/srv/utils/types.d.ts +10 -2
- package/srv/utils/validators.d.ts +1 -1
- package/srv/utils/validators.js +2 -2
package/package.json
CHANGED
|
@@ -120,6 +120,9 @@ class BlockfrostBackend {
|
|
|
120
120
|
fee: tx.fees,
|
|
121
121
|
deposit: tx.deposit,
|
|
122
122
|
size: tx.size,
|
|
123
|
+
// `spends === 'collaterals'` in Ogmios terms: the script phase failed, so the
|
|
124
|
+
// ledger applied neither the declared inputs/outputs nor the declared mint.
|
|
125
|
+
spendsCollaterals: tx.valid_contract === false,
|
|
123
126
|
inputs: txUtxos.inputs.map(input => ({
|
|
124
127
|
address: input.address,
|
|
125
128
|
txHash: input.tx_hash,
|
|
@@ -128,8 +131,10 @@ class BlockfrostBackend {
|
|
|
128
131
|
dataHash: input.data_hash,
|
|
129
132
|
inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(input.inline_datum),
|
|
130
133
|
referenceScriptHash: input.reference_script_hash,
|
|
131
|
-
collateral
|
|
132
|
-
reference
|
|
134
|
+
// TxInputLine's names — these were mapped as `collateral`/`reference` before,
|
|
135
|
+
// which nothing reads, so every consumer saw a reference input as a consumed one.
|
|
136
|
+
isCollateral: input.collateral === true,
|
|
137
|
+
isReference: input.reference === true,
|
|
133
138
|
})),
|
|
134
139
|
outputs: txUtxos.outputs.map(output => ({
|
|
135
140
|
address: output.address,
|
|
@@ -248,4 +248,26 @@ export interface PaginatingBackend extends CardanoBackend {
|
|
|
248
248
|
}
|
|
249
249
|
/** Type guard: can this backend be walked forward by pagination? */
|
|
250
250
|
export declare function isPaginatingBackend(backend: CardanoBackend): backend is PaginatingBackend;
|
|
251
|
+
/**
|
|
252
|
+
* Backend that can enumerate the full stake-pool and DRep set and fetch them in batches —
|
|
253
|
+
* what the crawler's epoch-boundary snapshots need (v2.0 analytics coverage).
|
|
254
|
+
*
|
|
255
|
+
* Koios only, and deliberately so: it lists ids (`/pool_list`, `/drep_list`) and resolves
|
|
256
|
+
* them in batches (`POST /pool_info`, `POST /drep_info`), which turns a mainnet snapshot of
|
|
257
|
+
* ~3 200 pools into a handful of requests. Blockfrost can list ids but has no batch info
|
|
258
|
+
* endpoint, so the same snapshot would be thousands of single requests — the snapshots stay
|
|
259
|
+
* off rather than being served that way (same rule as GetUTxOsByCredential).
|
|
260
|
+
*/
|
|
261
|
+
export interface EnumeratingBackend extends CardanoBackend {
|
|
262
|
+
/** All known stake-pool ids (bech32). */
|
|
263
|
+
getPoolIds(): Promise<string[]>;
|
|
264
|
+
/** Resolve a batch of pool ids. Ids the backend does not know are omitted, not faked. */
|
|
265
|
+
getPools(poolIds: string[]): Promise<PoolData[]>;
|
|
266
|
+
/** All known DRep ids (bech32). */
|
|
267
|
+
getDrepIds(): Promise<string[]>;
|
|
268
|
+
/** Resolve a batch of DRep ids. Ids the backend does not know are omitted. */
|
|
269
|
+
getDreps(drepIds: string[]): Promise<DrepData[]>;
|
|
270
|
+
}
|
|
271
|
+
/** Type guard: can this backend enumerate pools and DReps? */
|
|
272
|
+
export declare function isEnumeratingBackend(backend: CardanoBackend): backend is EnumeratingBackend;
|
|
251
273
|
//# sourceMappingURL=cardano-backend.d.ts.map
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isEvaluatingBackend = isEvaluatingBackend;
|
|
4
4
|
exports.isChainSyncBackend = isChainSyncBackend;
|
|
5
5
|
exports.isPaginatingBackend = isPaginatingBackend;
|
|
6
|
+
exports.isEnumeratingBackend = isEnumeratingBackend;
|
|
6
7
|
/**
|
|
7
8
|
* Type guard to check if a backend supports transaction evaluation
|
|
8
9
|
* @param backend - The backend to check
|
|
@@ -22,4 +23,12 @@ function isPaginatingBackend(backend) {
|
|
|
22
23
|
&& typeof b.getNextBlocks === 'function'
|
|
23
24
|
&& typeof b.getBlockTransactions === 'function';
|
|
24
25
|
}
|
|
26
|
+
/** Type guard: can this backend enumerate pools and DReps? */
|
|
27
|
+
function isEnumeratingBackend(backend) {
|
|
28
|
+
const b = backend;
|
|
29
|
+
return typeof b.getPoolIds === 'function'
|
|
30
|
+
&& typeof b.getPools === 'function'
|
|
31
|
+
&& typeof b.getDrepIds === 'function'
|
|
32
|
+
&& typeof b.getDreps === 'function';
|
|
33
|
+
}
|
|
25
34
|
//# sourceMappingURL=cardano-backend.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { CardanoBackend, PaginatingBackend } from './cardano-backend';
|
|
1
|
+
import { CardanoBackend, PaginatingBackend, EnumeratingBackend } from './cardano-backend';
|
|
2
2
|
import { Transaction, BlockData, Address, UTxO, NetworkInformation, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters } from '../../utils/types';
|
|
3
3
|
import { Network } from '../cardano-client';
|
|
4
4
|
/**
|
|
5
5
|
* KoiosBackend Implementation for CardanoBackend Interface
|
|
6
6
|
* Implements the CardanoBackend interface using Koios API with Axios
|
|
7
7
|
*/
|
|
8
|
-
export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
|
|
8
|
+
export declare class KoiosBackend implements CardanoBackend, PaginatingBackend, EnumeratingBackend {
|
|
9
9
|
readonly name = "koios";
|
|
10
10
|
private api;
|
|
11
11
|
private network;
|
|
@@ -95,6 +95,8 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
|
|
|
95
95
|
* @returns {Promise<PoolData>} pool data
|
|
96
96
|
*/
|
|
97
97
|
getPool(poolId: string): Promise<PoolData>;
|
|
98
|
+
/** Map one Koios /pool_info row to the canonical PoolData. */
|
|
99
|
+
private _mapKoiosPool;
|
|
98
100
|
/**
|
|
99
101
|
* Get Asset Info (supply, mint history, CIP-25 + CIP-26 metadata).
|
|
100
102
|
* Koios's `asset_info` returns total_supply, mint/burn counts split,
|
|
@@ -120,6 +122,8 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
|
|
|
120
122
|
* @returns {Promise<DrepData>} drep data
|
|
121
123
|
*/
|
|
122
124
|
getDrep(drepId: string): Promise<DrepData>;
|
|
125
|
+
/** Map one Koios /drep_info row to the canonical DrepData. */
|
|
126
|
+
private _mapKoiosDrep;
|
|
123
127
|
/**
|
|
124
128
|
* Get Account Data for specified stake address
|
|
125
129
|
* @param accountId account id
|
|
@@ -191,6 +195,34 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend {
|
|
|
191
195
|
* round-trip is skipped entirely.
|
|
192
196
|
*/
|
|
193
197
|
getNextBlocks(afterHash: string, count: number, afterHeight?: number): Promise<BlockData[]>;
|
|
198
|
+
/** Rows per page when listing ids (PostgREST caps a response at 1000 rows). */
|
|
199
|
+
private static readonly LIST_PAGE_SIZE;
|
|
200
|
+
/** Ids resolved per /pool_info / /drep_info request. */
|
|
201
|
+
private static readonly INFO_BATCH_SIZE;
|
|
202
|
+
/**
|
|
203
|
+
* Refuse to page forever if an endpoint keeps returning full pages — 500 pages is
|
|
204
|
+
* 500 000 ids, far beyond any real pool or DRep set.
|
|
205
|
+
*/
|
|
206
|
+
private static readonly LIST_MAX_PAGES;
|
|
207
|
+
/**
|
|
208
|
+
* Page through a PostgREST list endpoint and collect one id column. Stops on the first
|
|
209
|
+
* short page, so a complete set costs exactly ceil(n / 1000) + 1 requests.
|
|
210
|
+
*/
|
|
211
|
+
private listAllIds;
|
|
212
|
+
/**
|
|
213
|
+
* All stake-pool ids known to Koios (bech32), including retired ones — a snapshot that
|
|
214
|
+
* silently dropped retiring pools would misreport the epoch's pool set.
|
|
215
|
+
*/
|
|
216
|
+
getPoolIds(): Promise<string[]>;
|
|
217
|
+
/**
|
|
218
|
+
* Resolve pool ids in batches. Ids Koios does not return are omitted rather than
|
|
219
|
+
* substituted with empty rows — a missing pool is better than an invented one.
|
|
220
|
+
*/
|
|
221
|
+
getPools(poolIds: string[]): Promise<PoolData[]>;
|
|
222
|
+
/** All DRep ids known to Koios (bech32). */
|
|
223
|
+
getDrepIds(): Promise<string[]>;
|
|
224
|
+
/** Resolve DRep ids in batches; unknown ids are omitted (see getPools). */
|
|
225
|
+
getDreps(drepIds: string[]): Promise<DrepData[]>;
|
|
194
226
|
/**
|
|
195
227
|
* Get the full transaction list of a block in block order via /block_txs → /tx_info
|
|
196
228
|
* batch. Handles both the current flattened shape ({tx_hash} per row) and the older
|
|
@@ -450,28 +450,31 @@ class KoiosBackend {
|
|
|
450
450
|
if (!Array.isArray(data) || data.length === 0) {
|
|
451
451
|
throw new errors_1.NotFoundError('Pool', this.name);
|
|
452
452
|
}
|
|
453
|
-
|
|
454
|
-
return {
|
|
455
|
-
poolId: poolData.pool_id_bech32 || poolData.pool_id_hex || poolId,
|
|
456
|
-
vrfKeyHash: poolData.vrf_key_hash,
|
|
457
|
-
blocksMinted: poolData.block_count,
|
|
458
|
-
// Koios pool_info has no blocks-in-current-epoch figure — epoch_no
|
|
459
|
-
// (the epoch NUMBER) was mapped here before, which is a different
|
|
460
|
-
// semantic than Blockfrost's blocks_epoch. 0 = not available.
|
|
461
|
-
blocksEpoch: 0,
|
|
462
|
-
liveStake: poolData.live_stake || '0',
|
|
463
|
-
liveSize: poolData.live_size || 0,
|
|
464
|
-
liveDelegators: poolData.live_delegators || 0,
|
|
465
|
-
liveSaturation: poolData.live_saturation || 0,
|
|
466
|
-
activeStake: poolData.active_stake || '0',
|
|
467
|
-
activeSize: poolData.active_size || 0,
|
|
468
|
-
pledge: poolData.pledge || '0',
|
|
469
|
-
margin: poolData.margin || 0,
|
|
470
|
-
fixedCost: poolData.fixed_cost || '0',
|
|
471
|
-
rewardAccount: poolData.reward_addr,
|
|
472
|
-
};
|
|
453
|
+
return this._mapKoiosPool(data[0], poolId);
|
|
473
454
|
}, this.name);
|
|
474
455
|
}
|
|
456
|
+
/** Map one Koios /pool_info row to the canonical PoolData. */
|
|
457
|
+
_mapKoiosPool(poolData, fallbackId) {
|
|
458
|
+
return {
|
|
459
|
+
poolId: poolData.pool_id_bech32 || poolData.pool_id_hex || fallbackId,
|
|
460
|
+
vrfKeyHash: poolData.vrf_key_hash,
|
|
461
|
+
blocksMinted: poolData.block_count,
|
|
462
|
+
// Koios pool_info has no blocks-in-current-epoch figure — epoch_no
|
|
463
|
+
// (the epoch NUMBER) was mapped here before, which is a different
|
|
464
|
+
// semantic than Blockfrost's blocks_epoch. 0 = not available.
|
|
465
|
+
blocksEpoch: 0,
|
|
466
|
+
liveStake: poolData.live_stake || '0',
|
|
467
|
+
liveSize: poolData.live_size || 0,
|
|
468
|
+
liveDelegators: poolData.live_delegators || 0,
|
|
469
|
+
liveSaturation: poolData.live_saturation || 0,
|
|
470
|
+
activeStake: poolData.active_stake || '0',
|
|
471
|
+
activeSize: poolData.active_size || 0,
|
|
472
|
+
pledge: poolData.pledge || '0',
|
|
473
|
+
margin: poolData.margin || 0,
|
|
474
|
+
fixedCost: poolData.fixed_cost || '0',
|
|
475
|
+
rewardAccount: poolData.reward_addr,
|
|
476
|
+
};
|
|
477
|
+
}
|
|
475
478
|
/**
|
|
476
479
|
* Get Asset Info (supply, mint history, CIP-25 + CIP-26 metadata).
|
|
477
480
|
* Koios's `asset_info` returns total_supply, mint/burn counts split,
|
|
@@ -596,27 +599,30 @@ class KoiosBackend {
|
|
|
596
599
|
if (!Array.isArray(data) || data.length === 0) {
|
|
597
600
|
throw new errors_1.NotFoundError('Drep', this.name);
|
|
598
601
|
}
|
|
599
|
-
|
|
600
|
-
// Koios changed the /drep_info schema (observed 2026-07): the old
|
|
601
|
-
// `expired`/`retired`/`last_active_epoch` fields were replaced by
|
|
602
|
-
// `drep_status` ('registered' | 'retired'), `active` (boolean) and
|
|
603
|
-
// `expires_epoch_no`. Read the old fields first (mainnet/preprod may
|
|
604
|
-
// lag the migration), then derive from the new ones.
|
|
605
|
-
const retired = drepData.retired ?? drepData.drep_status === 'retired';
|
|
606
|
-
const expired = drepData.expired ?? (drepData.active === false && !retired);
|
|
607
|
-
return {
|
|
608
|
-
drepId: drepData.drep_id,
|
|
609
|
-
hex: drepData.hex,
|
|
610
|
-
amount: drepData.amount,
|
|
611
|
-
hasScript: drepData.has_script,
|
|
612
|
-
// The new schema no longer reports the last-activity epoch (only
|
|
613
|
-
// `expires_epoch_no`, which has different semantics) — keep 0 there.
|
|
614
|
-
lastActiveEpoch: drepData.last_active_epoch ?? 0,
|
|
615
|
-
expired,
|
|
616
|
-
retired,
|
|
617
|
-
};
|
|
602
|
+
return this._mapKoiosDrep(data[0]);
|
|
618
603
|
}, this.name);
|
|
619
604
|
}
|
|
605
|
+
/** Map one Koios /drep_info row to the canonical DrepData. */
|
|
606
|
+
_mapKoiosDrep(drepData) {
|
|
607
|
+
// Koios changed the /drep_info schema (observed 2026-07): the old
|
|
608
|
+
// `expired`/`retired`/`last_active_epoch` fields were replaced by
|
|
609
|
+
// `drep_status` ('registered' | 'retired'), `active` (boolean) and
|
|
610
|
+
// `expires_epoch_no`. Read the old fields first (mainnet/preprod may
|
|
611
|
+
// lag the migration), then derive from the new ones.
|
|
612
|
+
const retired = drepData.retired ?? drepData.drep_status === 'retired';
|
|
613
|
+
const expired = drepData.expired ?? (drepData.active === false && !retired);
|
|
614
|
+
return {
|
|
615
|
+
drepId: drepData.drep_id,
|
|
616
|
+
hex: drepData.hex,
|
|
617
|
+
amount: drepData.amount,
|
|
618
|
+
hasScript: drepData.has_script,
|
|
619
|
+
// The new schema no longer reports the last-activity epoch (only
|
|
620
|
+
// `expires_epoch_no`, which has different semantics) — keep 0 there.
|
|
621
|
+
lastActiveEpoch: drepData.last_active_epoch ?? 0,
|
|
622
|
+
expired,
|
|
623
|
+
retired,
|
|
624
|
+
};
|
|
625
|
+
}
|
|
620
626
|
/**
|
|
621
627
|
* Get Account Data for specified stake address
|
|
622
628
|
* @param accountId account id
|
|
@@ -935,6 +941,84 @@ class KoiosBackend {
|
|
|
935
941
|
.sort((a, b) => (a.height ?? 0) - (b.height ?? 0));
|
|
936
942
|
}, this.name);
|
|
937
943
|
}
|
|
944
|
+
// ---------------------------------------------------------------------------
|
|
945
|
+
// EnumeratingBackend — full pool/DRep set for the crawler's epoch snapshots
|
|
946
|
+
// ---------------------------------------------------------------------------
|
|
947
|
+
/** Rows per page when listing ids (PostgREST caps a response at 1000 rows). */
|
|
948
|
+
static LIST_PAGE_SIZE = 1000;
|
|
949
|
+
/** Ids resolved per /pool_info / /drep_info request. */
|
|
950
|
+
static INFO_BATCH_SIZE = 50;
|
|
951
|
+
/**
|
|
952
|
+
* Refuse to page forever if an endpoint keeps returning full pages — 500 pages is
|
|
953
|
+
* 500 000 ids, far beyond any real pool or DRep set.
|
|
954
|
+
*/
|
|
955
|
+
static LIST_MAX_PAGES = 500;
|
|
956
|
+
/**
|
|
957
|
+
* Page through a PostgREST list endpoint and collect one id column. Stops on the first
|
|
958
|
+
* short page, so a complete set costs exactly ceil(n / 1000) + 1 requests.
|
|
959
|
+
*/
|
|
960
|
+
async listAllIds(path, column, label) {
|
|
961
|
+
const ids = [];
|
|
962
|
+
for (let page = 0; page < KoiosBackend.LIST_MAX_PAGES; page++) {
|
|
963
|
+
const offset = page * KoiosBackend.LIST_PAGE_SIZE;
|
|
964
|
+
const { data } = await this.getWithRetryOn42804(`${path}?select=${column}&limit=${KoiosBackend.LIST_PAGE_SIZE}&offset=${offset}`, {}, label);
|
|
965
|
+
if (!Array.isArray(data) || data.length === 0)
|
|
966
|
+
return ids;
|
|
967
|
+
for (const row of data) {
|
|
968
|
+
const id = row[column];
|
|
969
|
+
if (typeof id === 'string' && id)
|
|
970
|
+
ids.push(id);
|
|
971
|
+
}
|
|
972
|
+
if (data.length < KoiosBackend.LIST_PAGE_SIZE)
|
|
973
|
+
return ids;
|
|
974
|
+
}
|
|
975
|
+
logger.warn(`${label}: stopped after ${KoiosBackend.LIST_MAX_PAGES} pages — the list may be truncated`);
|
|
976
|
+
return ids;
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* All stake-pool ids known to Koios (bech32), including retired ones — a snapshot that
|
|
980
|
+
* silently dropped retiring pools would misreport the epoch's pool set.
|
|
981
|
+
*/
|
|
982
|
+
async getPoolIds() {
|
|
983
|
+
return (0, backend_request_handler_1.handleBackendRequest)(() => this.listAllIds('/pool_list', 'pool_id_bech32', 'getPoolIds'), this.name);
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Resolve pool ids in batches. Ids Koios does not return are omitted rather than
|
|
987
|
+
* substituted with empty rows — a missing pool is better than an invented one.
|
|
988
|
+
*/
|
|
989
|
+
async getPools(poolIds) {
|
|
990
|
+
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
991
|
+
const out = [];
|
|
992
|
+
for (let i = 0; i < poolIds.length; i += KoiosBackend.INFO_BATCH_SIZE) {
|
|
993
|
+
const batch = poolIds.slice(i, i + KoiosBackend.INFO_BATCH_SIZE);
|
|
994
|
+
const { data } = await this.api.post('/pool_info', { _pool_bech32_ids: batch });
|
|
995
|
+
if (!Array.isArray(data))
|
|
996
|
+
continue;
|
|
997
|
+
for (const row of data)
|
|
998
|
+
out.push(this._mapKoiosPool(row, ''));
|
|
999
|
+
}
|
|
1000
|
+
return out;
|
|
1001
|
+
}, this.name);
|
|
1002
|
+
}
|
|
1003
|
+
/** All DRep ids known to Koios (bech32). */
|
|
1004
|
+
async getDrepIds() {
|
|
1005
|
+
return (0, backend_request_handler_1.handleBackendRequest)(() => this.listAllIds('/drep_list', 'drep_id', 'getDrepIds'), this.name);
|
|
1006
|
+
}
|
|
1007
|
+
/** Resolve DRep ids in batches; unknown ids are omitted (see getPools). */
|
|
1008
|
+
async getDreps(drepIds) {
|
|
1009
|
+
return (0, backend_request_handler_1.handleBackendRequest)(async () => {
|
|
1010
|
+
const out = [];
|
|
1011
|
+
for (let i = 0; i < drepIds.length; i += KoiosBackend.INFO_BATCH_SIZE) {
|
|
1012
|
+
const batch = drepIds.slice(i, i + KoiosBackend.INFO_BATCH_SIZE);
|
|
1013
|
+
const { data } = await this.api.post('/drep_info', { _drep_ids: batch });
|
|
1014
|
+
if (!Array.isArray(data))
|
|
1015
|
+
continue;
|
|
1016
|
+
for (const row of data)
|
|
1017
|
+
out.push(this._mapKoiosDrep(row));
|
|
1018
|
+
}
|
|
1019
|
+
return out;
|
|
1020
|
+
}, this.name);
|
|
1021
|
+
}
|
|
938
1022
|
/**
|
|
939
1023
|
* Get the full transaction list of a block in block order via /block_txs → /tx_info
|
|
940
1024
|
* batch. Handles both the current flattened shape ({tx_hash} per row) and the older
|
|
@@ -990,6 +1074,16 @@ class KoiosBackend {
|
|
|
990
1074
|
index: tx.tx_block_index ?? 0,
|
|
991
1075
|
fee: tx.fee || '0',
|
|
992
1076
|
deposit: tx.deposit || '0',
|
|
1077
|
+
// undefined (not []) when Koios does not report the field at all — the indexer then
|
|
1078
|
+
// falls back to the input/output delta instead of reading "no mint" into a gap.
|
|
1079
|
+
mint: Array.isArray(tx.assets_minted)
|
|
1080
|
+
? tx.assets_minted
|
|
1081
|
+
.filter((a) => a?.policy_id && a.quantity != null)
|
|
1082
|
+
.map((a) => ({
|
|
1083
|
+
unit: `${a.policy_id}${a.asset_name ?? ''}`,
|
|
1084
|
+
quantity: String(a.quantity),
|
|
1085
|
+
}))
|
|
1086
|
+
: undefined,
|
|
993
1087
|
size: tx.tx_size,
|
|
994
1088
|
inputs: tx.inputs.map((input) => {
|
|
995
1089
|
const amount = [
|
|
@@ -1002,6 +1002,9 @@ class OgmiosBackend {
|
|
|
1002
1002
|
spendsCollaterals,
|
|
1003
1003
|
totalCollateral,
|
|
1004
1004
|
deposit: '0',
|
|
1005
|
+
// The ledger applies no mint when the script phase failed: the body's mint field is
|
|
1006
|
+
// declared but never enacted, so a phase-2 failure must report none at all.
|
|
1007
|
+
mint: spendsCollaterals ? undefined : this.convertOgmiosValue(tx.mint ?? {}),
|
|
1005
1008
|
// null = unknown (chain-sync doesn't surface the serialized size) — matches the
|
|
1006
1009
|
// lazy path's `size ?? null` convention; 0 would masquerade as a real size
|
|
1007
1010
|
size: null,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainSyncBackend, PaginatingBackend } from './backends/cardano-backend';
|
|
1
|
+
import { ChainSyncBackend, PaginatingBackend, EnumeratingBackend } from './backends/cardano-backend';
|
|
2
2
|
import { type CircuitBreakerConfig } from './circuit-breaker';
|
|
3
3
|
import { Transaction, Address, UTxO, NetworkInformation, BlockData, EpochData, MetadataLabelTx, PoolData, DrepData, AccountData, AssetInfo, AssetHistoryEntry, LedgerProtocolParameters, ScriptEvaluationResult } from '../utils/types';
|
|
4
4
|
export type Network = 'mainnet' | 'preview' | 'preprod';
|
|
@@ -245,6 +245,13 @@ export declare class CardanoClient {
|
|
|
245
245
|
* uninitialized backend would wedge it.
|
|
246
246
|
*/
|
|
247
247
|
getChainSyncBackend(): ChainSyncBackend | null;
|
|
248
|
+
/**
|
|
249
|
+
* Get a backend that can enumerate the full pool/DRep set (Koios), or null. Used by the
|
|
250
|
+
* crawler's epoch-boundary snapshots; without one they stay off rather than degrade into
|
|
251
|
+
* thousands of single requests (see EnumeratingBackend).
|
|
252
|
+
* Skips backends whose init() failed (see getChainSyncBackend).
|
|
253
|
+
*/
|
|
254
|
+
getEnumeratingBackend(): EnumeratingBackend | null;
|
|
248
255
|
/**
|
|
249
256
|
* Get a backend that can be walked forward by pagination (Blockfrost/Koios), or null.
|
|
250
257
|
* The crawler's fallback source when no Ogmios chain-sync is available.
|
|
@@ -549,6 +549,20 @@ class CardanoClient {
|
|
|
549
549
|
}
|
|
550
550
|
return null;
|
|
551
551
|
}
|
|
552
|
+
/**
|
|
553
|
+
* Get a backend that can enumerate the full pool/DRep set (Koios), or null. Used by the
|
|
554
|
+
* crawler's epoch-boundary snapshots; without one they stay off rather than degrade into
|
|
555
|
+
* thousands of single requests (see EnumeratingBackend).
|
|
556
|
+
* Skips backends whose init() failed (see getChainSyncBackend).
|
|
557
|
+
*/
|
|
558
|
+
getEnumeratingBackend() {
|
|
559
|
+
const candidates = [...this.historicalBackends, this.liveBackend];
|
|
560
|
+
for (const b of candidates) {
|
|
561
|
+
if (b && !this.uninitializedBackends.has(b) && (0, cardano_backend_1.isEnumeratingBackend)(b))
|
|
562
|
+
return b;
|
|
563
|
+
}
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
552
566
|
/**
|
|
553
567
|
* Get a backend that can be walked forward by pagination (Blockfrost/Koios), or null.
|
|
554
568
|
* The crawler's fallback source when no Ogmios chain-sync is available.
|
|
@@ -37,6 +37,44 @@ export declare class CardanoIndexer {
|
|
|
37
37
|
private crawlEpochCache;
|
|
38
38
|
private crawlEpochCurrent;
|
|
39
39
|
private crawlEpochPrevious;
|
|
40
|
+
/**
|
|
41
|
+
* Analytics coverage of the crawl path (v2.0, FR "crawler coverage for analytics"). The
|
|
42
|
+
* defaults mirror the crawler config defaults, so an indexer the crawler never configured
|
|
43
|
+
* (unit tests, the lazy-only path) behaves exactly like a configured one.
|
|
44
|
+
*/
|
|
45
|
+
private crawlAssetHistory;
|
|
46
|
+
private crawlAssetCatalogue;
|
|
47
|
+
/** Units known to have an `Assets` row, so a repeat sighting costs no DB round-trip. */
|
|
48
|
+
private static readonly ASSET_MEMO_CAP;
|
|
49
|
+
private assetMemo;
|
|
50
|
+
/**
|
|
51
|
+
* Background registry enrichment (`assetCatalogue: 'enrich'`). Bare rows are queued here and
|
|
52
|
+
* resolved at a fixed rate OUTSIDE the block transaction, so a mint storm can slow the queue
|
|
53
|
+
* but never the crawl. Above the cap the oldest entries are dropped: the unit keeps its bare
|
|
54
|
+
* row and is still enriched by the lazy path on its first API read.
|
|
55
|
+
*/
|
|
56
|
+
private static readonly ENRICH_QUEUE_CAP;
|
|
57
|
+
private enrichQueue;
|
|
58
|
+
private enrichTimer;
|
|
59
|
+
private enrichRate;
|
|
60
|
+
/**
|
|
61
|
+
* Adopt the crawler's coverage settings. Called once from the crawler's start path; the
|
|
62
|
+
* lazy request path never touches these.
|
|
63
|
+
*/
|
|
64
|
+
configureCrawlCoverage(coverage: {
|
|
65
|
+
assetHistory: boolean;
|
|
66
|
+
assetCatalogue: 'off' | 'bare' | 'enrich';
|
|
67
|
+
assetEnrichRate?: number;
|
|
68
|
+
}): void;
|
|
69
|
+
/**
|
|
70
|
+
* Drain the enrichment queue at `enrichRate` units per second, one `indexAsset()` per tick in
|
|
71
|
+
* its own transaction. The timer is unref'd, so it never holds the process open, and a failing
|
|
72
|
+
* unit (404 from every backend, provider outage) is dropped rather than retried — its bare row
|
|
73
|
+
* stays and the lazy path can still enrich it later.
|
|
74
|
+
*/
|
|
75
|
+
private startAssetEnrichment;
|
|
76
|
+
/** Stop the enrichment loop and forget what is still queued (shutdown, crawler halt, mode change). */
|
|
77
|
+
stopAssetEnrichment(): void;
|
|
40
78
|
/**
|
|
41
79
|
* Network-only epoch prefetch for the crawler. Call BEFORE opening the per-block
|
|
42
80
|
* write transaction — the backend round-trip must never run while the DB write
|
|
@@ -201,10 +239,81 @@ export declare class CardanoIndexer {
|
|
|
201
239
|
* declared fee is kept in that case and the transaction is logged: a value that is wrong in
|
|
202
240
|
* a known, named way beats one that looks derived but is short by an unknown amount.
|
|
203
241
|
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
242
|
+
* Applies to every backend that reports phase-2 validity — the chain-sync path (`spends`)
|
|
243
|
+
* and Blockfrost (`valid_contract`), whose declared `fees` are likewise never collected on a
|
|
244
|
+
* failed script phase. Koios carries `spendsCollaterals` as undefined and passes through
|
|
245
|
+
* untouched.
|
|
206
246
|
*/
|
|
207
247
|
private applyCollateralFees;
|
|
248
|
+
/**
|
|
249
|
+
* Mint/burn rows for a whole block, as a by-product of data the crawler already holds —
|
|
250
|
+
* no provider round-trip (v2.1 analytics coverage).
|
|
251
|
+
*
|
|
252
|
+
* Two sources, in this order:
|
|
253
|
+
* 1. `t.mint` — the ledger's own mint field, reported natively by Ogmios (`mint`) and
|
|
254
|
+
* Koios (`assets_minted`). Authoritative: it needs no resolved inputs and states the
|
|
255
|
+
* net per unit directly.
|
|
256
|
+
* 2. Σ outputs − Σ inputs per unit, for backends without that field (Blockfrost), whose
|
|
257
|
+
* inputs all carry their full `amount` so the delta is exact.
|
|
258
|
+
*
|
|
259
|
+
* The delta path excludes what the ledger does not consume or produce: reference inputs are
|
|
260
|
+
* read, never spent, and collateral only moves when the script phase failed — which applies
|
|
261
|
+
* no mint at all, so those transactions are skipped outright. Both exclusions rest on
|
|
262
|
+
* `isReference` / `isCollateral` / `spendsCollaterals`, which every backend that can reach
|
|
263
|
+
* this branch has to set — Blockfrost does since rc.12. A transaction with even one
|
|
264
|
+
* unresolvable consumed input (an output created before the crawl start, so no local row) is
|
|
265
|
+
* skipped and logged rather than reported with a delta that is short by an unknown amount —
|
|
266
|
+
* the same discipline as applyCollateralFees() above.
|
|
267
|
+
*/
|
|
268
|
+
private buildAssetHistoryRows;
|
|
269
|
+
/**
|
|
270
|
+
* Keep the `Assets` catalogue complete for every unit the crawl meets, from the data already
|
|
271
|
+
* in hand — no provider call (FR "crawler coverage for analytics", variant "bare row").
|
|
272
|
+
*
|
|
273
|
+
* `Assets` is temporal, so its key is `(validFrom, unit)` and a row is a slice. The bare row
|
|
274
|
+
* therefore carries the fixed epoch-zero stamp (`BARE_ASSET_STAMP`), which no wall-clock slice
|
|
275
|
+
* from mapAsset() can ever alias: the write cannot overwrite enriched registry data, and it
|
|
276
|
+
* stays a single idempotent row per unit. That makes UPSERT safe — and safe is what it has to
|
|
277
|
+
* be, because this runs inside the crawler's block transaction, where a unique-key violation
|
|
278
|
+
* from a lazy-path write racing us would take the whole block down with it (and on PostgreSQL
|
|
279
|
+
* poison the transaction beyond any catch).
|
|
280
|
+
*
|
|
281
|
+
* The existence check is then only an optimization — it keeps a settled catalogue from
|
|
282
|
+
* rewriting every unit of every block. It runs against the DB-LEVEL entity on purpose: the
|
|
283
|
+
* service projection carries the temporal filter (`validFrom < $valid.to AND validTo >
|
|
284
|
+
* $valid.from`), which hides precisely the born-expired rows this check is looking for.
|
|
285
|
+
*/
|
|
286
|
+
private ensureAssetRows;
|
|
287
|
+
/**
|
|
288
|
+
* Remember a unit as present in the catalogue. Insertion-ordered Set → the oldest entries
|
|
289
|
+
* are evicted first once the cap is reached, which keeps a long backfill's memory flat while
|
|
290
|
+
* hot policies stay memoized. Losing an entry costs one SELECT, never a wrong write.
|
|
291
|
+
*/
|
|
292
|
+
private noteAssetSeen;
|
|
293
|
+
/**
|
|
294
|
+
* Snapshot every stake pool and DRep at an epoch boundary (v2.0 analytics coverage).
|
|
295
|
+
*
|
|
296
|
+
* Runs in its OWN transaction, called by the crawler after a block commit — never inside the
|
|
297
|
+
* block's write transaction: a few thousand rows would inflate an otherwise small atomic
|
|
298
|
+
* write, and a snapshot failure would fail the block and burn its persist retries.
|
|
299
|
+
*
|
|
300
|
+
* Writes two things per entity: the dated snapshot row (authoritative, never expires) and a
|
|
301
|
+
* refresh of the live temporal row, so `Pools` / `Dreps` also stop being empty on a crawled
|
|
302
|
+
* instance. Needs an enumerating backend (Koios); without one it is a logged no-op.
|
|
303
|
+
*
|
|
304
|
+
* @param epoch the epoch the snapshot is taken for
|
|
305
|
+
* @param at slot and block time of the block that triggered the boundary
|
|
306
|
+
* @returns counts actually written, for the caller's log
|
|
307
|
+
*/
|
|
308
|
+
snapshotEpoch(epoch: number, at: {
|
|
309
|
+
slot: number;
|
|
310
|
+
time: number;
|
|
311
|
+
}): Promise<{
|
|
312
|
+
pools: number;
|
|
313
|
+
dreps: number;
|
|
314
|
+
}>;
|
|
315
|
+
/** Every native-asset unit a block touches: outputs, consumed inputs and mint/burn rows. */
|
|
316
|
+
private collectBlockUnits;
|
|
208
317
|
/**
|
|
209
318
|
* Index & return the epoch information data
|
|
210
319
|
* @param tx CAP transaction object
|