@odatano/core 2.0.0-rc.43 → 2.0.0-rc.45
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 +0 -46
- package/@cds-models/CardanoBackendService/index.d.ts +0 -10
- package/@cds-models/CardanoIndexerService/index.d.ts +36 -20
- package/@cds-models/CardanoIndexerService/index.js +4 -0
- package/@cds-models/CardanoODataService/index.d.ts +19 -47
- package/@cds-models/CardanoSignService/index.d.ts +3 -18
- package/@cds-models/CardanoTransactionService/index.d.ts +9 -31
- package/@cds-models/CardanoWorkerService/index.d.ts +3 -19
- package/@cds-models/index.d.ts +17 -0
- package/@cds-models/index.js +2 -0
- package/@cds-models/odatano/cardano/index.d.ts +1 -34
- package/README.md +6 -6
- package/db/schema.cds +29 -44
- package/db/types.cds +22 -5
- package/package.json +3 -1
- package/scripts/migrate-slot-leader.mjs +3 -11
- package/scripts/migrate-txseq.mjs +3 -12
- package/src/index.d.ts +0 -4
- package/src/index.js +3 -5
- package/src/plugin.js +4 -8
- 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 +2 -10
- package/srv/blockchain/backends/blockfrost-backend.js +15 -21
- package/srv/blockchain/backends/cardano-backend.d.ts +12 -71
- package/srv/blockchain/backends/koios-backend.d.ts +14 -147
- package/srv/blockchain/backends/koios-backend.js +40 -164
- package/srv/blockchain/backends/odatano-backend.d.ts +1 -11
- package/srv/blockchain/backends/odatano-backend.js +11 -12
- package/srv/blockchain/backends/ogmios-backend.d.ts +13 -160
- package/srv/blockchain/backends/ogmios-backend.js +48 -175
- package/srv/blockchain/backends/ogmios-frame-guard.d.ts +2 -18
- package/srv/blockchain/backends/ogmios-frame-guard.js +8 -20
- package/srv/blockchain/cardano-client.d.ts +12 -80
- package/srv/blockchain/cardano-client.js +36 -88
- package/srv/blockchain/cardano-indexer.d.ts +12 -192
- package/srv/blockchain/cardano-indexer.js +132 -222
- package/srv/blockchain/cardano-tx-builder.d.ts +1 -28
- package/srv/blockchain/cardano-tx-builder.js +17 -34
- package/srv/blockchain/circuit-breaker.d.ts +1 -13
- package/srv/blockchain/circuit-breaker.js +5 -15
- package/srv/blockchain/crawler/asset-decimals-backfill.d.ts +15 -0
- package/srv/blockchain/crawler/asset-decimals-backfill.js +56 -0
- package/srv/blockchain/crawler/certificate-backfill.d.ts +0 -17
- package/srv/blockchain/crawler/certificate-backfill.js +8 -22
- package/srv/blockchain/crawler/crawler.d.ts +16 -93
- package/srv/blockchain/crawler/crawler.js +85 -160
- package/srv/blockchain/crawler/credential-backfill.d.ts +0 -9
- package/srv/blockchain/crawler/credential-backfill.js +6 -6
- package/srv/blockchain/crawler/hooks.d.ts +1 -5
- package/srv/blockchain/crawler/index.d.ts +0 -12
- package/srv/blockchain/crawler/index.js +6 -20
- package/srv/blockchain/crawler/sync-state.d.ts +6 -44
- package/srv/blockchain/crawler/sync-state.js +18 -53
- package/srv/blockchain/crawler/transaction-backfill.d.ts +0 -11
- package/srv/blockchain/crawler/transaction-backfill.js +11 -30
- package/srv/blockchain/crawler/utxo-set-import.d.ts +1 -30
- package/srv/blockchain/crawler/utxo-set-import.js +27 -53
- package/srv/blockchain/ledger-state.d.ts +10 -54
- package/srv/blockchain/ledger-state.js +11 -27
- package/srv/blockchain/pending-spends.d.ts +0 -12
- package/srv/blockchain/pending-spends.js +4 -12
- 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 +0 -9
- package/srv/blockchain/signing/cose-verifier.js +4 -10
- package/srv/blockchain/signing/external-signer.d.ts +1 -4
- package/srv/blockchain/signing/external-signer.js +2 -8
- package/srv/blockchain/signing/hsm-signer.d.ts +6 -18
- package/srv/blockchain/signing/hsm-signer.js +16 -28
- package/srv/blockchain/signing/signature-verifier.d.ts +1 -8
- package/srv/blockchain/signing/signature-verifier.js +9 -19
- package/srv/blockchain/signing/submission-finalizer.d.ts +10 -16
- package/srv/blockchain/signing/submission-finalizer.js +48 -19
- package/srv/blockchain/stored-chain.d.ts +1 -14
- package/srv/blockchain/stored-chain.js +3 -8
- package/srv/blockchain/transaction-building/buildooor-fee-patch.d.ts +0 -4
- package/srv/blockchain/transaction-building/buildooor-fee-patch.js +4 -9
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +7 -150
- package/srv/blockchain/transaction-building/buildooor-tx.js +91 -196
- package/srv/blockchain/transaction-building/caller-datums.d.ts +0 -14
- package/srv/blockchain/transaction-building/caller-datums.js +3 -9
- package/srv/blockchain/transaction-building/cardano-tx.d.ts +1 -4
- package/srv/blockchain/wallet-worker/build-request.d.ts +0 -5
- package/srv/blockchain/wallet-worker/build-request.js +6 -9
- package/srv/blockchain/wallet-worker/confirmation-tracker.d.ts +5 -23
- package/srv/blockchain/wallet-worker/confirmation-tracker.js +16 -20
- package/srv/blockchain/wallet-worker/index.d.ts +1 -1
- package/srv/blockchain/wallet-worker/index.js +3 -5
- package/srv/blockchain/wallet-worker/job-store.d.ts +15 -65
- package/srv/blockchain/wallet-worker/job-store.js +0 -0
- package/srv/blockchain/wallet-worker/lease-heartbeat.d.ts +2 -10
- package/srv/blockchain/wallet-worker/lease-heartbeat.js +6 -12
- package/srv/blockchain/wallet-worker/signers.d.ts +3 -11
- package/srv/blockchain/wallet-worker/signers.js +3 -6
- package/srv/blockchain/wallet-worker/wallet-worker.d.ts +3 -21
- package/srv/blockchain/wallet-worker/wallet-worker.js +47 -54
- package/srv/cardano-agent-service.cds +123 -146
- package/srv/cardano-agent-service.js +2 -5
- package/srv/cardano-backend-service.cds +10 -17
- package/srv/cardano-backend-service.js +7 -12
- package/srv/cardano-indexer-service.cds +35 -37
- package/srv/cardano-indexer-service.d.ts +5 -1
- package/srv/cardano-indexer-service.js +64 -33
- package/srv/cardano-service.cds +56 -40
- package/srv/cardano-service.js +42 -69
- package/srv/cardano-sign-service.cds +14 -23
- package/srv/cardano-sign-service.js +18 -24
- package/srv/cardano-tx-service.cds +27 -29
- package/srv/cardano-tx-service.js +60 -122
- package/srv/cardano-worker-service.cds +109 -125
- package/srv/cardano-worker-service.js +21 -31
- package/srv/cbor/cip68.d.ts +13 -0
- package/srv/cbor/cip68.js +56 -0
- package/srv/cbor/index.d.ts +1 -0
- package/srv/cbor/index.js +6 -1
- package/srv/cbor/parse.d.ts +3 -18
- package/srv/cbor/parse.js +2 -7
- package/srv/cbor/plutus-data-json.d.ts +0 -4
- package/srv/server.d.ts +5 -36
- package/srv/server.js +30 -51
- package/srv/utils/agent-grants-config.d.ts +0 -18
- package/srv/utils/agent-grants-config.js +6 -13
- package/srv/utils/agent-grants.d.ts +14 -68
- package/srv/utils/agent-grants.js +42 -60
- package/srv/utils/agent-token-auth.d.ts +0 -5
- package/srv/utils/agent-token-auth.js +2 -5
- package/srv/utils/backend-request-handler.d.ts +1 -1
- package/srv/utils/collections.d.ts +1 -4
- package/srv/utils/collections.js +1 -4
- package/srv/utils/const.d.ts +0 -18
- package/srv/utils/const.js +7 -18
- package/srv/utils/crypto.js +3 -5
- package/srv/utils/db-indexes.d.ts +2 -0
- package/srv/utils/db-indexes.js +22 -9
- package/srv/utils/db-sanitize.d.ts +1 -8
- package/srv/utils/db-sanitize.js +3 -8
- package/srv/utils/epoch-slots.d.ts +1 -8
- package/srv/utils/epoch-slots.js +3 -8
- package/srv/utils/error-codes.d.ts +0 -4
- package/srv/utils/error-codes.js +2 -4
- package/srv/utils/errors.d.ts +2 -22
- package/srv/utils/errors.js +13 -27
- package/srv/utils/liveness.d.ts +0 -4
- package/srv/utils/liveness.js +2 -4
- package/srv/utils/mappers.d.ts +0 -37
- package/srv/utils/mappers.js +22 -39
- package/srv/utils/network-context.js +2 -4
- package/srv/utils/paging.d.ts +31 -0
- package/srv/utils/paging.js +43 -0
- package/srv/utils/pg-inline-json.js +3 -7
- package/srv/utils/pg-order-nulls.js +2 -5
- package/srv/utils/plutus-placeholders.d.ts +0 -13
- package/srv/utils/plutus-placeholders.js +6 -13
- package/srv/utils/rate-limiter.d.ts +0 -8
- package/srv/utils/rate-limiter.js +2 -4
- package/srv/utils/reference-script.d.ts +0 -18
- package/srv/utils/reference-script.js +8 -19
- package/srv/utils/service-events.d.ts +0 -4
- package/srv/utils/service-events.js +2 -4
- package/srv/utils/signing-helper.d.ts +1 -8
- package/srv/utils/signing-helper.js +3 -8
- package/srv/utils/tx-build-helper.d.ts +2 -32
- package/srv/utils/tx-build-helper.js +26 -40
- package/srv/utils/tx-request-parsers.d.ts +1 -25
- package/srv/utils/tx-request-parsers.js +10 -25
- package/srv/utils/tx-utils.d.ts +0 -8
- package/srv/utils/tx-utils.js +10 -13
- package/srv/utils/types.d.ts +2 -37
- package/srv/utils/validators.d.ts +0 -4
- package/srv/utils/validators.js +2 -4
|
@@ -11,8 +11,8 @@ const errors_1 = require("../../utils/errors");
|
|
|
11
11
|
const plutus_placeholders_1 = require("../../utils/plutus-placeholders");
|
|
12
12
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
13
13
|
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
14
|
-
// Metadata classes come from the
|
|
15
|
-
//
|
|
14
|
+
// Metadata classes come from the dist paths on purpose. Buildooor's `instanceof` checks
|
|
15
|
+
// match these exact classes, not the package-root re-exports.
|
|
16
16
|
const TxMetadata_1 = require("@harmoniclabs/cardano-ledger-ts/dist/tx/metadata/TxMetadata");
|
|
17
17
|
const TxMetadatum_1 = require("@harmoniclabs/cardano-ledger-ts/dist/tx/metadata/TxMetadatum");
|
|
18
18
|
const plutus_data_1 = require("@harmoniclabs/plutus-data");
|
|
@@ -22,9 +22,7 @@ const buildooor_fee_patch_1 = require("./buildooor-fee-patch");
|
|
|
22
22
|
const reference_script_1 = require("../../utils/reference-script");
|
|
23
23
|
const logger = cds_1.default.log('BuildooorTxBuilder');
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
* local CEK budget and, without `onScriptInvalid`, aborts on a local failure; we only record
|
|
27
|
-
* failures here and let `_buildScriptTx` decide (Ogmios result wins, otherwise abort).
|
|
25
|
+
* Records local script failures instead of aborting, so `_buildScriptTx` can let Ogmios decide.
|
|
28
26
|
*/
|
|
29
27
|
function makeScriptBuildOpts(failures) {
|
|
30
28
|
return {
|
|
@@ -63,17 +61,14 @@ function ceilDiv(a, b) {
|
|
|
63
61
|
function maxBig(a, b) {
|
|
64
62
|
return a > b ? a : b;
|
|
65
63
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Parse a protocol-parameter value (number or decimal string) into a non-negative safe integer;
|
|
68
|
-
* undefined for null/empty/invalid so callers keep library defaults instead of coercing to 0.
|
|
69
|
-
*/
|
|
64
|
+
/** Non-negative safe integer, or undefined so callers keep library defaults instead of 0. */
|
|
70
65
|
function toUInt(value) {
|
|
71
66
|
if (value === null || value === undefined || value === '')
|
|
72
67
|
return undefined;
|
|
73
68
|
const n = Number(value);
|
|
74
69
|
return Number.isSafeInteger(n) && n >= 0 ? n : undefined;
|
|
75
70
|
}
|
|
76
|
-
/**
|
|
71
|
+
/** Strictly positive finite number, else undefined. */
|
|
77
72
|
function toPositiveNumber(value) {
|
|
78
73
|
if (value === null || value === undefined || value === '')
|
|
79
74
|
return undefined;
|
|
@@ -86,7 +81,7 @@ function protocolParamsFingerprint(p) {
|
|
|
86
81
|
return `${p.network}#${p.epoch}`;
|
|
87
82
|
return JSON.stringify(p);
|
|
88
83
|
}
|
|
89
|
-
/** Ledger limit for
|
|
84
|
+
/** Ledger limit for one text or bytes metadatum, counted in bytes. */
|
|
90
85
|
const METADATA_BYTE_LIMIT = 64;
|
|
91
86
|
/** Split a string into pieces of at most maxBytes UTF-8 bytes without splitting a code point. */
|
|
92
87
|
function chunkUtf8(str, maxBytes) {
|
|
@@ -109,11 +104,8 @@ function chunkUtf8(str, maxBytes) {
|
|
|
109
104
|
chunks.push(current);
|
|
110
105
|
return chunks;
|
|
111
106
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
* compiler's bare bytestring) and toCbor() returns them, while an output's script_ref must hold the
|
|
115
|
-
* ledger form [language, bytes]; the hash is the same either way.
|
|
116
|
-
*/
|
|
107
|
+
// Script.fromCbor keeps the compiler bytes, but an output's script_ref needs the ledger form.
|
|
108
|
+
// Rebuilding the script gives that form. The hash stays the same.
|
|
117
109
|
function ledgerScript(script) {
|
|
118
110
|
return new cardano_ledger_ts_1.Script(script.type, script.bytes);
|
|
119
111
|
}
|
|
@@ -131,15 +123,9 @@ class BuildooorTxBuilder {
|
|
|
131
123
|
cardanoClient;
|
|
132
124
|
genesisInfos;
|
|
133
125
|
paramsFingerprint;
|
|
134
|
-
/**
|
|
135
|
-
* Chain cost-model arrays kept verbatim for language-view hashing; set by _mapCostModels,
|
|
136
|
-
* empty when the current parameters carry no usable cost models.
|
|
137
|
-
*/
|
|
126
|
+
/** Chain cost-model arrays kept verbatim for language-view hashing. */
|
|
138
127
|
rawCostModelArrays = {};
|
|
139
|
-
/**
|
|
140
|
-
* Initialize the builder.
|
|
141
|
-
* @param protocolParams - optional; fetched from the backend when omitted
|
|
142
|
-
*/
|
|
128
|
+
/** Initialize the builder. Protocol parameters are fetched when omitted. */
|
|
143
129
|
async init(client, protocolParams) {
|
|
144
130
|
this.cardanoClient = client;
|
|
145
131
|
const params = protocolParams ?? await client.getProtocolParameters();
|
|
@@ -151,10 +137,7 @@ class BuildooorTxBuilder {
|
|
|
151
137
|
this._applyProtocolParameters(params, protocolParamsFingerprint(params));
|
|
152
138
|
logger.debug(`Initialized with protocol parameters and ${client.network} genesis infos`);
|
|
153
139
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Rebuild the TxBuilder when the per-request protocol parameters differ from the current
|
|
156
|
-
* ones; the TxBuilder has no setter but its constructor is cheap (effectively once per epoch).
|
|
157
|
-
*/
|
|
140
|
+
/** TxBuilder has no setter, so it is rebuilt when the protocol parameters change. */
|
|
158
141
|
_ensureCurrentProtocolParameters(ctx) {
|
|
159
142
|
const params = ctx.protocolParameters;
|
|
160
143
|
if (!params)
|
|
@@ -177,10 +160,7 @@ class BuildooorTxBuilder {
|
|
|
177
160
|
buildUnsignedTransactionWithMetadata(req, ctx) {
|
|
178
161
|
return this._withRefScriptFallback(ctx.utxos, (include) => this._buildSimpleTransfer(req, ctx, 'metadata transfer', include));
|
|
179
162
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Shared non-script transfer build; assets, outputDatum and metadataJson are each
|
|
182
|
-
* handled only when present in the request.
|
|
183
|
-
*/
|
|
163
|
+
/** Shared non-script transfer build. */
|
|
184
164
|
async _buildSimpleTransfer(req, ctx, label, includeRefScriptUtxos) {
|
|
185
165
|
try {
|
|
186
166
|
this._ensureCurrentProtocolParameters(ctx);
|
|
@@ -304,8 +284,7 @@ class BuildooorTxBuilder {
|
|
|
304
284
|
const mints = this._buildMintEntries(req.mintActions, (a, i) => ({ inline: this._mintActionScript(a, script, i) }), resolvedMintRedeemer, resolveCtx);
|
|
305
285
|
// CIP-31: map resolved reference input UTxOs to Buildooor LedgerUTxO format
|
|
306
286
|
const readonlyRefInputs = this._mapReferenceInputs(ctx.referenceInputUtxos);
|
|
307
|
-
//
|
|
308
|
-
// and fee computation stay consistent (a mismatch would force re-evaluation).
|
|
287
|
+
// Both passes must share the validity bounds so redeemer ExUnits and fee stay consistent.
|
|
309
288
|
const { invalidBefore, invalidAfter } = this._resolveValiditySlots(req, 'script');
|
|
310
289
|
// Auxiliary metadata (CIP-20, label 674, ...) must be identical across eval + final passes:
|
|
311
290
|
// it affects tx size (fee) and the script data hash.
|
|
@@ -333,7 +312,7 @@ class BuildooorTxBuilder {
|
|
|
333
312
|
return this._withRefScriptFallback(ctx.utxos, (include) => this._buildPlutusSpendTransaction(req, ctx, include));
|
|
334
313
|
}
|
|
335
314
|
async _buildPlutusSpendTransaction(req, ctx, includeRefScriptUtxos) {
|
|
336
|
-
//
|
|
315
|
+
// Same collateral-partition context as in _buildMintTransaction.
|
|
337
316
|
let coinSelectionContext;
|
|
338
317
|
let requestedOutputs;
|
|
339
318
|
try {
|
|
@@ -342,7 +321,7 @@ class BuildooorTxBuilder {
|
|
|
342
321
|
const script = this._parsePlutusV3Script(plutusScriptExecution.validatorScript, 'plutusScriptExecution.validatorScript');
|
|
343
322
|
if (!plutusScriptExecution.datum) {
|
|
344
323
|
// Without an explicit datum the script UTxO must carry an inline datum.
|
|
345
|
-
logger.debug('No datumJson provided
|
|
324
|
+
logger.debug('No datumJson provided, expecting inline datum on script UTxO');
|
|
346
325
|
}
|
|
347
326
|
const scriptUtxoRef = plutusScriptExecution.scriptUtxo;
|
|
348
327
|
const scriptOdatanoUtxo = ctx.utxos.find(u => u.txHash === scriptUtxoRef.txHash && u.outputIndex === scriptUtxoRef.outputIndex);
|
|
@@ -354,7 +333,7 @@ class BuildooorTxBuilder {
|
|
|
354
333
|
const senderUtxos = ctx.utxos.filter(u => !(u.txHash === scriptUtxoRef.txHash && u.outputIndex === scriptUtxoRef.outputIndex));
|
|
355
334
|
const recipientAddress = cardano_ledger_ts_1.Address.fromString(req.recipientAddress);
|
|
356
335
|
const changeAddress = cardano_ledger_ts_1.Address.fromString(req.changeAddress ?? req.senderAddress);
|
|
357
|
-
//
|
|
336
|
+
// A forced input that matches the script UTxO is silently ignored.
|
|
358
337
|
const forceInputsFiltered = (req.forceInputs ?? []).filter(r => !(r.txHash === scriptUtxoRef.txHash && r.outputIndex === scriptUtxoRef.outputIndex));
|
|
359
338
|
const { forced, rest } = this._partitionForcedInputs(senderUtxos, forceInputsFiltered, this._referencedKeys(ctx, req.referenceInputs), req.protectInputs, includeRefScriptUtxos);
|
|
360
339
|
const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
|
|
@@ -375,8 +354,7 @@ class BuildooorTxBuilder {
|
|
|
375
354
|
const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
|
|
376
355
|
const selectedFundingInputs = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
377
356
|
logger.debug(`Coin selection: ${selectedFundingInputs.length}/${allFundingInputs.length} UTxOs selected (${forcedInputs.length} forced) for Plutus spend`);
|
|
378
|
-
//
|
|
379
|
-
// in redeemer / datum / output datums BEFORE PlutusData encoding.
|
|
357
|
+
// Resolve __INPUT_IDX__ placeholders against Buildooor's input order before PlutusData encoding.
|
|
380
358
|
const sortedInputs = this._computeSortedInputs([scriptUtxoRef], forced, this._extractFundingRefs(selectedFundingInputs));
|
|
381
359
|
const resolveCtx = { sortedInputs };
|
|
382
360
|
const resolvedRedeemer = (0, plutus_placeholders_1.resolveIndexPlaceholders)(plutusScriptExecution.redeemer, resolveCtx);
|
|
@@ -402,7 +380,7 @@ class BuildooorTxBuilder {
|
|
|
402
380
|
mintScript = this._parsePlutusV3Script(req.mintingPolicyScript, 'mintingPolicyScript');
|
|
403
381
|
mintScriptHash = mintScript.hash.toString();
|
|
404
382
|
}
|
|
405
|
-
//
|
|
383
|
+
// The continuing output carries the multi-assets of the script UTxO.
|
|
406
384
|
const scriptNonAdaAssets = scriptOdatanoUtxo.amount.filter(a => a.unit.toLowerCase() !== 'lovelace' && BigInt(a.quantity) > 0n);
|
|
407
385
|
let outputValue = cardano_ledger_ts_1.Value.lovelaces(BigInt(req.lovelaceAmount || const_1.MIN_CHANGE_LOVELACE));
|
|
408
386
|
if (scriptNonAdaAssets.length > 0) {
|
|
@@ -436,8 +414,7 @@ class BuildooorTxBuilder {
|
|
|
436
414
|
const inputs = [scriptInput, ...forcedInputs, ...selectedFundingInputs];
|
|
437
415
|
// CIP-31: map resolved reference input UTxOs to Buildooor LedgerUTxO format
|
|
438
416
|
const readonlyRefInputs = this._mapReferenceInputs(ctx.referenceInputUtxos);
|
|
439
|
-
//
|
|
440
|
-
// and fee computation stay consistent (a mismatch would force re-evaluation).
|
|
417
|
+
// Both passes must share the validity bounds so redeemer ExUnits and fee stay consistent.
|
|
441
418
|
const { invalidBefore, invalidAfter } = this._resolveValiditySlots(req, 'script');
|
|
442
419
|
// One set of build args shared by both internal passes and the Ogmios evaluation.
|
|
443
420
|
const buildParams = {
|
|
@@ -461,10 +438,8 @@ class BuildooorTxBuilder {
|
|
|
461
438
|
(0, tx_build_helper_1.mapBuilderError)(err, undefined, coinSelectionContext, requestedOutputs);
|
|
462
439
|
}
|
|
463
440
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
* reference-script UTxO), the outputs exactly in the given order and change after them.
|
|
467
|
-
*/
|
|
441
|
+
// Several script inputs, each with its own redeemer and an inline or referenced validator.
|
|
442
|
+
// Outputs keep the given order, change comes after them.
|
|
468
443
|
buildUnsignedPlutusTransaction(req, ctx) {
|
|
469
444
|
return this._withRefScriptFallback(ctx.utxos, (include) => this._buildPlutusTransaction(req, ctx, include));
|
|
470
445
|
}
|
|
@@ -702,10 +677,7 @@ class BuildooorTxBuilder {
|
|
|
702
677
|
(0, tx_build_helper_1.mapBuilderError)(err, undefined, coinSelectionContext, requestedOutputs);
|
|
703
678
|
}
|
|
704
679
|
}
|
|
705
|
-
/**
|
|
706
|
-
* Outputs of a BuildPlutusTransaction in the given order: inline datum or datum hash, ref script, min-ADA each.
|
|
707
|
-
* Returns the inline datums given as CBOR, keyed by output index.
|
|
708
|
-
*/
|
|
680
|
+
/** Appends the outputs in order and returns the CBOR inline datums by output index. */
|
|
709
681
|
_appendPlutusOutputs(outputs, list) {
|
|
710
682
|
const callerDatums = new Map();
|
|
711
683
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -727,11 +699,8 @@ class BuildooorTxBuilder {
|
|
|
727
699
|
}
|
|
728
700
|
return callerDatums;
|
|
729
701
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
* Buildooor's encoding. `forAnyAmount` sizes the coin field for the largest amount, so the
|
|
733
|
-
* result stays valid once written into the output.
|
|
734
|
-
*/
|
|
702
|
+
// Min-ADA also counts caller datum bytes that are longer than Buildooor's encoding.
|
|
703
|
+
// `forAnyAmount` sizes the coin field for the largest amount, so the result stays valid.
|
|
735
704
|
_minOutputLovelace(txOut, callerDatum, forAnyAmount = false) {
|
|
736
705
|
const base = forAnyAmount
|
|
737
706
|
? this.txBuilder.minimizeLovelaces(txOut).value.lovelaces
|
|
@@ -802,16 +771,13 @@ class BuildooorTxBuilder {
|
|
|
802
771
|
warnings: [],
|
|
803
772
|
};
|
|
804
773
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
* budgets and ignores caller-supplied units, so build once, evaluate via Ogmios when available,
|
|
808
|
-
* rebuild with a fee floor for the target units, then stamp them and recompute scriptDataHash.
|
|
809
|
-
*/
|
|
774
|
+
// Buildooor stamps local CEK budgets and ignores caller units. So build once, evaluate via Ogmios,
|
|
775
|
+
// rebuild with a fee floor for the target units, then stamp them and recompute scriptDataHash.
|
|
810
776
|
async _buildScriptTx(buildParams, evaluator, callerDatums = new Map(), witnessDatums = []) {
|
|
811
777
|
const pass1Failures = [];
|
|
812
778
|
const tx1 = await this.txBuilder.build(buildParams, makeScriptBuildOpts(pass1Failures));
|
|
813
779
|
if (!tx1) {
|
|
814
|
-
throw new errors_1.TransactionValidationError('Buildooor txBuilder.build() returned null
|
|
780
|
+
throw new errors_1.TransactionValidationError('Buildooor txBuilder.build() returned null; check inputs, datum, and collateral configuration');
|
|
815
781
|
}
|
|
816
782
|
const rdmrs1 = tx1.witnesses.redeemers ?? [];
|
|
817
783
|
if (rdmrs1.length === 0) {
|
|
@@ -823,7 +789,7 @@ class BuildooorTxBuilder {
|
|
|
823
789
|
? await this._evaluateExUnitsByRedeemer((0, uint8array_utils_1.toHex)(tx1.toCbor()), evaluator)
|
|
824
790
|
: undefined;
|
|
825
791
|
if (!evaluator) {
|
|
826
|
-
logger.debug('No evaluator available
|
|
792
|
+
logger.debug('No evaluator available, falling back to buffered local execution units');
|
|
827
793
|
}
|
|
828
794
|
const targets1 = this._resolveTargetExUnits(rdmrs1, evaluatedUnits, pass1Failures);
|
|
829
795
|
// Fee floor: Buildooor's fee already covers local budgets and future vkey witnesses; add the
|
|
@@ -840,10 +806,8 @@ class BuildooorTxBuilder {
|
|
|
840
806
|
const tx = (0, caller_datums_1.writeCallerDatums)(this._stampExecUnits(tx2, targets2), callerDatums);
|
|
841
807
|
return (0, caller_datums_1.writeWitnessDatums)(tx, witnessDatums, this._languageViews(tx));
|
|
842
808
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
* evaluation is unusable (transient failure, empty result). Validation errors are rethrown.
|
|
846
|
-
*/
|
|
809
|
+
// Cushioned Ogmios budgets keyed `tag:index`. Undefined when the evaluation is unusable.
|
|
810
|
+
// Validation errors are rethrown.
|
|
847
811
|
async _evaluateExUnitsByRedeemer(evalTxCbor, evaluator) {
|
|
848
812
|
try {
|
|
849
813
|
const evalResults = await evaluator(evalTxCbor);
|
|
@@ -885,21 +849,15 @@ class BuildooorTxBuilder {
|
|
|
885
849
|
return undefined;
|
|
886
850
|
}
|
|
887
851
|
}
|
|
888
|
-
|
|
889
|
-
* Cushion: relative multiplier for proportional drift on large validators, absolute floor
|
|
890
|
-
* for sub-percent drift on small ones.
|
|
891
|
-
*/
|
|
852
|
+
// The multiplier covers drift on large validators, the absolute floor covers small ones.
|
|
892
853
|
_applyExUnitBuffer(mem, cpu) {
|
|
893
854
|
return {
|
|
894
855
|
mem: BigInt(Math.ceil(Number(mem) * const_1.EXECUTION_UNIT_BUFFER) + const_1.ABS_MEM_BUFFER),
|
|
895
856
|
cpu: BigInt(Math.ceil(Number(cpu) * const_1.EXECUTION_UNIT_BUFFER) + const_1.ABS_CPU_BUFFER)
|
|
896
857
|
};
|
|
897
858
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
* local without Ogmios, Ogmios alone after a local failure; a local failure without Ogmios
|
|
901
|
-
* aborts because unreliable units would forfeit the signer's collateral.
|
|
902
|
-
*/
|
|
859
|
+
// Per redeemer: max of local and Ogmios, else buffered local, else Ogmios after a local failure.
|
|
860
|
+
// A local failure without Ogmios aborts, since unreliable units would forfeit the collateral.
|
|
903
861
|
_resolveTargetExUnits(rdmrs, evaluatedUnits, failures) {
|
|
904
862
|
return rdmrs.map(r => {
|
|
905
863
|
const local = { mem: BigInt(r.execUnits.mem), cpu: BigInt(r.execUnits.cpu) };
|
|
@@ -909,7 +867,7 @@ class BuildooorTxBuilder {
|
|
|
909
867
|
if (!evaluated) {
|
|
910
868
|
throw new errors_1.TransactionValidationError(`Plutus script failed local evaluation (redeemer ${(0, cardano_ledger_ts_1.txRedeemerTagToString)(r.tag)}:${r.index}) ` +
|
|
911
869
|
`and no Ogmios evaluation is available to certify its execution units. Refusing to return a ` +
|
|
912
|
-
`transaction with unreliable execution units
|
|
870
|
+
`transaction with unreliable execution units. Signing and submitting it would forfeit the collateral. ` +
|
|
913
871
|
`Configure an Ogmios backend for authoritative script evaluation, or fix the script/datum/redeemer. ` +
|
|
914
872
|
`Script logs: [${failure.logs.join(', ')}]`);
|
|
915
873
|
}
|
|
@@ -955,11 +913,8 @@ class BuildooorTxBuilder {
|
|
|
955
913
|
_txFeePerByte() {
|
|
956
914
|
return BigInt(this.txBuilder.protocolParamters.txFeePerByte);
|
|
957
915
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
* cost-model arrays (TxBuilder.overrideTxRedeemers hashes with clamped named-key models,
|
|
961
|
-
* which mismatches once the on-chain cost model grows). Recomputed even when units match.
|
|
962
|
-
*/
|
|
916
|
+
// Recomputes scriptDataHash with the raw chain cost-model arrays, even when units match.
|
|
917
|
+
// TxBuilder.overrideTxRedeemers hashes clamped models, which breaks once the chain model grows.
|
|
963
918
|
_stampExecUnits(tx, targets) {
|
|
964
919
|
const rdmrs = tx.witnesses.redeemers ?? [];
|
|
965
920
|
const unchanged = rdmrs.every((r, i) => BigInt(r.execUnits.mem) === targets[i].mem && BigInt(r.execUnits.cpu) === targets[i].cpu);
|
|
@@ -982,10 +937,8 @@ class BuildooorTxBuilder {
|
|
|
982
937
|
_languageViews(tx) {
|
|
983
938
|
return (0, buildooor_1.costModelsToLanguageViewCbor)(this._languageViewCostModels(), this._usedLanguageViewOpts(tx));
|
|
984
939
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
* finds the datum by the hash of its bytes. Inline-datum UTxOs need no witness datum.
|
|
988
|
-
*/
|
|
940
|
+
// The ledger finds a witness datum by the hash of its bytes, so it must match the UTxO's datum hash.
|
|
941
|
+
// Inline-datum UTxOs need no witness datum.
|
|
989
942
|
_checkWitnessDatum(utxo, datum, field, hint) {
|
|
990
943
|
if (!utxo.datumHash || utxo.inlineDatum)
|
|
991
944
|
return;
|
|
@@ -994,11 +947,8 @@ class BuildooorTxBuilder {
|
|
|
994
947
|
throw new errors_1.TransactionValidationError(`${field} hashes to ${hash}, but ${utxo.txHash}#${utxo.outputIndex} is locked with datum hash ${utxo.datumHash}${hint}`);
|
|
995
948
|
}
|
|
996
949
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
* (which flags the languages of *executed* scripts). This builder only attaches
|
|
1000
|
-
* scripts inline, so the witness set carries every executed script.
|
|
1001
|
-
*/
|
|
950
|
+
// Mirrors Buildooor's initTxBuild, which flags the languages of executed scripts.
|
|
951
|
+
// Scripts are attached inline here, so the witness set carries every executed script.
|
|
1002
952
|
_usedLanguageViewOpts(tx) {
|
|
1003
953
|
const w = tx.witnesses;
|
|
1004
954
|
const opts = {
|
|
@@ -1010,21 +960,16 @@ class BuildooorTxBuilder {
|
|
|
1010
960
|
opts.mustHaveV3 = true;
|
|
1011
961
|
return opts;
|
|
1012
962
|
}
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
* parameter count this library release knows, but the ledger hashes every entry served,
|
|
1016
|
-
* so raw chain arrays (passed through unclamped) are substituted where available.
|
|
1017
|
-
*/
|
|
963
|
+
// Named-key models are clamped to the parameter count the library knows.
|
|
964
|
+
// The ledger hashes every served entry, so the raw chain arrays win where available.
|
|
1018
965
|
_languageViewCostModels() {
|
|
1019
966
|
const models = this.txBuilder.protocolParamters.costModels;
|
|
1020
967
|
if (Object.keys(this.rawCostModelArrays).length === 0)
|
|
1021
968
|
return models;
|
|
1022
969
|
return { ...models, ...this.rawCostModelArrays };
|
|
1023
970
|
}
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
* and such UTxOs exist, build again with them in the pool (their script bytes then count in the fee).
|
|
1027
|
-
*/
|
|
971
|
+
// Builds without the sender's reference-script UTxOs first, since their script bytes raise the fee.
|
|
972
|
+
// When funds are short, builds again with them in the pool.
|
|
1028
973
|
async _withRefScriptFallback(utxos, build) {
|
|
1029
974
|
try {
|
|
1030
975
|
return await build(false);
|
|
@@ -1032,14 +977,11 @@ class BuildooorTxBuilder {
|
|
|
1032
977
|
catch (err) {
|
|
1033
978
|
if (!(err instanceof errors_1.InsufficientFundsError) || !(utxos ?? []).some(hasRefScript))
|
|
1034
979
|
throw err;
|
|
1035
|
-
logger.info('Funds short without the reference-script UTxOs
|
|
980
|
+
logger.info('Funds short without the reference-script UTxOs, building again with them in the coin-selection pool');
|
|
1036
981
|
return build(true);
|
|
1037
982
|
}
|
|
1038
983
|
}
|
|
1039
|
-
|
|
1040
|
-
* Split UTxOs into forced inputs (must be consumed) and remaining candidates; forceInputs
|
|
1041
|
-
* refs absent from utxos are ignored (existence is validated upstream).
|
|
1042
|
-
*/
|
|
984
|
+
// Forced inputs must be consumed. Refs absent from utxos are ignored, upstream validates them.
|
|
1043
985
|
_partitionForcedInputs(utxos, forceInputs, referenced = new Set(), protectInputs, includeRefScriptUtxos = false) {
|
|
1044
986
|
const excluded = (u) => !includeRefScriptUtxos && hasRefScript(u);
|
|
1045
987
|
const key = (r) => `${r.txHash.toLowerCase()}#${r.outputIndex}`;
|
|
@@ -1051,7 +993,7 @@ class BuildooorTxBuilder {
|
|
|
1051
993
|
// a UTxO cannot be spent and referenced in one transaction
|
|
1052
994
|
const clash = [...forcedKeys].find(k => referenced.has(k));
|
|
1053
995
|
if (clash)
|
|
1054
|
-
throw new errors_1.TransactionValidationError(`forceInputs ${clash} is also a reference input
|
|
996
|
+
throw new errors_1.TransactionValidationError(`forceInputs ${clash} is also a reference input; a UTxO cannot be spent and referenced in one transaction`);
|
|
1055
997
|
const protectedClash = [...forcedKeys].find(k => protectedKeys.has(k));
|
|
1056
998
|
if (protectedClash)
|
|
1057
999
|
throw new errors_1.TransactionValidationError(`forceInputs ${protectedClash} is also in protectInputs`);
|
|
@@ -1067,10 +1009,8 @@ class BuildooorTxBuilder {
|
|
|
1067
1009
|
}
|
|
1068
1010
|
return { forced, rest };
|
|
1069
1011
|
}
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
* carries the same hash), by reference, or none (key witness).
|
|
1073
|
-
*/
|
|
1012
|
+
// Script of a withdrawal, certificate or mint. Inline scripts are swapped for a reference input
|
|
1013
|
+
// with the same hash. No script means a key witness.
|
|
1074
1014
|
_resolveScriptWitness(w, at, referencedByHash, refUtxoByKey, scriptField = 'stakingScript') {
|
|
1075
1015
|
if (w.script) {
|
|
1076
1016
|
const script = this._parsePlutusV3Script(w.script, `${at}.${scriptField}`);
|
|
@@ -1090,11 +1030,8 @@ class BuildooorTxBuilder {
|
|
|
1090
1030
|
}
|
|
1091
1031
|
return { refLedgerUtxo };
|
|
1092
1032
|
}
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
* numbers withdrawal redeemers by hash alone, so a scripted withdrawal whose position differs
|
|
1096
|
-
* between the two orders would get the wrong redeemer; such a build is refused.
|
|
1097
|
-
*/
|
|
1033
|
+
// Ledger order of withdrawal credential hashes, used by `__WDRL_IDX__`. Buildooor numbers
|
|
1034
|
+
// withdrawal redeemers by hash alone, so a build where the two orders differ is refused.
|
|
1098
1035
|
_ledgerWithdrawalOrder(entries) {
|
|
1099
1036
|
const withHash = entries.map(e => ({
|
|
1100
1037
|
credentialHash: e.rewardAccount.credentials.toString().toLowerCase(),
|
|
@@ -1110,11 +1047,8 @@ class BuildooorTxBuilder {
|
|
|
1110
1047
|
}
|
|
1111
1048
|
return ledger;
|
|
1112
1049
|
}
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
* and every unit they bring must be spent by the outputs, so none of it lands in the sender's change.
|
|
1116
|
-
* Script addresses are refused; those UTxOs are script inputs.
|
|
1117
|
-
*/
|
|
1050
|
+
// A forced input of another key address needs its owner as required signer, and the outputs
|
|
1051
|
+
// must spend all it brings so nothing lands in the sender's change. Script addresses are refused.
|
|
1118
1052
|
_checkForeignForcedInputs(forced, req) {
|
|
1119
1053
|
const sender = req.senderAddress.toLowerCase();
|
|
1120
1054
|
const foreign = forced.filter(u => u.address.toLowerCase() !== sender);
|
|
@@ -1173,10 +1107,7 @@ class BuildooorTxBuilder {
|
|
|
1173
1107
|
return [];
|
|
1174
1108
|
return referenceInputUtxos.map(u => this._mapMultiAssetUtxoToLedgerUtxo(u));
|
|
1175
1109
|
}
|
|
1176
|
-
|
|
1177
|
-
* Funding contributed by extra outputs on a mint build: their summed lovelace plus, per asset
|
|
1178
|
-
* unit, the demand the transaction's own positive mints do not cover.
|
|
1179
|
-
*/
|
|
1110
|
+
// Extra outputs need their lovelace plus any asset amount the mints themselves do not cover.
|
|
1180
1111
|
_extraOutputsFundingAfterMint(mintActions, extraOutputs) {
|
|
1181
1112
|
const mintedByUnit = new Map();
|
|
1182
1113
|
for (const action of mintActions) {
|
|
@@ -1203,20 +1134,14 @@ class BuildooorTxBuilder {
|
|
|
1203
1134
|
}
|
|
1204
1135
|
return { lovelace, ...(assets.length > 0 ? { assets } : {}) };
|
|
1205
1136
|
}
|
|
1206
|
-
/**
|
|
1207
|
-
* Script a mint action executes under: its per-action policy when set, else the request's
|
|
1208
|
-
* top-level policy script.
|
|
1209
|
-
*/
|
|
1137
|
+
/** Per-action policy script when set, else the request's policy script. */
|
|
1210
1138
|
_mintActionScript(action, defaultScript, index) {
|
|
1211
1139
|
if (!action.mintingPolicyScript)
|
|
1212
1140
|
return defaultScript;
|
|
1213
1141
|
return this._parsePlutusV3Script(action.mintingPolicyScript, `mintActions[${index}].mintingPolicyScript`);
|
|
1214
1142
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
* or as a reference-script UTxO. Each action may carry its own redeemer (falling back to the
|
|
1218
|
-
* request-level one); the ledger holds ONE redeemer per policy, so actions on the same policy must agree.
|
|
1219
|
-
*/
|
|
1143
|
+
// Mint entries for all mint flows. An action may carry its own redeemer, but the ledger holds
|
|
1144
|
+
// one redeemer per policy, so actions on the same policy must agree.
|
|
1220
1145
|
_buildMintEntries(mintActions, scriptFor, resolvedMintRedeemer, resolveCtx) {
|
|
1221
1146
|
const redeemerByPolicy = new Map();
|
|
1222
1147
|
return mintActions.map((action, index) => {
|
|
@@ -1234,7 +1159,7 @@ class BuildooorTxBuilder {
|
|
|
1234
1159
|
const redeemerFingerprint = (0, plutus_data_1.dataToCbor)(redeemerData).toString();
|
|
1235
1160
|
const seen = redeemerByPolicy.get(policyId);
|
|
1236
1161
|
if (seen !== undefined && seen !== redeemerFingerprint) {
|
|
1237
|
-
throw new Error(`mint actions under policy ${policyId} carry different redeemers
|
|
1162
|
+
throw new Error(`mint actions under policy ${policyId} carry different redeemers; the ledger allows one redeemer per policy; ` +
|
|
1238
1163
|
'split them into separate transactions or align the redeemers');
|
|
1239
1164
|
}
|
|
1240
1165
|
redeemerByPolicy.set(policyId, redeemerFingerprint);
|
|
@@ -1245,10 +1170,8 @@ class BuildooorTxBuilder {
|
|
|
1245
1170
|
};
|
|
1246
1171
|
});
|
|
1247
1172
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
* message counts only the funding pool, so the reservation would otherwise be invisible.
|
|
1251
|
-
*/
|
|
1173
|
+
// The builder's insufficient-funds message counts only the funding pool.
|
|
1174
|
+
// This context makes the collateral reservation visible.
|
|
1252
1175
|
_collateralPartitionContext(collateralUtxos, fundingUtxos, forced = []) {
|
|
1253
1176
|
const fundingLovelace = fundingUtxos.reduce((s, u) => s + (0, tx_build_helper_1.getLovelace)(u), 0n);
|
|
1254
1177
|
if (collateralUtxos.length === 0) {
|
|
@@ -1263,14 +1186,9 @@ class BuildooorTxBuilder {
|
|
|
1263
1186
|
`${alsoFunding ? ' and also offered as funding' : alsoForced ? ' and also spent as a forced input' : ''}; ` +
|
|
1264
1187
|
`${fundingUtxos.length} UTxO(s) with ${fundingLovelace} lovelace for coin selection`;
|
|
1265
1188
|
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
* (Buildooor sets no collateralReturn for ADA-only collateral). Throws without an ADA-only UTxO.
|
|
1270
|
-
* When the rest cannot pay `requiredLovelace` plus fee and change, the collateral UTxO is
|
|
1271
|
-
* funding too. The ledger allows one UTxO as input and as collateral.
|
|
1272
|
-
* When no UTxO in `utxos` covers the floor, a forced input of the sender that does is the collateral.
|
|
1273
|
-
*/
|
|
1189
|
+
// Smallest ADA-only UTxO covering COLLATERAL_LOVELACE, else a forced sender input. Buildooor sets no
|
|
1190
|
+
// collateralReturn for it, so the excess is returned here. When funds are short the collateral
|
|
1191
|
+
// UTxO also funds the transaction, which the ledger allows.
|
|
1274
1192
|
_setupCollateral(utxos, requiredLovelace, forced = [], senderAddress = '') {
|
|
1275
1193
|
const byLovelace = (a, b) => {
|
|
1276
1194
|
const diff = (0, tx_build_helper_1.getLovelace)(a) - (0, tx_build_helper_1.getLovelace)(b);
|
|
@@ -1290,7 +1208,7 @@ class BuildooorTxBuilder {
|
|
|
1290
1208
|
const chosen = forcedChoice ?? sorted.find(coversFloor) ?? sorted[sorted.length - 1];
|
|
1291
1209
|
if ((0, tx_build_helper_1.getLovelace)(chosen) < const_1.COLLATERAL_LOVELACE) {
|
|
1292
1210
|
logger.warn(`Largest ADA-only UTxO (${(0, tx_build_helper_1.getLovelace)(chosen)} lovelace) is below the ${const_1.COLLATERAL_LOVELACE} lovelace ` +
|
|
1293
|
-
`collateral floor
|
|
1211
|
+
`collateral floor; the node will reject the transaction if collateralPercentage × fee exceeds it`);
|
|
1294
1212
|
}
|
|
1295
1213
|
const collateralUtxos = [this._mapOdatanoUtxoToLedgerUtxo(chosen)];
|
|
1296
1214
|
const rest = utxos.filter(u => !(u.txHash === chosen.txHash && u.outputIndex === chosen.outputIndex));
|
|
@@ -1338,11 +1256,8 @@ class BuildooorTxBuilder {
|
|
|
1338
1256
|
}
|
|
1339
1257
|
return new cardano_ledger_ts_1.TxOut(params);
|
|
1340
1258
|
}
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
* defaults to V3 and would hash with the 0x03 prefix, giving a silently wrong script hash.
|
|
1344
|
-
* The UPLC version is the first three flat naturals of the unwrapped script: [1,0,0] vs [1,1,0].
|
|
1345
|
-
*/
|
|
1259
|
+
// Rejects UPLC 1.0.0 code. Script.fromCbor assumes V3 and would give a wrong script hash.
|
|
1260
|
+
// The UPLC version is the first three flat naturals of the unwrapped script.
|
|
1346
1261
|
_parsePlutusV3Script(hex, field) {
|
|
1347
1262
|
let script;
|
|
1348
1263
|
try {
|
|
@@ -1354,7 +1269,7 @@ class BuildooorTxBuilder {
|
|
|
1354
1269
|
}
|
|
1355
1270
|
const b = script.bytes;
|
|
1356
1271
|
if (b.length >= 3 && b[0] === 1 && b[1] === 0 && b[2] === 0) {
|
|
1357
|
-
throw new errors_1.TransactionValidationError(`${field} contains UPLC 1.0.0 code (PlutusV1/V2)
|
|
1272
|
+
throw new errors_1.TransactionValidationError(`${field} contains UPLC 1.0.0 code (PlutusV1/V2). ODATANO builds Plutus V3 transactions only. ` +
|
|
1358
1273
|
`Hashing it as V3 would yield a different script hash (wrong policy ID / unspendable address).`);
|
|
1359
1274
|
}
|
|
1360
1275
|
return script;
|
|
@@ -1365,28 +1280,25 @@ class BuildooorTxBuilder {
|
|
|
1365
1280
|
return undefined;
|
|
1366
1281
|
return ledgerScript(this._parsePlutusV3Script(hex, 'referenceScript'));
|
|
1367
1282
|
}
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
* `scriptRef` (Koios). With the hash and size only (Blockfrost, the tables) a placeholder of
|
|
1371
|
-
* that size stands in, so the fee counts its bytes; without the size nothing can be counted.
|
|
1372
|
-
*/
|
|
1283
|
+
// Uses `scriptRefCbor`, else a full-CBOR `scriptRef`. With hash and size only, a placeholder
|
|
1284
|
+
// of that size stands in so the fee counts its bytes.
|
|
1373
1285
|
_buildInputRefScript(utxo) {
|
|
1374
1286
|
const cbor = utxo.scriptRefCbor ?? (utxo.scriptRef && utxo.scriptRef.length > 56 ? utxo.scriptRef : undefined);
|
|
1375
1287
|
if (!cbor) {
|
|
1376
1288
|
if (utxo.scriptRef && utxo.scriptRefSize) {
|
|
1377
|
-
logger.debug(`UTxO ${utxo.txHash}#${utxo.outputIndex} carries scriptRef hash and size only
|
|
1289
|
+
logger.debug(`UTxO ${utxo.txHash}#${utxo.outputIndex} carries scriptRef hash and size only; fee counts ${utxo.scriptRefSize} bytes, local Plutus eval will not see the script`);
|
|
1378
1290
|
return (0, reference_script_1.sizePlaceholderScript)(utxo.scriptRefSize);
|
|
1379
1291
|
}
|
|
1380
1292
|
if (utxo.scriptRef)
|
|
1381
|
-
logger.warn(`UTxO ${utxo.txHash}#${utxo.outputIndex} carries scriptRef hash only
|
|
1293
|
+
logger.warn(`UTxO ${utxo.txHash}#${utxo.outputIndex} carries scriptRef hash only; its reference-script fee cannot be counted, the node may reject the transaction as underpaid`);
|
|
1382
1294
|
return undefined;
|
|
1383
1295
|
}
|
|
1384
1296
|
try {
|
|
1385
1297
|
const script = ledgerScript(cardano_ledger_ts_1.Script.fromCbor(Buffer.from(cbor, 'hex')));
|
|
1386
|
-
//
|
|
1298
|
+
// Chain data, not consumer input, so warn instead of rejecting.
|
|
1387
1299
|
const b = script.bytes;
|
|
1388
1300
|
if (b.length >= 3 && b[0] === 1 && b[1] === 0 && b[2] === 0) {
|
|
1389
|
-
logger.warn(`Input refScript on ${utxo.txHash}#${utxo.outputIndex} is UPLC 1.0.0 (PlutusV1/V2)
|
|
1301
|
+
logger.warn(`Input refScript on ${utxo.txHash}#${utxo.outputIndex} is UPLC 1.0.0 (PlutusV1/V2), treated as V3, local eval may misbehave`);
|
|
1390
1302
|
}
|
|
1391
1303
|
return script;
|
|
1392
1304
|
}
|
|
@@ -1396,10 +1308,7 @@ class BuildooorTxBuilder {
|
|
|
1396
1308
|
return undefined;
|
|
1397
1309
|
}
|
|
1398
1310
|
}
|
|
1399
|
-
|
|
1400
|
-
* Post-sort input order so __INPUT_IDX__ placeholders resolve to the indices Buildooor assigns
|
|
1401
|
-
* in build(): all inputs (script, forced, funding) sorted lexicographically on (txHash, outputIndex).
|
|
1402
|
-
*/
|
|
1311
|
+
// Buildooor sorts all inputs by txHash and outputIndex. __INPUT_IDX__ resolves against that order.
|
|
1403
1312
|
_computeSortedInputs(scriptUtxoRefs, forcedUtxos, fundingRefs) {
|
|
1404
1313
|
const all = [
|
|
1405
1314
|
...scriptUtxoRefs.map(r => ({ txHash: r.txHash, outputIndex: r.outputIndex })),
|
|
@@ -1426,10 +1335,7 @@ class BuildooorTxBuilder {
|
|
|
1426
1335
|
: undefined
|
|
1427
1336
|
}));
|
|
1428
1337
|
}
|
|
1429
|
-
/**
|
|
1430
|
-
* Append parsed extra outputs, enforcing min-ADA per entry; the rejection names the
|
|
1431
|
-
* required min-ADA so consumers can adjust without inspecting Buildooor internals.
|
|
1432
|
-
*/
|
|
1338
|
+
/** Appends extra outputs. A rejection names the required min-ADA. */
|
|
1433
1339
|
_appendExtraOutputs(outputs, extraOutputs) {
|
|
1434
1340
|
if (!extraOutputs || extraOutputs.length === 0)
|
|
1435
1341
|
return;
|
|
@@ -1448,10 +1354,8 @@ class BuildooorTxBuilder {
|
|
|
1448
1354
|
//---------------------------------------------------------------------------
|
|
1449
1355
|
// UTxO Mapping & Configuration Helpers
|
|
1450
1356
|
//---------------------------------------------------------------------------
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
* plain transfers pass explicit bounds through without defaulting.
|
|
1454
|
-
*/
|
|
1357
|
+
// Script builds default to two minutes ago until one hour ahead.
|
|
1358
|
+
// Plain transfers pass only explicit bounds through.
|
|
1455
1359
|
_resolveValiditySlots(req, mode) {
|
|
1456
1360
|
const hasStart = req.validityStartMs !== undefined && req.validityStartMs !== null && req.validityStartMs !== '';
|
|
1457
1361
|
const hasEnd = req.validityEndMs !== undefined && req.validityEndMs !== null && req.validityEndMs !== '';
|
|
@@ -1473,11 +1377,8 @@ class BuildooorTxBuilder {
|
|
|
1473
1377
|
invalidAfter: BigInt(endSlot),
|
|
1474
1378
|
};
|
|
1475
1379
|
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
* missing value keeps the library default instead of degrading to 0 (e.g. utxoCostPerByte = 0
|
|
1479
|
-
* disables min-ADA); cost models and ExUnit prices feed scriptDataHash and the fee math.
|
|
1480
|
-
*/
|
|
1380
|
+
// A missing value keeps the library default instead of 0. For example, utxoCostPerByte = 0
|
|
1381
|
+
// would disable min-ADA.
|
|
1481
1382
|
_mapLedgerParametersToBuildooorParams(protocolParameters) {
|
|
1482
1383
|
const pp = protocolParameters;
|
|
1483
1384
|
const d = cardano_ledger_ts_1.defaultProtocolParameters;
|
|
@@ -1521,16 +1422,13 @@ class BuildooorTxBuilder {
|
|
|
1521
1422
|
mapped.costModels = costModels;
|
|
1522
1423
|
}
|
|
1523
1424
|
else {
|
|
1524
|
-
logger.warn('Protocol parameters carry no usable cost models
|
|
1425
|
+
logger.warn('Protocol parameters carry no usable cost models; keeping library defaults. ' +
|
|
1525
1426
|
'scriptDataHash of script transactions may not match the ledger (PPViewHashesDontMatch risk).');
|
|
1526
1427
|
}
|
|
1527
1428
|
return mapped;
|
|
1528
1429
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
* CostModels; undefined when nothing usable is found. Also (re)sets this.rawCostModelArrays with
|
|
1532
|
-
* the unclamped chain arrays, which the scriptDataHash must cover (see _languageViewCostModels).
|
|
1533
|
-
*/
|
|
1430
|
+
// Accepts the keys 'PlutusVN', 'plutus:vN' and 'PlutusScriptVN'. Also resets rawCostModelArrays,
|
|
1431
|
+
// since the scriptDataHash must cover the unclamped chain arrays.
|
|
1534
1432
|
_mapCostModels(costModelsJson) {
|
|
1535
1433
|
this.rawCostModelArrays = {};
|
|
1536
1434
|
if (!costModelsJson)
|
|
@@ -1550,7 +1448,7 @@ class BuildooorTxBuilder {
|
|
|
1550
1448
|
PlutusV2: 'PlutusScriptV2', 'plutus:v2': 'PlutusScriptV2', PlutusScriptV2: 'PlutusScriptV2',
|
|
1551
1449
|
PlutusV3: 'PlutusScriptV3', 'plutus:v3': 'PlutusScriptV3', PlutusScriptV3: 'PlutusScriptV3',
|
|
1552
1450
|
};
|
|
1553
|
-
// Buildooor's CEK
|
|
1451
|
+
// Buildooor's CEK machine rejects array-form cost models, so convert them to named-key objects.
|
|
1554
1452
|
const result = {};
|
|
1555
1453
|
const rawArrays = {};
|
|
1556
1454
|
for (const [key, value] of Object.entries(raw)) {
|
|
@@ -1571,14 +1469,14 @@ class BuildooorTxBuilder {
|
|
|
1571
1469
|
rawArrays[target] = arr;
|
|
1572
1470
|
}
|
|
1573
1471
|
catch {
|
|
1574
|
-
logger.warn(`Cost-model array for ${key} has unexpected length (${value.length})
|
|
1472
|
+
logger.warn(`Cost-model array for ${key} has unexpected length (${value.length}), skipping`);
|
|
1575
1473
|
}
|
|
1576
1474
|
}
|
|
1577
1475
|
if (Object.keys(result).length === 0)
|
|
1578
1476
|
return undefined;
|
|
1579
1477
|
if (!(0, buildooor_1.isCostModels)(result)) {
|
|
1580
|
-
// Buildooor would silently substitute default cost models
|
|
1581
|
-
logger.warn('Mapped cost models failed Buildooor validation
|
|
1478
|
+
// Buildooor would silently substitute default cost models, so surface it instead.
|
|
1479
|
+
logger.warn('Mapped cost models failed Buildooor validation, keeping library defaults');
|
|
1582
1480
|
return undefined;
|
|
1583
1481
|
}
|
|
1584
1482
|
this.rawCostModelArrays = rawArrays;
|
|
@@ -1625,21 +1523,18 @@ class BuildooorTxBuilder {
|
|
|
1625
1523
|
const metadata = {};
|
|
1626
1524
|
for (const [label, value] of Object.entries(metadataJson)) {
|
|
1627
1525
|
if (!/^\d+$/.test(label)) {
|
|
1628
|
-
throw new errors_1.TransactionValidationError(`Invalid metadata label "${label}"
|
|
1526
|
+
throw new errors_1.TransactionValidationError(`Invalid metadata label "${label}": labels must be non-negative integers`);
|
|
1629
1527
|
}
|
|
1630
1528
|
metadata[Number(label)] = this._jsonToTxMetadatum(value, label);
|
|
1631
1529
|
}
|
|
1632
1530
|
return new TxMetadata_1.TxMetadata(metadata);
|
|
1633
1531
|
}
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
* over 64 BYTES chunked into a list, "0x..." strings become bytes, over-long map keys rejected.
|
|
1637
|
-
* @param path label-rooted position of `value` (e.g. "721.files[0].src"), named in every rejection
|
|
1638
|
-
*/
|
|
1532
|
+
// Ledger rules: integers only, text over 64 bytes is chunked into a list, "0x" strings become bytes.
|
|
1533
|
+
// `path` is the position of `value`, for example "721.files[0].src", named in every rejection.
|
|
1639
1534
|
_jsonToTxMetadatum(value, path) {
|
|
1640
1535
|
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
1641
1536
|
if (typeof value === 'number' && !Number.isInteger(value)) {
|
|
1642
|
-
throw new errors_1.TransactionValidationError(`Metadata numbers must be integers (got ${value} at ${path})
|
|
1537
|
+
throw new errors_1.TransactionValidationError(`Metadata numbers must be integers (got ${value} at ${path}); encode decimals as strings`);
|
|
1643
1538
|
}
|
|
1644
1539
|
return new TxMetadatum_1.TxMetadatumInt(BigInt(value));
|
|
1645
1540
|
}
|
|
@@ -1676,7 +1571,7 @@ class BuildooorTxBuilder {
|
|
|
1676
1571
|
return new TxMetadatum_1.TxMetadatumMap(map);
|
|
1677
1572
|
}
|
|
1678
1573
|
throw new errors_1.TransactionValidationError(`Unsupported metadata value type: ${value === null ? 'null' : typeof value} at ${path}` +
|
|
1679
|
-
(typeof value === 'boolean' ? '
|
|
1574
|
+
(typeof value === 'boolean' ? '; on-chain metadata has no boolean, encode as string or 0/1' : ''));
|
|
1680
1575
|
}
|
|
1681
1576
|
}
|
|
1682
1577
|
exports.BuildooorTxBuilder = BuildooorTxBuilder;
|