@odatano/core 2.0.0-rc.2 → 2.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +251 -0
- package/@cds-models/CardanoAgentService/index.js +36 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +139 -2
- package/@cds-models/CardanoIndexerService/index.js +18 -0
- package/@cds-models/CardanoODataService/index.d.ts +231 -6
- package/@cds-models/CardanoODataService/index.js +27 -0
- package/@cds-models/CardanoSignService/index.d.ts +5 -2
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -9
- package/@cds-models/odatano/cardano/index.d.ts +323 -6
- package/@cds-models/odatano/cardano/index.js +33 -0
- package/README.md +195 -136
- package/db/schema.cds +2133 -1633
- package/package.json +181 -173
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +10 -10
- package/src/index.js +24 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +45 -158
- package/srv/blockchain/backends/cardano-backend.d.ts +83 -158
- package/srv/blockchain/backends/cardano-backend.js +14 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +293 -203
- package/srv/blockchain/backends/ogmios-backend.d.ts +69 -94
- package/srv/blockchain/backends/ogmios-backend.js +319 -185
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +32 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +142 -0
- package/srv/blockchain/cardano-client.d.ts +57 -204
- package/srv/blockchain/cardano-client.js +94 -226
- package/srv/blockchain/cardano-indexer.d.ts +176 -240
- package/srv/blockchain/cardano-indexer.js +615 -338
- package/srv/blockchain/cardano-tx-builder.d.ts +29 -82
- package/srv/blockchain/cardano-tx-builder.js +88 -128
- package/srv/blockchain/crawler/certificate-backfill.d.ts +45 -0
- package/srv/blockchain/crawler/certificate-backfill.js +150 -0
- package/srv/blockchain/crawler/crawler.d.ts +121 -53
- package/srv/blockchain/crawler/crawler.js +403 -89
- package/srv/blockchain/crawler/hooks.d.ts +3 -14
- package/srv/blockchain/crawler/index.d.ts +5 -0
- package/srv/blockchain/crawler/index.js +35 -7
- package/srv/blockchain/crawler/sync-state.d.ts +44 -28
- package/srv/blockchain/crawler/sync-state.js +115 -43
- package/srv/blockchain/crawler/utxo-set-import.d.ts +69 -0
- package/srv/blockchain/crawler/utxo-set-import.js +269 -0
- package/srv/blockchain/ledger-state.d.ts +80 -0
- package/srv/blockchain/ledger-state.js +383 -0
- package/srv/blockchain/signing/cose-verifier.d.ts +5 -12
- package/srv/blockchain/signing/cose-verifier.js +6 -12
- package/srv/blockchain/signing/external-signer.d.ts +16 -113
- package/srv/blockchain/signing/external-signer.js +19 -122
- package/srv/blockchain/signing/hsm-signer.d.ts +13 -45
- package/srv/blockchain/signing/hsm-signer.js +23 -63
- package/srv/blockchain/signing/signature-verifier.d.ts +8 -44
- package/srv/blockchain/signing/signature-verifier.js +13 -54
- package/srv/blockchain/signing/submission-finalizer.d.ts +9 -36
- package/srv/blockchain/signing/submission-finalizer.js +16 -48
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +71 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +185 -260
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +8 -34
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +42 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +39 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +25 -17
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +87 -41
- package/srv/blockchain/wallet-worker/index.js +2 -8
- package/srv/blockchain/wallet-worker/job-store.d.ts +36 -103
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +4 -20
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +4 -20
- package/srv/blockchain/wallet-worker/signers.d.ts +6 -19
- package/srv/blockchain/wallet-worker/signers.js +3 -8
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +15 -71
- package/srv/blockchain/wallet-worker/wallet-worker.js +40 -91
- package/srv/cardano-agent-service.cds +146 -0
- package/srv/cardano-agent-service.d.ts +2 -0
- package/srv/cardano-agent-service.js +12 -0
- package/srv/cardano-indexer-service.cds +164 -73
- package/srv/cardano-indexer-service.js +156 -11
- package/srv/cardano-service.cds +45 -0
- package/srv/cardano-service.js +38 -96
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +32 -26
- package/srv/cardano-tx-service.js +136 -196
- package/srv/cardano-worker-service.js +7 -15
- package/srv/server.d.ts +28 -86
- package/srv/server.js +95 -128
- package/srv/utils/agent-grants-config.d.ts +37 -0
- package/srv/utils/agent-grants-config.js +138 -0
- package/srv/utils/agent-grants.d.ts +262 -0
- package/srv/utils/agent-grants.js +914 -0
- package/srv/utils/agent-token-auth.d.ts +16 -0
- package/srv/utils/agent-token-auth.js +78 -0
- package/srv/utils/backend-request-handler.d.ts +2 -16
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/collections.d.ts +4 -8
- package/srv/utils/collections.js +4 -8
- package/srv/utils/const.d.ts +19 -68
- package/srv/utils/const.js +20 -69
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +5 -18
- package/srv/utils/db-indexes.d.ts +25 -0
- package/srv/utils/db-indexes.js +93 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/epoch-slots.d.ts +13 -0
- package/srv/utils/epoch-slots.js +25 -0
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +36 -179
- package/srv/utils/errors.js +62 -220
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +41 -0
- package/srv/utils/mappers.d.ts +89 -214
- package/srv/utils/mappers.js +289 -301
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +57 -0
- package/srv/utils/plutus-placeholders.d.ts +6 -18
- package/srv/utils/plutus-placeholders.js +6 -20
- package/srv/utils/rate-limiter.d.ts +46 -0
- package/srv/utils/rate-limiter.js +116 -0
- package/srv/utils/service-events.d.ts +2 -22
- package/srv/utils/service-events.js +3 -23
- package/srv/utils/signing-helper.d.ts +3 -18
- package/srv/utils/signing-helper.js +10 -32
- package/srv/utils/tx-build-helper.d.ts +18 -92
- package/srv/utils/tx-build-helper.js +32 -123
- package/srv/utils/tx-request-parsers.d.ts +14 -20
- package/srv/utils/tx-request-parsers.js +33 -20
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +114 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -4,19 +4,11 @@ import type { CardanoTransactionBuilder } from './cardano-tx-builder';
|
|
|
4
4
|
import { Transaction as CardanoTransaction, AddressUTxOs, TransactionMetadata, NetworkInformation, Block, Epoch, AssetHistory, Account, Drep, Pool, Asset, Address, LedgerProtocolParameter, AddressTransactions } from '#cds-models/CardanoODataService';
|
|
5
5
|
import { TransactionBuild, TransactionSubmission } from '#cds-models/CardanoTransactionService';
|
|
6
6
|
import { TxBuildRequest, Transaction as ProviderTransaction, BlockData } from '../utils/types';
|
|
7
|
+
import { type LedgerAnchor } from './ledger-state';
|
|
7
8
|
import type { TxCacheTargets } from '../utils/tx-build-helper';
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Provides methods to index & manage db consistency for various Cardano blockchain data (transactions, addresses, blocks, epochs, accounts, pools, dreps)
|
|
12
|
-
* 1. Fetches data from the configured Cardano data provider via the CardanoClient
|
|
13
|
-
* 2. Maps the provider data into corresponding OData entity rows
|
|
14
|
-
* 3. Upserts the data rows into the database via CAP transactions
|
|
15
|
-
* 4. Ensures referential integrity and consistency across related entities (e.g., addresses in transactions, UTxOs in addresses)
|
|
16
|
-
* 5. Returns the indexed entity data for further processing
|
|
17
|
-
*
|
|
18
|
-
* Each method corresponds to a specific Cardano Entity type and handles the necessary mapping and persistence
|
|
19
|
-
* into the corresponding OData entities defined in the CardanoODataService(M1) and CardanoTransactionService(M2) models.
|
|
10
|
+
* Indexes Cardano data into the OData entities: fetches via CardanoClient, maps provider data
|
|
11
|
+
* to entity rows and UPSERTs them inside the caller's CAP transaction.
|
|
20
12
|
*/
|
|
21
13
|
export declare class CardanoIndexer {
|
|
22
14
|
private client;
|
|
@@ -25,261 +17,232 @@ export declare class CardanoIndexer {
|
|
|
25
17
|
private static readonly CRAWL_EPOCH_REFRESH_MS;
|
|
26
18
|
private static readonly CRAWL_EPOCH_RETRY_MS;
|
|
27
19
|
/**
|
|
28
|
-
* Crawler epoch memo
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* At most the current and immediately previous epoch are retained. The rows are
|
|
33
|
-
* intentionally UPSERTed in every block transaction: the caller owns that
|
|
34
|
-
* transaction, so an in-memory "persisted" bit cannot know whether its commit later
|
|
35
|
-
* succeeded. Repeating one local UPSERT is cheap and remains correct after rollback.
|
|
20
|
+
* Crawler epoch memo: refreshed periodically while an epoch is live and once more when the
|
|
21
|
+
* next one starts; holds at most the current and previous epoch. Rows are UPSERTed in every
|
|
22
|
+
* block transaction because the caller owns the commit.
|
|
36
23
|
*/
|
|
37
24
|
private crawlEpochCache;
|
|
38
25
|
private crawlEpochCurrent;
|
|
39
26
|
private crawlEpochPrevious;
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
/** Analytics coverage of the crawl path; defaults mirror the crawler config defaults. */
|
|
28
|
+
private crawlAssetHistory;
|
|
29
|
+
private crawlAssetCatalogue;
|
|
30
|
+
/** Certificates + withdrawals per block (ledger-state coverage). Opt-in. */
|
|
31
|
+
private crawlCertificates;
|
|
32
|
+
/** Logged once per process: the active source reports no certificates (Blockfrost). */
|
|
33
|
+
private certificatesUnreportedWarned;
|
|
34
|
+
/**
|
|
35
|
+
* Crawler-fed ledger state (`crawler.utxoSet`): blocks after `utxoAnchor` are applied to the
|
|
36
|
+
* Ledger* tables; no anchor means configured but inactive.
|
|
37
|
+
*/
|
|
38
|
+
private crawlUtxoSet;
|
|
39
|
+
private utxoAnchor;
|
|
40
|
+
/** The anchor block was found in the crawled chain (checked once, before the first apply). */
|
|
41
|
+
private utxoAnchorVerified;
|
|
42
|
+
/**
|
|
43
|
+
* Invalidation decided inside a block transaction; the anchor stays until the crawler confirms
|
|
44
|
+
* the commit (`takeLedgerInvalidation`), so a rolled-back attempt changes nothing.
|
|
45
|
+
*/
|
|
46
|
+
private ledgerInvalidation;
|
|
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 queue (`assetCatalogue: 'enrich'`), drained at a fixed rate
|
|
52
|
+
* outside the block transaction. Above the cap the oldest units are dropped (bare row stays).
|
|
53
|
+
*/
|
|
54
|
+
private static readonly ENRICH_QUEUE_CAP;
|
|
55
|
+
private enrichQueue;
|
|
56
|
+
private enrichTimer;
|
|
57
|
+
private enrichRate;
|
|
58
|
+
/** Adopt the crawler's coverage settings; the lazy request path never touches these. */
|
|
59
|
+
configureCrawlCoverage(coverage: {
|
|
60
|
+
assetHistory: boolean;
|
|
61
|
+
assetCatalogue: 'off' | 'bare' | 'enrich';
|
|
62
|
+
assetEnrichRate?: number;
|
|
63
|
+
certificates?: boolean;
|
|
64
|
+
utxoSet?: boolean;
|
|
65
|
+
}): void;
|
|
66
|
+
/**
|
|
67
|
+
* What the crawled data answers authoritatively: only while a live crawler is at the tip.
|
|
68
|
+
* Every block after `fromSlot` is held; `ledger` = the crawled UTxO set is active.
|
|
69
|
+
*/
|
|
70
|
+
private localCoverage;
|
|
71
|
+
/**
|
|
72
|
+
* Block counts of a pool from crawled blocks (`slotLeader` = pool id): the current epoch when the
|
|
73
|
+
* crawl covers it from its first slot, the lifetime total when it covers the chain since Shelley.
|
|
74
|
+
*/
|
|
75
|
+
private localPoolBlocks;
|
|
76
|
+
/** The anchor the imported UTxO set describes (null = ledger mode inactive). */
|
|
77
|
+
setUtxoAnchor(anchor: LedgerAnchor | null): void;
|
|
78
|
+
/**
|
|
79
|
+
* The imported set describes the chain AT the anchor block, so before the first block past it
|
|
80
|
+
* is applied the cursor (not yet advanced in this transaction) must equal the anchor exactly;
|
|
81
|
+
* otherwise the snapshot was taken on a fork. Skipped once `utxoAppliedSlot` is set.
|
|
82
|
+
*/
|
|
83
|
+
private verifyUtxoAnchor;
|
|
84
|
+
/** Null while the mode is off, nothing is imported, or an invalidation awaits its commit. */
|
|
85
|
+
getUtxoAnchor(): LedgerAnchor | null;
|
|
86
|
+
/** Hand out a pending invalidation (dropping the anchor) exactly once after the block commit, or null. */
|
|
87
|
+
takeLedgerInvalidation(): string | null;
|
|
88
|
+
/**
|
|
89
|
+
* Drain the enrichment queue at `enrichRate` units per second, one `indexAsset()` per tick in
|
|
90
|
+
* its own transaction. A failing unit is dropped; its bare row stays for the lazy path.
|
|
91
|
+
*/
|
|
92
|
+
private startAssetEnrichment;
|
|
93
|
+
/** Stop the enrichment loop and forget what is still queued (shutdown, crawler halt, mode change). */
|
|
94
|
+
stopAssetEnrichment(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Network-only epoch prefetch for the crawler. Call BEFORE opening the per-block write
|
|
97
|
+
* transaction so no backend round-trip runs under the DB write lock. Never throws.
|
|
44
98
|
*/
|
|
45
99
|
prefetchCrawlEpoch(epochNumber: number): Promise<void>;
|
|
46
100
|
private refreshCrawlEpoch;
|
|
47
101
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @param txBuilder - The CardanoTransactionBuilder instance for transaction building
|
|
102
|
+
* Block, transaction and fee totals of an epoch summed over the crawled blocks, when the crawl
|
|
103
|
+
* covers the epoch from its first slot; null otherwise. Output and active stake stay with the backend.
|
|
51
104
|
*/
|
|
105
|
+
private crawledEpochTotals;
|
|
106
|
+
/** Epoch row with only the slot-derived bounds, for an epoch the backend cannot describe. */
|
|
107
|
+
private bareEpochRow;
|
|
52
108
|
constructor(client: CardanoClient, txBuilder: CardanoTransactionBuilder);
|
|
53
109
|
/**
|
|
54
|
-
* Index
|
|
55
|
-
*
|
|
56
|
-
* atomicity: either all entities are persisted or none are (automatic rollback on error).
|
|
57
|
-
* @param tx CAP transaction (cds.tx(req))
|
|
58
|
-
* @param txHash Cardano transaction hash (hex)
|
|
59
|
-
* @returns {Promise<CardanoTransaction>} transaction entity data
|
|
110
|
+
* Index a transaction with inputs/outputs/assets/metadata; all UPSERTs run in the caller's
|
|
111
|
+
* transaction, so either everything persists or nothing does.
|
|
60
112
|
*/
|
|
61
113
|
indexTransaction(tx: CapTransaction, txHash: string): Promise<CardanoTransaction>;
|
|
114
|
+
/** Lazy path: inputs, outputs, their assets and metadata of one transaction. */
|
|
115
|
+
private writeTransactionChildren;
|
|
62
116
|
/**
|
|
63
|
-
* Index
|
|
64
|
-
*
|
|
65
|
-
* @param tx CAP transaction
|
|
66
|
-
* @param addr bech32 address
|
|
67
|
-
* @return {Promise<Address>} address entity data
|
|
117
|
+
* Index address data with assets and UTxOs; transactions are loaded separately via
|
|
118
|
+
* indexAddressTransactions().
|
|
68
119
|
*/
|
|
69
120
|
indexAddress(tx: CapTransaction, addr: string): Promise<Address>;
|
|
70
121
|
/**
|
|
71
|
-
* Index UTxOs by 28-byte payment credential
|
|
72
|
-
*
|
|
73
|
-
* current data. Underlying AddressUTxOs/UTxOAssets rows are UPSERTed and stay
|
|
74
|
-
* available for follow-up address-keyed queries within the TTL.
|
|
75
|
-
*
|
|
76
|
-
* Does NOT upsert parent Addresses rows; child rows reference bech32 addresses
|
|
77
|
-
* that may not yet have a parent stub. Same pattern as TransactionInputs.
|
|
78
|
-
*
|
|
79
|
-
* @param tx CAP transaction
|
|
80
|
-
* @param credHash 28-byte payment credential as 56-char lowercase hex
|
|
81
|
-
* @return UTxO entity rows across all bech32 addresses sharing the credential
|
|
122
|
+
* Index UTxOs by 28-byte payment credential (56-char hex), always fresh from Koios. Child
|
|
123
|
+
* rows are UPSERTed without a parent Addresses row (same pattern as TransactionInputs).
|
|
82
124
|
*/
|
|
83
125
|
indexCredentialUtxos(tx: CapTransaction, credHash: string): Promise<AddressUTxOs[]>;
|
|
84
126
|
/**
|
|
85
|
-
* Index
|
|
86
|
-
*
|
|
87
|
-
* the live UTxO set but not address aggregation (e.g. Ogmios). Used as the
|
|
88
|
-
* GetUTxOsByAddress fallback when no configured backend supports getAddress.
|
|
89
|
-
*
|
|
90
|
-
* Does NOT upsert a parent Addresses row (same pattern as indexCredentialUtxos);
|
|
91
|
-
* AddressUTxOs/UTxOAssets reference the bech32 address directly.
|
|
92
|
-
*
|
|
93
|
-
* @param tx CAP transaction
|
|
94
|
-
* @param addr bech32 address
|
|
95
|
-
* @return UTxO entity rows for the address (empty when the address holds none)
|
|
127
|
+
* Index only the UTxOs of an address via getAddressUtxos (no getAddress call), so it works on
|
|
128
|
+
* backends without address aggregation such as Ogmios. Writes no parent Addresses row.
|
|
96
129
|
*/
|
|
97
130
|
indexAddressUtxos(tx: CapTransaction, addr: string): Promise<AddressUTxOs[]>;
|
|
98
131
|
/**
|
|
99
|
-
* Evict cached rows a submitted transaction made stale
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* - all address-level rows of the output addresses (their UTxO set gained
|
|
103
|
-
* the new outputs — sender change included) and of `extraAddresses`
|
|
104
|
-
* (e.g. the build's sender when the CBOR could not be parsed).
|
|
105
|
-
*
|
|
106
|
-
* Only the read cache is touched; submissions/builds stay untouched. Note the
|
|
107
|
-
* next refetch may STILL see pre-submit state on lagging backends
|
|
108
|
-
* (Blockfrost/Koios propagation) — that matches cache-less behaviour and is
|
|
109
|
-
* not recoverable server-side.
|
|
110
|
-
*
|
|
111
|
-
* @param tx CAP transaction
|
|
112
|
-
* @param targets input refs + output addresses from extractTxCacheTargets
|
|
113
|
-
* @param extraAddresses additional bech32 addresses to evict
|
|
132
|
+
* Evict cached rows a submitted transaction made stale: every consumed input ref (under any
|
|
133
|
+
* address) and all address-level rows of the output addresses plus `extraAddresses`. Only the
|
|
134
|
+
* read cache is touched; lagging backends may still serve pre-submit state on refetch.
|
|
114
135
|
*/
|
|
115
136
|
invalidateUtxoCacheForTx(tx: CapTransaction, targets: TxCacheTargets, extraAddresses?: string[]): Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* Index & return address transactions (separate from indexAddress for lazy loading)
|
|
118
|
-
* @param tx CAP transaction
|
|
119
|
-
* @param addr bech32 address
|
|
120
|
-
* @param limit maximum number of transactions to fetch
|
|
121
|
-
* @return {Promise<AddressTransactions[]>} address transaction entities
|
|
122
|
-
*/
|
|
137
|
+
/** Index address transactions (separate from indexAddress for lazy loading). */
|
|
123
138
|
indexAddressTransactions(tx: CapTransaction, addr: string, limit: number): Promise<AddressTransactions[]>;
|
|
124
|
-
/**
|
|
125
|
-
* Index & return address signing request association
|
|
126
|
-
* Links an address to a signing request for address-based queries
|
|
127
|
-
* @param tx CAP transaction
|
|
128
|
-
* @param addr bech32 address
|
|
129
|
-
* @param signingRequestId signing request UUID
|
|
130
|
-
* @return {Promise<void>}
|
|
131
|
-
*/
|
|
139
|
+
/** Link an address to a signing request for address-based queries. */
|
|
132
140
|
indexAddressSigningRequests(tx: CapTransaction, addr: string, signingRequestId: string): Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* Index & return address transaction build association
|
|
135
|
-
* Links an address to a transaction build for address-based queries
|
|
136
|
-
* @param tx CAP transaction
|
|
137
|
-
* @param addr bech32 address
|
|
138
|
-
* @param buildId transaction build UUID
|
|
139
|
-
* @return {Promise<void>}
|
|
140
|
-
*/
|
|
141
|
+
/** Link an address to a transaction build for address-based queries. */
|
|
141
142
|
indexAddressTransactionBuilds(tx: CapTransaction, addr: string, buildId: string): Promise<void>;
|
|
143
|
+
/** Index the metadata rows of a transaction. */
|
|
144
|
+
indexTransactionMetadata(tx: CapTransaction, tx_hash: string): Promise<TransactionMetadata[]>;
|
|
145
|
+
/** Index the network information; circulating supply comes from the crawled UTxO set when it is current. */
|
|
146
|
+
indexNetworkInformation(tx: CapTransaction): Promise<NetworkInformation>;
|
|
147
|
+
/** Index a block by hash, with best-effort epoch enrichment. */
|
|
148
|
+
indexBlock(tx: CapTransaction, blockHash: string): Promise<Block>;
|
|
142
149
|
/**
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* @param metadata raw metadata object (label -> JSONValue)
|
|
147
|
-
* @return {Promise<TransactionMetadata[]>} array of transaction metadata rows
|
|
150
|
+
* Bulk-index a whole block and its transactions in one pass for the crawler: no per-hash
|
|
151
|
+
* re-fetch, one UPSERT per table, all inside the caller's transaction so the block persists
|
|
152
|
+
* atomically. Bare chain-sync inputs are backfilled by resolveInputs() first.
|
|
148
153
|
*/
|
|
149
|
-
|
|
154
|
+
indexBlockFull(tx: CapTransaction, blockData: BlockData, txs: ProviderTransaction[]): Promise<void>;
|
|
150
155
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @returns {Promise<NetworkInformation>} network information entity data
|
|
156
|
+
* Drop other Block rows at the crawled block's height that no transaction references: lazily
|
|
157
|
+
* indexed tips that were rolled back, which no crawler reorg covers.
|
|
154
158
|
*/
|
|
155
|
-
|
|
159
|
+
private removeSupersededBlocks;
|
|
156
160
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* @param blockHash block hash (hex)
|
|
160
|
-
* @returns {Promise<Block>} block entity data
|
|
161
|
+
* Drop transactions of another fork that hold one of this block's txSeq keys (a lazily indexed
|
|
162
|
+
* tx from a rolled-back block at the same slot); their input/output rows would mix with ours.
|
|
161
163
|
*/
|
|
162
|
-
|
|
164
|
+
private removeStaleTxSeqs;
|
|
163
165
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* crawler already carries the block + full tx list from the stream/page. Rows are
|
|
167
|
-
* accumulated across the block's txs and UPSERTed once per table (few statements).
|
|
168
|
-
*
|
|
169
|
-
* All writes run inside the caller's CAP transaction (`tx`), so a block is persisted
|
|
170
|
-
* atomically — a failure mid-block rolls the whole block back, keeping the cursor and
|
|
171
|
-
* the data consistent.
|
|
172
|
-
*
|
|
173
|
-
* Inputs from the Ogmios chain-sync path arrive as bare references (no address/amount);
|
|
174
|
-
* resolveInputs() backfills them from this block's own outputs and previously-indexed
|
|
175
|
-
* outputs before mapping. Blockfrost/Koios inputs already carry address/amount and are
|
|
176
|
-
* left untouched.
|
|
177
|
-
*
|
|
178
|
-
* @param tx CAP transaction (one per block, committed by the crawler)
|
|
179
|
-
* @param blockData block header/summary from the crawler source
|
|
180
|
-
* @param txs the block's full transaction list (in block order)
|
|
166
|
+
* Warn once when `crawler.certificates` is on but the source reports none (`certificates`
|
|
167
|
+
* undefined, as with Blockfrost). `[]` means "none" and is not a warning.
|
|
181
168
|
*/
|
|
182
|
-
|
|
169
|
+
private warnIfCertificatesUnreported;
|
|
183
170
|
/**
|
|
184
|
-
* Backfill
|
|
185
|
-
*
|
|
186
|
-
* tx's output in the same block), then batch-reads previously-indexed outputs from the
|
|
187
|
-
* DB. Inputs that already carry an address (Blockfrost/Koios) are skipped.
|
|
171
|
+
* Backfill address/amount of bare chain-sync inputs: from this block's own outputs first,
|
|
172
|
+
* then earlier-indexed outputs from the DB. Inputs that already carry an address are skipped.
|
|
188
173
|
*/
|
|
189
174
|
private resolveInputs;
|
|
190
175
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* @returns {Promise<Epoch>} epoch entity data
|
|
176
|
+
* Settle the fee of phase-2-invalid transactions (collateral inputs minus collateral return)
|
|
177
|
+
* and the block total. The declared fee is kept when the mapper already set it via
|
|
178
|
+
* `total_collateral` or a collateral input is not indexed locally (the sum would be short).
|
|
195
179
|
*/
|
|
196
|
-
|
|
180
|
+
private applyCollateralFees;
|
|
197
181
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
indexAccount(tx: CapTransaction, stakeAddress: string): Promise<Account>;
|
|
182
|
+
* Mint/burn rows for a block from data in hand: the ledger's mint field when the source
|
|
183
|
+
* reports it (Ogmios, Koios), else Σ outputs − Σ inputs per unit, excluding reference and
|
|
184
|
+
* collateral inputs. A tx with an unresolvable consumed input is skipped and logged.
|
|
185
|
+
*/
|
|
186
|
+
private buildAssetHistoryRows;
|
|
204
187
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
188
|
+
* Keep the `Assets` catalogue complete for every unit the crawl meets, without provider calls.
|
|
189
|
+
* `Assets` is temporal, key `(validFrom, unit)`: the bare row's fixed epoch-zero stamp never
|
|
190
|
+
* aliases an enriched slice, so the UPSERT is safe inside the block transaction. The existence
|
|
191
|
+
* check uses the DB-level entity: the service projection's temporal filter hides such rows.
|
|
209
192
|
*/
|
|
210
|
-
|
|
193
|
+
private ensureAssetRows;
|
|
211
194
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* @param poolId pool id (hex)
|
|
215
|
-
* @returns {Promise<Pool>} pool entity data
|
|
195
|
+
* Remember a unit as present in the catalogue. Insertion-ordered eviction keeps a long
|
|
196
|
+
* backfill's memory flat; losing an entry costs one SELECT, never a wrong write.
|
|
216
197
|
*/
|
|
217
|
-
|
|
198
|
+
private noteAssetSeen;
|
|
218
199
|
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* @
|
|
222
|
-
* @returns {Promise<Asset>} asset entity data
|
|
200
|
+
* Snapshot every pool and DRep for an epoch in its OWN transaction (after the block commit):
|
|
201
|
+
* dated snapshot rows plus a refresh of the live `Pools` / `Dreps` rows. Needs Koios, else a no-op.
|
|
202
|
+
* @returns counts written
|
|
223
203
|
*/
|
|
204
|
+
snapshotEpoch(epoch: number, at: {
|
|
205
|
+
slot: number;
|
|
206
|
+
time: number;
|
|
207
|
+
}): Promise<{
|
|
208
|
+
pools: number;
|
|
209
|
+
dreps: number;
|
|
210
|
+
}>;
|
|
211
|
+
/** Every native-asset unit a block touches: outputs, consumed inputs and mint/burn rows. */
|
|
212
|
+
private collectBlockUnits;
|
|
213
|
+
/** Index an epoch by number. */
|
|
214
|
+
indexEpoch(tx: CapTransaction, epochNumber: number): Promise<Epoch>;
|
|
215
|
+
/** Index an account by stake address, plus its addresses when it has any. */
|
|
216
|
+
indexAccount(tx: CapTransaction, stakeAddress: string): Promise<Account>;
|
|
217
|
+
/** Index a DRep by bech32 id. */
|
|
218
|
+
indexDrep(tx: CapTransaction, drepId: string): Promise<Drep>;
|
|
219
|
+
/** Index a pool by id. */
|
|
220
|
+
indexPool(tx: CapTransaction, poolId: string): Promise<Pool>;
|
|
221
|
+
/** Index an asset by unit (policyId + assetNameHex). */
|
|
224
222
|
indexAsset(tx: CapTransaction, unit: string): Promise<Asset>;
|
|
225
223
|
/**
|
|
226
|
-
* Index
|
|
227
|
-
*
|
|
228
|
-
* UPSERTs entries by (unit, txHash) — events are immutable, so re-fetching
|
|
229
|
-
* just refreshes the cap of recent entries; older cached entries persist.
|
|
230
|
-
* @param tx CAP transaction object
|
|
231
|
-
* @param unit asset unit (policyId + assetNameHex)
|
|
232
|
-
* @param limit max number of recent events to fetch (default 100)
|
|
233
|
-
* @returns {Promise<AssetHistory[]>} list of mint/burn event entity rows
|
|
224
|
+
* Index mint/burn history for an asset, always fresh. Rows are keyed (unit, txHash), so a
|
|
225
|
+
* refetch refreshes the recent cap and older cached entries persist.
|
|
234
226
|
*/
|
|
235
227
|
indexAssetHistory(tx: CapTransaction, unit: string, limit?: number): Promise<AssetHistory[]>;
|
|
236
|
-
/**
|
|
237
|
-
* Common method: build a transaction, persist build result with inputs/outputs/address associations.
|
|
238
|
-
* All four public indexBuild*Result methods delegate to this to eliminate duplication.
|
|
239
|
-
* @param tx CAP transaction object
|
|
240
|
-
* @param buildreq transaction build request data
|
|
241
|
-
* @param buildFn the specific builder method to call
|
|
242
|
-
* @returns {Promise<TransactionBuild>} transaction build entity data
|
|
243
|
-
*/
|
|
228
|
+
/** Build a transaction and persist the build result with inputs/outputs/address association. */
|
|
244
229
|
private _indexBuildResult;
|
|
245
230
|
indexSimpleBuildResult(tx: CapTransaction, buildreq: TxBuildRequest): Promise<TransactionBuild>;
|
|
246
231
|
indexMetadataBuildResult(tx: CapTransaction, buildreq: TxBuildRequest): Promise<TransactionBuild>;
|
|
247
232
|
indexMultiAssetBuildResult(tx: CapTransaction, buildreq: TxBuildRequest): Promise<TransactionBuild>;
|
|
248
233
|
indexMintBuildResult(tx: CapTransaction, buildreq: TxBuildRequest): Promise<TransactionBuild>;
|
|
249
234
|
indexPlutusSpendBuildResult(tx: CapTransaction, buildreq: TxBuildRequest): Promise<TransactionBuild>;
|
|
250
|
-
/**
|
|
251
|
-
* Index & return the protocol parameters data
|
|
252
|
-
* @param tx CAP transaction object
|
|
253
|
-
* @returns {Promise<LedgerProtocolParameter>} protocol parameters entity data
|
|
254
|
-
*/
|
|
235
|
+
/** Protocol parameters, served from the DB row within a 5-minute TTL. */
|
|
255
236
|
indexProtocolParameters(tx: CapTransaction): Promise<LedgerProtocolParameter>;
|
|
256
|
-
/**
|
|
257
|
-
* Persist a transaction submission with optional build association
|
|
258
|
-
* Handles: TransactionSubmission insert, optional Build status update
|
|
259
|
-
* @param tx CAP transaction object
|
|
260
|
-
* @param params submission parameters
|
|
261
|
-
* @returns {Promise<TransactionSubmission>} persisted transaction submission entity
|
|
262
|
-
*/
|
|
237
|
+
/** Persist a transaction submission and flag the build as submitted when linked. */
|
|
263
238
|
persistTransactionSubmission(tx: CapTransaction, params: {
|
|
264
239
|
signedTxCbor: string;
|
|
265
240
|
txHash: string;
|
|
266
241
|
buildId?: string | null;
|
|
267
242
|
}): Promise<TransactionSubmission>;
|
|
268
|
-
/**
|
|
269
|
-
* Update the status of a transaction submission
|
|
270
|
-
* Used for the two-phase submit flow: pending → submitted (or failed)
|
|
271
|
-
* @param tx CAP transaction object
|
|
272
|
-
* @param submissionId the submission to update
|
|
273
|
-
* @param status new status value
|
|
274
|
-
* @param errorMessage optional error message for failed status
|
|
275
|
-
*/
|
|
243
|
+
/** Update a submission's status (two-phase submit: pending → submitted or failed). */
|
|
276
244
|
updateSubmissionStatus(tx: CapTransaction, submissionId: string, status: string, errorMessage?: string): Promise<void>;
|
|
277
|
-
/**
|
|
278
|
-
* Persist a new signing request
|
|
279
|
-
* @param tx CAP transaction object
|
|
280
|
-
* @param params signing request parameters from external signer module
|
|
281
|
-
* @returns persisted signing request record
|
|
282
|
-
*/
|
|
245
|
+
/** Persist a new signing request and link it to the build's sender address. */
|
|
283
246
|
persistSigningRequest(tx: CapTransaction, params: {
|
|
284
247
|
buildId: string;
|
|
285
248
|
signingPayload: {
|
|
@@ -308,13 +271,7 @@ export declare class CardanoIndexer {
|
|
|
308
271
|
cardanoCliCommand: string | undefined;
|
|
309
272
|
cip30TxCbor: string | undefined;
|
|
310
273
|
}>;
|
|
311
|
-
/**
|
|
312
|
-
* Persist a signature verification with signing request status update
|
|
313
|
-
* Handles: SignatureVerification insert, SigningRequest status update
|
|
314
|
-
* @param tx CAP transaction object
|
|
315
|
-
* @param params verification parameters
|
|
316
|
-
* @returns persisted signature verification record
|
|
317
|
-
*/
|
|
274
|
+
/** Persist a signature verification and update the signing request status. */
|
|
318
275
|
persistSignatureVerification(tx: CapTransaction, params: {
|
|
319
276
|
signingRequestId: string;
|
|
320
277
|
signedTxCbor: string;
|
|
@@ -340,13 +297,7 @@ export declare class CardanoIndexer {
|
|
|
340
297
|
warnings: string;
|
|
341
298
|
verifiedAt: string;
|
|
342
299
|
}>;
|
|
343
|
-
/**
|
|
344
|
-
* Index a verified transaction submission with all related records
|
|
345
|
-
* Handles persistence of: SignatureVerification, TransactionSubmission, SigningRequest update, Build update
|
|
346
|
-
* @param tx CAP transaction object
|
|
347
|
-
* @param params submission parameters
|
|
348
|
-
* @returns {Promise<TransactionSubmission>} transaction submission entity data
|
|
349
|
-
*/
|
|
300
|
+
/** Persist a verified submission: verification, submission, signing request and build updates. */
|
|
350
301
|
indexVerifiedTransactionSubmission(tx: CapTransaction, params: {
|
|
351
302
|
signingRequestId: string;
|
|
352
303
|
buildId: string;
|
|
@@ -361,38 +312,23 @@ export declare class CardanoIndexer {
|
|
|
361
312
|
signerType?: string;
|
|
362
313
|
signerInfo?: string;
|
|
363
314
|
}): Promise<TransactionSubmission>;
|
|
364
|
-
/**
|
|
365
|
-
* Index & return the latest epoch information data
|
|
366
|
-
* @param tx CAP transaction object
|
|
367
|
-
* @returns {Promise<Epoch>} epoch entity data
|
|
368
|
-
*/
|
|
315
|
+
/** Index the latest epoch. */
|
|
369
316
|
indexLatestEpoch(tx: CapTransaction): Promise<Epoch>;
|
|
370
|
-
/**
|
|
371
|
-
* Index & return the latest block information data
|
|
372
|
-
* @param tx CAP transaction object
|
|
373
|
-
* @returns {Promise<Block>} block entity data
|
|
374
|
-
*/
|
|
317
|
+
/** Index the latest block, with best-effort epoch enrichment. */
|
|
375
318
|
indexLatestBlock(tx: CapTransaction): Promise<Block>;
|
|
376
319
|
/** Max addresses to index concurrently (avoid overloading backends) */
|
|
377
320
|
private static readonly ADDR_CONCURRENCY;
|
|
321
|
+
/** Block position of a transaction already in the local index (crawled or cached), or null. */
|
|
322
|
+
findIndexedTransaction(tx: CapTransaction, txHash: string): Promise<{
|
|
323
|
+
slot: number | null;
|
|
324
|
+
blockHeight: number | null;
|
|
325
|
+
} | null>;
|
|
378
326
|
/**
|
|
379
|
-
* Ensure a set of transactions
|
|
380
|
-
*
|
|
381
|
-
* 2. Check which hashes already exist in DB
|
|
382
|
-
* 3. Batch-fetch missing transactions from backend
|
|
383
|
-
* 4. UPSERT all entities (Transactions, Inputs, Outputs, Assets, Metadata)
|
|
384
|
-
*
|
|
385
|
-
* @param tx CAP transaction (cds.tx)
|
|
386
|
-
* @param txHashes array of transaction hashes to ensure
|
|
387
|
-
* @returns Map of txHash → provider Transaction (all requested, from DB fetch or backend)
|
|
327
|
+
* Ensure a set of transactions is indexed: DB check, batch fetch of the missing ones, UPSERT.
|
|
328
|
+
* @returns provider transactions for the hashes that had to be fetched
|
|
388
329
|
*/
|
|
389
330
|
ensureTransactionsIndexed(tx: CapTransaction, txHashes: string[]): Promise<Map<string, ProviderTransaction>>;
|
|
390
|
-
/**
|
|
391
|
-
* Index multiple addresses with concurrency-limited parallelism.
|
|
392
|
-
* Processes addresses in chunks to avoid overwhelming backends.
|
|
393
|
-
* @param tx CAP transaction object
|
|
394
|
-
* @param bech32List array of bech32 addresses
|
|
395
|
-
*/
|
|
331
|
+
/** Index addresses with bounded concurrency. */
|
|
396
332
|
private _ensureAddresses;
|
|
397
333
|
}
|
|
398
334
|
//# sourceMappingURL=cardano-indexer.d.ts.map
|