@odatano/core 2.0.0-rc.5 → 2.0.0-rc.50

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.
Files changed (208) hide show
  1. package/@cds-models/CardanoAgentService/index.d.ts +99 -51
  2. package/@cds-models/CardanoAgentService/index.js +15 -0
  3. package/@cds-models/CardanoBackendService/index.d.ts +347 -0
  4. package/@cds-models/CardanoBackendService/index.js +40 -0
  5. package/@cds-models/CardanoIndexerService/index.d.ts +496 -11
  6. package/@cds-models/CardanoIndexerService/index.js +64 -0
  7. package/@cds-models/CardanoODataService/index.d.ts +414 -57
  8. package/@cds-models/CardanoODataService/index.js +42 -0
  9. package/@cds-models/CardanoSignService/index.d.ts +32 -19
  10. package/@cds-models/CardanoSignService/index.js +3 -0
  11. package/@cds-models/CardanoTransactionService/index.d.ts +58 -44
  12. package/@cds-models/CardanoTransactionService/index.js +4 -0
  13. package/@cds-models/CardanoWorkerService/index.d.ts +7 -22
  14. package/@cds-models/index.d.ts +101 -1
  15. package/@cds-models/index.js +16 -1
  16. package/@cds-models/odatano/cardano/index.d.ts +437 -32
  17. package/@cds-models/odatano/cardano/index.js +48 -0
  18. package/README.md +207 -167
  19. package/db/schema.cds +2402 -1705
  20. package/db/types.cds +446 -295
  21. package/package.json +41 -16
  22. package/scripts/migrate-schema.mjs +334 -0
  23. package/scripts/migrate-slot-leader.mjs +96 -0
  24. package/src/index.d.ts +20 -21
  25. package/src/index.js +45 -31
  26. package/src/plugin.js +17 -35
  27. package/srv/blockchain/asset-decimals.d.ts +7 -0
  28. package/srv/blockchain/asset-decimals.js +91 -0
  29. package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -135
  30. package/srv/blockchain/backends/blockfrost-backend.js +66 -172
  31. package/srv/blockchain/backends/cardano-backend.d.ts +94 -186
  32. package/srv/blockchain/backends/cardano-backend.js +29 -5
  33. package/srv/blockchain/backends/koios-backend.d.ts +103 -168
  34. package/srv/blockchain/backends/koios-backend.js +428 -360
  35. package/srv/blockchain/backends/odatano-backend.d.ts +54 -0
  36. package/srv/blockchain/backends/odatano-backend.js +169 -0
  37. package/srv/blockchain/backends/ogmios-backend.d.ts +123 -190
  38. package/srv/blockchain/backends/ogmios-backend.js +637 -315
  39. package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
  40. package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
  41. package/srv/blockchain/cardano-client.d.ts +61 -241
  42. package/srv/blockchain/cardano-client.js +253 -293
  43. package/srv/blockchain/cardano-indexer.d.ts +282 -281
  44. package/srv/blockchain/cardano-indexer.js +1551 -484
  45. package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
  46. package/srv/blockchain/cardano-tx-builder.js +164 -140
  47. package/srv/blockchain/circuit-breaker.d.ts +1 -13
  48. package/srv/blockchain/circuit-breaker.js +5 -15
  49. package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
  50. package/srv/blockchain/crawler/account-snapshots.js +153 -0
  51. package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
  52. package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
  53. package/srv/blockchain/crawler/asset-registry-backfill.d.ts +43 -0
  54. package/srv/blockchain/crawler/asset-registry-backfill.js +153 -0
  55. package/srv/blockchain/crawler/certificate-backfill.d.ts +52 -0
  56. package/srv/blockchain/crawler/certificate-backfill.js +162 -0
  57. package/srv/blockchain/crawler/crawler.d.ts +104 -81
  58. package/srv/blockchain/crawler/crawler.js +532 -160
  59. package/srv/blockchain/crawler/credential-backfill.d.ts +28 -0
  60. package/srv/blockchain/crawler/credential-backfill.js +124 -0
  61. package/srv/blockchain/crawler/hooks.d.ts +2 -17
  62. package/srv/blockchain/crawler/index.d.ts +1 -8
  63. package/srv/blockchain/crawler/index.js +31 -17
  64. package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
  65. package/srv/blockchain/crawler/input-asset-copies.js +171 -0
  66. package/srv/blockchain/crawler/metadata-position-backfill.d.ts +16 -0
  67. package/srv/blockchain/crawler/metadata-position-backfill.js +55 -0
  68. package/srv/blockchain/crawler/output-datum-backfill.d.ts +39 -0
  69. package/srv/blockchain/crawler/output-datum-backfill.js +110 -0
  70. package/srv/blockchain/crawler/sync-state.d.ts +27 -47
  71. package/srv/blockchain/crawler/sync-state.js +113 -63
  72. package/srv/blockchain/crawler/transaction-backfill.d.ts +44 -0
  73. package/srv/blockchain/crawler/transaction-backfill.js +278 -0
  74. package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
  75. package/srv/blockchain/crawler/utxo-set-import.js +399 -0
  76. package/srv/blockchain/ledger-state.d.ts +62 -0
  77. package/srv/blockchain/ledger-state.js +419 -0
  78. package/srv/blockchain/pending-spends.d.ts +16 -0
  79. package/srv/blockchain/pending-spends.js +81 -0
  80. package/srv/blockchain/pool-metadata.d.ts +15 -0
  81. package/srv/blockchain/pool-metadata.js +132 -0
  82. package/srv/blockchain/request-coalescer.d.ts +2 -16
  83. package/srv/blockchain/request-coalescer.js +2 -16
  84. package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
  85. package/srv/blockchain/signing/cose-verifier.js +146 -70
  86. package/srv/blockchain/signing/external-signer.d.ts +15 -115
  87. package/srv/blockchain/signing/external-signer.js +17 -126
  88. package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
  89. package/srv/blockchain/signing/hsm-signer.js +28 -79
  90. package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
  91. package/srv/blockchain/signing/signature-verifier.js +70 -83
  92. package/srv/blockchain/signing/submission-finalizer.d.ts +23 -45
  93. package/srv/blockchain/signing/submission-finalizer.js +219 -86
  94. package/srv/blockchain/stored-chain.d.ts +20 -0
  95. package/srv/blockchain/stored-chain.js +237 -0
  96. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
  97. package/srv/blockchain/transaction-building/buildooor-tx.js +652 -416
  98. package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
  99. package/srv/blockchain/transaction-presence.d.ts +5 -0
  100. package/srv/blockchain/transaction-presence.js +29 -0
  101. package/srv/blockchain/transaction-rows.d.ts +12 -0
  102. package/srv/blockchain/transaction-rows.js +44 -0
  103. package/srv/blockchain/wallet-worker/build-request.d.ts +5 -20
  104. package/srv/blockchain/wallet-worker/build-request.js +47 -30
  105. package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -46
  106. package/srv/blockchain/wallet-worker/confirmation-tracker.js +25 -45
  107. package/srv/blockchain/wallet-worker/index.d.ts +1 -1
  108. package/srv/blockchain/wallet-worker/index.js +3 -11
  109. package/srv/blockchain/wallet-worker/job-store.d.ts +30 -148
  110. package/srv/blockchain/wallet-worker/job-store.js +101 -201
  111. package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
  112. package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
  113. package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
  114. package/srv/blockchain/wallet-worker/signers.js +4 -12
  115. package/srv/blockchain/wallet-worker/wallet-worker.d.ts +8 -80
  116. package/srv/blockchain/wallet-worker/wallet-worker.js +107 -155
  117. package/srv/cardano-agent-service.cds +122 -84
  118. package/srv/cardano-agent-service.js +4 -9
  119. package/srv/cardano-backend-service.cds +78 -0
  120. package/srv/cardano-backend-service.d.ts +2 -0
  121. package/srv/cardano-backend-service.js +242 -0
  122. package/srv/cardano-indexer-service.cds +387 -73
  123. package/srv/cardano-indexer-service.d.ts +5 -1
  124. package/srv/cardano-indexer-service.js +532 -16
  125. package/srv/cardano-service.cds +424 -269
  126. package/srv/cardano-service.js +289 -201
  127. package/srv/cardano-sign-service.cds +201 -180
  128. package/srv/cardano-sign-service.js +71 -201
  129. package/srv/cardano-tx-service.cds +451 -370
  130. package/srv/cardano-tx-service.js +271 -289
  131. package/srv/cardano-ui.cds +16 -16
  132. package/srv/cardano-worker-service.cds +118 -125
  133. package/srv/cardano-worker-service.js +52 -61
  134. package/srv/cbor/cip68.d.ts +13 -0
  135. package/srv/cbor/cip68.js +56 -0
  136. package/srv/cbor/index.d.ts +3 -1
  137. package/srv/cbor/index.js +9 -1
  138. package/srv/cbor/parse.d.ts +30 -18
  139. package/srv/cbor/parse.js +44 -9
  140. package/srv/cbor/plutus-data-json.d.ts +20 -0
  141. package/srv/cbor/plutus-data-json.js +32 -0
  142. package/srv/config.d.ts +113 -0
  143. package/srv/config.js +409 -0
  144. package/srv/server.d.ts +15 -110
  145. package/srv/server.js +84 -404
  146. package/srv/utils/agent-access.d.ts +9 -0
  147. package/srv/utils/agent-access.js +67 -0
  148. package/srv/utils/agent-grants-config.d.ts +0 -46
  149. package/srv/utils/agent-grants-config.js +17 -85
  150. package/srv/utils/agent-grants.d.ts +106 -122
  151. package/srv/utils/agent-grants.js +538 -236
  152. package/srv/utils/agent-token-auth.d.ts +4 -99
  153. package/srv/utils/agent-token-auth.js +18 -182
  154. package/srv/utils/backend-request-handler.d.ts +3 -17
  155. package/srv/utils/backend-request-handler.js +3 -18
  156. package/srv/utils/collections.d.ts +3 -10
  157. package/srv/utils/collections.js +3 -10
  158. package/srv/utils/const.d.ts +23 -74
  159. package/srv/utils/const.js +32 -79
  160. package/srv/utils/crypto.d.ts +3 -12
  161. package/srv/utils/crypto.js +6 -21
  162. package/srv/utils/db-indexes.d.ts +27 -0
  163. package/srv/utils/db-indexes.js +120 -0
  164. package/srv/utils/db-sanitize.d.ts +20 -0
  165. package/srv/utils/db-sanitize.js +80 -0
  166. package/srv/utils/deep-json.d.ts +6 -0
  167. package/srv/utils/deep-json.js +240 -0
  168. package/srv/utils/epoch-slots.d.ts +13 -0
  169. package/srv/utils/epoch-slots.js +38 -0
  170. package/srv/utils/error-codes.d.ts +22 -75
  171. package/srv/utils/error-codes.js +23 -72
  172. package/srv/utils/errors.d.ts +46 -187
  173. package/srv/utils/errors.js +114 -230
  174. package/srv/utils/liveness.d.ts +12 -0
  175. package/srv/utils/liveness.js +35 -0
  176. package/srv/utils/mappers.d.ts +102 -223
  177. package/srv/utils/mappers.js +387 -316
  178. package/srv/utils/network-context.js +2 -13
  179. package/srv/utils/paging.d.ts +31 -0
  180. package/srv/utils/paging.js +43 -0
  181. package/srv/utils/pg-inline-json.d.ts +8 -0
  182. package/srv/utils/pg-inline-json.js +58 -0
  183. package/srv/utils/pg-order-nulls.d.ts +14 -0
  184. package/srv/utils/pg-order-nulls.js +54 -0
  185. package/srv/utils/plutus-placeholders.d.ts +16 -22
  186. package/srv/utils/plutus-placeholders.js +62 -33
  187. package/srv/utils/rate-limiter.d.ts +2 -21
  188. package/srv/utils/rate-limiter.js +5 -17
  189. package/srv/utils/readiness.d.ts +12 -0
  190. package/srv/utils/readiness.js +29 -0
  191. package/srv/utils/reference-script.d.ts +19 -0
  192. package/srv/utils/reference-script.js +84 -0
  193. package/srv/utils/result-numbers.d.ts +15 -0
  194. package/srv/utils/result-numbers.js +61 -0
  195. package/srv/utils/service-events.d.ts +0 -24
  196. package/srv/utils/service-events.js +3 -25
  197. package/srv/utils/signing-helper.d.ts +3 -20
  198. package/srv/utils/signing-helper.js +35 -64
  199. package/srv/utils/tx-build-helper.d.ts +10 -105
  200. package/srv/utils/tx-build-helper.js +81 -144
  201. package/srv/utils/tx-request-parsers.d.ts +82 -33
  202. package/srv/utils/tx-request-parsers.js +401 -49
  203. package/srv/utils/tx-utils.d.ts +3 -27
  204. package/srv/utils/tx-utils.js +32 -50
  205. package/srv/utils/types.d.ts +261 -191
  206. package/srv/utils/types.js +2 -6
  207. package/srv/utils/validators.d.ts +22 -92
  208. package/srv/utils/validators.js +50 -149
