@odatano/core 2.0.0-rc.5 → 2.0.0-rc.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/CardanoAgentService/index.d.ts +99 -51
- package/@cds-models/CardanoAgentService/index.js +15 -0
- package/@cds-models/CardanoBackendService/index.d.ts +358 -0
- package/@cds-models/CardanoBackendService/index.js +41 -0
- package/@cds-models/CardanoIndexerService/index.d.ts +594 -11
- package/@cds-models/CardanoIndexerService/index.js +74 -0
- package/@cds-models/CardanoODataService/index.d.ts +417 -57
- package/@cds-models/CardanoODataService/index.js +42 -0
- package/@cds-models/CardanoSignService/index.d.ts +45 -19
- package/@cds-models/CardanoSignService/index.js +4 -0
- package/@cds-models/CardanoTransactionService/index.d.ts +70 -44
- package/@cds-models/CardanoTransactionService/index.js +5 -0
- package/@cds-models/CardanoWorkerService/index.d.ts +35 -22
- package/@cds-models/CardanoWorkerService/index.js +2 -0
- package/@cds-models/index.d.ts +114 -4
- package/@cds-models/index.js +20 -4
- package/@cds-models/odatano/cardano/index.d.ts +451 -32
- package/@cds-models/odatano/cardano/index.js +48 -0
- package/README.md +103 -167
- package/db/schema.cds +2455 -1705
- package/db/types.cds +456 -295
- package/package.json +41 -53
- package/scripts/deploy-schema.mjs +113 -0
- package/scripts/migrate-schema.mjs +528 -0
- package/scripts/migrate-slot-leader.mjs +96 -0
- package/src/index.d.ts +20 -21
- package/src/index.js +45 -31
- package/src/plugin.js +17 -35
- package/srv/blockchain/asset-decimals.d.ts +7 -0
- package/srv/blockchain/asset-decimals.js +91 -0
- package/srv/blockchain/backends/blockfrost-backend.d.ts +25 -137
- package/srv/blockchain/backends/blockfrost-backend.js +125 -215
- package/srv/blockchain/backends/call-signal.d.ts +7 -0
- package/srv/blockchain/backends/call-signal.js +22 -0
- package/srv/blockchain/backends/cardano-backend.d.ts +100 -189
- package/srv/blockchain/backends/cardano-backend.js +29 -5
- package/srv/blockchain/backends/koios-backend.d.ts +108 -170
- package/srv/blockchain/backends/koios-backend.js +488 -482
- package/srv/blockchain/backends/odatano-backend.d.ts +55 -0
- package/srv/blockchain/backends/odatano-backend.js +211 -0
- package/srv/blockchain/backends/ogmios-backend.d.ts +122 -190
- package/srv/blockchain/backends/ogmios-backend.js +683 -327
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +14 -0
- package/srv/blockchain/backends/ogmios-frame-guard.js +89 -0
- package/srv/blockchain/cardano-client.d.ts +71 -241
- package/srv/blockchain/cardano-client.js +354 -322
- package/srv/blockchain/cardano-indexer.d.ts +295 -283
- package/srv/blockchain/cardano-indexer.js +1690 -502
- package/srv/blockchain/cardano-tx-builder.d.ts +25 -89
- package/srv/blockchain/cardano-tx-builder.js +164 -140
- package/srv/blockchain/circuit-breaker.d.ts +2 -13
- package/srv/blockchain/circuit-breaker.js +11 -15
- package/srv/blockchain/crawler/account-snapshots.d.ts +29 -0
- package/srv/blockchain/crawler/account-snapshots.js +173 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +17 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/asset-registry-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/asset-registry-backfill.js +157 -0
- package/srv/blockchain/crawler/asset-slice-backfill.d.ts +35 -0
- package/srv/blockchain/crawler/asset-slice-backfill.js +149 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +56 -0
- package/srv/blockchain/crawler/certificate-backfill.js +174 -0
- package/srv/blockchain/crawler/crawler.d.ts +125 -81
- package/srv/blockchain/crawler/crawler.js +738 -167
- package/srv/blockchain/crawler/credential-backfill.d.ts +30 -0
- package/srv/blockchain/crawler/credential-backfill.js +101 -0
- package/srv/blockchain/crawler/hooks.d.ts +2 -17
- package/srv/blockchain/crawler/index.d.ts +1 -8
- package/srv/blockchain/crawler/index.js +31 -17
- package/srv/blockchain/crawler/input-asset-copies.d.ts +34 -0
- package/srv/blockchain/crawler/input-asset-copies.js +161 -0
- package/srv/blockchain/crawler/key-pages.d.ts +12 -0
- package/srv/blockchain/crawler/key-pages.js +48 -0
- package/srv/blockchain/crawler/metadata-position-backfill.d.ts +22 -0
- package/srv/blockchain/crawler/metadata-position-backfill.js +59 -0
- package/srv/blockchain/crawler/output-datum-backfill.d.ts +41 -0
- package/srv/blockchain/crawler/output-datum-backfill.js +100 -0
- package/srv/blockchain/crawler/sync-state.d.ts +31 -47
- package/srv/blockchain/crawler/sync-state.js +135 -128
- package/srv/blockchain/crawler/transaction-backfill.d.ts +46 -0
- package/srv/blockchain/crawler/transaction-backfill.js +271 -0
- package/srv/blockchain/crawler/utxo-set-import.d.ts +66 -0
- package/srv/blockchain/crawler/utxo-set-import.js +399 -0
- package/srv/blockchain/crawler/window-plan.d.ts +31 -0
- package/srv/blockchain/crawler/window-plan.js +59 -0
- package/srv/blockchain/ledger-state.d.ts +62 -0
- package/srv/blockchain/ledger-state.js +521 -0
- package/srv/blockchain/pending-spends.d.ts +16 -0
- package/srv/blockchain/pending-spends.js +81 -0
- package/srv/blockchain/pool-metadata.d.ts +15 -0
- package/srv/blockchain/pool-metadata.js +132 -0
- package/srv/blockchain/request-coalescer.d.ts +2 -16
- package/srv/blockchain/request-coalescer.js +2 -16
- package/srv/blockchain/signing/cose-verifier.d.ts +3 -17
- package/srv/blockchain/signing/cose-verifier.js +146 -70
- package/srv/blockchain/signing/external-signer.d.ts +15 -115
- package/srv/blockchain/signing/external-signer.js +22 -131
- package/srv/blockchain/signing/failed-recheck.d.ts +17 -0
- package/srv/blockchain/signing/failed-recheck.js +135 -0
- package/srv/blockchain/signing/hsm-signer.d.ts +10 -54
- package/srv/blockchain/signing/hsm-signer.js +28 -79
- package/srv/blockchain/signing/landing-proof.d.ts +60 -0
- package/srv/blockchain/signing/landing-proof.js +224 -0
- package/srv/blockchain/signing/signature-verifier.d.ts +9 -47
- package/srv/blockchain/signing/signature-verifier.js +71 -87
- package/srv/blockchain/signing/submission-finalizer.d.ts +37 -45
- package/srv/blockchain/signing/submission-finalizer.js +280 -86
- package/srv/blockchain/stored-chain.d.ts +19 -0
- package/srv/blockchain/stored-chain.js +258 -0
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +31 -229
- package/srv/blockchain/transaction-building/buildooor-tx.js +663 -421
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +9 -37
- package/srv/blockchain/transaction-presence.d.ts +12 -0
- package/srv/blockchain/transaction-presence.js +29 -0
- package/srv/blockchain/transaction-rows.d.ts +12 -0
- package/srv/blockchain/transaction-rows.js +44 -0
- package/srv/blockchain/wallet-worker/build-request.d.ts +8 -23
- package/srv/blockchain/wallet-worker/build-request.js +40 -353
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +27 -47
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +158 -61
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -11
- package/srv/blockchain/wallet-worker/invalidation.d.ts +35 -0
- package/srv/blockchain/wallet-worker/invalidation.js +128 -0
- package/srv/blockchain/wallet-worker/job-store.d.ts +58 -150
- package/srv/blockchain/wallet-worker/job-store.js +200 -273
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -26
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -28
- package/srv/blockchain/wallet-worker/signers.d.ts +5 -24
- package/srv/blockchain/wallet-worker/signers.js +4 -12
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +29 -82
- package/srv/blockchain/wallet-worker/wallet-worker.js +334 -198
- package/srv/cardano-agent-service.cds +122 -84
- package/srv/cardano-agent-service.js +12 -9
- package/srv/cardano-backend-service.cds +81 -0
- package/srv/cardano-backend-service.d.ts +2 -0
- package/srv/cardano-backend-service.js +259 -0
- package/srv/cardano-indexer-service.cds +393 -18
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +477 -16
- package/srv/cardano-service.cds +426 -269
- package/srv/cardano-service.js +640 -217
- package/srv/cardano-sign-service.cds +211 -180
- package/srv/cardano-sign-service.js +210 -287
- package/srv/cardano-tx-service.cds +462 -370
- package/srv/cardano-tx-service.js +283 -800
- package/srv/cardano-ui.cds +16 -16
- package/srv/cardano-worker-service.cds +141 -125
- package/srv/cardano-worker-service.js +104 -61
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +3 -1
- package/srv/cbor/index.js +9 -1
- package/srv/cbor/parse.d.ts +30 -18
- package/srv/cbor/parse.js +44 -9
- package/srv/cbor/plutus-data-json.d.ts +20 -0
- package/srv/cbor/plutus-data-json.js +32 -0
- package/srv/config.d.ts +117 -0
- package/srv/config.js +419 -0
- package/srv/server.d.ts +15 -110
- package/srv/server.js +83 -405
- package/srv/utils/agent-access.d.ts +11 -0
- package/srv/utils/agent-access.js +86 -0
- package/srv/utils/agent-grants-config.d.ts +0 -46
- package/srv/utils/agent-grants-config.js +17 -85
- package/srv/utils/agent-grants.d.ts +106 -122
- package/srv/utils/agent-grants.js +538 -237
- package/srv/utils/agent-token-auth.d.ts +4 -99
- package/srv/utils/agent-token-auth.js +62 -186
- package/srv/utils/backend-request-handler.d.ts +3 -17
- package/srv/utils/backend-request-handler.js +3 -18
- package/srv/utils/build-request.d.ts +52 -0
- package/srv/utils/build-request.js +487 -0
- package/srv/utils/collections.d.ts +4 -10
- package/srv/utils/collections.js +14 -10
- package/srv/utils/const.d.ts +32 -75
- package/srv/utils/const.js +40 -80
- package/srv/utils/crypto.d.ts +3 -12
- package/srv/utils/crypto.js +11 -25
- package/srv/utils/db-indexes.d.ts +31 -0
- package/srv/utils/db-indexes.js +185 -0
- package/srv/utils/db-kind.d.ts +23 -0
- package/srv/utils/db-kind.js +42 -0
- package/srv/utils/db-sanitize.d.ts +20 -0
- package/srv/utils/db-sanitize.js +80 -0
- package/srv/utils/deep-json.d.ts +6 -0
- package/srv/utils/deep-json.js +240 -0
- package/srv/utils/detached-run.d.ts +41 -0
- package/srv/utils/detached-run.js +101 -0
- package/srv/utils/epoch-slots.d.ts +14 -0
- package/srv/utils/epoch-slots.js +45 -0
- package/srv/utils/error-codes.d.ts +26 -75
- package/srv/utils/error-codes.js +27 -72
- package/srv/utils/errors.d.ts +55 -187
- package/srv/utils/errors.js +161 -235
- package/srv/utils/lease.d.ts +20 -0
- package/srv/utils/lease.js +62 -0
- package/srv/utils/liveness.d.ts +12 -0
- package/srv/utils/liveness.js +35 -0
- package/srv/utils/mappers.d.ts +111 -223
- package/srv/utils/mappers.js +432 -371
- package/srv/utils/navigation.d.ts +17 -0
- package/srv/utils/navigation.js +52 -0
- package/srv/utils/network-context.d.ts +0 -1
- package/srv/utils/network-context.js +9 -15
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.d.ts +8 -0
- package/srv/utils/pg-inline-json.js +58 -0
- package/srv/utils/pg-order-nulls.d.ts +14 -0
- package/srv/utils/pg-order-nulls.js +54 -0
- package/srv/utils/plutus-placeholders.d.ts +16 -22
- package/srv/utils/plutus-placeholders.js +62 -33
- package/srv/utils/rate-limiter.d.ts +2 -21
- package/srv/utils/rate-limiter.js +5 -17
- package/srv/utils/readiness.d.ts +12 -0
- package/srv/utils/readiness.js +29 -0
- package/srv/utils/reference-script.d.ts +19 -0
- package/srv/utils/reference-script.js +84 -0
- package/srv/utils/resolution.d.ts +13 -0
- package/srv/utils/resolution.js +47 -0
- package/srv/utils/result-numbers.d.ts +15 -0
- package/srv/utils/result-numbers.js +61 -0
- package/srv/utils/row-values.d.ts +7 -0
- package/srv/utils/row-values.js +27 -0
- package/srv/utils/service-events.d.ts +0 -24
- package/srv/utils/service-events.js +3 -25
- package/srv/utils/signing-helper.d.ts +3 -20
- package/srv/utils/signing-helper.js +35 -64
- package/srv/utils/tx-build-helper.d.ts +25 -105
- package/srv/utils/tx-build-helper.js +108 -156
- package/srv/utils/tx-request-parsers.d.ts +82 -33
- package/srv/utils/tx-request-parsers.js +401 -49
- package/srv/utils/tx-utils.d.ts +3 -27
- package/srv/utils/tx-utils.js +32 -50
- package/srv/utils/types.d.ts +294 -232
- package/srv/utils/types.js +2 -22
- package/srv/utils/validators.d.ts +22 -92
- package/srv/utils/validators.js +60 -170
|
@@ -0,0 +1,258 @@
|
|
|
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 deep_json_1 = require("../utils/deep-json");
|
|
16
|
+
const cardano_1 = require("#cds-models/odatano/cardano");
|
|
17
|
+
const collections_1 = require("../utils/collections");
|
|
18
|
+
const errors_1 = require("../utils/errors");
|
|
19
|
+
const { SELECT } = cds_1.default.ql;
|
|
20
|
+
const num = (v) => Number(v ?? 0);
|
|
21
|
+
const numOrNull = (v) => (v == null ? null : Number(v));
|
|
22
|
+
const str = (v) => (v == null ? '' : String(v));
|
|
23
|
+
/** `Blocks` row -> BlockData. */
|
|
24
|
+
function blockRowToData(row) {
|
|
25
|
+
return {
|
|
26
|
+
time: Math.floor(Date.parse(str(row.time)) / 1000),
|
|
27
|
+
height: numOrNull(row.height),
|
|
28
|
+
hash: str(row.hash),
|
|
29
|
+
slot: numOrNull(row.slot),
|
|
30
|
+
slotLeader: str(row.slotLeader),
|
|
31
|
+
epoch: numOrNull(row.epochNumber),
|
|
32
|
+
epochSlot: numOrNull(row.epochSlot),
|
|
33
|
+
size: num(row.size),
|
|
34
|
+
txCount: num(row.txCount),
|
|
35
|
+
fees: row.fees == null ? null : String(row.fees),
|
|
36
|
+
previousHash: row.previousHash == null ? null : String(row.previousHash),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** A stored block by hash; null when not indexed. */
|
|
40
|
+
async function readBlock(db, hash) {
|
|
41
|
+
const row = await db.run(SELECT.one.from(cardano_1.Blocks).where({ hash }));
|
|
42
|
+
return row ? blockRowToData(row) : null;
|
|
43
|
+
}
|
|
44
|
+
/** A stored block by height; null when not indexed. */
|
|
45
|
+
async function readBlockByHeight(db, height) {
|
|
46
|
+
const row = await db.run(SELECT.one.from(cardano_1.Blocks).where({ height }));
|
|
47
|
+
return row ? blockRowToData(row) : null;
|
|
48
|
+
}
|
|
49
|
+
// The one row of `candidates` that follows `parent`: its stored parent hash names it, or it is the
|
|
50
|
+
// only row at that height and its parent is unknown. Of two rows that both may follow, the one a
|
|
51
|
+
// stored block at the next height names wins. Null when no row follows or it stays ambiguous.
|
|
52
|
+
function successor(candidates, parent, next) {
|
|
53
|
+
const fits = candidates.filter((r) => r.previousHash == null || parent == null || r.previousHash === parent);
|
|
54
|
+
if (fits.length <= 1)
|
|
55
|
+
return fits[0] ?? null;
|
|
56
|
+
const named = fits.filter((r) => r.previousHash === parent && parent != null);
|
|
57
|
+
if (named.length === 1)
|
|
58
|
+
return named[0];
|
|
59
|
+
const continued = fits.filter((r) => next.some((n) => n.previousHash === r.hash));
|
|
60
|
+
return continued.length === 1 ? continued[0] : null;
|
|
61
|
+
}
|
|
62
|
+
// Up to `count` stored blocks after `afterHeight`, following the stored parent hashes from `afterHash`.
|
|
63
|
+
// Stops at a gap, at a block that names another parent, and where two rows at one height stay
|
|
64
|
+
// ambiguous; nothing is served past a point the store cannot decide. `previousHash` is the stored one.
|
|
65
|
+
async function readNextBlocks(db, afterHeight, count, afterHash = null) {
|
|
66
|
+
const rows = await db.run(
|
|
67
|
+
// one operator per column object: `{ '>': a, '<=': b }` renders as `height > a <= b`
|
|
68
|
+
SELECT.from(cardano_1.Blocks).where({ height: { between: afterHeight + 1, and: afterHeight + count + 1 } }).orderBy('height asc')) ?? [];
|
|
69
|
+
const byHeight = new Map();
|
|
70
|
+
for (const row of rows)
|
|
71
|
+
byHeight.set(num(row.height), [...(byHeight.get(num(row.height)) ?? []), row]);
|
|
72
|
+
const out = [];
|
|
73
|
+
let parent = afterHash;
|
|
74
|
+
for (let height = afterHeight + 1; height <= afterHeight + count; height++) {
|
|
75
|
+
const row = successor(byHeight.get(height) ?? [], parent, byHeight.get(height + 1) ?? []);
|
|
76
|
+
if (!row) {
|
|
77
|
+
if (out.length === 0 && (byHeight.get(height)?.length ?? 0) > 1) {
|
|
78
|
+
throw new errors_1.ProviderUnavailableError(`two stored blocks at height ${height} may follow ${parent ?? 'the cursor'}; the stored chain cannot tell which one`, 'odatano');
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
out.push(blockRowToData(row));
|
|
83
|
+
parent = str(row.hash);
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/** True when a stored input lacks its outpoint (row indexed before outpoints were recorded). */
|
|
88
|
+
function lacksOutpoints(t) {
|
|
89
|
+
return (t.inputs ?? []).some(i => i.txHash == null);
|
|
90
|
+
}
|
|
91
|
+
/** Stored transactions by hash (missing hashes are absent from the map). */
|
|
92
|
+
async function readTransactionsByHash(db, hashes) {
|
|
93
|
+
const rows = [];
|
|
94
|
+
for (const hashChunk of (0, collections_1.chunk)(hashes, collections_1.IN_CHUNK)) {
|
|
95
|
+
rows.push(...((await db.run(SELECT.from(cardano_1.Transactions).where({ hash: { in: hashChunk } }))) ?? []));
|
|
96
|
+
}
|
|
97
|
+
const txs = await assembleTransactions(db, rows);
|
|
98
|
+
return new Map(txs.map(t => [t.hash, t]));
|
|
99
|
+
}
|
|
100
|
+
// Stored transactions of a block in order. Null unless all are stored, since a lazily indexed
|
|
101
|
+
// block may hold only some.
|
|
102
|
+
async function readBlockTransactions(db, blockHash) {
|
|
103
|
+
const block = await db.run(SELECT.one.from(cardano_1.Blocks).columns('txCount').where({ hash: blockHash }));
|
|
104
|
+
if (!block)
|
|
105
|
+
return null;
|
|
106
|
+
const rows = await db.run(SELECT.from(cardano_1.Transactions).where({ blockHash }).orderBy('txIndex asc'));
|
|
107
|
+
if ((rows ?? []).length !== num(block.txCount))
|
|
108
|
+
return null;
|
|
109
|
+
return assembleTransactions(db, rows ?? []);
|
|
110
|
+
}
|
|
111
|
+
/** Metadata of a stored transaction; null when the transaction is not stored. */
|
|
112
|
+
async function readTransactionMetadata(db, txHash) {
|
|
113
|
+
const known = await db.run(SELECT.one.from(cardano_1.Transactions).columns('hash').where({ hash: txHash }));
|
|
114
|
+
if (!known)
|
|
115
|
+
return null;
|
|
116
|
+
const rows = await db.run(SELECT.from(cardano_1.TransactionMetadata_).where({ tx_hash: txHash }));
|
|
117
|
+
return (rows ?? []).map(metadataRow);
|
|
118
|
+
}
|
|
119
|
+
function metadataRow(r) {
|
|
120
|
+
return {
|
|
121
|
+
txHash: str(r.tx_hash),
|
|
122
|
+
label: str(r.label),
|
|
123
|
+
json: r.payload == null ? undefined : (0, deep_json_1.parseJson)(String(r.payload)),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/** Amount list with lovelace first, as the providers deliver it. */
|
|
127
|
+
function amounts(assets) {
|
|
128
|
+
const list = assets.map(a => ({ unit: str(a.unit), quantity: str(a.asset_quantity) }));
|
|
129
|
+
return [...list.filter(a => a.unit === 'lovelace'), ...list.filter(a => a.unit !== 'lovelace')];
|
|
130
|
+
}
|
|
131
|
+
function groupBy(rows, key) {
|
|
132
|
+
const out = new Map();
|
|
133
|
+
for (const r of rows) {
|
|
134
|
+
const k = key(r);
|
|
135
|
+
const list = out.get(k);
|
|
136
|
+
if (list)
|
|
137
|
+
list.push(r);
|
|
138
|
+
else
|
|
139
|
+
out.set(k, [r]);
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
/** Transactions rows + their child tables -> provider transactions, in the order of `rows`. */
|
|
144
|
+
async function assembleTransactions(db, rows) {
|
|
145
|
+
if (rows.length === 0)
|
|
146
|
+
return [];
|
|
147
|
+
const seqs = rows.map(r => r.txSeq);
|
|
148
|
+
const hashes = rows.map(r => str(r.hash));
|
|
149
|
+
const fetchIn = async (entity, column, keys) => {
|
|
150
|
+
const out = [];
|
|
151
|
+
for (const c of (0, collections_1.chunk)(keys, collections_1.IN_CHUNK)) {
|
|
152
|
+
out.push(...((await db.run(SELECT.from(entity).where({ [column]: { in: c } }))) ?? []));
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
155
|
+
};
|
|
156
|
+
const [inputs, inputAssets, outputs, outputAssets, metadata, certificates, withdrawals, redeemers, datums] = await Promise.all([
|
|
157
|
+
fetchIn(cardano_1.TransactionInputs, 'txSeq', seqs),
|
|
158
|
+
fetchIn(cardano_1.TransactionInputAssets, 'input_txSeq', seqs),
|
|
159
|
+
fetchIn(cardano_1.TransactionOutputs, 'txSeq', seqs),
|
|
160
|
+
fetchIn(cardano_1.TransactionOutputAssets, 'output_txSeq', seqs),
|
|
161
|
+
fetchIn(cardano_1.TransactionMetadata_, 'tx_hash', hashes),
|
|
162
|
+
fetchIn(cardano_1.TransactionCertificates, 'tx_hash', hashes),
|
|
163
|
+
fetchIn(cardano_1.TransactionWithdrawals, 'tx_hash', hashes),
|
|
164
|
+
fetchIn(cardano_1.TransactionRedeemers, 'tx_hash', hashes),
|
|
165
|
+
fetchIn(cardano_1.TransactionDatums, 'tx_hash', hashes),
|
|
166
|
+
]);
|
|
167
|
+
const inputsBySeq = groupBy(inputs, r => str(r.txSeq));
|
|
168
|
+
const inputAssetsByKey = groupBy(inputAssets, r => `${r.input_txSeq}#${r.input_inputIndex}`);
|
|
169
|
+
const outputsBySeq = groupBy(outputs, r => str(r.txSeq));
|
|
170
|
+
const outputAssetsByKey = groupBy(outputAssets, r => `${r.output_txSeq}#${r.output_outputIndex}`);
|
|
171
|
+
const metadataByHash = groupBy(metadata, r => str(r.tx_hash));
|
|
172
|
+
const certsByHash = groupBy(certificates, r => str(r.tx_hash));
|
|
173
|
+
const withdrawalsByHash = groupBy(withdrawals, r => str(r.tx_hash));
|
|
174
|
+
const redeemersByHash = groupBy(redeemers, r => str(r.tx_hash));
|
|
175
|
+
const datumsByHash = groupBy(datums, r => str(r.tx_hash));
|
|
176
|
+
return rows.map((t) => {
|
|
177
|
+
const seq = str(t.txSeq);
|
|
178
|
+
const hash = str(t.hash);
|
|
179
|
+
const txInputs = (inputsBySeq.get(seq) ?? [])
|
|
180
|
+
.sort((a, b) => num(a.inputIndex) - num(b.inputIndex))
|
|
181
|
+
.map(i => ({
|
|
182
|
+
address: str(i.address_address),
|
|
183
|
+
amount: amounts(inputAssetsByKey.get(`${seq}#${i.inputIndex}`) ?? []),
|
|
184
|
+
// null on rows indexed before the outpoint was recorded, never a made-up reference
|
|
185
|
+
txHash: (i.spentTxHash ?? null),
|
|
186
|
+
outputIndex: numOrNull(i.spentOutputIndex),
|
|
187
|
+
dataHash: i.utxoData_dataHash ?? null,
|
|
188
|
+
inlineDatum: i.utxoData_inlineDatum ?? null,
|
|
189
|
+
referenceScriptHash: i.utxoData_referenceScriptHash ?? null,
|
|
190
|
+
referenceScriptSize: numOrNull(i.utxoData_referenceScriptSize),
|
|
191
|
+
referenceScriptType: i.utxoData_referenceScriptType ?? null,
|
|
192
|
+
isCollateral: Boolean(i.isCollateral),
|
|
193
|
+
isReference: Boolean(i.isReference),
|
|
194
|
+
}));
|
|
195
|
+
// a phase-2 failure keeps only collateral and reference inputs, and its collateral return
|
|
196
|
+
const spendsCollaterals = txInputs.some(i => i.isCollateral) && !txInputs.some(i => !i.isCollateral && !i.isReference);
|
|
197
|
+
const txOutputs = (outputsBySeq.get(seq) ?? [])
|
|
198
|
+
.sort((a, b) => num(a.outputIndex) - num(b.outputIndex))
|
|
199
|
+
.map(o => ({
|
|
200
|
+
address: str(o.address_address),
|
|
201
|
+
amount: amounts(outputAssetsByKey.get(`${seq}#${o.outputIndex}`) ?? []),
|
|
202
|
+
txHash: hash,
|
|
203
|
+
outputIndex: num(o.outputIndex),
|
|
204
|
+
dataHash: o.utxo_dataHash ?? null,
|
|
205
|
+
inlineDatum: o.utxo_inlineDatum ?? null,
|
|
206
|
+
isCollateral: spendsCollaterals,
|
|
207
|
+
referenceScriptHash: o.utxo_referenceScriptHash ?? null,
|
|
208
|
+
referenceScriptSize: numOrNull(o.utxo_referenceScriptSize),
|
|
209
|
+
referenceScriptType: o.utxo_referenceScriptType ?? null,
|
|
210
|
+
}));
|
|
211
|
+
const certs = certsByHash.get(hash);
|
|
212
|
+
const withdrawn = withdrawalsByHash.get(hash);
|
|
213
|
+
const redeemed = redeemersByHash.get(hash);
|
|
214
|
+
const witnessDatums = datumsByHash.get(hash);
|
|
215
|
+
return {
|
|
216
|
+
hash,
|
|
217
|
+
blockHash: str(t.blockHash),
|
|
218
|
+
blockHeight: num(t.blockHeight),
|
|
219
|
+
slot: num(t.slot),
|
|
220
|
+
index: num(t.txIndex),
|
|
221
|
+
fee: str(t.fee ?? '0'),
|
|
222
|
+
deposit: t.deposit == null ? null : str(t.deposit),
|
|
223
|
+
size: numOrNull(t.size),
|
|
224
|
+
blockTime: num(t.blockTime),
|
|
225
|
+
spendsCollaterals,
|
|
226
|
+
// AssetHistory may hold only some mint rows of a transaction, read on demand for single units.
|
|
227
|
+
// Without a complete mint the reader derives it from inputs and outputs.
|
|
228
|
+
mint: undefined,
|
|
229
|
+
inputs: txInputs,
|
|
230
|
+
outputs: txOutputs,
|
|
231
|
+
metadata: (metadataByHash.get(hash) ?? []).map(metadataRow),
|
|
232
|
+
certificates: certs?.map((c) => ({
|
|
233
|
+
certIndex: num(c.certIndex),
|
|
234
|
+
kind: str(c.kind),
|
|
235
|
+
stakeAddress: c.stakeAddress ?? null,
|
|
236
|
+
poolId: c.poolId ?? null,
|
|
237
|
+
drepId: c.drepId ?? null,
|
|
238
|
+
deposit: c.deposit == null ? null : String(c.deposit),
|
|
239
|
+
epoch: numOrNull(c.epoch),
|
|
240
|
+
})),
|
|
241
|
+
withdrawals: withdrawn?.map((w) => ({ stakeAddress: str(w.stakeAddress), amount: str(w.lovelace) })),
|
|
242
|
+
redeemers: redeemed
|
|
243
|
+
?.sort((a, b) => str(a.purpose).localeCompare(str(b.purpose)) || num(a.redeemerIndex) - num(b.redeemerIndex))
|
|
244
|
+
.map((r) => ({
|
|
245
|
+
purpose: str(r.purpose),
|
|
246
|
+
index: num(r.redeemerIndex),
|
|
247
|
+
data: str(r.data),
|
|
248
|
+
mem: str(r.mem),
|
|
249
|
+
steps: str(r.steps),
|
|
250
|
+
txHash: r.spentTxHash ?? null,
|
|
251
|
+
outputIndex: numOrNull(r.spentOutputIndex),
|
|
252
|
+
policyId: r.policyId ?? null,
|
|
253
|
+
})),
|
|
254
|
+
datums: witnessDatums?.map((d) => ({ hash: str(d.dataHash), cbor: str(d.datum) })),
|
|
255
|
+
};
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=stored-chain.js.map
|
|
@@ -1,291 +1,93 @@
|
|
|
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
|
-
/**
|
|
5
|
-
* BuildooorTxBuilder - Implementation of CardanoTxBuilder using Buildooor library
|
|
6
|
-
*/
|
|
4
|
+
/** CardanoTxBuilder implementation on top of Buildooor. */
|
|
7
5
|
export declare class BuildooorTxBuilder implements CardanoTxBuilder {
|
|
8
6
|
readonly name = "BuildooorTxBuilder";
|
|
9
7
|
private txBuilder;
|
|
10
8
|
private cardanoClient;
|
|
11
9
|
private genesisInfos;
|
|
12
10
|
private paramsFingerprint;
|
|
13
|
-
/**
|
|
14
|
-
* Chain cost-model arrays kept verbatim for language-view hashing. Maintained by
|
|
15
|
-
* _mapCostModels (in lockstep with the named-key models the TxBuilder is built
|
|
16
|
-
* with); consumed by _languageViewCostModels. Empty when the current parameters
|
|
17
|
-
* carry no usable cost models (library defaults in effect).
|
|
18
|
-
*/
|
|
11
|
+
/** Chain cost-model arrays kept verbatim for language-view hashing. */
|
|
19
12
|
private rawCostModelArrays;
|
|
20
|
-
/**
|
|
21
|
-
* Initialize the builder
|
|
22
|
-
* @param client - The CardanoClient instance
|
|
23
|
-
* @param protocolParams - Optional protocol parameters (if not provided, fetched from backend)
|
|
24
|
-
*/
|
|
13
|
+
/** Initialize the builder. Protocol parameters are fetched when omitted. */
|
|
25
14
|
init(client: CardanoClient, protocolParams?: LedgerProtocolParameters): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Rebuild the TxBuilder when the per-request protocol parameters differ from
|
|
28
|
-
* the ones the current TxBuilder was constructed with. Buildooor's TxBuilder
|
|
29
|
-
* has no setter for protocol params, but its constructor is cheap, so we
|
|
30
|
-
* rebuild on change (effectively once per epoch) instead of staying frozen
|
|
31
|
-
* at init-time parameters for the process lifetime.
|
|
32
|
-
*/
|
|
15
|
+
/** TxBuilder has no setter, so it is rebuilt when the protocol parameters change. */
|
|
33
16
|
private _ensureCurrentProtocolParameters;
|
|
34
17
|
private _applyProtocolParameters;
|
|
35
|
-
/**
|
|
36
|
-
* Build unsigned transfer transaction (ADA-only or with native assets).
|
|
37
|
-
*/
|
|
18
|
+
/** Build an unsigned transfer transaction (ADA-only or with native assets). */
|
|
38
19
|
buildUnsignedTransfer(req: TxBuildRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
39
|
-
/**
|
|
40
|
-
* Build unsigned transfer transaction with attached metadata.
|
|
41
|
-
*/
|
|
20
|
+
/** Build an unsigned transfer transaction with attached metadata. */
|
|
42
21
|
buildUnsignedTransactionWithMetadata(req: TxBuildRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
43
|
-
/**
|
|
44
|
-
* Shared non-script transfer build. The two public entry points only differ in
|
|
45
|
-
* the optional pieces of the request they carry (assets/outputDatum on the
|
|
46
|
-
* plain-transfer path, metadataJson on the metadata path) — all handled here
|
|
47
|
-
* conditionally on the field being present, so behaviour matches both.
|
|
48
|
-
*/
|
|
22
|
+
/** Shared non-script transfer build. */
|
|
49
23
|
private _buildSimpleTransfer;
|
|
50
24
|
buildUnsignedMintTransaction(req: TxBuildMintRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
25
|
+
private _buildMintTransaction;
|
|
51
26
|
buildUnsignedPlutusSpendTransaction(req: TxBuildPlutusSpendRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
27
|
+
private _buildPlutusSpendTransaction;
|
|
28
|
+
buildUnsignedPlutusTransaction(req: TxBuildPlutusRequest, ctx: TxBuildContext): Promise<TxBuildResult>;
|
|
29
|
+
private _buildPlutusTransaction;
|
|
30
|
+
/** Appends the outputs in order. A CBOR inline datum keeps its bytes. */
|
|
31
|
+
private _appendPlutusOutputs;
|
|
32
|
+
private _minOutputLovelace;
|
|
52
33
|
/** Extract CBOR, hash, fee, size, inputs and outputs from a built Buildooor Tx */
|
|
53
34
|
private _extractTxDetails;
|
|
54
35
|
/** Build the standard TxBuildResult object */
|
|
55
36
|
private _buildResult;
|
|
56
|
-
/**
|
|
57
|
-
* Build a script-bearing transaction whose redeemers carry *real* execution units and
|
|
58
|
-
* whose fee covers them.
|
|
59
|
-
*
|
|
60
|
-
* Background (verified against the vendored Buildooor source): `initTxBuild` constructs
|
|
61
|
-
* every redeemer with a dummy budget — caller-supplied execution units in the build args
|
|
62
|
-
* are never read — and `onEvaluationResult` unconditionally stamps each redeemer with
|
|
63
|
-
* the budget the local CEK run consumed, even when the script failed (partial budget).
|
|
64
|
-
* So the declared units are whatever the *local* evaluation produced, and any cushion
|
|
65
|
-
* passed into the args silently evaporates. This method makes the declared units real:
|
|
66
|
-
*
|
|
67
|
-
* 1. First pass: build once; redeemers now carry the local CEK budgets.
|
|
68
|
-
* 2. Evaluate that CBOR via Ogmios (when configured) for authoritative per-redeemer
|
|
69
|
-
* budgets, cushioned by EXECUTION_UNIT_BUFFER / ABS_*_BUFFER.
|
|
70
|
-
* 3. Resolve target units per redeemer (Ogmios beats buffered-local; a local failure
|
|
71
|
-
* without an Ogmios result aborts — see makeScriptBuildOpts).
|
|
72
|
-
* 4. Second pass with a fee floor covering the target units (Buildooor prices the fee
|
|
73
|
-
* from its own local budgets, so the floor adds the price + encoding-size delta).
|
|
74
|
-
* 5. Stamp the target units into the redeemers and recompute scriptDataHash.
|
|
75
|
-
*/
|
|
76
37
|
private _buildScriptTx;
|
|
77
|
-
/**
|
|
78
|
-
* Evaluate a transaction via Ogmios and return cushioned budgets keyed per redeemer
|
|
79
|
-
* (`tag:index`). Returns undefined when the evaluation is unusable (transient backend
|
|
80
|
-
* failure, empty result) so callers fall back to buffered local units. A
|
|
81
|
-
* TransactionValidationError or ScriptValidationError from the evaluator is
|
|
82
|
-
* authoritative (the script really failed on the ledger) and is rethrown.
|
|
83
|
-
*/
|
|
84
38
|
private _evaluateExUnitsByRedeemer;
|
|
85
|
-
/**
|
|
86
|
-
* Combined cushion: relative multiplier catches proportional drift on large
|
|
87
|
-
* validators, absolute floor catches sub-percent drift on small ones (observed
|
|
88
|
-
* when metadata affects the real tx body vs the evaluator's ScriptContext).
|
|
89
|
-
*/
|
|
90
39
|
private _applyExUnitBuffer;
|
|
91
|
-
/**
|
|
92
|
-
* Decide the execution units each redeemer must declare.
|
|
93
|
-
* - Local run succeeded + Ogmios result → max of both (local is a real lower bound).
|
|
94
|
-
* - Local run succeeded, no Ogmios → buffered local (cushions local↔ledger drift).
|
|
95
|
-
* - Local run failed + Ogmios result → Ogmios (the local partial budget is meaningless).
|
|
96
|
-
* - Local run failed, no Ogmios → abort: declaring unreliable units would forfeit the
|
|
97
|
-
* collateral of whoever signs and submits the returned CBOR.
|
|
98
|
-
*/
|
|
99
40
|
private _resolveTargetExUnits;
|
|
100
41
|
/** Fee delta of the target vs local units, priced like Buildooor's own fee loop. */
|
|
101
42
|
private _exUnitsPriceDelta;
|
|
102
43
|
/** CBOR size growth (bytes) from stamping larger budgets into the redeemers. */
|
|
103
44
|
private _exUnitsSizeDelta;
|
|
104
45
|
private _txFeePerByte;
|
|
105
|
-
/**
|
|
106
|
-
* Replace the redeemers' execution units and recompute scriptDataHash.
|
|
107
|
-
*
|
|
108
|
-
* Still not implemented via TxBuilder.overrideTxRedeemers, although buildooor
|
|
109
|
-
* 0.2.9 fixed its old-witness-set hashing (our PR): that method hashes with the
|
|
110
|
-
* builder's named-key cost models, which clamp the chain array to the parameter
|
|
111
|
-
* count the library release knows — wrong whenever the on-chain cost model has
|
|
112
|
-
* grown past that (ScriptIntegrityHashMismatch at submit). This recompute with
|
|
113
|
-
* _languageViewCostModels (raw chain arrays) stays governance-proof, so the hash
|
|
114
|
-
* is recomputed here even when the target units already match.
|
|
115
|
-
*/
|
|
116
46
|
private _stampExecUnits;
|
|
117
|
-
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
* scripts inline, so the witness set carries every executed script.
|
|
121
|
-
*/
|
|
47
|
+
/** Language views the scriptDataHash covers, from the chain's cost models. */
|
|
48
|
+
private _languageViews;
|
|
49
|
+
private _checkWitnessDatum;
|
|
122
50
|
private _usedLanguageViewOpts;
|
|
123
|
-
/**
|
|
124
|
-
* Cost models for language-view hashing. The named-key objects the TxBuilder was
|
|
125
|
-
* constructed with clamp the chain array to the parameter count this costmodels-ts
|
|
126
|
-
* release knows (e.g. 297 for V3 pre-protocol-11), but the ledger hashes EVERY
|
|
127
|
-
* entry the chain serves (350 on protocol-11 networks). toCostModelArrVN passes
|
|
128
|
-
* array form through unclamped, so substitute the raw chain arrays where we have
|
|
129
|
-
* them. (The named-key form stays in the TxBuilder — the CEK machine needs it.)
|
|
130
|
-
*/
|
|
131
51
|
private _languageViewCostModels;
|
|
132
|
-
|
|
133
|
-
* Split UTxOs into forced inputs (must be consumed) and remaining candidates (free for
|
|
134
|
-
* coin selection / collateral). Refs in forceInputs that are not present in utxos are
|
|
135
|
-
* silently ignored — the resolver upstream has already validated existence.
|
|
136
|
-
*/
|
|
52
|
+
private _withRefScriptFallback;
|
|
137
53
|
private _partitionForcedInputs;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
54
|
+
private _resolveScriptWitness;
|
|
55
|
+
private _ledgerWithdrawalOrder;
|
|
56
|
+
private _checkForeignForcedInputs;
|
|
57
|
+
/** Keys (`txhash#index`) of the reference inputs of a build, from the resolved UTxOs and the request refs. */
|
|
58
|
+
private _referencedKeys;
|
|
59
|
+
/** Map resolved CIP-31 reference input UTxOs to Buildooor LedgerUTxO; empty when none. */
|
|
142
60
|
private _mapReferenceInputs;
|
|
143
|
-
/**
|
|
144
|
-
* Funding requirement contributed by extra outputs on a mint build:
|
|
145
|
-
* the summed lovelace of all entries plus, per asset unit, the demand the
|
|
146
|
-
* transaction's own positive mints do NOT cover. Minted quantities are
|
|
147
|
-
* aggregated per unit and subtracted from the aggregated output demand;
|
|
148
|
-
* only a positive remainder is requested from the wallet (a fully covered
|
|
149
|
-
* unit is not requested at all — it does not exist before this tx).
|
|
150
|
-
*/
|
|
151
61
|
private _extraOutputsFundingAfterMint;
|
|
152
|
-
/**
|
|
153
|
-
* The script an individual mint action executes under: its own
|
|
154
|
-
* per-action policy when set (multi-policy mint FR), else the request's
|
|
155
|
-
* top-level policy script.
|
|
156
|
-
*/
|
|
62
|
+
/** Per-action policy script when set, else the request's policy script. */
|
|
157
63
|
private _mintActionScript;
|
|
158
|
-
/**
|
|
159
|
-
* Build the Buildooor mint-entry array shared by the mint-only flow and the
|
|
160
|
-
* combined spend+mint flow (Buildooor ignores caller-supplied execution units;
|
|
161
|
-
* they are stamped into the redeemers post-build by _buildScriptTx).
|
|
162
|
-
*
|
|
163
|
-
* Multi-policy mint FR: each action may carry its own policy script and
|
|
164
|
-
* redeemer; absent fields fall back to the request-level ones. The ledger
|
|
165
|
-
* carries ONE redeemer per policy, so actions resolving to the same policy
|
|
166
|
-
* must agree on their redeemer, checked here.
|
|
167
|
-
*/
|
|
168
64
|
private _buildMintEntries;
|
|
169
|
-
/**
|
|
170
|
-
* Consumer-facing context for insufficient-funds rejections after the
|
|
171
|
-
* collateral partition: the builder's own "not enough …" message counts only
|
|
172
|
-
* the funding pool, and without this the reservation is invisible ("but the
|
|
173
|
-
* address HAS enough ADA").
|
|
174
|
-
*/
|
|
175
65
|
private _collateralPartitionContext;
|
|
176
|
-
/**
|
|
177
|
-
* Pick a collateral UTxO and return remaining funding UTxOs.
|
|
178
|
-
* Throws if no ADA-only UTxO is available.
|
|
179
|
-
*
|
|
180
|
-
* Selection: the SMALLEST ADA-only UTxO that still covers the static
|
|
181
|
-
* COLLATERAL_LOVELACE floor (5 ADA ≳ collateralPercentage × any realistic fee).
|
|
182
|
-
* The previous "first ADA-only" pick failed both ways: a dust UTxO below
|
|
183
|
-
* collateralPercentage × fee is rejected at submit, and a large UTxO is
|
|
184
|
-
* fully forfeited on phase-2 failure (Buildooor sets no collateralReturn
|
|
185
|
-
* for ADA-only collateral). Everything above the floor is therefore handed
|
|
186
|
-
* back via an explicit collateralReturn when the excess satisfies min-ADA.
|
|
187
|
-
*/
|
|
188
66
|
private _setupCollateral;
|
|
189
67
|
/** Build a Ledger Value from lovelace + optional multi-asset array */
|
|
190
68
|
private _buildLedgerValue;
|
|
191
69
|
/** Build a TxOut with optional inline datum and optional reference script (CIP-33) */
|
|
192
70
|
private _buildTxOut;
|
|
193
|
-
/**
|
|
194
|
-
* Parse a consumer-provided, CBOR-wrapped Plutus script and reject UPLC 1.0.0
|
|
195
|
-
* code (PlutusV1/V2). `Script.fromCbor` defaults to PlutusV3, so V1/V2 bytes
|
|
196
|
-
* would be hashed with the 0x03 prefix — a silently wrong script hash, i.e.
|
|
197
|
-
* wrong policy IDs and unspendable script addresses with no error anywhere
|
|
198
|
-
* down the line. The UPLC version is the first three flat-encoded naturals
|
|
199
|
-
* of the unwrapped script: [1,0,0] (V1/V2) vs [1,1,0] (V3).
|
|
200
|
-
*/
|
|
201
71
|
private _parsePlutusV3Script;
|
|
202
72
|
/** Parse a Plutus V3 CBOR hex into a Buildooor Script for refScript attachment. */
|
|
203
73
|
private _parseReferenceScript;
|
|
204
|
-
/**
|
|
205
|
-
* Map an input UTxO's scriptRef field to a Buildooor Script when possible.
|
|
206
|
-
* UTxO.scriptRef is overloaded across backends: Blockfrost/Ogmios set it to a 28-byte
|
|
207
|
-
* hash (56 hex chars), Koios sets it to the full CBOR script bytes. Only full bytes
|
|
208
|
-
* are usable here — hash-only entries are preserved only on-chain, not in local eval.
|
|
209
|
-
*/
|
|
210
74
|
private _buildInputRefScript;
|
|
211
|
-
/**
|
|
212
|
-
* Compute the post-sort input order so __INPUT_IDX__ placeholders (FR-3) resolve to the
|
|
213
|
-
* same indices Buildooor will assign during build(). Order: script-input first by convention,
|
|
214
|
-
* then forced + funding sorted lexicographically on (txHash, outputIndex).
|
|
215
|
-
* Buildooor sorts ALL inputs together; we mirror that exact behaviour via sortInputsLikeBuildooor.
|
|
216
|
-
*/
|
|
217
75
|
private _computeSortedInputs;
|
|
218
76
|
/** Extract InputRef list from the Buildooor-shaped funding inputs returned by keepRelevant. */
|
|
219
77
|
private _extractFundingRefs;
|
|
220
|
-
/**
|
|
221
|
-
* Resolve __INPUT_IDX__ placeholders (FR-3) inside each extraOutput.inlineDatum.
|
|
222
|
-
* Returns a new array with resolved datums; non-datum fields pass through unchanged.
|
|
223
|
-
*/
|
|
78
|
+
/** Resolve __INPUT_IDX__ placeholders inside each extraOutput.inlineDatum; other fields pass through. */
|
|
224
79
|
private _resolveExtraOutputPlaceholders;
|
|
225
|
-
/**
|
|
226
|
-
* Append parsed extraOutputs (FR-2) to the outputs array, enforcing min-ADA per entry.
|
|
227
|
-
* Throws TransactionValidationError with the required min-ADA in the message so consumers
|
|
228
|
-
* can adjust without having to inspect Buildooor internals.
|
|
229
|
-
*/
|
|
80
|
+
/** Appends extra outputs. A rejection names the required min-ADA. */
|
|
230
81
|
private _appendExtraOutputs;
|
|
231
|
-
/**
|
|
232
|
-
* Resolve the transaction's validity window (slots) from the request.
|
|
233
|
-
* Falls back to `now - 2 min` / `now + 1 h` when the request omits bounds.
|
|
234
|
-
* Script-validated builds must call this; plain transfers pass their own
|
|
235
|
-
* explicit bounds through (no defaulting) so replay behavior is opt-in.
|
|
236
|
-
*/
|
|
237
82
|
private _resolveValiditySlots;
|
|
238
|
-
/**
|
|
239
|
-
* Map ODATANO LedgerProtocolParameter to Buildooor's ProtocolParameters shape.
|
|
240
|
-
*
|
|
241
|
-
* Every field is null-guarded: a missing/null source value keeps the library
|
|
242
|
-
* default instead of degrading to 0 (`Number(null) === 0` previously set
|
|
243
|
-
* utxoCostPerByte = 0, disabling min-ADA checks entirely). Cost models and
|
|
244
|
-
* execution-unit prices are mapped because they feed the scriptDataHash
|
|
245
|
-
* (language views) and the fee/ExUnits math — stale defaults there cause
|
|
246
|
-
* PPViewHashesDontMatch or fee underestimation on-chain.
|
|
247
|
-
*/
|
|
248
83
|
private _mapLedgerParametersToBuildooorParams;
|
|
249
|
-
/**
|
|
250
|
-
* Parse the cost-models JSON blob (backend-normalized number arrays, keys
|
|
251
|
-
* 'PlutusV1'/'PlutusV2'/'PlutusV3' or Ogmios 'plutus:vN') into Buildooor's
|
|
252
|
-
* CostModels shape ('PlutusScriptVN' keys). Returns undefined when nothing
|
|
253
|
-
* usable is found, so the caller can keep defaults and warn.
|
|
254
|
-
*
|
|
255
|
-
* Side effect: (re)sets this.rawCostModelArrays with the unclamped chain arrays
|
|
256
|
-
* for the versions mapped here — the named-key conversion drops every entry past
|
|
257
|
-
* the parameter count this costmodels-ts release knows, and the scriptDataHash
|
|
258
|
-
* must cover all of them (see _languageViewCostModels).
|
|
259
|
-
*/
|
|
260
84
|
private _mapCostModels;
|
|
261
|
-
/**
|
|
262
|
-
* Map ODATANO UTxO to Ledger UTxO (ADA-only)
|
|
263
|
-
*/
|
|
85
|
+
/** Map an ADA-only UTxO to a Ledger UTxO. */
|
|
264
86
|
private _mapOdatanoUtxoToLedgerUtxo;
|
|
265
|
-
/**
|
|
266
|
-
* Map ODATANO UTxO to Ledger UTxO (with multi-asset support)
|
|
267
|
-
*/
|
|
87
|
+
/** Map a UTxO (with multi-assets) to a Ledger UTxO. */
|
|
268
88
|
private _mapMultiAssetUtxoToLedgerUtxo;
|
|
269
|
-
/**
|
|
270
|
-
* Map ODATANO metadata JSON to Ledger TxMetadata
|
|
271
|
-
*/
|
|
89
|
+
/** Map metadata JSON (label -> value) to Ledger TxMetadata. */
|
|
272
90
|
private _mapOdatanoMetadataToLedgerMetadata;
|
|
273
|
-
/**
|
|
274
|
-
* Recursively convert JSON value to TxMetadatum.
|
|
275
|
-
*
|
|
276
|
-
* Ledger rules enforced here (instead of a node-side rejection or a raw 500):
|
|
277
|
-
* - numbers must be integers (BigInt(1.5) would throw a bare RangeError)
|
|
278
|
-
* - text and byte values are limited to 64 BYTES per metadatum — longer values
|
|
279
|
-
* are chunked into a list of ≤64-byte pieces (the established convention,
|
|
280
|
-
* e.g. CIP-25 long strings)
|
|
281
|
-
* - strings prefixed with "0x" (even hex length) become byte metadata
|
|
282
|
-
* - map keys are not auto-chunked (readers match on the literal key) — over-long
|
|
283
|
-
* keys are rejected with a clear 400
|
|
284
|
-
*
|
|
285
|
-
* @param path position of `value` inside the metadata JSON (label-rooted, e.g.
|
|
286
|
-
* "1155.result" or "721.files[0].src") — named in every rejection
|
|
287
|
-
* so the consumer can locate the offending value.
|
|
288
|
-
*/
|
|
289
91
|
private _jsonToTxMetadatum;
|
|
290
92
|
}
|
|
291
93
|
//# sourceMappingURL=buildooor-tx.d.ts.map
|