@odatano/core 2.0.0-rc.3 → 2.0.0-rc.30
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/CardanoBackendService/index.d.ts +357 -0
- package/@cds-models/CardanoBackendService/index.js +40 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +194 -2
- package/@cds-models/CardanoIndexerService/index.js +25 -0
- package/@cds-models/CardanoODataService/index.d.ts +294 -7
- package/@cds-models/CardanoODataService/index.js +33 -0
- package/@cds-models/CardanoSignService/index.d.ts +28 -3
- package/@cds-models/CardanoSignService/index.js +3 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +52 -19
- package/@cds-models/CardanoTransactionService/index.js +4 -0
- package/@cds-models/index.d.ts +18 -0
- package/@cds-models/index.js +3 -0
- package/@cds-models/odatano/cardano/index.d.ts +408 -7
- package/@cds-models/odatano/cardano/index.js +42 -0
- package/README.md +64 -5
- package/db/schema.cds +677 -13
- package/db/types.cds +27 -0
- package/package.json +182 -173
- package/scripts/migrate-slot-leader.mjs +104 -0
- package/scripts/migrate-txseq.mjs +147 -0
- package/src/index.d.ts +11 -10
- package/src/index.js +28 -14
- package/src/plugin.js +39 -52
- package/srv/blockchain/backends/blockfrost-backend.d.ts +29 -131
- package/srv/blockchain/backends/blockfrost-backend.js +49 -160
- package/srv/blockchain/backends/cardano-backend.d.ts +104 -158
- package/srv/blockchain/backends/cardano-backend.js +19 -5
- package/srv/blockchain/backends/koios-backend.d.ts +126 -60
- package/srv/blockchain/backends/koios-backend.js +356 -217
- package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
- package/srv/blockchain/backends/odatano-backend.js +170 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +162 -94
- package/srv/blockchain/backends/ogmios-backend.js +548 -197
- 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 +78 -205
- package/srv/blockchain/cardano-client.js +186 -242
- package/srv/blockchain/cardano-indexer.d.ts +302 -242
- package/srv/blockchain/cardano-indexer.js +1191 -362
- package/srv/blockchain/cardano-tx-builder.d.ts +43 -81
- package/srv/blockchain/cardano-tx-builder.js +177 -132
- package/srv/blockchain/crawler/certificate-backfill.d.ts +67 -0
- package/srv/blockchain/crawler/certificate-backfill.js +169 -0
- package/srv/blockchain/crawler/crawler.d.ts +139 -54
- package/srv/blockchain/crawler/crawler.js +478 -96
- 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 +46 -28
- package/srv/blockchain/crawler/sync-state.js +128 -43
- package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
- package/srv/blockchain/crawler/transaction-backfill.js +283 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +78 -0
- package/srv/blockchain/crawler/utxo-set-import.js +363 -0
- package/srv/blockchain/ledger-state.d.ts +101 -0
- package/srv/blockchain/ledger-state.js +432 -0
- package/srv/blockchain/pending-spends.d.ts +28 -0
- package/srv/blockchain/pending-spends.js +89 -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 -49
- package/srv/blockchain/stored-chain.d.ts +33 -0
- package/srv/blockchain/stored-chain.js +234 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +108 -160
- package/srv/blockchain/transaction-building/buildooor-tx.js +620 -285
- package/srv/blockchain/transaction-building/caller-datums.d.ts +17 -0
- package/srv/blockchain/transaction-building/caller-datums.js +50 -0
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +10 -35
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +43 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +4 -17
- package/srv/blockchain/wallet-worker/build-request.js +48 -24
- 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-backend-service.cds +52 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +244 -0
- package/srv/cardano-indexer-service.cds +201 -73
- package/srv/cardano-indexer-service.js +280 -11
- package/srv/cardano-service.cds +56 -1
- package/srv/cardano-service.js +52 -113
- package/srv/cardano-sign-service.cds +200 -180
- package/srv/cardano-sign-service.js +55 -173
- package/srv/cardano-tx-service.cds +439 -364
- package/srv/cardano-tx-service.js +305 -209
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.js +7 -15
- package/srv/cbor/parse.js +13 -1
- package/srv/server.d.ts +28 -86
- package/srv/server.js +127 -135
- 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 +922 -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 +30 -67
- package/srv/utils/const.js +32 -72
- 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 +94 -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 +20 -73
- package/srv/utils/error-codes.js +19 -70
- package/srv/utils/errors.d.ts +50 -177
- package/srv/utils/errors.js +94 -218
- package/srv/utils/liveness.d.ts +16 -0
- package/srv/utils/liveness.js +40 -0
- package/srv/utils/mappers.d.ts +128 -214
- package/srv/utils/mappers.js +354 -299
- package/srv/utils/network-context.js +2 -11
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +62 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +56 -0
- package/srv/utils/plutus-placeholders.d.ts +23 -16
- package/srv/utils/plutus-placeholders.js +63 -27
- 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 +26 -92
- package/srv/utils/tx-build-helper.js +68 -123
- package/srv/utils/tx-request-parsers.d.ts +107 -21
- package/srv/utils/tx-request-parsers.js +433 -34
- package/srv/utils/tx-utils.d.ts +4 -23
- package/srv/utils/tx-utils.js +12 -41
- package/srv/utils/types.d.ts +238 -169
- package/srv/utils/types.js +2 -6
- package/srv/utils/validators.d.ts +24 -90
- package/srv/utils/validators.js +50 -147
|
@@ -8,29 +8,301 @@ 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 transaction_backfill_1 = require("./blockchain/crawler/transaction-backfill");
|
|
14
|
+
const validators_1 = require("./utils/validators");
|
|
11
15
|
const server_1 = require("./server");
|
|
16
|
+
const liveness_1 = require("./utils/liveness");
|
|
17
|
+
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
18
|
+
const { SELECT } = cds_1.default.ql;
|
|
12
19
|
const logger = cds_1.default.log('CardanoIndexerService');
|
|
20
|
+
/** One import at a time per process; the promise is only used as the busy flag. */
|
|
21
|
+
let utxoSetImportInFlight = null;
|
|
22
|
+
/** Set while a start request is validated, so a second request cannot start a parallel run. */
|
|
23
|
+
let certificateBackfillStarting = false;
|
|
24
|
+
let certificateBackfill = {
|
|
25
|
+
status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0,
|
|
26
|
+
startedAt: null, finishedAt: null, error: null,
|
|
27
|
+
};
|
|
28
|
+
let transactionBackfillStarting = false;
|
|
29
|
+
let transactionBackfill = {
|
|
30
|
+
status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, rewritten: 0, skipped: 0,
|
|
31
|
+
startedAt: null, finishedAt: null, error: null,
|
|
32
|
+
};
|
|
33
|
+
/** Slot range of a backfill: defaults to crawl start .. cursor, never past the cursor. */
|
|
34
|
+
async function backfillRange(db, data) {
|
|
35
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
36
|
+
if (!cursor)
|
|
37
|
+
throw new errors_1.TransactionValidationError('No crawler cursor yet — the backfill covers crawled blocks only.');
|
|
38
|
+
const fromSlot = data.fromSlot != null ? Number(data.fromSlot) : (cursor.startSlot ?? 0);
|
|
39
|
+
const toSlot = data.toSlot != null ? Number(data.toSlot) : cursor.lastSlot;
|
|
40
|
+
if (toSlot < fromSlot)
|
|
41
|
+
throw new errors_1.TransactionValidationError(`toSlot ${toSlot} lies before fromSlot ${fromSlot}.`);
|
|
42
|
+
if (toSlot > cursor.lastSlot)
|
|
43
|
+
throw new errors_1.TransactionValidationError(`toSlot ${toSlot} is past the crawler cursor (slot ${cursor.lastSlot}) — only crawled blocks can be backfilled.`);
|
|
44
|
+
return { fromSlot, toSlot };
|
|
45
|
+
}
|
|
46
|
+
function utxoSetConfigured() {
|
|
47
|
+
try {
|
|
48
|
+
return Boolean((0, server_1.loadCrawlerConfigFromEnv)()?.utxoSet);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function epochSnapshotsConfigured() {
|
|
55
|
+
try {
|
|
56
|
+
return Boolean((0, server_1.loadCrawlerConfigFromEnv)()?.epochSnapshots);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Source the next epoch snapshot would use: the node's ledger first, Koios second. */
|
|
63
|
+
function epochSnapshotSource() {
|
|
64
|
+
try {
|
|
65
|
+
const client = (0, server_1.getCardanoClient)();
|
|
66
|
+
if (client.getEpochStateBackend())
|
|
67
|
+
return 'ogmios';
|
|
68
|
+
return client.getEnumeratingBackend() ? 'koios' : null;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
13
74
|
/**
|
|
14
|
-
* CardanoIndexerService handlers
|
|
15
|
-
* singleton (srv/blockchain/crawler).
|
|
16
|
-
* cursor and starts/stops the crawler.
|
|
75
|
+
* CardanoIndexerService handlers: control/observability surface over the crawler
|
|
76
|
+
* singleton (srv/blockchain/crawler). Reads the cursor and starts/stops the crawler.
|
|
17
77
|
*/
|
|
18
78
|
module.exports = (srv) => {
|
|
19
|
-
//
|
|
79
|
+
// getLiveness — unauthenticated probe (@requires: 'any'); no handleRequest, no app context.
|
|
80
|
+
srv.on('getLiveness', async () => (0, liveness_1.buildLiveness)());
|
|
81
|
+
// getStatus — live run state + sync progress (numeric fields as strings, CAP 10 convention)
|
|
20
82
|
srv.on('getStatus', async (req) => {
|
|
21
83
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
22
84
|
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
85
|
+
const lastSnapshot = await db.run(SELECT.one.from(cardano_1.EpochLedgerSnapshots).columns('epoch', 'source', 'snapshotSlot').orderBy('epoch desc'));
|
|
23
86
|
const lastHeight = cursor?.lastHeight ?? 0;
|
|
24
87
|
const tipHeight = cursor?.tipHeight ?? 0;
|
|
25
88
|
const progress = tipHeight > 0 ? Math.min(100, (lastHeight / tipHeight) * 100) : 0;
|
|
26
89
|
return {
|
|
27
90
|
running: (0, sync_state_1.isCrawlerLeaseActive)(cursor),
|
|
28
91
|
syncStatus: cursor?.syncStatus ?? 'stopped',
|
|
92
|
+
// Process-local: a standby without the lease or a stopped crawler reports null.
|
|
93
|
+
source: (0, crawler_1.getCrawler)()?.getActiveSource() ?? null,
|
|
29
94
|
lastSlot: String(cursor?.lastSlot ?? 0),
|
|
30
95
|
lastHeight: String(lastHeight),
|
|
31
96
|
tipHeight: String(tipHeight),
|
|
32
97
|
syncProgress: progress.toFixed(2),
|
|
33
98
|
consecutiveErrors: cursor?.consecutiveErrors ?? 0,
|
|
99
|
+
utxoSet: {
|
|
100
|
+
enabled: utxoSetConfigured(),
|
|
101
|
+
status: utxoSetImportInFlight ? 'importing' : (cursor?.utxoSet?.status ?? 'none'),
|
|
102
|
+
anchorSlot: cursor?.utxoSet?.anchorSlot == null ? null : String(cursor.utxoSet.anchorSlot),
|
|
103
|
+
anchorHash: cursor?.utxoSet?.anchorHash ?? null,
|
|
104
|
+
importedAt: cursor?.utxoSet?.importedAt ?? null,
|
|
105
|
+
error: cursor?.utxoSet?.error ?? null,
|
|
106
|
+
},
|
|
107
|
+
certificateBackfill: {
|
|
108
|
+
status: certificateBackfill.status,
|
|
109
|
+
fromSlot: String(certificateBackfill.fromSlot),
|
|
110
|
+
toSlot: String(certificateBackfill.toSlot),
|
|
111
|
+
atSlot: String(certificateBackfill.atSlot),
|
|
112
|
+
blocks: certificateBackfill.blocks,
|
|
113
|
+
certificates: certificateBackfill.certificates,
|
|
114
|
+
withdrawals: certificateBackfill.withdrawals,
|
|
115
|
+
startedAt: certificateBackfill.startedAt,
|
|
116
|
+
finishedAt: certificateBackfill.finishedAt,
|
|
117
|
+
error: certificateBackfill.error,
|
|
118
|
+
},
|
|
119
|
+
transactionBackfill: {
|
|
120
|
+
status: transactionBackfill.status,
|
|
121
|
+
fromSlot: String(transactionBackfill.fromSlot),
|
|
122
|
+
toSlot: String(transactionBackfill.toSlot),
|
|
123
|
+
atSlot: String(transactionBackfill.atSlot),
|
|
124
|
+
blocks: transactionBackfill.blocks,
|
|
125
|
+
transactions: transactionBackfill.transactions,
|
|
126
|
+
inputs: transactionBackfill.inputs,
|
|
127
|
+
redeemers: transactionBackfill.redeemers,
|
|
128
|
+
rewritten: transactionBackfill.rewritten,
|
|
129
|
+
skipped: transactionBackfill.skipped,
|
|
130
|
+
startedAt: transactionBackfill.startedAt,
|
|
131
|
+
finishedAt: transactionBackfill.finishedAt,
|
|
132
|
+
error: transactionBackfill.error,
|
|
133
|
+
},
|
|
134
|
+
epochSnapshots: {
|
|
135
|
+
enabled: epochSnapshotsConfigured(),
|
|
136
|
+
source: epochSnapshotSource(),
|
|
137
|
+
lastEpoch: lastSnapshot?.epoch ?? null,
|
|
138
|
+
lastSource: lastSnapshot?.source ?? null,
|
|
139
|
+
lastSlot: lastSnapshot?.snapshotSlot == null ? null : String(lastSnapshot.snapshotSlot),
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
// backfillCertificates — second chain-sync stream over already crawled blocks; writes the
|
|
145
|
+
// certificate and withdrawal tables only. Validates, then runs detached.
|
|
146
|
+
srv.on('backfillCertificates', async (req) => {
|
|
147
|
+
const data = (req.data ?? {});
|
|
148
|
+
if (data.fromSlot != null && !Number.isInteger(Number(data.fromSlot)))
|
|
149
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillCertificates', 'fromSlot must be an integer', 'fromSlot');
|
|
150
|
+
if (data.toSlot != null && !Number.isInteger(Number(data.toSlot)))
|
|
151
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillCertificates', 'toSlot must be an integer', 'toSlot');
|
|
152
|
+
if (certificateBackfill.status === 'running' || certificateBackfillStarting)
|
|
153
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillCertificates', 'A certificate backfill is already running');
|
|
154
|
+
if (!(0, server_1.getCardanoClient)().getChainSyncBackend())
|
|
155
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillCertificates', 'No chain-sync backend available (needs Ogmios)');
|
|
156
|
+
certificateBackfillStarting = true;
|
|
157
|
+
try {
|
|
158
|
+
return await (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
159
|
+
const { fromSlot, toSlot } = await backfillRange(db, data);
|
|
160
|
+
certificateBackfill = {
|
|
161
|
+
status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, certificates: 0, withdrawals: 0,
|
|
162
|
+
startedAt: new Date().toISOString(), finishedAt: null, error: null,
|
|
163
|
+
};
|
|
164
|
+
void (0, certificate_backfill_1.backfillCertificates)({
|
|
165
|
+
client: (0, server_1.getCardanoClient)(), fromSlot, toSlot,
|
|
166
|
+
onProgress: (p) => {
|
|
167
|
+
Object.assign(certificateBackfill, p);
|
|
168
|
+
if (certificateBackfill.blocks % 20_000 < 200)
|
|
169
|
+
logger.info(`Certificate backfill at slot ${p.atSlot}: ${p.blocks} blocks, ${p.certificates} certificates, ${p.withdrawals} withdrawals`);
|
|
170
|
+
},
|
|
171
|
+
})
|
|
172
|
+
.then((r) => { Object.assign(certificateBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
|
|
173
|
+
.catch((err) => {
|
|
174
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
175
|
+
Object.assign(certificateBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
|
|
176
|
+
logger.error(`Certificate backfill failed: ${message}`);
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
accepted: true,
|
|
180
|
+
fromSlot: String(fromSlot),
|
|
181
|
+
toSlot: String(toSlot),
|
|
182
|
+
message: `Certificate backfill started for slots ${fromSlot}..${toSlot}; poll getStatus().certificateBackfill.`,
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
certificateBackfillStarting = false;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
// backfillTransactions — second chain-sync stream over already crawled blocks; fills empty
|
|
191
|
+
// input fields (outpoint, datum, address) and the redeemers. Validates, then runs detached.
|
|
192
|
+
srv.on('backfillTransactions', async (req) => {
|
|
193
|
+
const data = (req.data ?? {});
|
|
194
|
+
if (data.fromSlot != null && !Number.isInteger(Number(data.fromSlot)))
|
|
195
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillTransactions', 'fromSlot must be an integer', 'fromSlot');
|
|
196
|
+
if (data.toSlot != null && !Number.isInteger(Number(data.toSlot)))
|
|
197
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillTransactions', 'toSlot must be an integer', 'toSlot');
|
|
198
|
+
if (transactionBackfill.status === 'running' || transactionBackfillStarting)
|
|
199
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillTransactions', 'A transaction backfill is already running');
|
|
200
|
+
if (!(0, server_1.getCardanoClient)().getChainSyncBackend())
|
|
201
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillTransactions', 'No chain-sync backend available (needs Ogmios)');
|
|
202
|
+
transactionBackfillStarting = true;
|
|
203
|
+
try {
|
|
204
|
+
return await (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
205
|
+
const { fromSlot, toSlot } = await backfillRange(db, data);
|
|
206
|
+
transactionBackfill = {
|
|
207
|
+
status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, rewritten: 0, skipped: 0,
|
|
208
|
+
startedAt: new Date().toISOString(), finishedAt: null, error: null,
|
|
209
|
+
};
|
|
210
|
+
void (0, transaction_backfill_1.backfillTransactions)({
|
|
211
|
+
client: (0, server_1.getCardanoClient)(), indexer: (0, server_1.getCardanoIndexer)(), fromSlot, toSlot,
|
|
212
|
+
onProgress: (p) => {
|
|
213
|
+
Object.assign(transactionBackfill, p);
|
|
214
|
+
if (transactionBackfill.blocks % 20_000 < 200)
|
|
215
|
+
logger.info(`Transaction backfill at slot ${p.atSlot}: ${p.blocks} blocks, ${p.inputs} inputs, ${p.redeemers} redeemers`);
|
|
216
|
+
},
|
|
217
|
+
})
|
|
218
|
+
.then((r) => { Object.assign(transactionBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
|
|
219
|
+
.catch((err) => {
|
|
220
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
221
|
+
Object.assign(transactionBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
|
|
222
|
+
logger.error(`Transaction backfill failed: ${message}`);
|
|
223
|
+
});
|
|
224
|
+
return {
|
|
225
|
+
accepted: true,
|
|
226
|
+
fromSlot: String(fromSlot),
|
|
227
|
+
toSlot: String(toSlot),
|
|
228
|
+
message: `Transaction backfill started for slots ${fromSlot}..${toSlot}; poll getStatus().transactionBackfill.`,
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
transactionBackfillStarting = false;
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
// importUtxoSet — one-off snapshot import that anchors crawler.utxoSet. Validates, then
|
|
237
|
+
// runs detached; progress via getStatus().utxoSet.
|
|
238
|
+
srv.on('importUtxoSet', async (req) => {
|
|
239
|
+
const data = (req.data ?? {});
|
|
240
|
+
if (data.source === 'aggregates') {
|
|
241
|
+
if ((0, crawler_1.isCrawlerRunning)())
|
|
242
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'Crawler is running in this process — pauseCrawler first');
|
|
243
|
+
if (utxoSetImportInFlight)
|
|
244
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'A UTxO set import is already running');
|
|
245
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
246
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
247
|
+
const { anchorSlot, anchorHash } = cursor?.utxoSet ?? {};
|
|
248
|
+
if (anchorSlot == null || !anchorHash)
|
|
249
|
+
throw new errors_1.TransactionValidationError('No imported UTxO set to rebuild the sums from — run importUtxoSet first.');
|
|
250
|
+
utxoSetImportInFlight = (0, utxo_set_import_1.rebuildUtxoSetAggregates)({ indexer: (0, server_1.getCardanoIndexer)() })
|
|
251
|
+
.then((r) => logger.info(`UTxO set sums rebuilt: ${r.utxos} rows at ${r.anchor.slot}/${r.anchor.hash}`))
|
|
252
|
+
.catch((err) => logger.error(`UTxO set aggregate rebuild failed: ${err instanceof Error ? err.message : String(err)}`))
|
|
253
|
+
.finally(() => { utxoSetImportInFlight = null; });
|
|
254
|
+
return {
|
|
255
|
+
accepted: true,
|
|
256
|
+
anchorSlot: String(anchorSlot),
|
|
257
|
+
anchorHash,
|
|
258
|
+
message: 'UTxO set sums are rebuilt from the imported rows; poll getStatus().utxoSet, then resumeCrawler.',
|
|
259
|
+
};
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
const source = data.source === 'file' || data.source === 'ogmios' ? data.source : null;
|
|
263
|
+
if (!source)
|
|
264
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'source must be "ogmios", "file" or "aggregates"', 'source');
|
|
265
|
+
if (source === 'file' && !data.filePath)
|
|
266
|
+
return (0, errors_1.rejectMissing)(req, 'importUtxoSet', 'filePath');
|
|
267
|
+
const anchorGiven = data.anchorSlot != null || !!data.anchorHash;
|
|
268
|
+
if (source === 'file' && !anchorGiven) {
|
|
269
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'source "file" needs anchorSlot + anchorHash: the tip at dump time', 'anchorSlot');
|
|
270
|
+
}
|
|
271
|
+
if (anchorGiven && (data.anchorSlot == null || !Number.isInteger(Number(data.anchorSlot)) || !(0, validators_1.isBlockHash)(data.anchorHash))) {
|
|
272
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'anchorSlot must be an integer and anchorHash a 64-hex block hash', 'anchorHash');
|
|
273
|
+
}
|
|
274
|
+
if ((0, crawler_1.isCrawlerRunning)())
|
|
275
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'Crawler is running in this process — pauseCrawler first');
|
|
276
|
+
if (utxoSetImportInFlight)
|
|
277
|
+
return (0, errors_1.rejectInvalid)(req, 'importUtxoSet', 'A UTxO set import is already running');
|
|
278
|
+
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
279
|
+
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
280
|
+
if (!cursor)
|
|
281
|
+
throw new errors_1.TransactionValidationError('No crawler cursor yet — start the crawler once before importing.');
|
|
282
|
+
if ((0, sync_state_1.isCrawlerLeaseActive)(cursor))
|
|
283
|
+
throw new errors_1.TransactionValidationError('Crawler is running (active lease) — pauseCrawler first.');
|
|
284
|
+
const anchor = anchorGiven
|
|
285
|
+
? { slot: Number(data.anchorSlot), hash: String(data.anchorHash).toLowerCase() }
|
|
286
|
+
: { slot: cursor.lastSlot, hash: cursor.lastBlockHash ?? '' };
|
|
287
|
+
if (!anchor.hash)
|
|
288
|
+
throw new errors_1.TransactionValidationError('Cursor has no block hash yet — pass anchorSlot + anchorHash.');
|
|
289
|
+
if (cursor.lastSlot > anchor.slot) {
|
|
290
|
+
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.`);
|
|
291
|
+
}
|
|
292
|
+
utxoSetImportInFlight = (0, utxo_set_import_1.importUtxoSet)({
|
|
293
|
+
source, filePath: data.filePath, anchor,
|
|
294
|
+
client: (0, server_1.getCardanoClient)(), indexer: (0, server_1.getCardanoIndexer)(),
|
|
295
|
+
onProgress: (n) => { if (n % 100_000 === 0)
|
|
296
|
+
logger.info(`UTxO set import: ${n} entries`); },
|
|
297
|
+
})
|
|
298
|
+
.then((r) => logger.info(`UTxO set import done: ${r.utxos} entries at ${r.anchor.slot}/${r.anchor.hash}`))
|
|
299
|
+
.catch((err) => logger.error(`UTxO set import failed: ${err instanceof Error ? err.message : String(err)}`))
|
|
300
|
+
.finally(() => { utxoSetImportInFlight = null; });
|
|
301
|
+
return {
|
|
302
|
+
accepted: true,
|
|
303
|
+
anchorSlot: String(anchor.slot),
|
|
304
|
+
anchorHash: anchor.hash,
|
|
305
|
+
message: `UTxO set import started (source=${source}); poll getStatus().utxoSet, then resumeCrawler.`,
|
|
34
306
|
};
|
|
35
307
|
});
|
|
36
308
|
});
|
|
@@ -42,19 +314,16 @@ module.exports = (srv) => {
|
|
|
42
314
|
return true;
|
|
43
315
|
});
|
|
44
316
|
});
|
|
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.
|
|
317
|
+
// resumeCrawler — (re)start from the persisted cursor. Gated on config.enabled so an
|
|
318
|
+
// unconfigured crawler is never started (it would sync from genesis). Resume on a running
|
|
319
|
+
// crawler is a no-op; pauseCrawler first to apply changed config.
|
|
50
320
|
srv.on('resumeCrawler', async (req) => {
|
|
51
321
|
let config;
|
|
52
322
|
try {
|
|
53
323
|
config = (0, server_1.loadCrawlerConfigFromEnv)();
|
|
54
324
|
}
|
|
55
325
|
catch (err) {
|
|
56
|
-
// e.g.
|
|
57
|
-
// caller's 400, not a raw 500 from an escaping throw
|
|
326
|
+
// A config problem (e.g. enabled without a start block) is the caller's 400.
|
|
58
327
|
return (0, errors_1.rejectInvalid)(req, 'resumeCrawler', err instanceof Error ? err.message : String(err));
|
|
59
328
|
}
|
|
60
329
|
if (!config.enabled) {
|
package/srv/cardano-service.cds
CHANGED
|
@@ -62,6 +62,21 @@ 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
|
+
|
|
75
|
+
@readonly
|
|
76
|
+
@title : 'Epoch Ledger Snapshots'
|
|
77
|
+
@description: 'Projection for per-epoch network ledger figures written by the chain crawler'
|
|
78
|
+
entity EpochLedgerSnapshots as projection on db.EpochLedgerSnapshots;
|
|
79
|
+
|
|
65
80
|
@readonly
|
|
66
81
|
@title : 'Assets'
|
|
67
82
|
@description: 'Projection for Native-Asset Information'
|
|
@@ -97,6 +112,46 @@ service CardanoODataService @(impl: './cardano-service') {
|
|
|
97
112
|
@description: 'Projection for Transaction Output Assets'
|
|
98
113
|
entity TransactionOutputAssets as projection on db.TransactionOutputAssets;
|
|
99
114
|
|
|
115
|
+
@readonly
|
|
116
|
+
@title : 'Transaction Certificates'
|
|
117
|
+
@description: 'Projection for Transaction Certificates (crawler-fed, crawler.certificates)'
|
|
118
|
+
entity TransactionCertificates as projection on db.TransactionCertificates;
|
|
119
|
+
|
|
120
|
+
@readonly
|
|
121
|
+
@title : 'Transaction Withdrawals'
|
|
122
|
+
@description: 'Projection for Transaction Withdrawals (crawler-fed, crawler.certificates)'
|
|
123
|
+
entity TransactionWithdrawals as projection on db.TransactionWithdrawals;
|
|
124
|
+
|
|
125
|
+
@readonly
|
|
126
|
+
@title : 'Transaction Redeemers'
|
|
127
|
+
@description: 'Projection for Transaction Redeemers (crawler-fed, Ogmios chain-sync)'
|
|
128
|
+
entity TransactionRedeemers as projection on db.TransactionRedeemers;
|
|
129
|
+
|
|
130
|
+
@readonly
|
|
131
|
+
@title : 'Ledger UTxOs'
|
|
132
|
+
@description: 'Crawler-maintained UTxO set (crawler.utxoSet); unspent while spentTxHash is null'
|
|
133
|
+
entity LedgerUTxOs as projection on db.LedgerUTxOs;
|
|
134
|
+
|
|
135
|
+
@readonly
|
|
136
|
+
@title : 'Ledger UTxO Assets'
|
|
137
|
+
@description: 'Native assets of a LedgerUTxOs row'
|
|
138
|
+
entity LedgerUTxOAssets as projection on db.LedgerUTxOAssets;
|
|
139
|
+
|
|
140
|
+
@readonly
|
|
141
|
+
@title : 'Ledger Addresses'
|
|
142
|
+
@description: 'Per-address balances from the crawler-maintained UTxO set (crawler.utxoSet)'
|
|
143
|
+
entity LedgerAddresses as projection on db.LedgerAddresses;
|
|
144
|
+
|
|
145
|
+
@readonly
|
|
146
|
+
@title : 'Ledger Address Assets'
|
|
147
|
+
@description: 'Native-asset balances per address (crawler.utxoSet)'
|
|
148
|
+
entity LedgerAddressAssets as projection on db.LedgerAddressAssets;
|
|
149
|
+
|
|
150
|
+
@readonly
|
|
151
|
+
@title : 'Ledger Accounts'
|
|
152
|
+
@description: 'Per-stake-key balances from the crawler-maintained UTxO set (crawler.utxoSet)'
|
|
153
|
+
entity LedgerAccounts as projection on db.LedgerAccounts;
|
|
154
|
+
|
|
100
155
|
@readonly
|
|
101
156
|
@title : 'Accounts'
|
|
102
157
|
@description: 'Projection for Accounts'
|
|
@@ -225,7 +280,7 @@ service CardanoODataService @(impl: './cardano-service') {
|
|
|
225
280
|
address: Bech32) returns many AddressUTxOs;
|
|
226
281
|
|
|
227
282
|
@title : 'Get UTxOs by Payment Credential'
|
|
228
|
-
@description: 'Retrieve UTxOs across all bech32 addresses sharing the given 28-byte payment credential (key hash or script hash). Useful for protocols that write to multiple bech32 forms of the same script (e.g. Indigo CDPs, Liqwid positions). Koios
|
|
283
|
+
@description: 'Retrieve UTxOs across all bech32 addresses sharing the given 28-byte payment credential (key hash or script hash). Useful for protocols that write to multiple bech32 forms of the same script (e.g. Indigo CDPs, Liqwid positions). Served from the crawled UTxO set (crawler.utxoSet active and synced) with outputs read from the node at the tip, else from Koios; throws ProviderUnavailableError when neither is available. Always fresh, no cache check.'
|
|
229
284
|
action GetUTxOsByCredential(
|
|
230
285
|
@title: 'Payment Credential'
|
|
231
286
|
@description: '28-byte payment credential hash as 56-char lowercase hex string'
|