@odatano/core 2.0.0-rc.2 → 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 +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 +224 -0
- 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 +316 -0
- package/@cds-models/odatano/cardano/index.js +33 -0
- package/README.md +195 -136
- package/db/schema.cds +2121 -1633
- package/package.json +179 -173
- 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 +78 -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 +292 -202
- package/srv/blockchain/backends/ogmios-backend.d.ts +59 -96
- package/srv/blockchain/backends/ogmios-backend.js +241 -153
- 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 +50 -205
- package/srv/blockchain/cardano-client.js +80 -224
- package/srv/blockchain/cardano-indexer.d.ts +146 -244
- package/srv/blockchain/cardano-indexer.js +442 -285
- 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 +121 -53
- package/srv/blockchain/crawler/crawler.js +402 -82
- 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/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 +34 -90
- 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 +133 -195
- 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 +89 -0
- package/srv/utils/db-sanitize.d.ts +27 -0
- package/srv/utils/db-sanitize.js +85 -0
- package/srv/utils/error-codes.d.ts +18 -73
- package/srv/utils/error-codes.js +17 -70
- package/srv/utils/errors.d.ts +34 -178
- package/srv/utils/errors.js +55 -217
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +41 -0
- package/srv/utils/mappers.d.ts +82 -210
- package/srv/utils/mappers.js +272 -293
- 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 +112 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +19 -89
- package/srv/utils/validators.js +31 -138
|
@@ -1,73 +1,164 @@
|
|
|
1
|
-
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Cardano Indexer Service (v2.0)
|
|
5
|
-
*
|
|
6
|
-
* Control + observability surface for the chain crawler / pre-sync engine:
|
|
7
|
-
* - read-only projections of the sync cursor and reorg audit log
|
|
8
|
-
* - status function + pause/resume actions delegating to the crawler singleton
|
|
9
|
-
*
|
|
10
|
-
* Security note: see CardanoODataService (cardano-service.cds) for the rationale on
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
@requires:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
@
|
|
28
|
-
@
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@title : '
|
|
40
|
-
@description: '
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
using {odatano.cardano as db} from '../db/schema';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cardano Indexer Service (v2.0)
|
|
5
|
+
*
|
|
6
|
+
* Control + observability surface for the chain crawler / pre-sync engine:
|
|
7
|
+
* - read-only projections of the sync cursor and reorg audit log
|
|
8
|
+
* - status function + pause/resume actions delegating to the crawler singleton
|
|
9
|
+
*
|
|
10
|
+
* Security note: see CardanoODataService (cardano-service.cds) for the rationale on
|
|
11
|
+
* auth. pause/resume are operational actions — gate behind a dedicated Admin scope.
|
|
12
|
+
* Read-only status and audit data remain available to authenticated users.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately NO service-level @requires: CAP checks a service-level requirement
|
|
15
|
+
* on every request BEFORE the operation's own annotation, so an operation-level
|
|
16
|
+
* `@requires: 'any'` can never open a single function on an otherwise
|
|
17
|
+
* authenticated service (anonymous callers get the 401 challenge first). The
|
|
18
|
+
* requirement therefore sits on each element, and getLiveness() alone is 'any'.
|
|
19
|
+
*/
|
|
20
|
+
// Service-level 'any' on purpose: CAP authorizes the service BEFORE the operation and
|
|
21
|
+
// treats a service without a service-level @requires as authenticated-user under
|
|
22
|
+
// NODE_ENV=production, which would 401 the anonymous operation below despite its own
|
|
23
|
+
// 'any'. Every element carries its requirement; the service itself refuses nothing.
|
|
24
|
+
@requires: 'any'
|
|
25
|
+
service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
26
|
+
|
|
27
|
+
@readonly
|
|
28
|
+
@requires : 'authenticated-user'
|
|
29
|
+
@title : 'Sync State'
|
|
30
|
+
@description: 'Singleton crawl cursor — pre-sync progress, tip lag, status, errors'
|
|
31
|
+
entity SyncState as projection on db.CardanoSyncState;
|
|
32
|
+
|
|
33
|
+
@readonly
|
|
34
|
+
@requires : 'authenticated-user'
|
|
35
|
+
@title : 'Reorg Log'
|
|
36
|
+
@description: 'Audit trail of chain rollbacks handled by the crawler'
|
|
37
|
+
entity ReorgLog as projection on db.CardanoReorgLog;
|
|
38
|
+
|
|
39
|
+
@title : 'Crawler Status'
|
|
40
|
+
@description: 'Live crawler status summary (numeric fields as strings, CAP-10 aligned)'
|
|
41
|
+
type CrawlerStatus {
|
|
42
|
+
running : Boolean;
|
|
43
|
+
syncStatus : String;
|
|
44
|
+
// 'chain-sync' | 'pagination' for the crawler in this process; null when this
|
|
45
|
+
// instance is not the one crawling. Pagination is ~50x slower, and a crawl that
|
|
46
|
+
// degraded to it still advances the cursor — this is how an operator tells.
|
|
47
|
+
source : String;
|
|
48
|
+
lastSlot : String;
|
|
49
|
+
lastHeight : String;
|
|
50
|
+
tipHeight : String;
|
|
51
|
+
syncProgress : String;
|
|
52
|
+
consecutiveErrors : Integer;
|
|
53
|
+
// crawler-fed ledger state (crawler.utxoSet): snapshot anchor + validity
|
|
54
|
+
utxoSet : UtxoSetStatus;
|
|
55
|
+
// one-off certificate/withdrawal backfill over already crawled blocks (this process)
|
|
56
|
+
certificateBackfill : CertificateBackfillStatus;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@title : 'Certificate Backfill Status'
|
|
60
|
+
@description: 'Progress of the certificate/withdrawal backfill started with backfillCertificates; process-local, none after a restart'
|
|
61
|
+
type CertificateBackfillStatus {
|
|
62
|
+
status : String; // none | running | done | failed
|
|
63
|
+
fromSlot : String;
|
|
64
|
+
toSlot : String;
|
|
65
|
+
atSlot : String; // last slot handled
|
|
66
|
+
blocks : Integer64;
|
|
67
|
+
certificates : Integer64;
|
|
68
|
+
withdrawals : Integer64;
|
|
69
|
+
startedAt : Timestamp;
|
|
70
|
+
finishedAt : Timestamp;
|
|
71
|
+
error : String;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@title : 'Certificate Backfill Result'
|
|
75
|
+
type CertificateBackfillResult {
|
|
76
|
+
accepted : Boolean;
|
|
77
|
+
fromSlot : String;
|
|
78
|
+
toSlot : String;
|
|
79
|
+
message : String;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@title : 'UTxO Set Status'
|
|
83
|
+
@description: 'State of the crawler-maintained UTxO set (crawler.utxoSet)'
|
|
84
|
+
type UtxoSetStatus {
|
|
85
|
+
enabled : Boolean; // crawler.utxoSet configured
|
|
86
|
+
status : String; // none | importing | active | invalid
|
|
87
|
+
anchorSlot : String; // null until imported
|
|
88
|
+
anchorHash : String;
|
|
89
|
+
importedAt : Timestamp;
|
|
90
|
+
error : String; // why invalid
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@title : 'UTxO Set Import Result'
|
|
94
|
+
type UtxoSetImportResult {
|
|
95
|
+
accepted : Boolean;
|
|
96
|
+
anchorSlot : String;
|
|
97
|
+
anchorHash : String;
|
|
98
|
+
message : String;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@title : 'Get Crawler Status'
|
|
102
|
+
@description: 'Return the current crawler run state and sync progress'
|
|
103
|
+
/**
|
|
104
|
+
* Emitted AFTER each block is committed. Subscribe instead of polling:
|
|
105
|
+
* (await cds.connect.to('CardanoIndexerService')).on('blockIndexed', ({ data }) => …)
|
|
106
|
+
* In-process (plugin mode) this needs no messaging service.
|
|
107
|
+
*/
|
|
108
|
+
event blockIndexed {
|
|
109
|
+
hash : String(64);
|
|
110
|
+
slot : Integer64;
|
|
111
|
+
height : Integer64;
|
|
112
|
+
txHashes : many String(64);
|
|
113
|
+
tipSlot : Integer64;
|
|
114
|
+
tipHeight: Integer64;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Emitted AFTER a rollback is committed. Everything above `forkSlot` was removed. */
|
|
118
|
+
event reorg {
|
|
119
|
+
forkSlot : Integer64;
|
|
120
|
+
forkHeight : Integer64;
|
|
121
|
+
blocksRolledBack : Integer;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@requires : 'authenticated-user'
|
|
125
|
+
function getStatus() returns CrawlerStatus;
|
|
126
|
+
|
|
127
|
+
@title : 'Liveness'
|
|
128
|
+
type Liveness {
|
|
129
|
+
status : String; // 'alive'
|
|
130
|
+
timestamp : Timestamp;
|
|
131
|
+
uptime : Integer; // seconds since process start
|
|
132
|
+
version : String; // @odatano/core version
|
|
133
|
+
network : String; // configured network
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Anonymous on purpose: a liveness probe carries no credentials. 200 as long
|
|
137
|
+
// as the process answers — no backend or DB probe, no secrets, no backend
|
|
138
|
+
// names, no API key state. Readiness stays with getStatus and the worker
|
|
139
|
+
// status, which remain authenticated.
|
|
140
|
+
@title : 'Get Liveness'
|
|
141
|
+
@description: 'Unauthenticated liveness probe: 200 while the process answers. Docker HEALTHCHECK and upstream probes use this instead of the service document.'
|
|
142
|
+
@requires : 'any'
|
|
143
|
+
function getLiveness() returns Liveness;
|
|
144
|
+
|
|
145
|
+
@title : 'Pause Crawler'
|
|
146
|
+
@description: 'Stop the crawler (closes the chain-sync stream). Resume continues from the cursor.'
|
|
147
|
+
@requires : 'Admin'
|
|
148
|
+
action pauseCrawler() returns Boolean;
|
|
149
|
+
|
|
150
|
+
@title : 'Resume Crawler'
|
|
151
|
+
@description: 'Start/restart the crawler from the persisted cursor using the configured source.'
|
|
152
|
+
@requires : 'Admin'
|
|
153
|
+
action resumeCrawler() returns Boolean;
|
|
154
|
+
|
|
155
|
+
@title : 'Import UTxO Set'
|
|
156
|
+
@description: 'One-off import of the UTxO set that anchors crawler.utxoSet. Pause the crawler first. source=ogmios acquires the set at the crawler cursor (crawl must be at the tip); source=file loads a cardano-cli query utxo --whole-utxo dump (.json, or .ndjson from jq -c to_entries[]) taken at anchorSlot/anchorHash. Runs in the background; progress via getStatus().utxoSet.'
|
|
157
|
+
@requires : 'Admin'
|
|
158
|
+
action importUtxoSet(source: String, filePath: String, anchorSlot: Integer64, anchorHash: String) returns UtxoSetImportResult;
|
|
159
|
+
|
|
160
|
+
@title : 'Backfill Certificates'
|
|
161
|
+
@description: 'Fill TransactionCertificates and TransactionWithdrawals for blocks the crawl already holds, from a second chain-sync stream (Ogmios). fromSlot defaults to the crawl start, toSlot to the cursor. Writes only those two tables; the crawler may keep running. Runs in the background; progress via getStatus().certificateBackfill.'
|
|
162
|
+
@requires : 'Admin'
|
|
163
|
+
action backfillCertificates(fromSlot: Integer64, toSlot: Integer64) returns CertificateBackfillResult;
|
|
164
|
+
}
|
|
@@ -8,15 +8,36 @@ const backend_request_handler_1 = require("./utils/backend-request-handler");
|
|
|
8
8
|
const errors_1 = require("./utils/errors");
|
|
9
9
|
const crawler_1 = require("./blockchain/crawler");
|
|
10
10
|
const sync_state_1 = require("./blockchain/crawler/sync-state");
|
|
11
|
+
const utxo_set_import_1 = require("./blockchain/crawler/utxo-set-import");
|
|
12
|
+
const certificate_backfill_1 = require("./blockchain/crawler/certificate-backfill");
|
|
13
|
+
const validators_1 = require("./utils/validators");
|
|
11
14
|
const server_1 = require("./server");
|
|
15
|
+
const liveness_1 = require("./utils/liveness");
|
|
12
16
|
const logger = cds_1.default.log('CardanoIndexerService');
|
|
17
|
+
/** One import at a time per process; the promise is only used as the busy flag. */
|
|
18
|
+
let utxoSetImportInFlight = null;
|
|
19
|
+
/** Set while a start request is validated, so a second request cannot start a parallel run. */
|
|
20
|
+
let certificateBackfillStarting = false;
|
|
21
|
+
let certificateBackfill = {
|
|
22
|
+
status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0,
|
|
23
|
+
startedAt: null, finishedAt: null, error: null,
|
|
24
|
+
};
|
|
25
|
+
function utxoSetConfigured() {
|
|
26
|
+
try {
|
|
27
|
+
return Boolean((0, server_1.loadCrawlerConfigFromEnv)()?.utxoSet);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
13
33
|
/**
|
|
14
|
-
* CardanoIndexerService handlers
|
|
15
|
-
* singleton (srv/blockchain/crawler).
|
|
16
|
-
* cursor and starts/stops the crawler.
|
|
34
|
+
* CardanoIndexerService handlers: control/observability surface over the crawler
|
|
35
|
+
* singleton (srv/blockchain/crawler). Reads the cursor and starts/stops the crawler.
|
|
17
36
|
*/
|
|
18
37
|
module.exports = (srv) => {
|
|
19
|
-
//
|
|
38
|
+
// getLiveness — unauthenticated probe (@requires: 'any'); no handleRequest, no app context.
|
|
39
|
+
srv.on('getLiveness', async () => (0, liveness_1.buildLiveness)());
|
|
40
|
+
// getStatus — live run state + sync progress (numeric fields as strings, CAP 10 convention)
|
|
20
41
|
srv.on('getStatus', async (req) => {
|
|
21
42
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
22
43
|
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
@@ -26,11 +47,138 @@ module.exports = (srv) => {
|
|
|
26
47
|
return {
|
|
27
48
|
running: (0, sync_state_1.isCrawlerLeaseActive)(cursor),
|
|
28
49
|
syncStatus: cursor?.syncStatus ?? 'stopped',
|
|
50
|
+
// Process-local: a standby without the lease or a stopped crawler reports null.
|
|
51
|
+
source: (0, crawler_1.getCrawler)()?.getActiveSource() ?? null,
|
|
29
52
|
lastSlot: String(cursor?.lastSlot ?? 0),
|
|
30
53
|
lastHeight: String(lastHeight),
|
|
31
54
|
tipHeight: String(tipHeight),
|
|
32
55
|
syncProgress: progress.toFixed(2),
|
|
33
56
|
consecutiveErrors: cursor?.consecutiveErrors ?? 0,
|
|
57
|
+
utxoSet: {
|
|
58
|
+
enabled: utxoSetConfigured(),
|
|
59
|
+
status: utxoSetImportInFlight ? 'importing' : (cursor?.utxoSet?.status ?? 'none'),
|
|
60
|
+
anchorSlot: cursor?.utxoSet?.anchorSlot == null ? null : String(cursor.utxoSet.anchorSlot),
|
|
61
|
+
anchorHash: cursor?.utxoSet?.anchorHash ?? null,
|
|
62
|
+
importedAt: cursor?.utxoSet?.importedAt ?? null,
|
|
63
|
+
error: cursor?.utxoSet?.error ?? null,
|
|
64
|
+
},
|
|
65
|
+
certificateBackfill: {
|
|
66
|
+
status: certificateBackfill.status,
|
|
67
|
+
fromSlot: String(certificateBackfill.fromSlot),
|
|
68
|
+
toSlot: String(certificateBackfill.toSlot),
|
|
69
|
+
atSlot: String(certificateBackfill.atSlot),
|
|
70
|
+
blocks: certificateBackfill.blocks,
|
|
71
|
+
certificates: certificateBackfill.certificates,
|
|
72
|
+
withdrawals: certificateBackfill.withdrawals,
|
|
73
|
+
startedAt: certificateBackfill.startedAt,
|
|
74
|
+
finishedAt: certificateBackfill.finishedAt,
|
|
75
|
+
error: certificateBackfill.error,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
// backfillCertificates — second chain-sync stream over already crawled blocks; writes the
|
|
81
|
+
// certificate and withdrawal tables only. Validates, then runs detached.
|
|
82
|
+
srv.on('backfillCertificates', async (req) => {
|
|
83
|
+
const data = (req.data ?? {});
|
|
84
|
+
if (data.fromSlot != null && !Number.isInteger(Number(data.fromSlot)))
|
|
85
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillCertificates', 'fromSlot must be an integer', 'fromSlot');
|
|
86
|
+
if (data.toSlot != null && !Number.isInteger(Number(data.toSlot)))
|
|
87
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillCertificates', 'toSlot must be an integer', 'toSlot');
|
|
88
|
+
if (certificateBackfill.status === 'running' || certificateBackfillStarting)
|
|
89
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillCertificates', 'A certificate backfill is already running');
|
|
90
|
+
if (!(0, server_1.getCardanoClient)().getChainSyncBackend())
|
|
91
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillCertificates', 'No chain-sync backend available (needs Ogmios)');
|
|
92
|
+
certificateBackfillStarting = true;
|
|
93
|
+
try {
|
|
94
|
+
return await (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
95
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
96
|
+
if (!cursor)
|
|
97
|
+
throw new errors_1.TransactionValidationError('No crawler cursor yet — the backfill covers crawled blocks only.');
|
|
98
|
+
const fromSlot = data.fromSlot != null ? Number(data.fromSlot) : (cursor.startSlot ?? 0);
|
|
99
|
+
const toSlot = data.toSlot != null ? Number(data.toSlot) : cursor.lastSlot;
|
|
100
|
+
if (toSlot < fromSlot)
|
|
101
|
+
throw new errors_1.TransactionValidationError(`toSlot ${toSlot} lies before fromSlot ${fromSlot}.`);
|
|
102
|
+
if (toSlot > cursor.lastSlot)
|
|
103
|
+
throw new errors_1.TransactionValidationError(`toSlot ${toSlot} is past the crawler cursor (slot ${cursor.lastSlot}) — only crawled blocks can be backfilled.`);
|
|
104
|
+
certificateBackfill = {
|
|
105
|
+
status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0,
|
|
106
|
+
startedAt: new Date().toISOString(), finishedAt: null, error: null,
|
|
107
|
+
};
|
|
108
|
+
void (0, certificate_backfill_1.backfillCertificates)({
|
|
109
|
+
client: (0, server_1.getCardanoClient)(), fromSlot, toSlot,
|
|
110
|
+
onProgress: (p) => {
|
|
111
|
+
Object.assign(certificateBackfill, p);
|
|
112
|
+
if (certificateBackfill.blocks % 20_000 < 200)
|
|
113
|
+
logger.info(`Certificate backfill at slot ${p.atSlot}: ${p.blocks} blocks, ${p.certificates} certificates, ${p.withdrawals} withdrawals`);
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
.then((r) => { Object.assign(certificateBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
|
|
117
|
+
.catch((err) => {
|
|
118
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
119
|
+
Object.assign(certificateBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
|
|
120
|
+
logger.error(`Certificate backfill failed: ${message}`);
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
accepted: true,
|
|
124
|
+
fromSlot: String(fromSlot),
|
|
125
|
+
toSlot: String(toSlot),
|
|
126
|
+
message: `Certificate backfill started for slots ${fromSlot}..${toSlot}; poll getStatus().certificateBackfill.`,
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
certificateBackfillStarting = false;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
// importUtxoSet — one-off snapshot import that anchors crawler.utxoSet. Validates, then
|
|
135
|
+
// runs detached; progress via getStatus().utxoSet.
|
|
136
|
+
srv.on('importUtxoSet', async (req) => {
|
|
137
|
+
const data = (req.data ?? {});
|
|
138
|
+
const source = data.source === 'file' || data.source === 'ogmios' ? data.source : null;
|
|
139
|
+
if (!source)
|
|
140
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'source must be "ogmios" or "file"', 'source');
|
|
141
|
+
if (source === 'file' && !data.filePath)
|
|
142
|
+
return (0, errors_1.rejectMissing)(req, 'importUtxoSet', 'filePath');
|
|
143
|
+
const anchorGiven = data.anchorSlot != null || !!data.anchorHash;
|
|
144
|
+
if (source === 'file' && !anchorGiven) {
|
|
145
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'source "file" needs anchorSlot + anchorHash: the tip at dump time', 'anchorSlot');
|
|
146
|
+
}
|
|
147
|
+
if (anchorGiven && (data.anchorSlot == null || !Number.isInteger(Number(data.anchorSlot)) || !(0, validators_1.isBlockHash)(data.anchorHash))) {
|
|
148
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'anchorSlot must be an integer and anchorHash a 64-hex block hash', 'anchorHash');
|
|
149
|
+
}
|
|
150
|
+
if ((0, crawler_1.isCrawlerRunning)())
|
|
151
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'Crawler is running in this process — pauseCrawler first');
|
|
152
|
+
if (utxoSetImportInFlight)
|
|
153
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'A UTxO set import is already running');
|
|
154
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
155
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
156
|
+
if (!cursor)
|
|
157
|
+
throw new errors_1.TransactionValidationError('No crawler cursor yet — start the crawler once before importing.');
|
|
158
|
+
if ((0, sync_state_1.isCrawlerLeaseActive)(cursor))
|
|
159
|
+
throw new errors_1.TransactionValidationError('Crawler is running (active lease) — pauseCrawler first.');
|
|
160
|
+
const anchor = anchorGiven
|
|
161
|
+
? { slot: Number(data.anchorSlot), hash: String(data.anchorHash).toLowerCase() }
|
|
162
|
+
: { slot: cursor.lastSlot, hash: cursor.lastBlockHash ?? '' };
|
|
163
|
+
if (!anchor.hash)
|
|
164
|
+
throw new errors_1.TransactionValidationError('Cursor has no block hash yet — pass anchorSlot + anchorHash.');
|
|
165
|
+
if (cursor.lastSlot > anchor.slot) {
|
|
166
|
+
throw new errors_1.TransactionValidationError(`Crawler cursor (slot ${cursor.lastSlot}) is past the anchor (slot ${anchor.slot}) — dump the set at or after the cursor.`);
|
|
167
|
+
}
|
|
168
|
+
utxoSetImportInFlight = (0, utxo_set_import_1.importUtxoSet)({
|
|
169
|
+
source, filePath: data.filePath, anchor,
|
|
170
|
+
client: (0, server_1.getCardanoClient)(), indexer: (0, server_1.getCardanoIndexer)(),
|
|
171
|
+
onProgress: (n) => { if (n % 100_000 === 0)
|
|
172
|
+
logger.info(`UTxO set import: ${n} entries`); },
|
|
173
|
+
})
|
|
174
|
+
.then((r) => logger.info(`UTxO set import done: ${r.utxos} entries at ${r.anchor.slot}/${r.anchor.hash}`))
|
|
175
|
+
.catch((err) => logger.error(`UTxO set import failed: ${err instanceof Error ? err.message : String(err)}`))
|
|
176
|
+
.finally(() => { utxoSetImportInFlight = null; });
|
|
177
|
+
return {
|
|
178
|
+
accepted: true,
|
|
179
|
+
anchorSlot: String(anchor.slot),
|
|
180
|
+
anchorHash: anchor.hash,
|
|
181
|
+
message: `UTxO set import started (source=${source}); poll getStatus().utxoSet, then resumeCrawler.`,
|
|
34
182
|
};
|
|
35
183
|
});
|
|
36
184
|
});
|
|
@@ -42,19 +190,16 @@ module.exports = (srv) => {
|
|
|
42
190
|
return true;
|
|
43
191
|
});
|
|
44
192
|
});
|
|
45
|
-
// resumeCrawler — (re)start from the persisted cursor
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
// NOTE: to apply CHANGED config to a running crawler, call pauseCrawler first —
|
|
49
|
-
// resume on a running crawler is a no-op by design.
|
|
193
|
+
// resumeCrawler — (re)start from the persisted cursor. Gated on config.enabled so an
|
|
194
|
+
// unconfigured crawler is never started (it would sync from genesis). Resume on a running
|
|
195
|
+
// crawler is a no-op; pauseCrawler first to apply changed config.
|
|
50
196
|
srv.on('resumeCrawler', async (req) => {
|
|
51
197
|
let config;
|
|
52
198
|
try {
|
|
53
199
|
config = (0, server_1.loadCrawlerConfigFromEnv)();
|
|
54
200
|
}
|
|
55
201
|
catch (err) {
|
|
56
|
-
// e.g.
|
|
57
|
-
// caller's 400, not a raw 500 from an escaping throw
|
|
202
|
+
// A config problem (e.g. enabled without a start block) is the caller's 400.
|
|
58
203
|
return (0, errors_1.rejectInvalid)(req, 'resumeCrawler', err instanceof Error ? err.message : String(err));
|
|
59
204
|
}
|
|
60
205
|
if (!config.enabled) {
|
package/srv/cardano-service.cds
CHANGED
|
@@ -62,6 +62,16 @@ service CardanoODataService @(impl: './cardano-service') {
|
|
|
62
62
|
@description: 'Projection for Dreps'
|
|
63
63
|
entity Dreps as projection on db.Dreps;
|
|
64
64
|
|
|
65
|
+
@readonly
|
|
66
|
+
@title : 'Pool Epoch Snapshots'
|
|
67
|
+
@description: 'Projection for per-epoch stake-pool snapshots written by the chain crawler'
|
|
68
|
+
entity PoolEpochSnapshots as projection on db.PoolEpochSnapshots;
|
|
69
|
+
|
|
70
|
+
@readonly
|
|
71
|
+
@title : 'DRep Epoch Snapshots'
|
|
72
|
+
@description: 'Projection for per-epoch DRep snapshots written by the chain crawler'
|
|
73
|
+
entity DrepEpochSnapshots as projection on db.DrepEpochSnapshots;
|
|
74
|
+
|
|
65
75
|
@readonly
|
|
66
76
|
@title : 'Assets'
|
|
67
77
|
@description: 'Projection for Native-Asset Information'
|
|
@@ -97,6 +107,41 @@ service CardanoODataService @(impl: './cardano-service') {
|
|
|
97
107
|
@description: 'Projection for Transaction Output Assets'
|
|
98
108
|
entity TransactionOutputAssets as projection on db.TransactionOutputAssets;
|
|
99
109
|
|
|
110
|
+
@readonly
|
|
111
|
+
@title : 'Transaction Certificates'
|
|
112
|
+
@description: 'Projection for Transaction Certificates (crawler-fed, crawler.certificates)'
|
|
113
|
+
entity TransactionCertificates as projection on db.TransactionCertificates;
|
|
114
|
+
|
|
115
|
+
@readonly
|
|
116
|
+
@title : 'Transaction Withdrawals'
|
|
117
|
+
@description: 'Projection for Transaction Withdrawals (crawler-fed, crawler.certificates)'
|
|
118
|
+
entity TransactionWithdrawals as projection on db.TransactionWithdrawals;
|
|
119
|
+
|
|
120
|
+
@readonly
|
|
121
|
+
@title : 'Ledger UTxOs'
|
|
122
|
+
@description: 'Crawler-maintained UTxO set (crawler.utxoSet); unspent while spentTxHash is null'
|
|
123
|
+
entity LedgerUTxOs as projection on db.LedgerUTxOs;
|
|
124
|
+
|
|
125
|
+
@readonly
|
|
126
|
+
@title : 'Ledger UTxO Assets'
|
|
127
|
+
@description: 'Native assets of a LedgerUTxOs row'
|
|
128
|
+
entity LedgerUTxOAssets as projection on db.LedgerUTxOAssets;
|
|
129
|
+
|
|
130
|
+
@readonly
|
|
131
|
+
@title : 'Ledger Addresses'
|
|
132
|
+
@description: 'Per-address balances from the crawler-maintained UTxO set (crawler.utxoSet)'
|
|
133
|
+
entity LedgerAddresses as projection on db.LedgerAddresses;
|
|
134
|
+
|
|
135
|
+
@readonly
|
|
136
|
+
@title : 'Ledger Address Assets'
|
|
137
|
+
@description: 'Native-asset balances per address (crawler.utxoSet)'
|
|
138
|
+
entity LedgerAddressAssets as projection on db.LedgerAddressAssets;
|
|
139
|
+
|
|
140
|
+
@readonly
|
|
141
|
+
@title : 'Ledger Accounts'
|
|
142
|
+
@description: 'Per-stake-key balances from the crawler-maintained UTxO set (crawler.utxoSet)'
|
|
143
|
+
entity LedgerAccounts as projection on db.LedgerAccounts;
|
|
144
|
+
|
|
100
145
|
@readonly
|
|
101
146
|
@title : 'Accounts'
|
|
102
147
|
@description: 'Projection for Accounts'
|