@odatano/core 2.0.0-rc.23 → 2.0.0-rc.25

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 (80) hide show
  1. package/@cds-models/CardanoBackendService/index.d.ts +357 -0
  2. package/@cds-models/CardanoBackendService/index.js +40 -0
  3. package/@cds-models/CardanoIndexerService/index.d.ts +37 -0
  4. package/@cds-models/CardanoIndexerService/index.js +4 -0
  5. package/@cds-models/CardanoODataService/index.d.ts +27 -2
  6. package/@cds-models/CardanoODataService/index.js +3 -0
  7. package/@cds-models/CardanoSignService/index.d.ts +23 -1
  8. package/@cds-models/CardanoSignService/index.js +3 -0
  9. package/@cds-models/CardanoTransactionService/index.d.ts +34 -1
  10. package/@cds-models/CardanoTransactionService/index.js +4 -0
  11. package/@cds-models/index.d.ts +18 -0
  12. package/@cds-models/index.js +3 -0
  13. package/@cds-models/odatano/cardano/index.d.ts +49 -2
  14. package/@cds-models/odatano/cardano/index.js +6 -0
  15. package/db/schema.cds +74 -3
  16. package/db/types.cds +27 -0
  17. package/package.json +182 -181
  18. package/srv/blockchain/backends/blockfrost-backend.js +4 -2
  19. package/srv/blockchain/backends/cardano-backend.d.ts +0 -2
  20. package/srv/blockchain/backends/koios-backend.d.ts +1 -1
  21. package/srv/blockchain/backends/koios-backend.js +61 -14
  22. package/srv/blockchain/backends/odatano-backend.d.ts +64 -0
  23. package/srv/blockchain/backends/odatano-backend.js +166 -0
  24. package/srv/blockchain/backends/ogmios-backend.d.ts +12 -2
  25. package/srv/blockchain/backends/ogmios-backend.js +91 -21
  26. package/srv/blockchain/cardano-client.d.ts +23 -9
  27. package/srv/blockchain/cardano-client.js +77 -25
  28. package/srv/blockchain/cardano-indexer.d.ts +61 -15
  29. package/srv/blockchain/cardano-indexer.js +248 -79
  30. package/srv/blockchain/cardano-tx-builder.d.ts +11 -1
  31. package/srv/blockchain/cardano-tx-builder.js +59 -4
  32. package/srv/blockchain/crawler/certificate-backfill.d.ts +22 -0
  33. package/srv/blockchain/crawler/certificate-backfill.js +49 -30
  34. package/srv/blockchain/crawler/crawler.d.ts +3 -1
  35. package/srv/blockchain/crawler/crawler.js +12 -7
  36. package/srv/blockchain/crawler/sync-state.d.ts +3 -1
  37. package/srv/blockchain/crawler/sync-state.js +15 -2
  38. package/srv/blockchain/crawler/transaction-backfill.d.ts +52 -0
  39. package/srv/blockchain/crawler/transaction-backfill.js +283 -0
  40. package/srv/blockchain/crawler/utxo-set-import.d.ts +9 -0
  41. package/srv/blockchain/crawler/utxo-set-import.js +138 -47
  42. package/srv/blockchain/ledger-state.d.ts +16 -1
  43. package/srv/blockchain/ledger-state.js +38 -18
  44. package/srv/blockchain/pending-spends.d.ts +28 -0
  45. package/srv/blockchain/pending-spends.js +89 -0
  46. package/srv/blockchain/stored-chain.d.ts +33 -0
  47. package/srv/blockchain/stored-chain.js +234 -0
  48. package/srv/blockchain/transaction-building/buildooor-tx.d.ts +12 -3
  49. package/srv/blockchain/transaction-building/buildooor-tx.js +203 -21
  50. package/srv/blockchain/transaction-building/cardano-tx.d.ts +2 -1
  51. package/srv/blockchain/transaction-rows.d.ts +1 -1
  52. package/srv/blockchain/transaction-rows.js +2 -1
  53. package/srv/blockchain/wallet-worker/build-request.js +1 -1
  54. package/srv/cardano-backend-service.cds +52 -0
  55. package/srv/cardano-backend-service.d.ts +2 -0
  56. package/srv/cardano-backend-service.js +244 -0
  57. package/srv/cardano-indexer-service.cds +201 -176
  58. package/srv/cardano-indexer-service.js +104 -10
  59. package/srv/cardano-service.cds +5 -0
  60. package/srv/cardano-tx-service.cds +39 -0
  61. package/srv/cardano-tx-service.js +88 -14
  62. package/srv/server.js +20 -2
  63. package/srv/utils/agent-grants.js +8 -0
  64. package/srv/utils/const.d.ts +5 -0
  65. package/srv/utils/const.js +6 -1
  66. package/srv/utils/error-codes.d.ts +2 -0
  67. package/srv/utils/error-codes.js +2 -0
  68. package/srv/utils/errors.d.ts +7 -0
  69. package/srv/utils/errors.js +11 -1
  70. package/srv/utils/mappers.d.ts +24 -2
  71. package/srv/utils/mappers.js +49 -0
  72. package/srv/utils/pg-inline-json.d.ts +8 -0
  73. package/srv/utils/pg-inline-json.js +63 -0
  74. package/srv/utils/tx-build-helper.d.ts +2 -0
  75. package/srv/utils/tx-build-helper.js +12 -0
  76. package/srv/utils/tx-request-parsers.d.ts +46 -5
  77. package/srv/utils/tx-request-parsers.js +227 -16
  78. package/srv/utils/types.d.ts +59 -0
  79. package/srv/utils/validators.d.ts +5 -1
  80. package/srv/utils/validators.js +19 -9
