@odatano/core 2.0.0-rc.42 → 2.0.0-rc.43
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/CardanoIndexerService/index.d.ts +47 -0
- package/@cds-models/CardanoIndexerService/index.js +7 -0
- package/@cds-models/CardanoODataService/index.d.ts +35 -0
- package/@cds-models/CardanoODataService/index.js +4 -0
- package/@cds-models/CardanoSignService/index.d.ts +1 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +1 -0
- package/@cds-models/index.d.ts +1 -0
- package/@cds-models/odatano/cardano/index.d.ts +24 -0
- package/@cds-models/odatano/cardano/index.js +3 -0
- package/README.md +195 -195
- package/db/schema.cds +23 -0
- package/db/types.cds +421 -417
- package/package.json +1 -1
- package/srv/blockchain/backends/ogmios-backend.js +1 -0
- package/srv/blockchain/cardano-indexer.js +4 -1
- package/srv/blockchain/crawler/credential-backfill.d.ts +37 -0
- package/srv/blockchain/crawler/credential-backfill.js +124 -0
- package/srv/blockchain/crawler/transaction-backfill.d.ts +3 -2
- package/srv/blockchain/crawler/transaction-backfill.js +8 -4
- package/srv/blockchain/ledger-state.d.ts +1 -0
- package/srv/blockchain/ledger-state.js +1 -0
- package/srv/blockchain/stored-chain.js +5 -1
- package/srv/blockchain/transaction-rows.d.ts +1 -1
- package/srv/blockchain/transaction-rows.js +2 -1
- package/srv/cardano-indexer-service.cds +29 -2
- package/srv/cardano-indexer-service.js +25 -2
- package/srv/cardano-service.cds +344 -332
- package/srv/cardano-service.js +9 -0
- package/srv/cbor/index.d.ts +1 -0
- package/srv/cbor/index.js +4 -1
- package/srv/cbor/plutus-data-json.d.ts +24 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/utils/agent-grants.js +1 -1
- package/srv/utils/db-indexes.js +5 -0
- package/srv/utils/mappers.d.ts +6 -2
- package/srv/utils/mappers.js +13 -0
- package/srv/utils/types.d.ts +9 -0
package/package.json
CHANGED
|
@@ -1032,8 +1032,9 @@ class CardanoIndexer {
|
|
|
1032
1032
|
: [];
|
|
1033
1033
|
if (this.crawlCertificates)
|
|
1034
1034
|
this.warnIfCertificatesUnreported(txs);
|
|
1035
|
-
// Redeemers come with the block on chain-sync; keyed
|
|
1035
|
+
// Redeemers and witness datums come with the block on chain-sync; keyed by tx like the certificates.
|
|
1036
1036
|
const redeemerRows = txs.flatMap(t => (0, mappers_1.mapTransactionRedeemers)(t.hash, t.redeemers ?? []));
|
|
1037
|
+
const datumRows = txs.flatMap(t => (0, mappers_1.mapTransactionDatums)(t.hash, t.datums ?? []));
|
|
1037
1038
|
// Mint/burn is derived from rows already in hand — keyed (unit, txHash), so a re-crawl is
|
|
1038
1039
|
// idempotent and a reorg removes these rows with their transactions (crawler handleReorg).
|
|
1039
1040
|
const assetHistoryRows = this.crawlAssetHistory ? this.buildAssetHistoryRows(blockData, txs) : [];
|
|
@@ -1055,6 +1056,8 @@ class CardanoIndexer {
|
|
|
1055
1056
|
await tx.run(UPSERT.into(CardanoODataService_1.TransactionWithdrawals).entries(withdrawalRows));
|
|
1056
1057
|
if (redeemerRows.length)
|
|
1057
1058
|
await tx.run(UPSERT.into(CardanoODataService_1.TransactionRedeemers).entries(redeemerRows));
|
|
1059
|
+
if (datumRows.length)
|
|
1060
|
+
await tx.run(UPSERT.into(CardanoODataService_1.TransactionDatums).entries(datumRows));
|
|
1058
1061
|
// Same transaction, so the UTxO set can never be a block ahead of or behind the cursor.
|
|
1059
1062
|
if (ledgerDue) {
|
|
1060
1063
|
if (priorInvalidation) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fills the payment credential of UTxO-shaped rows written before the column existed:
|
|
3
|
+
* TransactionOutputs, TransactionInputs and LedgerUTxOs. Each table is walked once in key
|
|
4
|
+
* order; rows that already carry a credential are skipped, so a second run changes nothing.
|
|
5
|
+
*/
|
|
6
|
+
export interface CredentialBackfillProgress {
|
|
7
|
+
/** Table being walked; null when finished. */
|
|
8
|
+
table: 'TransactionOutputs' | 'TransactionInputs' | 'LedgerUTxOs' | null;
|
|
9
|
+
outputs: number;
|
|
10
|
+
inputs: number;
|
|
11
|
+
ledgerUtxos: number;
|
|
12
|
+
}
|
|
13
|
+
export interface CredentialBackfillOptions {
|
|
14
|
+
/** Rows per statement. */
|
|
15
|
+
chunkSize?: number;
|
|
16
|
+
onProgress?: (p: CredentialBackfillProgress) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface CredentialTableSpec {
|
|
19
|
+
name: NonNullable<CredentialBackfillProgress['table']>;
|
|
20
|
+
entity: unknown;
|
|
21
|
+
table: string;
|
|
22
|
+
/** Primary key in walk order. */
|
|
23
|
+
keys: [first: string, second: string];
|
|
24
|
+
/** Postgres type of the first key column. */
|
|
25
|
+
firstKeyType: 'bigint' | 'text';
|
|
26
|
+
column: string;
|
|
27
|
+
address: string;
|
|
28
|
+
counter: 'outputs' | 'inputs' | 'ledgerUtxos';
|
|
29
|
+
}
|
|
30
|
+
export declare const CREDENTIAL_TABLES: readonly CredentialTableSpec[];
|
|
31
|
+
/**
|
|
32
|
+
* One UPDATE per chunk: the fills travel as a JSON array and are joined on the key. Only rows
|
|
33
|
+
* still without a credential are touched. Postgres and SQLite; other databases get one UPDATE per row.
|
|
34
|
+
*/
|
|
35
|
+
export declare function credentialFillStatement(kind: string, spec: CredentialTableSpec): string | null;
|
|
36
|
+
export declare function backfillUtxoCredentials(opts?: CredentialBackfillOptions): Promise<CredentialBackfillProgress>;
|
|
37
|
+
//# sourceMappingURL=credential-backfill.d.ts.map
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CREDENTIAL_TABLES = void 0;
|
|
7
|
+
exports.credentialFillStatement = credentialFillStatement;
|
|
8
|
+
exports.backfillUtxoCredentials = backfillUtxoCredentials;
|
|
9
|
+
const cds_1 = __importDefault(require("@sap/cds"));
|
|
10
|
+
const mappers_1 = require("../../utils/mappers");
|
|
11
|
+
const collections_1 = require("../../utils/collections");
|
|
12
|
+
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
13
|
+
const { SELECT, UPDATE } = cds_1.default.ql;
|
|
14
|
+
const logger = cds_1.default.log('CredentialBackfill');
|
|
15
|
+
exports.CREDENTIAL_TABLES = [
|
|
16
|
+
{ name: 'TransactionOutputs', entity: cardano_1.TransactionOutputs, table: 'odatano_cardano_TransactionOutputs', keys: ['txSeq', 'outputIndex'], firstKeyType: 'bigint', column: 'utxo_paymentCredential', address: 'address_address', counter: 'outputs' },
|
|
17
|
+
{ name: 'TransactionInputs', entity: cardano_1.TransactionInputs, table: 'odatano_cardano_TransactionInputs', keys: ['txSeq', 'inputIndex'], firstKeyType: 'bigint', column: 'utxoData_paymentCredential', address: 'address_address', counter: 'inputs' },
|
|
18
|
+
{ name: 'LedgerUTxOs', entity: cardano_1.LedgerUTxOs, table: 'odatano_cardano_LedgerUTxOs', keys: ['txHash', 'outputIndex'], firstKeyType: 'text', column: 'utxo_paymentCredential', address: 'address', counter: 'ledgerUtxos' },
|
|
19
|
+
];
|
|
20
|
+
/**
|
|
21
|
+
* One UPDATE per chunk: the fills travel as a JSON array and are joined on the key. Only rows
|
|
22
|
+
* still without a credential are touched. Postgres and SQLite; other databases get one UPDATE per row.
|
|
23
|
+
*/
|
|
24
|
+
function credentialFillStatement(kind, spec) {
|
|
25
|
+
const [k1, k2] = spec.keys;
|
|
26
|
+
if (kind === 'postgres') {
|
|
27
|
+
return `UPDATE ${spec.table} AS t SET ${spec.column} = v.credential ` +
|
|
28
|
+
`FROM json_to_recordset($1::json) AS v(${k1.toLowerCase()} ${spec.firstKeyType}, ${k2.toLowerCase()} integer, credential text) ` +
|
|
29
|
+
`WHERE t.${k1} = v.${k1.toLowerCase()} AND t.${k2} = v.${k2.toLowerCase()} AND t.${spec.column} IS NULL`;
|
|
30
|
+
}
|
|
31
|
+
if (kind === 'sqlite' || kind === 'better-sqlite') {
|
|
32
|
+
const cols = [k1, k2, 'credential'].map((c) => `json_extract(value, '$.${c.toLowerCase()}') AS ${c}`).join(', ');
|
|
33
|
+
return `UPDATE ${spec.table} AS t SET ${spec.column} = v.credential FROM (SELECT ${cols} FROM json_each(?)) AS v ` +
|
|
34
|
+
`WHERE t.${k1} = v.${k1} AND t.${k2} = v.${k2} AND t.${spec.column} IS NULL`;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
async function writeFills(tx, spec, fills, chunkSize) {
|
|
39
|
+
if (!fills.length)
|
|
40
|
+
return;
|
|
41
|
+
const sql = credentialFillStatement(cds_1.default.db?.kind ?? '', spec);
|
|
42
|
+
const [k1, k2] = spec.keys;
|
|
43
|
+
if (!sql) {
|
|
44
|
+
for (const f of fills) {
|
|
45
|
+
await tx.run(UPDATE.entity(spec.entity).set({ [spec.column]: f.credential }).where({ [k1]: f.first, [k2]: f.second, [spec.column]: null }));
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
for (const part of (0, collections_1.chunk)(fills, chunkSize)) {
|
|
50
|
+
const records = part.map((f) => ({ [k1.toLowerCase()]: f.first, [k2.toLowerCase()]: f.second, credential: f.credential }));
|
|
51
|
+
await tx.run(sql, [JSON.stringify(records)]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const keyValue = (v, type) => type === 'bigint' ? Number(v) : String(v);
|
|
55
|
+
/** Walks one table from its lowest key; returns the rows that received a credential. */
|
|
56
|
+
async function fillTable(spec, chunkSize, onChunk) {
|
|
57
|
+
const [k1, k2] = spec.keys;
|
|
58
|
+
let filled = 0;
|
|
59
|
+
let cursor = null;
|
|
60
|
+
const decoded = new Map();
|
|
61
|
+
for (;;) {
|
|
62
|
+
const done = await cds_1.default.tx(async (tx) => {
|
|
63
|
+
const where = { [spec.column]: null };
|
|
64
|
+
if (cursor?.within) {
|
|
65
|
+
where[k1] = cursor.first;
|
|
66
|
+
where[k2] = { '>': cursor.second };
|
|
67
|
+
}
|
|
68
|
+
else if (cursor) {
|
|
69
|
+
where[k1] = { '>': cursor.first };
|
|
70
|
+
}
|
|
71
|
+
const rows = (await tx.run(SELECT.from(spec.entity).columns(k1, k2, spec.address).where(where).orderBy(k1, k2).limit(chunkSize))) ?? [];
|
|
72
|
+
const wasWithin = cursor?.within ?? false;
|
|
73
|
+
if (!rows.length) {
|
|
74
|
+
if (!wasWithin)
|
|
75
|
+
return true;
|
|
76
|
+
cursor = { ...cursor, within: false };
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const full = rows.length === chunkSize;
|
|
80
|
+
const lastFirst = rows[rows.length - 1][k1];
|
|
81
|
+
const allSame = rows.every((r) => r[k1] === lastFirst);
|
|
82
|
+
// The last key of a full batch may continue in the next one: its rows wait for it. When the
|
|
83
|
+
// whole batch is that one key, the walk continues inside it by the second key.
|
|
84
|
+
const complete = full && !allSame ? rows.filter((r) => r[k1] !== lastFirst) : rows;
|
|
85
|
+
const fills = [];
|
|
86
|
+
for (const r of complete) {
|
|
87
|
+
const address = r[spec.address];
|
|
88
|
+
if (!address)
|
|
89
|
+
continue;
|
|
90
|
+
if (!decoded.has(address))
|
|
91
|
+
decoded.set(address, (0, mappers_1.paymentCredentialOf)(address));
|
|
92
|
+
const credential = decoded.get(address);
|
|
93
|
+
if (credential)
|
|
94
|
+
fills.push({ first: keyValue(r[k1], spec.firstKeyType), second: Number(r[k2]), credential });
|
|
95
|
+
}
|
|
96
|
+
await writeFills(tx, spec, fills, chunkSize);
|
|
97
|
+
filled += fills.length;
|
|
98
|
+
const last = complete[complete.length - 1];
|
|
99
|
+
cursor = { first: keyValue(last[k1], spec.firstKeyType), second: Number(last[k2]), within: full && allSame };
|
|
100
|
+
return !full && !wasWithin;
|
|
101
|
+
});
|
|
102
|
+
onChunk(filled);
|
|
103
|
+
if (decoded.size > 50_000)
|
|
104
|
+
decoded.clear();
|
|
105
|
+
if (done)
|
|
106
|
+
return filled;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function backfillUtxoCredentials(opts = {}) {
|
|
110
|
+
const chunkSize = opts.chunkSize ?? 5000;
|
|
111
|
+
const progress = { table: null, outputs: 0, inputs: 0, ledgerUtxos: 0 };
|
|
112
|
+
for (const spec of exports.CREDENTIAL_TABLES) {
|
|
113
|
+
progress.table = spec.name;
|
|
114
|
+
opts.onProgress?.({ ...progress });
|
|
115
|
+
progress[spec.counter] = await fillTable(spec, chunkSize, (filled) => {
|
|
116
|
+
progress[spec.counter] = filled;
|
|
117
|
+
opts.onProgress?.({ ...progress });
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
progress.table = null;
|
|
121
|
+
logger.info(`payment credentials filled: ${progress.outputs} outputs, ${progress.inputs} inputs, ${progress.ledgerUtxos} ledger UTxOs`);
|
|
122
|
+
return progress;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=credential-backfill.js.map
|
|
@@ -6,8 +6,8 @@ import type { LedgerLookup } from '../ledger-state';
|
|
|
6
6
|
/**
|
|
7
7
|
* Completes transactions the crawl already holds from a second chain-sync stream: input
|
|
8
8
|
* outpoints (spentTxHash / spentOutputIndex), the spent output's datum and reference-script
|
|
9
|
-
* hash, a missing input address, and the
|
|
10
|
-
* transaction whose stored inputs do not line up with the stream is left as it is.
|
|
9
|
+
* hash, a missing input address, the redeemers and the witness datums. Only empty input fields
|
|
10
|
+
* are filled; a transaction whose stored inputs do not line up with the stream is left as it is.
|
|
11
11
|
*/
|
|
12
12
|
export declare class TransactionBackfillError extends Error {
|
|
13
13
|
constructor(message: string);
|
|
@@ -20,6 +20,7 @@ export interface TransactionBackfillProgress {
|
|
|
20
20
|
/** Input rows that got at least one field. */
|
|
21
21
|
inputs: number;
|
|
22
22
|
redeemers: number;
|
|
23
|
+
datums: number;
|
|
23
24
|
/** Transactions whose stored rows differed from the ledger view (order, inputs or outputs the ledger did not apply) and were rewritten. */
|
|
24
25
|
rewritten: number;
|
|
25
26
|
/** Transactions left as they are: stored inputs differ from the stream. */
|
|
@@ -16,8 +16,8 @@ const logger = cds_1.default.log('TransactionBackfill');
|
|
|
16
16
|
/**
|
|
17
17
|
* Completes transactions the crawl already holds from a second chain-sync stream: input
|
|
18
18
|
* outpoints (spentTxHash / spentOutputIndex), the spent output's datum and reference-script
|
|
19
|
-
* hash, a missing input address, and the
|
|
20
|
-
* transaction whose stored inputs do not line up with the stream is left as it is.
|
|
19
|
+
* hash, a missing input address, the redeemers and the witness datums. Only empty input fields
|
|
20
|
+
* are filled; a transaction whose stored inputs do not line up with the stream is left as it is.
|
|
21
21
|
*/
|
|
22
22
|
class TransactionBackfillError extends Error {
|
|
23
23
|
constructor(message) {
|
|
@@ -199,7 +199,7 @@ async function dropUnappliedOutputs(tx, txs) {
|
|
|
199
199
|
}
|
|
200
200
|
async function backfillTransactions(opts) {
|
|
201
201
|
const { fromSlot, toSlot, indexer } = opts;
|
|
202
|
-
const progress = { atSlot: 0, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, rewritten: 0, skipped: 0 };
|
|
202
|
+
const progress = { atSlot: 0, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, datums: 0, rewritten: 0, skipped: 0 };
|
|
203
203
|
let started = false;
|
|
204
204
|
const intersection = await (0, certificate_backfill_1.streamCrawledBlocks)({ ...opts, errorType: TransactionBackfillError }, (_block, txs) => txs, async (tx, blocks) => {
|
|
205
205
|
const txs = blocks.flatMap((b) => b.payload);
|
|
@@ -275,6 +275,10 @@ async function backfillTransactions(opts) {
|
|
|
275
275
|
progress.redeemers += redeemerRows.length;
|
|
276
276
|
if (redeemerRows.length)
|
|
277
277
|
await tx.run(UPSERT.into(cardano_1.TransactionRedeemers).entries(redeemerRows));
|
|
278
|
+
const datumRows = txs.flatMap((t) => (0, mappers_1.mapTransactionDatums)(t.hash, t.datums ?? []));
|
|
279
|
+
progress.datums += datumRows.length;
|
|
280
|
+
if (datumRows.length)
|
|
281
|
+
await tx.run(UPSERT.into(cardano_1.TransactionDatums).entries(datumRows));
|
|
278
282
|
}, (atSlot) => {
|
|
279
283
|
started = true;
|
|
280
284
|
progress.atSlot = atSlot;
|
|
@@ -283,7 +287,7 @@ async function backfillTransactions(opts) {
|
|
|
283
287
|
if (!started)
|
|
284
288
|
progress.atSlot = intersection === 'origin' ? 0 : intersection.slot;
|
|
285
289
|
logger.info(`Transaction backfill ${fromSlot}..${toSlot}: ${progress.blocks} blocks, ${progress.inputs} inputs, ` +
|
|
286
|
-
`${progress.redeemers} redeemers, ${progress.rewritten} transactions rewritten, ${progress.skipped} skipped`);
|
|
290
|
+
`${progress.redeemers} redeemers, ${progress.datums} datums, ${progress.rewritten} transactions rewritten, ${progress.skipped} skipped`);
|
|
287
291
|
return { ...progress, fromSlot, toSlot, intersection };
|
|
288
292
|
}
|
|
289
293
|
//# sourceMappingURL=transaction-backfill.js.map
|
|
@@ -34,6 +34,7 @@ export interface LedgerUtxoRow {
|
|
|
34
34
|
utxo_referenceScriptHash: string | null;
|
|
35
35
|
utxo_referenceScriptSize: number | null;
|
|
36
36
|
utxo_referenceScriptType: ReferenceScriptType | null;
|
|
37
|
+
utxo_paymentCredential: string | null;
|
|
37
38
|
hasAssets: boolean;
|
|
38
39
|
}
|
|
39
40
|
export interface LedgerUtxoAssetRow {
|
|
@@ -63,6 +63,7 @@ function buildLedgerUtxoRows(o, createdSlot) {
|
|
|
63
63
|
utxo_referenceScriptHash: o.referenceScriptHash || null,
|
|
64
64
|
utxo_referenceScriptSize: o.referenceScriptSize ?? null,
|
|
65
65
|
utxo_referenceScriptType: o.referenceScriptType ?? null,
|
|
66
|
+
utxo_paymentCredential: decoded.paymentCredential,
|
|
66
67
|
hasAssets: assets.length > 0,
|
|
67
68
|
},
|
|
68
69
|
assets,
|
|
@@ -133,7 +133,7 @@ async function assembleTransactions(db, rows) {
|
|
|
133
133
|
}
|
|
134
134
|
return out;
|
|
135
135
|
};
|
|
136
|
-
const [inputs, inputAssets, outputs, outputAssets, metadata, certificates, withdrawals, mints, redeemers] = await Promise.all([
|
|
136
|
+
const [inputs, inputAssets, outputs, outputAssets, metadata, certificates, withdrawals, mints, redeemers, datums] = await Promise.all([
|
|
137
137
|
fetchIn(cardano_1.TransactionInputs, 'txSeq', seqs),
|
|
138
138
|
fetchIn(cardano_1.TransactionInputAssets, 'input_txSeq', seqs),
|
|
139
139
|
fetchIn(cardano_1.TransactionOutputs, 'txSeq', seqs),
|
|
@@ -143,6 +143,7 @@ async function assembleTransactions(db, rows) {
|
|
|
143
143
|
fetchIn(cardano_1.TransactionWithdrawals, 'tx_hash', hashes),
|
|
144
144
|
fetchIn(cardano_1.AssetHistory_, 'txHash', hashes),
|
|
145
145
|
fetchIn(cardano_1.TransactionRedeemers, 'tx_hash', hashes),
|
|
146
|
+
fetchIn(cardano_1.TransactionDatums, 'tx_hash', hashes),
|
|
146
147
|
]);
|
|
147
148
|
const inputsBySeq = groupBy(inputs, r => str(r.txSeq));
|
|
148
149
|
const inputAssetsByKey = groupBy(inputAssets, r => `${r.input_txSeq}#${r.input_inputIndex}`);
|
|
@@ -153,6 +154,7 @@ async function assembleTransactions(db, rows) {
|
|
|
153
154
|
const withdrawalsByHash = groupBy(withdrawals, r => str(r.tx_hash));
|
|
154
155
|
const mintsByHash = groupBy(mints, r => str(r.txHash));
|
|
155
156
|
const redeemersByHash = groupBy(redeemers, r => str(r.tx_hash));
|
|
157
|
+
const datumsByHash = groupBy(datums, r => str(r.tx_hash));
|
|
156
158
|
return rows.map((t) => {
|
|
157
159
|
const seq = str(t.txSeq);
|
|
158
160
|
const hash = str(t.hash);
|
|
@@ -192,6 +194,7 @@ async function assembleTransactions(db, rows) {
|
|
|
192
194
|
const withdrawn = withdrawalsByHash.get(hash);
|
|
193
195
|
const minted = mintsByHash.get(hash);
|
|
194
196
|
const redeemed = redeemersByHash.get(hash);
|
|
197
|
+
const witnessDatums = datumsByHash.get(hash);
|
|
195
198
|
return {
|
|
196
199
|
hash,
|
|
197
200
|
blockHash: str(t.blockHash),
|
|
@@ -232,6 +235,7 @@ async function assembleTransactions(db, rows) {
|
|
|
232
235
|
outputIndex: numOrNull(r.spentOutputIndex),
|
|
233
236
|
policyId: r.policyId ?? null,
|
|
234
237
|
})),
|
|
238
|
+
datums: witnessDatums?.map((d) => ({ hash: str(d.dataHash), cbor: str(d.datum) })),
|
|
235
239
|
};
|
|
236
240
|
});
|
|
237
241
|
}
|
|
@@ -7,6 +7,6 @@ export interface TxKey {
|
|
|
7
7
|
export declare const seqKey: (txSeq: number | string) => string;
|
|
8
8
|
/** Hash and txSeq of the given transactions that are indexed. */
|
|
9
9
|
export declare function readTxKeys(tx: CapTransaction, hashes: string[]): Promise<TxKey[]>;
|
|
10
|
-
/** Delete transactions with their input/output, asset, metadata, certificate, withdrawal and
|
|
10
|
+
/** Delete transactions with their input/output, asset, metadata, certificate, withdrawal, redeemer and datum rows. */
|
|
11
11
|
export declare function deleteTransactionRows(tx: CapTransaction, keys: TxKey[]): Promise<void>;
|
|
12
12
|
//# sourceMappingURL=transaction-rows.d.ts.map
|
|
@@ -22,7 +22,7 @@ async function readTxKeys(tx, hashes) {
|
|
|
22
22
|
}
|
|
23
23
|
return keys;
|
|
24
24
|
}
|
|
25
|
-
/** Delete transactions with their input/output, asset, metadata, certificate, withdrawal and
|
|
25
|
+
/** Delete transactions with their input/output, asset, metadata, certificate, withdrawal, redeemer and datum rows. */
|
|
26
26
|
async function deleteTransactionRows(tx, keys) {
|
|
27
27
|
for (const keyChunk of (0, collections_1.chunk)(keys, collections_1.IN_CHUNK)) {
|
|
28
28
|
const hashes = keyChunk.map(k => k.hash);
|
|
@@ -37,6 +37,7 @@ async function deleteTransactionRows(tx, keys) {
|
|
|
37
37
|
await tx.run(DELETE.from(cardano_1.TransactionCertificates).where({ tx_hash: { in: hashes } }));
|
|
38
38
|
await tx.run(DELETE.from(cardano_1.TransactionWithdrawals).where({ tx_hash: { in: hashes } }));
|
|
39
39
|
await tx.run(DELETE.from(cardano_1.TransactionRedeemers).where({ tx_hash: { in: hashes } }));
|
|
40
|
+
await tx.run(DELETE.from(cardano_1.TransactionDatums).where({ tx_hash: { in: hashes } }));
|
|
40
41
|
await tx.run(DELETE.from(cardano_1.Transactions).where({ hash: { in: hashes } }));
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -54,8 +54,10 @@ service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
|
54
54
|
utxoSet : UtxoSetStatus;
|
|
55
55
|
// one-off certificate/withdrawal backfill over already crawled blocks (this process)
|
|
56
56
|
certificateBackfill : CertificateBackfillStatus;
|
|
57
|
-
// one-off input/redeemer backfill over already crawled blocks (this process)
|
|
57
|
+
// one-off input/redeemer/datum backfill over already crawled blocks (this process)
|
|
58
58
|
transactionBackfill : TransactionBackfillStatus;
|
|
59
|
+
// one-off payment-credential fill of UTxO-shaped rows (this process)
|
|
60
|
+
credentialBackfill : CredentialBackfillStatus;
|
|
59
61
|
// per-epoch pool/DRep/pot snapshots (crawler.epochSnapshots)
|
|
60
62
|
epochSnapshots : EpochSnapshotStatus;
|
|
61
63
|
}
|
|
@@ -96,6 +98,7 @@ service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
|
96
98
|
transactions : Integer64;
|
|
97
99
|
inputs : Integer64; // input rows that got at least one field
|
|
98
100
|
redeemers : Integer64;
|
|
101
|
+
datums : Integer64;
|
|
99
102
|
rewritten : Integer64; // transactions whose stored rows differed in order or extent from the ledger view, now rewritten
|
|
100
103
|
skipped : Integer64; // transactions whose stored inputs differ from the stream
|
|
101
104
|
startedAt : Timestamp;
|
|
@@ -103,6 +106,25 @@ service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
|
103
106
|
error : String;
|
|
104
107
|
}
|
|
105
108
|
|
|
109
|
+
@title : 'Credential Backfill Status'
|
|
110
|
+
@description: 'Progress of the payment-credential fill started with backfillPaymentCredentials; process-local, none after a restart'
|
|
111
|
+
type CredentialBackfillStatus {
|
|
112
|
+
status : String; // none | running | done | failed
|
|
113
|
+
table : String; // table being walked: TransactionOutputs | TransactionInputs | LedgerUTxOs; null when finished
|
|
114
|
+
outputs : Integer64; // rows that received a credential
|
|
115
|
+
inputs : Integer64;
|
|
116
|
+
ledgerUtxos : Integer64;
|
|
117
|
+
startedAt : Timestamp;
|
|
118
|
+
finishedAt : Timestamp;
|
|
119
|
+
error : String;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@title : 'Backfill Result'
|
|
123
|
+
type BackfillResult {
|
|
124
|
+
accepted : Boolean;
|
|
125
|
+
message : String;
|
|
126
|
+
}
|
|
127
|
+
|
|
106
128
|
@title : 'Certificate Backfill Result'
|
|
107
129
|
type CertificateBackfillResult {
|
|
108
130
|
accepted : Boolean;
|
|
@@ -195,7 +217,12 @@ service CardanoIndexerService @(impl: './cardano-indexer-service') {
|
|
|
195
217
|
action backfillCertificates(fromSlot: Integer64, toSlot: Integer64) returns CertificateBackfillResult;
|
|
196
218
|
|
|
197
219
|
@title : 'Backfill Transactions'
|
|
198
|
-
@description: 'Complete transactions the crawl already holds from a second chain-sync stream (Ogmios): input outpoints, the spent output datum and reference-script hash, missing input addresses, and
|
|
220
|
+
@description: 'Complete transactions the crawl already holds from a second chain-sync stream (Ogmios): input outpoints, the spent output datum and reference-script hash, missing input addresses, TransactionRedeemers and TransactionDatums. Fills empty fields only; a transaction whose stored inputs differ from the stream is skipped. fromSlot defaults to the crawl start, toSlot to the cursor; the crawler may keep running. Runs in the background; progress via getStatus().transactionBackfill.'
|
|
199
221
|
@requires : 'Admin'
|
|
200
222
|
action backfillTransactions(fromSlot: Integer64, toSlot: Integer64) returns CertificateBackfillResult;
|
|
223
|
+
|
|
224
|
+
@title : 'Backfill Payment Credentials'
|
|
225
|
+
@description: 'Fill utxo.paymentCredential on TransactionOutputs, TransactionInputs and LedgerUTxOs rows written before the column existed, decoded from the stored address. Walks each table once in key order; rows that carry a credential are left alone, so a second run is a no-op. No backend call; the crawler may keep running. Runs in the background; progress via getStatus().credentialBackfill.'
|
|
226
|
+
@requires : 'Admin'
|
|
227
|
+
action backfillPaymentCredentials() returns BackfillResult;
|
|
201
228
|
}
|
|
@@ -11,6 +11,7 @@ const sync_state_1 = require("./blockchain/crawler/sync-state");
|
|
|
11
11
|
const utxo_set_import_1 = require("./blockchain/crawler/utxo-set-import");
|
|
12
12
|
const certificate_backfill_1 = require("./blockchain/crawler/certificate-backfill");
|
|
13
13
|
const transaction_backfill_1 = require("./blockchain/crawler/transaction-backfill");
|
|
14
|
+
const credential_backfill_1 = require("./blockchain/crawler/credential-backfill");
|
|
14
15
|
const validators_1 = require("./utils/validators");
|
|
15
16
|
const server_1 = require("./server");
|
|
16
17
|
const liveness_1 = require("./utils/liveness");
|
|
@@ -27,9 +28,12 @@ let certificateBackfill = {
|
|
|
27
28
|
};
|
|
28
29
|
let transactionBackfillStarting = false;
|
|
29
30
|
let transactionBackfill = {
|
|
30
|
-
status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, rewritten: 0, skipped: 0,
|
|
31
|
+
status: 'none', fromSlot: 0, toSlot: 0, atSlot: 0, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, datums: 0, rewritten: 0, skipped: 0,
|
|
31
32
|
startedAt: null, finishedAt: null, error: null,
|
|
32
33
|
};
|
|
34
|
+
let credentialBackfill = {
|
|
35
|
+
status: 'none', table: null, outputs: 0, inputs: 0, ledgerUtxos: 0, startedAt: null, finishedAt: null, error: null,
|
|
36
|
+
};
|
|
33
37
|
/** Slot range of a backfill: defaults to crawl start .. cursor, never past the cursor. */
|
|
34
38
|
async function backfillRange(db, data) {
|
|
35
39
|
const cursor = await (0, sync_state_1.readCursor)(db);
|
|
@@ -125,12 +129,14 @@ module.exports = (srv) => {
|
|
|
125
129
|
transactions: transactionBackfill.transactions,
|
|
126
130
|
inputs: transactionBackfill.inputs,
|
|
127
131
|
redeemers: transactionBackfill.redeemers,
|
|
132
|
+
datums: transactionBackfill.datums,
|
|
128
133
|
rewritten: transactionBackfill.rewritten,
|
|
129
134
|
skipped: transactionBackfill.skipped,
|
|
130
135
|
startedAt: transactionBackfill.startedAt,
|
|
131
136
|
finishedAt: transactionBackfill.finishedAt,
|
|
132
137
|
error: transactionBackfill.error,
|
|
133
138
|
},
|
|
139
|
+
credentialBackfill: { ...credentialBackfill },
|
|
134
140
|
epochSnapshots: {
|
|
135
141
|
enabled: epochSnapshotsConfigured(),
|
|
136
142
|
source: epochSnapshotSource(),
|
|
@@ -204,7 +210,7 @@ module.exports = (srv) => {
|
|
|
204
210
|
return await (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
205
211
|
const { fromSlot, toSlot } = await backfillRange(db, data);
|
|
206
212
|
transactionBackfill = {
|
|
207
|
-
status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, rewritten: 0, skipped: 0,
|
|
213
|
+
status: 'running', fromSlot, toSlot, atSlot: fromSlot, blocks: 0, transactions: 0, inputs: 0, redeemers: 0, datums: 0, rewritten: 0, skipped: 0,
|
|
208
214
|
startedAt: new Date().toISOString(), finishedAt: null, error: null,
|
|
209
215
|
};
|
|
210
216
|
void (0, transaction_backfill_1.backfillTransactions)({
|
|
@@ -233,6 +239,23 @@ module.exports = (srv) => {
|
|
|
233
239
|
transactionBackfillStarting = false;
|
|
234
240
|
}
|
|
235
241
|
});
|
|
242
|
+
// backfillPaymentCredentials — walks the UTxO-shaped tables once and fills the credential
|
|
243
|
+
// from the stored address. No backend; runs detached, progress via getStatus().credentialBackfill.
|
|
244
|
+
srv.on('backfillPaymentCredentials', async (req) => {
|
|
245
|
+
if (credentialBackfill.status === 'running')
|
|
246
|
+
return (0, errors_1.rejectInvalid)(req, 'backfillPaymentCredentials', 'A payment-credential backfill is already running');
|
|
247
|
+
credentialBackfill = { status: 'running', table: null, outputs: 0, inputs: 0, ledgerUtxos: 0, startedAt: new Date().toISOString(), finishedAt: null, error: null };
|
|
248
|
+
void (0, credential_backfill_1.backfillUtxoCredentials)({
|
|
249
|
+
onProgress: (p) => { Object.assign(credentialBackfill, p); },
|
|
250
|
+
})
|
|
251
|
+
.then((r) => { Object.assign(credentialBackfill, r, { status: 'done', finishedAt: new Date().toISOString() }); })
|
|
252
|
+
.catch((err) => {
|
|
253
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
254
|
+
Object.assign(credentialBackfill, { status: 'failed', finishedAt: new Date().toISOString(), error: message.slice(0, 500) });
|
|
255
|
+
logger.error(`Payment-credential backfill failed: ${message}`);
|
|
256
|
+
});
|
|
257
|
+
return { accepted: true, message: 'Payment-credential backfill started; poll getStatus().credentialBackfill.' };
|
|
258
|
+
});
|
|
236
259
|
// importUtxoSet — one-off snapshot import that anchors crawler.utxoSet. Validates, then
|
|
237
260
|
// runs detached; progress via getStatus().utxoSet.
|
|
238
261
|
srv.on('importUtxoSet', async (req) => {
|