@@ -0,0 +1,28 @@
1
+ export interface CredentialBackfillProgress {
2
+ /** Table being walked; null when finished. */
3
+ table: 'TransactionOutputs' | 'TransactionInputs' | 'LedgerUTxOs' | null;
4
+ outputs: number;
5
+ inputs: number;
6
+ ledgerUtxos: number;
7
+ }
8
+ export interface CredentialBackfillOptions {
9
+ /** Rows per statement. */
10
+ chunkSize?: number;
11
+ onProgress?: (p: CredentialBackfillProgress) => void;
12
+ }
13
+ export interface CredentialTableSpec {
14
+ name: NonNullable<CredentialBackfillProgress['table']>;
15
+ entity: unknown;
16
+ table: string;
17
+ /** Primary key in walk order. */
18
+ keys: [first: string, second: string];
19
+ /** Postgres type of the first key column. */
20
+ firstKeyType: 'bigint' | 'text';
21
+ column: string;
22
+ address: string;
23
+ counter: 'outputs' | 'inputs' | 'ledgerUtxos';
24
+ }
25
+ export declare const CREDENTIAL_TABLES: readonly CredentialTableSpec[];
26
+ export declare function credentialFillStatement(kind: string, spec: CredentialTableSpec): string | null;
27
+ export declare function backfillUtxoCredentials(opts?: CredentialBackfillOptions): Promise<CredentialBackfillProgress>;
28
+ //# 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
+ // One UPDATE per chunk that joins a JSON array of fills on the key. Touches only rows without a
21
+ // credential. Null for databases other than Postgres and SQLite, which update row by row.
22
+ function credentialFillStatement(kind, spec) {
23
+ const [k1, k2] = spec.keys;
24
+ if (kind === 'postgres') {
25
+ return `UPDATE ${spec.table} AS t SET ${spec.column} = v.credential ` +
26
+ `FROM json_to_recordset($1::json) AS v(${k1.toLowerCase()} ${spec.firstKeyType}, ${k2.toLowerCase()} integer, credential text) ` +
27
+ `WHERE t.${k1} = v.${k1.toLowerCase()} AND t.${k2} = v.${k2.toLowerCase()} AND t.${spec.column} IS NULL`;
28
+ }
29
+ if (kind === 'sqlite' || kind === 'better-sqlite') {
30
+ const cols = [k1, k2, 'credential'].map((c) => `json_extract(value, '$.${c.toLowerCase()}') AS ${c}`).join(', ');
31
+ return `UPDATE ${spec.table} AS t SET ${spec.column} = v.credential FROM (SELECT ${cols} FROM json_each(?)) AS v ` +
32
+ `WHERE t.${k1} = v.${k1} AND t.${k2} = v.${k2} AND t.${spec.column} IS NULL`;
33
+ }
34
+ return null;
35
+ }
36
+ async function writeFills(tx, spec, fills, chunkSize) {
37
+ if (!fills.length)
38
+ return;
39
+ const sql = credentialFillStatement(cds_1.default.db?.kind ?? '', spec);
40
+ const [k1, k2] = spec.keys;
41
+ if (!sql) {
42
+ for (const f of fills) {
43
+ await tx.run(UPDATE.entity(spec.entity).set({ [spec.column]: f.credential }).where({ [k1]: f.first, [k2]: f.second, [spec.column]: null }));
44
+ }
45
+ return;
46
+ }
47
+ for (const part of (0, collections_1.chunk)(fills, chunkSize)) {
48
+ const records = part.map((f) => ({ [k1.toLowerCase()]: f.first, [k2.toLowerCase()]: f.second, credential: f.credential }));
49
+ await tx.run(sql, [JSON.stringify(records)]);
50
+ }
51
+ }
52
+ const keyValue = (v, type) => type === 'bigint' ? Number(v) : String(v);
53
+ /** Walks one table from its lowest key; returns the rows that received a credential. */
54
+ async function fillTable(spec, chunkSize, onChunk) {
55
+ const [k1, k2] = spec.keys;
56
+ let filled = 0;
57
+ let cursor = null;
58
+ const decoded = new Map();
59
+ for (;;) {
60
+ const done = await cds_1.default.tx(async (tx) => {
61
+ const where = {};
62
+ if (cursor?.within) {
63
+ where[k1] = cursor.first;
64
+ where[k2] = { '>': cursor.second };
65
+ }
66
+ else if (cursor) {
67
+ where[k1] = { '>': cursor.first };
68
+ }
69
+ const rows = (await tx.run(SELECT.from(spec.entity).columns(k1, k2, spec.address, spec.column).where(where).orderBy(k1, k2).limit(chunkSize))) ?? [];
70
+ const wasWithin = cursor?.within ?? false;
71
+ if (!rows.length) {
72
+ if (!wasWithin)
73
+ return true;
74
+ cursor = { ...cursor, within: false };
75
+ return false;
76
+ }
77
+ const full = rows.length === chunkSize;
78
+ const lastFirst = rows[rows.length - 1][k1];
79
+ const allSame = rows.every((r) => r[k1] === lastFirst);
80
+ // The last key of a full batch may continue in the next one: its rows wait for it. When the
81
+ // whole batch is that one key, the walk continues inside it by the second key.
82
+ const complete = full && !allSame ? rows.filter((r) => r[k1] !== lastFirst) : rows;
83
+ const fills = [];
84
+ for (const r of complete) {
85
+ if (r[spec.column] != null)
86
+ continue;
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
@@ -1,15 +1,3 @@
1
- /**
2
- * Crawler event hooks (v2.1).
3
- *
4
- * Small listener registry that lets other subsystems (currently the wallet-worker
5
- * confirmation tracker) observe crawler progress without the crawler importing
6
- * them (dependency direction stays crawler ← consumer). The crawler emits:
7
- * - `blockIndexed` after each successfully persisted block (with its tx hashes), and
8
- * - `reorg` after a completed rollback (with the fork slot).
9
- *
10
- * Listener failures are logged and swallowed — a broken consumer must never
11
- * stop the crawler.
12
- */
13
1
  export interface BlockIndexedEvent {
14
2
  hash: string;
15
3
  slot: number | null;
@@ -20,14 +8,11 @@ export interface BlockIndexedEvent {
20
8
  tipHeight: number | null;
21
9
  }
22
10
  export interface ReorgEvent {
23
- /** Absolute slot of the fork point — everything after it was rolled back. */
11
+ /** Absolute slot of the fork point. Everything after it was rolled back. */
24
12
  forkSlot: number;
25
13
  /** How many blocks the rollback removed (0 when the fork was already the tip). */
26
14
  blocksRolledBack?: number;
27
- /**
28
- * Block height of the fork point, when known. Listeners tracking confirmation
29
- * depth must clamp their tip to this — the pre-fork tip height no longer exists.
30
- */
15
+ /** Block height of the fork point, when known; depth trackers must clamp their tip to it. */
31
16
  forkHeight: number | null;
32
17
  }
33
18
  export type BlockIndexedListener = (event: BlockIndexedEvent) => void;
@@ -1,21 +1,14 @@
1
1
  import type { CardanoClient } from '../cardano-client';
2
2
  import type { CardanoIndexer } from '../cardano-indexer';
3
3
  import { CardanoCrawler, type CrawlerConfig } from './crawler';
4
+ export declare function standbyDelayMs(consecutiveErrors: number): number;
4
5
  export interface StartCrawlerDeps {
5
6
  client: CardanoClient;
6
7
  indexer: CardanoIndexer;
7
8
  network: string;
8
9
  config: CrawlerConfig;
9
10
  }
10
- /**
11
- * Start the crawler (idempotent — a no-op if one is already running). Fire-and-forget:
12
- * returns once the ingest pipeline is launched, not when catch-up completes.
13
- */
14
11
  export declare function startCrawler(deps: StartCrawlerDeps, resumeCluster?: boolean): Promise<void>;
15
- /**
16
- * Stop the local crawler. `pauseCluster=true` additionally fences every instance via
17
- * shared DB intent; ordinary app shutdown leaves the desired state intact for failover.
18
- */
19
12
  export declare function stopCrawler(pauseCluster?: boolean): Promise<void>;
20
13
  /** Whether a crawler is currently running. */
21
14
  export declare function isCrawlerRunning(): boolean;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.standbyDelayMs = standbyDelayMs;
6
7
  exports.startCrawler = startCrawler;
7
8
  exports.stopCrawler = stopCrawler;
8
9
  exports.isCrawlerRunning = isCrawlerRunning;
@@ -13,21 +14,22 @@ const node_crypto_1 = require("node:crypto");
13
14
  const crawler_1 = require("./crawler");
14
15
  const sync_state_1 = require("./sync-state");
15
16
  const logger = cds_1.default.log('CardanoCrawler');
16
- /**
17
- * Module-level singleton lifecycle for the chain crawler. Mirrors NIGHTGATE's
18
- * srv/crawler/index.ts: one active crawler per process, started fire-and-forget from
19
- * the server's `served` hook and controlled (pause/resume/status) via the indexer service.
20
- */
17
+ // Process-wide crawler, started from the `served` hook and controlled via the indexer service.
21
18
  let active = null;
22
19
  let lifecycleQueue = Promise.resolve();
23
20
  let standbyDeps = null;
24
21
  let standbyTimer = null;
25
22
  let standbyGeneration = 0;
26
23
  const STANDBY_RETRY_MS = 5_000;
27
- /**
28
- * Start the crawler (idempotent — a no-op if one is already running). Fire-and-forget:
29
- * returns once the ingest pipeline is launched, not when catch-up completes.
30
- */
24
+ const STANDBY_MAX_BACKOFF_MS = 5 * 60_000;
25
+ // Delay before the next standby start: 5 s when healthy. After an error halt it grows
26
+ // exponentially up to 5 min with the shared cursor's error streak.
27
+ function standbyDelayMs(consecutiveErrors) {
28
+ if (!Number.isFinite(consecutiveErrors) || consecutiveErrors <= 1)
29
+ return STANDBY_RETRY_MS;
30
+ return Math.min(STANDBY_MAX_BACKOFF_MS, STANDBY_RETRY_MS * 2 ** Math.min(consecutiveErrors - 1, 10));
31
+ }
32
+ // Start the crawler, a no-op if one runs. Returns once the pipeline is launched, not when caught up.
31
33
  async function startCrawler(deps, resumeCluster = false) {
32
34
  const generation = ++standbyGeneration;
33
35
  standbyDeps = deps;
@@ -70,10 +72,7 @@ async function startCrawlerAttempt(deps, resumeCluster, generation) {
70
72
  active = null;
71
73
  });
72
74
  }
73
- /**
74
- * Stop the local crawler. `pauseCluster=true` additionally fences every instance via
75
- * shared DB intent; ordinary app shutdown leaves the desired state intact for failover.
76
- */
75
+ // Stop the local crawler. `pauseCluster` stops every instance. A normal shutdown keeps failover possible.
77
76
  async function stopCrawler(pauseCluster = false) {
78
77
  ++standbyGeneration; // invalidate callbacks that already left the timer queue
79
78
  standbyDeps = null;
@@ -113,7 +112,7 @@ function serializeLifecycle(operation) {
113
112
  return result;
114
113
  }
115
114
  /** Keep non-leader instances warm so an expired/released lease fails over automatically. */
116
- function scheduleStandby(generation) {
115
+ function scheduleStandby(generation, delayMs = STANDBY_RETRY_MS) {
117
116
  if (standbyTimer || !standbyDeps)
118
117
  return;
119
118
  standbyTimer = setTimeout(() => {
@@ -123,13 +122,28 @@ function scheduleStandby(generation) {
123
122
  const deps = standbyDeps;
124
123
  if (!deps)
125
124
  return;
125
+ // Local evidence only, taken BEFORE the attempt replaces `active`.
126
+ const failedHere = active?.haltedWithError() ?? false;
126
127
  void startCrawlerAttempt(deps, false, generation)
127
128
  .catch((err) => logger.error('standby lease attempt failed:', err))
128
- .finally(() => {
129
+ .then(() => nextStandbyDelay(failedHere))
130
+ .then((delay) => {
129
131
  if (generation === standbyGeneration)
130
- scheduleStandby(generation);
132
+ scheduleStandby(generation, delay);
131
133
  });
132
- }, STANDBY_RETRY_MS);
134
+ }, delayMs);
133
135
  standbyTimer.unref?.();
134
136
  }
137
+ /** Backoff from the error streak after a local failure. A healthy tick costs no DB read. */
138
+ async function nextStandbyDelay(failedHere) {
139
+ if (!failedHere)
140
+ return STANDBY_RETRY_MS;
141
+ try {
142
+ const cursor = await cds_1.default.tx((tx) => (0, sync_state_1.readCursor)(tx));
143
+ return standbyDelayMs(cursor?.consecutiveErrors ?? 0);
144
+ }
145
+ catch {
146
+ return STANDBY_RETRY_MS;
147
+ }
148
+ }
135
149
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,34 @@
1
+ /** Columns of an asset row besides its key, the same in the copies and in the output assets. */
2
+ export declare const ASSET_COLUMNS: string[];
3
+ export interface InputCopyPruneProgress {
4
+ atSlot: number;
5
+ toSlot: number;
6
+ referenced: number;
7
+ kept: number;
8
+ deleted: number;
9
+ }
10
+ export interface InputCopyRestoreProgress {
11
+ atSlot: number;
12
+ toSlot: number;
13
+ restored: number;
14
+ rows: number;
15
+ }
16
+ export interface SlotWalkOptions<P> {
17
+ fromSlot: number;
18
+ toSlot: number;
19
+ slotWindow?: number;
20
+ onProgress?: (p: P) => void;
21
+ }
22
+ export declare function referenceStatement(kind: string): string | null;
23
+ /** Deletes the copies of the inputs of a window that have a reference. */
24
+ export declare function deleteCopiesStatement(kind: string): string | null;
25
+ /** Counts the inputs of a window that have no reference. */
26
+ export declare function keptStatement(kind: string): string | null;
27
+ /** Writes the copies of the inputs of a window that have a reference, from the outputs they spent. */
28
+ export declare function restoreCopiesStatement(kind: string): string | null;
29
+ /** Takes the reference from the inputs of a window, once their copies are written. */
30
+ export declare function dropReferenceStatement(kind: string): string | null;
31
+ export declare function bothStatement(kind: string): string | null;
32
+ export declare function pruneInputAssetCopies(opts: SlotWalkOptions<InputCopyPruneProgress>): Promise<InputCopyPruneProgress>;
33
+ export declare function restoreInputAssetCopies(opts: SlotWalkOptions<InputCopyRestoreProgress>): Promise<InputCopyRestoreProgress>;
34
+ //# sourceMappingURL=input-asset-copies.d.ts.map
@@ -0,0 +1,171 @@
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.ASSET_COLUMNS = void 0;
7
+ exports.referenceStatement = referenceStatement;
8
+ exports.deleteCopiesStatement = deleteCopiesStatement;
9
+ exports.keptStatement = keptStatement;
10
+ exports.restoreCopiesStatement = restoreCopiesStatement;
11
+ exports.dropReferenceStatement = dropReferenceStatement;
12
+ exports.bothStatement = bothStatement;
13
+ exports.pruneInputAssetCopies = pruneInputAssetCopies;
14
+ exports.restoreInputAssetCopies = restoreInputAssetCopies;
15
+ const cds_1 = __importDefault(require("@sap/cds"));
16
+ const mappers_1 = require("../../utils/mappers");
17
+ const cardano_1 = require("#cds-models/odatano/cardano");
18
+ const { SELECT } = cds_1.default.ql;
19
+ const logger = cds_1.default.log('InputAssetCopies');
20
+ // An input reads its assets from a stored copy or, through `spentTxSeq`, from the output it spent.
21
+ // It has one of the two, never both. The prune moves the inputs of a slot range from copies to the
22
+ // reference, the restore moves them back. Both walk by the slot of the spending transaction.
23
+ const INPUTS = 'odatano_cardano_TransactionInputs';
24
+ const COPIES = 'odatano_cardano_TransactionInputAssetCopies';
25
+ const TRANSACTIONS = 'odatano_cardano_Transactions';
26
+ const OUTPUTS = 'odatano_cardano_TransactionOutputs';
27
+ const OUTPUT_ASSETS = 'odatano_cardano_TransactionOutputAssets';
28
+ /** Columns of an asset row besides its key, the same in the copies and in the output assets. */
29
+ exports.ASSET_COLUMNS = ['asset_quantity', 'asset_policyId', 'asset_assetNameHex', 'asset_assetName', 'asset_fingerprint'];
30
+ const supported = (kind) => kind === 'postgres' || kind === 'sqlite' || kind === 'better-sqlite';
31
+ const bounds = (kind) => (kind === 'postgres' ? ['$1', '$2'] : ['?', '?']);
32
+ // Points the inputs of a window at their output. Only where the output is stored and holds
33
+ // exactly the asset rows of the input's copy, so the input reads the same assets afterwards.
34
+ function referenceStatement(kind) {
35
+ if (!supported(kind))
36
+ return null;
37
+ const [lo, hi] = bounds(kind);
38
+ const copy = `c.input_txSeq = i.txSeq AND c.input_inputIndex = i.inputIndex`;
39
+ const spent = `a.output_txSeq = t.txSeq AND a.output_outputIndex = i.spentOutputIndex`;
40
+ return `UPDATE ${INPUTS} AS i SET spentTxSeq = t.txSeq FROM ${TRANSACTIONS} AS t ` +
41
+ `WHERE t.hash = i.spentTxHash AND i.spentTxSeq IS NULL AND i.txSeq >= ${lo} AND i.txSeq < ${hi} ` +
42
+ `AND EXISTS (SELECT 1 FROM ${OUTPUTS} AS o WHERE o.txSeq = t.txSeq AND o.outputIndex = i.spentOutputIndex) ` +
43
+ `AND NOT EXISTS (SELECT 1 FROM ${COPIES} AS c WHERE ${copy} AND NOT EXISTS (` +
44
+ `SELECT 1 FROM ${OUTPUT_ASSETS} AS a WHERE ${spent} AND a.unit = c.unit AND a.asset_quantity = c.asset_quantity)) ` +
45
+ `AND (SELECT count(*) FROM ${COPIES} AS c WHERE ${copy}) = (SELECT count(*) FROM ${OUTPUT_ASSETS} AS a WHERE ${spent})`;
46
+ }
47
+ /** Deletes the copies of the inputs of a window that have a reference. */
48
+ function deleteCopiesStatement(kind) {
49
+ if (!supported(kind))
50
+ return null;
51
+ const [lo, hi] = bounds(kind);
52
+ return `DELETE FROM ${COPIES} WHERE input_txSeq >= ${lo} AND input_txSeq < ${hi} AND EXISTS (` +
53
+ `SELECT 1 FROM ${INPUTS} AS i WHERE i.txSeq = ${COPIES}.input_txSeq AND i.inputIndex = ${COPIES}.input_inputIndex ` +
54
+ `AND i.spentTxSeq IS NOT NULL)`;
55
+ }
56
+ /** Counts the inputs of a window that have no reference. */
57
+ function keptStatement(kind) {
58
+ if (!supported(kind))
59
+ return null;
60
+ const [lo, hi] = bounds(kind);
61
+ return `SELECT count(*) AS n FROM ${INPUTS} WHERE txSeq >= ${lo} AND txSeq < ${hi} AND spentTxSeq IS NULL`;
62
+ }
63
+ /** Writes the copies of the inputs of a window that have a reference, from the outputs they spent. */
64
+ function restoreCopiesStatement(kind) {
65
+ if (!supported(kind))
66
+ return null;
67
+ const [lo, hi] = bounds(kind);
68
+ const columns = exports.ASSET_COLUMNS.join(', ');
69
+ return `INSERT INTO ${COPIES} (input_txSeq, input_inputIndex, unit, ${columns}) ` +
70
+ `SELECT i.txSeq, i.inputIndex, a.unit, ${exports.ASSET_COLUMNS.map(c => `a.${c}`).join(', ')} FROM ${INPUTS} AS i ` +
71
+ `JOIN ${OUTPUT_ASSETS} AS a ON a.output_txSeq = i.spentTxSeq AND a.output_outputIndex = i.spentOutputIndex ` +
72
+ `WHERE i.txSeq >= ${lo} AND i.txSeq < ${hi}`;
73
+ }
74
+ /** Takes the reference from the inputs of a window, once their copies are written. */
75
+ function dropReferenceStatement(kind) {
76
+ if (!supported(kind))
77
+ return null;
78
+ const [lo, hi] = bounds(kind);
79
+ return `UPDATE ${INPUTS} SET spentTxSeq = NULL WHERE txSeq >= ${lo} AND txSeq < ${hi} AND spentTxSeq IS NOT NULL`;
80
+ }
81
+ // Counts the inputs of a window that have copies and a reference. The view would show their
82
+ // assets twice, so a window that leaves one behind is rolled back.
83
+ function bothStatement(kind) {
84
+ if (!supported(kind))
85
+ return null;
86
+ const [lo, hi] = bounds(kind);
87
+ return `SELECT count(*) AS n FROM ${INPUTS} AS i WHERE i.txSeq >= ${lo} AND i.txSeq < ${hi} AND i.spentTxSeq IS NOT NULL ` +
88
+ `AND EXISTS (SELECT 1 FROM ${COPIES} AS c WHERE c.input_txSeq = i.txSeq AND c.input_inputIndex = i.inputIndex)`;
89
+ }
90
+ async function assertOneSource(tx, check, window) {
91
+ const [found] = await tx.run(check, window);
92
+ const both = Number(found?.n ?? 0);
93
+ if (both > 0)
94
+ throw new Error(`${both} inputs between txSeq ${window[0]} and ${window[1]} would have copies and a reference; the window is left unchanged`);
95
+ }
96
+ const dbKind = () => cds_1.default.db?.kind ?? '';
97
+ /** Rows a plain statement changed; the drivers answer with their own result object. */
98
+ function changed(result) {
99
+ const r = result;
100
+ return typeof r === 'number' ? r : Number(r?.changes ?? r?.rowCount) || 0;
101
+ }
102
+ function statementFor(build) {
103
+ const sql = build(dbKind());
104
+ if (!sql)
105
+ throw new Error(`Input asset copies are pruned and restored on PostgreSQL and SQLite only (database kind: ${dbKind() || 'none'})`);
106
+ return sql;
107
+ }
108
+ /** The asked slots cut to the slots that hold a stored input. Null when there is nothing to walk. */
109
+ async function slotRange(opts) {
110
+ const stored = (await cds_1.default.tx((tx) => tx.run(SELECT.one.from(cardano_1.TransactionInputs).columns('min(txSeq) as lo', 'max(txSeq) as hi'))));
111
+ if (stored?.lo == null || stored.hi == null)
112
+ return null;
113
+ const from = Math.max(opts.fromSlot, Math.floor(Number(stored.lo) / mappers_1.TX_SEQ_SLOT_FACTOR));
114
+ const to = Math.min(opts.toSlot, Math.floor(Number(stored.hi) / mappers_1.TX_SEQ_SLOT_FACTOR));
115
+ return from <= to ? { from, to } : null;
116
+ }
117
+ /** Calls `step` with the txSeq bounds of each slot window, each in a transaction of its own. */
118
+ async function walk(opts, progress, step) {
119
+ const slotWindow = opts.slotWindow ?? 20_000;
120
+ const range = await slotRange(opts);
121
+ if (!range)
122
+ return null;
123
+ progress.toSlot = range.to;
124
+ for (let slot = range.from; slot <= range.to; slot += slotWindow) {
125
+ const window = [slot * mappers_1.TX_SEQ_SLOT_FACTOR, Math.min(slot + slotWindow, range.to + 1) * mappers_1.TX_SEQ_SLOT_FACTOR];
126
+ await cds_1.default.tx((tx) => step(tx, window));
127
+ progress.atSlot = Math.min(slot + slotWindow - 1, range.to);
128
+ opts.onProgress?.({ ...progress });
129
+ }
130
+ return range;
131
+ }
132
+ // Moves the inputs of the slot range from copies to the reference. Per window, in one transaction:
133
+ // set the reference where the output's assets equal the copy, then delete the copies of those inputs.
134
+ async function pruneInputAssetCopies(opts) {
135
+ const reference = statementFor(referenceStatement);
136
+ const remove = statementFor(deleteCopiesStatement);
137
+ const count = statementFor(keptStatement);
138
+ const check = statementFor(bothStatement);
139
+ const progress = { atSlot: 0, toSlot: 0, referenced: 0, kept: 0, deleted: 0 };
140
+ const range = await walk(opts, progress, async (tx, window) => {
141
+ const referenced = changed(await tx.run(reference, window));
142
+ const deleted = changed(await tx.run(remove, window));
143
+ await assertOneSource(tx, check, window);
144
+ const [left] = await tx.run(count, window);
145
+ progress.referenced += referenced;
146
+ progress.deleted += deleted;
147
+ progress.kept += Number(left?.n ?? 0);
148
+ });
149
+ if (range)
150
+ logger.info(`input asset copies pruned: ${progress.referenced} inputs read from their output, ${progress.kept} left without a reference,${progress.deleted} rows deleted, slots ${range.from} to ${range.to}`);
151
+ return progress;
152
+ }
153
+ // Moves the inputs of the slot range back to copies. Per window, in one transaction: write the
154
+ // copies from the outputs, then take the reference from those inputs.
155
+ async function restoreInputAssetCopies(opts) {
156
+ const write = statementFor(restoreCopiesStatement);
157
+ const release = statementFor(dropReferenceStatement);
158
+ const check = statementFor(bothStatement);
159
+ const progress = { atSlot: 0, toSlot: 0, restored: 0, rows: 0 };
160
+ const range = await walk(opts, progress, async (tx, window) => {
161
+ const rows = changed(await tx.run(write, window));
162
+ const restored = changed(await tx.run(release, window));
163
+ await assertOneSource(tx, check, window);
164
+ progress.rows += rows;
165
+ progress.restored += restored;
166
+ });
167
+ if (range)
168
+ logger.info(`input asset copies restored: ${progress.restored} inputs, ${progress.rows} rows, slots ${range.from} to ${range.to}`);
169
+ return progress;
170
+ }
171
+ //# sourceMappingURL=input-asset-copies.js.map
@@ -0,0 +1,16 @@
1
+ export interface MetadataPositionProgress {
2
+ /** Slot the walk has reached. */
3
+ atSlot: number;
4
+ /** Last slot that holds a stored transaction. */
5
+ toSlot: number;
6
+ /** Metadata rows that received their position. */
7
+ rows: number;
8
+ }
9
+ export interface MetadataPositionOptions {
10
+ /** Slots per statement. */
11
+ slotWindow?: number;
12
+ onProgress?: (p: MetadataPositionProgress) => void;
13
+ }
14
+ export declare function metadataPositionStatement(kind: string): string | null;
15
+ export declare function backfillMetadataPositions(opts?: MetadataPositionOptions): Promise<MetadataPositionProgress>;
16
+ //# sourceMappingURL=metadata-position-backfill.d.ts.map
@@ -0,0 +1,55 @@
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.metadataPositionStatement = metadataPositionStatement;
7
+ exports.backfillMetadataPositions = backfillMetadataPositions;
8
+ const cds_1 = __importDefault(require("@sap/cds"));
9
+ const mappers_1 = require("../../utils/mappers");
10
+ const cardano_1 = require("#cds-models/odatano/cardano");
11
+ const { SELECT, UPDATE } = cds_1.default.ql;
12
+ const logger = cds_1.default.log('MetadataPositionBackfill');
13
+ const METADATA_TABLE = 'odatano_cardano_TransactionMetadata';
14
+ const TRANSACTIONS_TABLE = 'odatano_cardano_Transactions';
15
+ // One UPDATE per window that takes the position from the transaction row. Null for databases
16
+ // other than Postgres and SQLite, which update transaction by transaction.
17
+ function metadataPositionStatement(kind) {
18
+ if (kind !== 'postgres' && kind !== 'sqlite' && kind !== 'better-sqlite')
19
+ return null;
20
+ const [lo, hi] = kind === 'postgres' ? ['$1', '$2'] : ['?', '?'];
21
+ return `UPDATE ${METADATA_TABLE} AS m SET txSeq = t.txSeq FROM ${TRANSACTIONS_TABLE} AS t ` +
22
+ `WHERE t.hash = m.tx_hash AND m.txSeq IS NULL AND t.txSeq >= ${lo} AND t.txSeq < ${hi}`;
23
+ }
24
+ async function fillWindow(tx, lo, hi) {
25
+ const sql = metadataPositionStatement(cds_1.default.db?.kind ?? '');
26
+ if (sql) {
27
+ // a plain statement answers with the driver's result object
28
+ const result = await tx.run(sql, [lo, hi]);
29
+ return Number(result?.changes) || 0;
30
+ }
31
+ const txs = (await tx.run(SELECT.from(cardano_1.Transactions).columns('hash', 'txSeq').where({ txSeq: { '>=': lo, '<': hi } }))) ?? [];
32
+ let rows = 0;
33
+ for (const t of txs) {
34
+ rows += Number(await tx.run(UPDATE.entity(cardano_1.TransactionMetadata).set({ txSeq: Number(t.txSeq) }).where({ tx_hash: t.hash, txSeq: null }))) || 0;
35
+ }
36
+ return rows;
37
+ }
38
+ async function backfillMetadataPositions(opts = {}) {
39
+ const slotWindow = opts.slotWindow ?? 20_000;
40
+ const bounds = (await cds_1.default.tx((tx) => tx.run(SELECT.one.from(cardano_1.Transactions).columns('min(txSeq) as lo', 'max(txSeq) as hi'))));
41
+ const progress = { atSlot: 0, toSlot: 0, rows: 0 };
42
+ if (bounds?.lo == null || bounds.hi == null)
43
+ return progress;
44
+ const firstSlot = Math.floor(Number(bounds.lo) / mappers_1.TX_SEQ_SLOT_FACTOR);
45
+ progress.toSlot = Math.floor(Number(bounds.hi) / mappers_1.TX_SEQ_SLOT_FACTOR);
46
+ for (let slot = firstSlot; slot <= progress.toSlot; slot += slotWindow) {
47
+ const next = slot + slotWindow;
48
+ progress.rows += await cds_1.default.tx((tx) => fillWindow(tx, slot * mappers_1.TX_SEQ_SLOT_FACTOR, next * mappers_1.TX_SEQ_SLOT_FACTOR));
49
+ progress.atSlot = Math.min(next - 1, progress.toSlot);
50
+ opts.onProgress?.({ ...progress });
51
+ }
52
+ logger.info(`metadata positions: ${progress.rows} rows filled up to slot ${progress.toSlot}`);
53
+ return progress;
54
+ }
55
+ //# sourceMappingURL=metadata-position-backfill.js.map
@@ -0,0 +1,39 @@
1
+ import type { Transaction as CapTransaction } from '@sap/cds';
2
+ import type { CardanoClient } from '../cardano-client';
3
+ import type { TxOutputLine } from '../../utils/types';
4
+ /** A transaction as the source of its outputs' fields. */
5
+ export interface OutputSource {
6
+ hash: string;
7
+ txSeq: number;
8
+ outputs: TxOutputLine[];
9
+ }
10
+ /** Rows that received at least one field, per table. */
11
+ export interface OutputFillCounts {
12
+ outputs: number;
13
+ inputs: number;
14
+ ledgerUtxos: number;
15
+ }
16
+ export declare function fillOutputFields(tx: CapTransaction, sources: OutputSource[]): Promise<OutputFillCounts>;
17
+ export declare class OutputDatumBackfillError extends Error {
18
+ constructor(message: string);
19
+ }
20
+ export interface OutputDatumBackfillProgress extends OutputFillCounts {
21
+ /** Stored outputs read. */
22
+ scanned: number;
23
+ /** Outputs with a datum hash and no inline datum. */
24
+ candidates: number;
25
+ /** Transactions read again from the backend. */
26
+ transactions: number;
27
+ /** Candidate transactions the backend did not return. */
28
+ missing: number;
29
+ }
30
+ export interface OutputDatumBackfillOptions {
31
+ client: Pick<CardanoClient, 'getTransactionsBatch' | 'supports'>;
32
+ /** Stored outputs per page. Must exceed the outputs one transaction can hold. */
33
+ chunkSize?: number;
34
+ /** Transactions per backend read. */
35
+ batchSize?: number;
36
+ onProgress?: (p: OutputDatumBackfillProgress) => void;
37
+ }
38
+ export declare function backfillOutputDatums(opts: OutputDatumBackfillOptions): Promise<OutputDatumBackfillProgress>;
39
+ //# sourceMappingURL=output-datum-backfill.d.ts.map