@@ -0,0 +1,28 @@
1
+ import type { UTxO } from '../utils/types';
2
+ /** How long a submitted transaction counts as pending when no crawled block confirms it earlier. */
3
+ export declare const PENDING_TX_TTL_MS: number;
4
+ /**
5
+ * Transactions this process submitted that the ledger view does not show yet. The node's ledger
6
+ * state and the crawled UTxO set both still list their inputs as unspent while they wait in the
7
+ * mempool, so a second build would spend the same outputs. Builders skip those inputs and may
8
+ * spend the pending outputs (change) instead. Process-local; an entry ends when a crawled block
9
+ * holds the transaction or after PENDING_TX_TTL_MS.
10
+ */
11
+ export declare class PendingSpends {
12
+ private readonly now;
13
+ private readonly txs;
14
+ constructor(now?: () => number);
15
+ /** Remember a submitted transaction; unparseable CBOR is ignored (the submit already succeeded). */
16
+ record(signedTxCbor: string): void;
17
+ /** The pending transaction that spends this output, if any. */
18
+ spentBy(txHash: string, outputIndex: number): string | undefined;
19
+ /**
20
+ * The UTxOs of an address as they are after the pending transactions: inputs they spend are
21
+ * removed, their outputs to the address are added. A pending transaction whose outputs already
22
+ * appear in `utxos` has been crawled and is forgotten.
23
+ */
24
+ apply(address: string, utxos: UTxO[]): UTxO[];
25
+ get size(): number;
26
+ private prune;
27
+ }
28
+ //# sourceMappingURL=pending-spends.d.ts.map
@@ -0,0 +1,89 @@
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.PendingSpends = exports.PENDING_TX_TTL_MS = void 0;
7
+ const cds_1 = __importDefault(require("@sap/cds"));
8
+ const parse_1 = require("../cbor/parse");
9
+ const logger = cds_1.default.log('PendingSpends');
10
+ /** How long a submitted transaction counts as pending when no crawled block confirms it earlier. */
11
+ exports.PENDING_TX_TTL_MS = 10 * 60_000;
12
+ const refKey = (txHash, outputIndex) => `${txHash.toLowerCase()}#${outputIndex}`;
13
+ /**
14
+ * Transactions this process submitted that the ledger view does not show yet. The node's ledger
15
+ * state and the crawled UTxO set both still list their inputs as unspent while they wait in the
16
+ * mempool, so a second build would spend the same outputs. Builders skip those inputs and may
17
+ * spend the pending outputs (change) instead. Process-local; an entry ends when a crawled block
18
+ * holds the transaction or after PENDING_TX_TTL_MS.
19
+ */
20
+ class PendingSpends {
21
+ now;
22
+ txs = new Map();
23
+ constructor(now = Date.now) {
24
+ this.now = now;
25
+ }
26
+ /** Remember a submitted transaction; unparseable CBOR is ignored (the submit already succeeded). */
27
+ record(signedTxCbor) {
28
+ try {
29
+ const parsed = (0, parse_1.parseTransaction)(signedTxCbor);
30
+ this.txs.set(parsed.txHash, {
31
+ inputs: parsed.inputs.map((i) => refKey(i.txHash, i.outputIndex)),
32
+ outputs: parsed.outputs.map((o, outputIndex) => ({
33
+ txHash: parsed.txHash,
34
+ outputIndex,
35
+ address: o.address,
36
+ amount: [{ unit: 'lovelace', quantity: o.lovelace }, ...o.assets],
37
+ datumHash: o.datumHash,
38
+ inlineDatum: o.inlineDatumHex,
39
+ scriptRefCbor: o.referenceScriptHex,
40
+ })),
41
+ expiresAt: this.now() + exports.PENDING_TX_TTL_MS,
42
+ });
43
+ }
44
+ catch (err) {
45
+ logger.warn(`submitted transaction not tracked as pending: ${err instanceof Error ? err.message : String(err)}`);
46
+ }
47
+ }
48
+ /** The pending transaction that spends this output, if any. */
49
+ spentBy(txHash, outputIndex) {
50
+ this.prune();
51
+ const key = refKey(txHash, outputIndex);
52
+ for (const [hash, tx] of this.txs)
53
+ if (tx.inputs.includes(key))
54
+ return hash;
55
+ return undefined;
56
+ }
57
+ /**
58
+ * The UTxOs of an address as they are after the pending transactions: inputs they spend are
59
+ * removed, their outputs to the address are added. A pending transaction whose outputs already
60
+ * appear in `utxos` has been crawled and is forgotten.
61
+ */
62
+ apply(address, utxos) {
63
+ this.prune();
64
+ if (this.txs.size === 0)
65
+ return utxos;
66
+ const listed = new Set(utxos.map((u) => u.txHash.toLowerCase()));
67
+ for (const hash of [...this.txs.keys()])
68
+ if (listed.has(hash))
69
+ this.txs.delete(hash);
70
+ const spent = new Set([...this.txs.values()].flatMap((t) => t.inputs));
71
+ const keep = utxos.filter((u) => !spent.has(refKey(u.txHash, u.outputIndex)));
72
+ const pendingOut = [...this.txs.values()]
73
+ .flatMap((t) => t.outputs)
74
+ .filter((o) => o.address === address && !spent.has(refKey(o.txHash, o.outputIndex)));
75
+ return [...keep, ...pendingOut];
76
+ }
77
+ get size() {
78
+ this.prune();
79
+ return this.txs.size;
80
+ }
81
+ prune() {
82
+ const now = this.now();
83
+ for (const [hash, tx] of this.txs)
84
+ if (tx.expiresAt <= now)
85
+ this.txs.delete(hash);
86
+ }
87
+ }
88
+ exports.PendingSpends = PendingSpends;
89
+ //# sourceMappingURL=pending-spends.js.map
@@ -0,0 +1,33 @@
1
+ import type { Transaction as CapTransaction } from '@sap/cds';
2
+ import type { BlockData, MetadataLabelTx, Transaction as ProviderTransaction } from '../utils/types';
3
+ /**
4
+ * Stored blocks and transactions back in the provider shape (`BlockData`, `Transaction`), for
5
+ * serving other ODATANO instances from what this one has indexed. The rows hold the ledger view
6
+ * (see ledgerView), so the phase-2 flag follows from them: a valid transaction always spends a
7
+ * regular input. Not stored, so absent: `totalCollateral` and `outputAmount`.
8
+ */
9
+ type Row = Record<string, unknown>;
10
+ /** `Blocks` row -> BlockData. */
11
+ export declare function blockRowToData(row: Row): BlockData;
12
+ /** A stored block by hash; null when not indexed. */
13
+ export declare function readBlock(db: CapTransaction, hash: string): Promise<BlockData | null>;
14
+ /** A stored block by height; null when not indexed. */
15
+ export declare function readBlockByHeight(db: CapTransaction, height: number): Promise<BlockData | null>;
16
+ /**
17
+ * Up to `count` stored blocks following height `afterHeight`, contiguous only: the run stops at
18
+ * the first missing height, so a caller never walks over a gap.
19
+ */
20
+ export declare function readNextBlocks(db: CapTransaction, afterHeight: number, count: number): Promise<BlockData[]>;
21
+ /** True when a stored input lacks its outpoint (row indexed before outpoints were recorded). */
22
+ export declare function lacksOutpoints(t: ProviderTransaction): boolean;
23
+ /** Stored transactions by hash (missing hashes are absent from the map). */
24
+ export declare function readTransactionsByHash(db: CapTransaction, hashes: string[]): Promise<Map<string, ProviderTransaction>>;
25
+ /**
26
+ * Stored transactions of a block in block order; null when the block is not stored with all of its
27
+ * transactions (a lazily indexed block may hold only the ones somebody asked for).
28
+ */
29
+ export declare function readBlockTransactions(db: CapTransaction, blockHash: string): Promise<ProviderTransaction[] | null>;
30
+ /** Metadata of a stored transaction; null when the transaction is not stored. */
31
+ export declare function readTransactionMetadata(db: CapTransaction, txHash: string): Promise<MetadataLabelTx[] | null>;
32
+ export {};
33
+ //# sourceMappingURL=stored-chain.d.ts.map
@@ -0,0 +1,234 @@
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.blockRowToData = blockRowToData;
7
+ exports.readBlock = readBlock;
8
+ exports.readBlockByHeight = readBlockByHeight;
9
+ exports.readNextBlocks = readNextBlocks;
10
+ exports.lacksOutpoints = lacksOutpoints;
11
+ exports.readTransactionsByHash = readTransactionsByHash;
12
+ exports.readBlockTransactions = readBlockTransactions;
13
+ exports.readTransactionMetadata = readTransactionMetadata;
14
+ const cds_1 = __importDefault(require("@sap/cds"));
15
+ const client_1 = require("@cardano-ogmios/client");
16
+ const cardano_1 = require("#cds-models/odatano/cardano");
17
+ const collections_1 = require("../utils/collections");
18
+ const { SELECT } = cds_1.default.ql;
19
+ const num = (v) => Number(v ?? 0);
20
+ const numOrNull = (v) => (v == null ? null : Number(v));
21
+ const str = (v) => (v == null ? '' : String(v));
22
+ /** `Blocks` row -> BlockData. */
23
+ function blockRowToData(row) {
24
+ return {
25
+ time: Math.floor(Date.parse(str(row.time)) / 1000),
26
+ height: numOrNull(row.height),
27
+ hash: str(row.hash),
28
+ slot: numOrNull(row.slot),
29
+ slotLeader: str(row.slotLeader),
30
+ epoch: numOrNull(row.epochNumber),
31
+ epochSlot: numOrNull(row.epochSlot),
32
+ size: num(row.size),
33
+ txCount: num(row.txCount),
34
+ fees: row.fees == null ? null : String(row.fees),
35
+ };
36
+ }
37
+ /** A stored block by hash; null when not indexed. */
38
+ async function readBlock(db, hash) {
39
+ const row = await db.run(SELECT.one.from(cardano_1.Blocks).where({ hash }));
40
+ return row ? blockRowToData(row) : null;
41
+ }
42
+ /** A stored block by height; null when not indexed. */
43
+ async function readBlockByHeight(db, height) {
44
+ const row = await db.run(SELECT.one.from(cardano_1.Blocks).where({ height }));
45
+ return row ? blockRowToData(row) : null;
46
+ }
47
+ /**
48
+ * Up to `count` stored blocks following height `afterHeight`, contiguous only: the run stops at
49
+ * the first missing height, so a caller never walks over a gap.
50
+ */
51
+ async function readNextBlocks(db, afterHeight, count) {
52
+ const rows = await db.run(
53
+ // one operator per column object: `{ '>': a, '<=': b }` renders as `height > a <= b`
54
+ SELECT.from(cardano_1.Blocks).where({ height: { between: afterHeight + 1, and: afterHeight + count } }).orderBy('height asc'));
55
+ const out = [];
56
+ let expected = afterHeight + 1;
57
+ for (const row of rows ?? []) {
58
+ if (num(row.height) !== expected)
59
+ break;
60
+ out.push(blockRowToData(row));
61
+ expected++;
62
+ }
63
+ return out;
64
+ }
65
+ /** True when a stored input lacks its outpoint (row indexed before outpoints were recorded). */
66
+ function lacksOutpoints(t) {
67
+ return (t.inputs ?? []).some(i => i.txHash == null);
68
+ }
69
+ /** Stored transactions by hash (missing hashes are absent from the map). */
70
+ async function readTransactionsByHash(db, hashes) {
71
+ const rows = [];
72
+ for (const hashChunk of (0, collections_1.chunk)(hashes, collections_1.IN_CHUNK)) {
73
+ rows.push(...((await db.run(SELECT.from(cardano_1.Transactions).where({ hash: { in: hashChunk } }))) ?? []));
74
+ }
75
+ const txs = await assembleTransactions(db, rows);
76
+ return new Map(txs.map(t => [t.hash, t]));
77
+ }
78
+ /**
79
+ * Stored transactions of a block in block order; null when the block is not stored with all of its
80
+ * transactions (a lazily indexed block may hold only the ones somebody asked for).
81
+ */
82
+ async function readBlockTransactions(db, blockHash) {
83
+ const block = await db.run(SELECT.one.from(cardano_1.Blocks).columns('txCount').where({ hash: blockHash }));
84
+ if (!block)
85
+ return null;
86
+ const rows = await db.run(SELECT.from(cardano_1.Transactions).where({ blockHash }).orderBy('txIndex asc'));
87
+ if ((rows ?? []).length !== num(block.txCount))
88
+ return null;
89
+ return assembleTransactions(db, rows ?? []);
90
+ }
91
+ /** Metadata of a stored transaction; null when the transaction is not stored. */
92
+ async function readTransactionMetadata(db, txHash) {
93
+ const known = await db.run(SELECT.one.from(cardano_1.Transactions).columns('hash').where({ hash: txHash }));
94
+ if (!known)
95
+ return null;
96
+ const rows = await db.run(SELECT.from(cardano_1.TransactionMetadata_).where({ tx_hash: txHash }));
97
+ return (rows ?? []).map(metadataRow);
98
+ }
99
+ function metadataRow(r) {
100
+ return {
101
+ txHash: str(r.tx_hash),
102
+ label: str(r.label),
103
+ json: r.payload == null ? undefined : client_1.safeJSON.parse(String(r.payload)),
104
+ };
105
+ }
106
+ /** Amount list with lovelace first, as the providers deliver it. */
107
+ function amounts(assets) {
108
+ const list = assets.map(a => ({ unit: str(a.unit), quantity: str(a.asset_quantity) }));
109
+ return [...list.filter(a => a.unit === 'lovelace'), ...list.filter(a => a.unit !== 'lovelace')];
110
+ }
111
+ function groupBy(rows, key) {
112
+ const out = new Map();
113
+ for (const r of rows) {
114
+ const k = key(r);
115
+ const list = out.get(k);
116
+ if (list)
117
+ list.push(r);
118
+ else
119
+ out.set(k, [r]);
120
+ }
121
+ return out;
122
+ }
123
+ /** Transactions rows + their child tables -> provider transactions, in the order of `rows`. */
124
+ async function assembleTransactions(db, rows) {
125
+ if (rows.length === 0)
126
+ return [];
127
+ const seqs = rows.map(r => r.txSeq);
128
+ const hashes = rows.map(r => str(r.hash));
129
+ const fetchIn = async (entity, column, keys) => {
130
+ const out = [];
131
+ for (const c of (0, collections_1.chunk)(keys, collections_1.IN_CHUNK)) {
132
+ out.push(...((await db.run(SELECT.from(entity).where({ [column]: { in: c } }))) ?? []));
133
+ }
134
+ return out;
135
+ };
136
+ const [inputs, inputAssets, outputs, outputAssets, metadata, certificates, withdrawals, mints, redeemers] = await Promise.all([
137
+ fetchIn(cardano_1.TransactionInputs, 'txSeq', seqs),
138
+ fetchIn(cardano_1.TransactionInputAssets, 'input_txSeq', seqs),
139
+ fetchIn(cardano_1.TransactionOutputs, 'txSeq', seqs),
140
+ fetchIn(cardano_1.TransactionOutputAssets, 'output_txSeq', seqs),
141
+ fetchIn(cardano_1.TransactionMetadata_, 'tx_hash', hashes),
142
+ fetchIn(cardano_1.TransactionCertificates, 'tx_hash', hashes),
143
+ fetchIn(cardano_1.TransactionWithdrawals, 'tx_hash', hashes),
144
+ fetchIn(cardano_1.AssetHistory_, 'txHash', hashes),
145
+ fetchIn(cardano_1.TransactionRedeemers, 'tx_hash', hashes),
146
+ ]);
147
+ const inputsBySeq = groupBy(inputs, r => str(r.txSeq));
148
+ const inputAssetsByKey = groupBy(inputAssets, r => `${r.input_txSeq}#${r.input_inputIndex}`);
149
+ const outputsBySeq = groupBy(outputs, r => str(r.txSeq));
150
+ const outputAssetsByKey = groupBy(outputAssets, r => `${r.output_txSeq}#${r.output_outputIndex}`);
151
+ const metadataByHash = groupBy(metadata, r => str(r.tx_hash));
152
+ const certsByHash = groupBy(certificates, r => str(r.tx_hash));
153
+ const withdrawalsByHash = groupBy(withdrawals, r => str(r.tx_hash));
154
+ const mintsByHash = groupBy(mints, r => str(r.txHash));
155
+ const redeemersByHash = groupBy(redeemers, r => str(r.tx_hash));
156
+ return rows.map((t) => {
157
+ const seq = str(t.txSeq);
158
+ const hash = str(t.hash);
159
+ const txInputs = (inputsBySeq.get(seq) ?? [])
160
+ .sort((a, b) => num(a.inputIndex) - num(b.inputIndex))
161
+ .map(i => ({
162
+ address: str(i.address_address),
163
+ amount: amounts(inputAssetsByKey.get(`${seq}#${i.inputIndex}`) ?? []),
164
+ // null on rows indexed before the outpoint was recorded, never a made-up reference
165
+ txHash: (i.spentTxHash ?? null),
166
+ outputIndex: numOrNull(i.spentOutputIndex),
167
+ dataHash: i.utxoData_dataHash ?? null,
168
+ inlineDatum: i.utxoData_inlineDatum ?? null,
169
+ referenceScriptHash: i.utxoData_referenceScriptHash ?? null,
170
+ isCollateral: Boolean(i.isCollateral),
171
+ isReference: Boolean(i.isReference),
172
+ }));
173
+ // a phase-2 failure keeps only collateral and reference inputs, and its collateral return
174
+ const spendsCollaterals = txInputs.some(i => i.isCollateral) && !txInputs.some(i => !i.isCollateral && !i.isReference);
175
+ const txOutputs = (outputsBySeq.get(seq) ?? [])
176
+ .sort((a, b) => num(a.outputIndex) - num(b.outputIndex))
177
+ .map(o => ({
178
+ address: str(o.address_address),
179
+ amount: amounts(outputAssetsByKey.get(`${seq}#${o.outputIndex}`) ?? []),
180
+ txHash: hash,
181
+ outputIndex: num(o.outputIndex),
182
+ dataHash: o.utxo_dataHash ?? null,
183
+ inlineDatum: o.utxo_inlineDatum ?? null,
184
+ isCollateral: spendsCollaterals,
185
+ referenceScriptHash: o.utxo_referenceScriptHash ?? null,
186
+ }));
187
+ const certs = certsByHash.get(hash);
188
+ const withdrawn = withdrawalsByHash.get(hash);
189
+ const minted = mintsByHash.get(hash);
190
+ const redeemed = redeemersByHash.get(hash);
191
+ return {
192
+ hash,
193
+ blockHash: str(t.blockHash),
194
+ blockHeight: num(t.blockHeight),
195
+ slot: num(t.slot),
196
+ index: num(t.txIndex),
197
+ fee: str(t.fee ?? '0'),
198
+ deposit: str(t.deposit ?? '0'),
199
+ size: numOrNull(t.size),
200
+ blockTime: num(t.blockTime),
201
+ spendsCollaterals,
202
+ mint: minted?.map(m => ({
203
+ unit: str(m.unit),
204
+ quantity: (m.action === 'burn' ? '-' : '') + str(m.quantity),
205
+ })),
206
+ inputs: txInputs,
207
+ outputs: txOutputs,
208
+ metadata: (metadataByHash.get(hash) ?? []).map(metadataRow),
209
+ certificates: certs?.map((c) => ({
210
+ certIndex: num(c.certIndex),
211
+ kind: str(c.kind),
212
+ stakeAddress: c.stakeAddress ?? null,
213
+ poolId: c.poolId ?? null,
214
+ drepId: c.drepId ?? null,
215
+ deposit: c.deposit == null ? null : String(c.deposit),
216
+ epoch: numOrNull(c.epoch),
217
+ })),
218
+ withdrawals: withdrawn?.map((w) => ({ stakeAddress: str(w.stakeAddress), amount: str(w.lovelace) })),
219
+ redeemers: redeemed
220
+ ?.sort((a, b) => str(a.purpose).localeCompare(str(b.purpose)) || num(a.redeemerIndex) - num(b.redeemerIndex))
221
+ .map((r) => ({
222
+ purpose: str(r.purpose),
223
+ index: num(r.redeemerIndex),
224
+ data: str(r.data),
225
+ mem: str(r.mem),
226
+ steps: str(r.steps),
227
+ txHash: r.spentTxHash ?? null,
228
+ outputIndex: numOrNull(r.spentOutputIndex),
229
+ policyId: r.policyId ?? null,
230
+ })),
231
+ };
232
+ });
233
+ }
234
+ //# sourceMappingURL=stored-chain.js.map
@@ -1,5 +1,5 @@
1
1
  import type { CardanoTxBuilder } from "./cardano-tx";
2
- import type { TxBuildRequest, TxBuildMintRequest, TxBuildPlutusSpendRequest, TxBuildContext, TxBuildResult, LedgerProtocolParameters } from "../../utils/types";
2
+ import type { TxBuildRequest, TxBuildMintRequest, TxBuildPlutusSpendRequest, TxBuildPlutusRequest, TxBuildContext, TxBuildResult, LedgerProtocolParameters } from "../../utils/types";
3
3
  import { CardanoClient } from "../cardano-client";
4
4
  /** CardanoTxBuilder implementation on top of Buildooor. */
5
5
  export declare class BuildooorTxBuilder implements CardanoTxBuilder {
@@ -35,6 +35,13 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
35
35
  private _buildSimpleTransfer;
36
36
  buildUnsignedMintTransaction(req: TxBuildMintRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
37
37
  buildUnsignedPlutusSpendTransaction(req: TxBuildPlutusSpendRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
38
+ /**
39
+ * Several script inputs in one transaction, each with its own redeemer (inline validator or a
40
+ * reference-script UTxO), the outputs exactly in the given order and change after them.
41
+ */
42
+ buildUnsignedPlutusTransaction(req: TxBuildPlutusRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
43
+ /** Outputs of a BuildPlutusTransaction in the given order: inline datum or datum hash, ref script, min-ADA each. */
44
+ private _appendPlutusOutputs;
38
45
  /** Extract CBOR, hash, fee, size, inputs and outputs from a built Buildooor Tx */
39
46
  private _extractTxDetails;
40
47
  /** Build the standard TxBuildResult object */
@@ -89,6 +96,8 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
89
96
  * refs absent from utxos are ignored (existence is validated upstream).
90
97
  */
91
98
  private _partitionForcedInputs;
99
+ /** Keys (`txhash#index`) of the reference inputs of a build, from the resolved UTxOs and the request refs. */
100
+ private _referencedKeys;
92
101
  /** Map resolved CIP-31 reference input UTxOs to Buildooor LedgerUTxO; empty when none. */
93
102
  private _mapReferenceInputs;
94
103
  /**
@@ -131,8 +140,8 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
131
140
  /** Parse a Plutus V3 CBOR hex into a Buildooor Script for refScript attachment. */
132
141
  private _parseReferenceScript;
133
142
  /**
134
- * Map an input UTxO's scriptRef to a Script. Blockfrost/Ogmios set scriptRef to the 28-byte
135
- * hash (56 hex chars), Koios to the full CBOR bytes; only full bytes are usable locally.
143
+ * Map an input UTxO's reference script to a Script: `scriptRefCbor` (Ogmios), else a full-CBOR
144
+ * `scriptRef` (Koios); Blockfrost and the tables carry the 28-byte hash only, unusable locally.
136
145
  */
137
146
  private _buildInputRefScript;
138
147
  /**