@odatano/core 2.0.0-rc.32 → 2.0.0-rc.33
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/db/schema.cds +1 -1
- package/package.json +1 -1
- package/srv/blockchain/backends/blockfrost-backend.js +2 -1
- package/srv/blockchain/backends/koios-backend.js +22 -20
- package/srv/blockchain/backends/ogmios-backend.js +2 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +2 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +57 -23
- package/srv/cardano-sign-service.js +2 -11
- package/srv/cardano-tx-service.cds +3 -3
- package/srv/cardano-tx-service.js +5 -2
- package/srv/cbor/parse.js +2 -1
- package/srv/utils/mappers.js +1 -1
- package/srv/utils/signing-helper.d.ts +6 -1
- package/srv/utils/signing-helper.js +33 -35
- package/srv/utils/tx-build-helper.d.ts +2 -1
- package/srv/utils/tx-build-helper.js +7 -1
- package/srv/utils/tx-request-parsers.d.ts +1 -1
- package/srv/utils/tx-request-parsers.js +4 -4
- package/srv/utils/types.d.ts +2 -1
package/db/schema.cds
CHANGED
|
@@ -542,7 +542,7 @@ entity Addresses : temporal {
|
|
|
542
542
|
stakeAddress : Bech32;
|
|
543
543
|
|
|
544
544
|
@title : 'Address Type'
|
|
545
|
-
@description: 'The
|
|
545
|
+
@description: 'The CIP-19 kind of address (base | pointer | enterprise | reward | byron | unknown); a script payment credential shows in isScript'
|
|
546
546
|
type : String(20);
|
|
547
547
|
|
|
548
548
|
@title : 'Is Script Address'
|
package/package.json
CHANGED
|
@@ -147,7 +147,8 @@ class BlockfrostBackend {
|
|
|
147
147
|
return {
|
|
148
148
|
address: address_data.address,
|
|
149
149
|
stakeAddress: address_data.stake_address,
|
|
150
|
-
|
|
150
|
+
// Blockfrost says shelley | byron; the other sources and the model use the CIP-19 kind
|
|
151
|
+
type: (0, mappers_1.decodeShelleyAddress)(address_data.address).type,
|
|
151
152
|
isScript: address_data.script,
|
|
152
153
|
amount: address_data.amount,
|
|
153
154
|
utxos: address_utxos.map(utxo => ({
|
|
@@ -216,10 +216,10 @@ class KoiosBackend {
|
|
|
216
216
|
end_time: data.end_time,
|
|
217
217
|
first_block_time: data.first_block_time,
|
|
218
218
|
last_block_time: data.last_block_time,
|
|
219
|
-
block_count: data.
|
|
219
|
+
block_count: data.blk_count,
|
|
220
220
|
tx_count: data.tx_count,
|
|
221
|
-
output: data.
|
|
222
|
-
fees: data.
|
|
221
|
+
output: data.out_sum,
|
|
222
|
+
fees: data.fees,
|
|
223
223
|
active_stake: data.active_stake,
|
|
224
224
|
};
|
|
225
225
|
}, this.name);
|
|
@@ -251,8 +251,9 @@ class KoiosBackend {
|
|
|
251
251
|
return {
|
|
252
252
|
address: address,
|
|
253
253
|
stakeAddress: addressData.stake_address || null,
|
|
254
|
-
type
|
|
255
|
-
|
|
254
|
+
// /address_info has no address type; it follows from the address itself
|
|
255
|
+
type: (0, mappers_1.decodeShelleyAddress)(address).type,
|
|
256
|
+
isScript: addressData.script_address,
|
|
256
257
|
amount: amount,
|
|
257
258
|
utxos: addressUtxos,
|
|
258
259
|
};
|
|
@@ -304,7 +305,6 @@ class KoiosBackend {
|
|
|
304
305
|
outputIndex: utxo.tx_index,
|
|
305
306
|
address: address,
|
|
306
307
|
amount: amount,
|
|
307
|
-
blockHash: utxo.block_hash,
|
|
308
308
|
datumHash: utxo.datum_hash || null,
|
|
309
309
|
scriptRef: koiosRefScriptBytes(utxo.reference_script),
|
|
310
310
|
inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(utxo.inline_datum),
|
|
@@ -339,7 +339,6 @@ class KoiosBackend {
|
|
|
339
339
|
outputIndex: utxo.tx_index,
|
|
340
340
|
address: utxo.address ?? '',
|
|
341
341
|
amount: amount,
|
|
342
|
-
blockHash: utxo.block_hash,
|
|
343
342
|
datumHash: utxo.datum_hash || null,
|
|
344
343
|
scriptRef: koiosRefScriptBytes(utxo.reference_script),
|
|
345
344
|
inlineDatum: (0, tx_build_helper_1.inlineDatumToHex)(utxo.inline_datum),
|
|
@@ -450,13 +449,14 @@ class KoiosBackend {
|
|
|
450
449
|
// a 0 would be indistinguishable from a real zero downstream.
|
|
451
450
|
blocksEpoch: null,
|
|
452
451
|
liveStake: poolData.live_stake || '0',
|
|
453
|
-
|
|
452
|
+
// /pool_info has no live share
|
|
453
|
+
liveSize: null,
|
|
454
454
|
liveDelegators: poolData.live_delegators || 0,
|
|
455
455
|
// Koios reports saturation in PERCENT (75.42); PoolData holds a fraction (0.7542)
|
|
456
456
|
// stored in Decimal(9, 4) — the percent value would overflow the column.
|
|
457
457
|
liveSaturation: (Number(poolData.live_saturation) || 0) / 100,
|
|
458
458
|
activeStake: poolData.active_stake || '0',
|
|
459
|
-
activeSize: poolData.
|
|
459
|
+
activeSize: Number(poolData.sigma) || 0,
|
|
460
460
|
pledge: poolData.pledge || '0',
|
|
461
461
|
margin: poolData.margin || 0,
|
|
462
462
|
fixedCost: poolData.fixed_cost || '0',
|
|
@@ -558,7 +558,8 @@ class KoiosBackend {
|
|
|
558
558
|
action: isNegative ? 'burn' : 'mint',
|
|
559
559
|
quantity: isNegative ? rawQty.slice(1) : rawQty,
|
|
560
560
|
blockTime: typeof entry.block_time === 'number' ? entry.block_time : null,
|
|
561
|
-
|
|
561
|
+
// minting_txs carry no block height
|
|
562
|
+
blockHeight: null,
|
|
562
563
|
};
|
|
563
564
|
});
|
|
564
565
|
// Sort newest-first and cap at limit (defensive — Koios may return ascending)
|
|
@@ -627,16 +628,17 @@ class KoiosBackend {
|
|
|
627
628
|
const accountData = data[0];
|
|
628
629
|
return {
|
|
629
630
|
stakeaddress: accountData.stake_address,
|
|
630
|
-
active: accountData.
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
631
|
+
active: accountData.status === 'registered',
|
|
632
|
+
// /account_info has no registration epoch
|
|
633
|
+
activeEpoch: 0,
|
|
634
|
+
controlledAmount: accountData.total_balance,
|
|
635
|
+
rewardsSum: accountData.rewards,
|
|
636
|
+
withdrawalsSum: accountData.withdrawals,
|
|
637
|
+
reservesSum: accountData.reserves,
|
|
638
|
+
treasurySum: accountData.treasury,
|
|
639
|
+
withdrawableAmount: accountData.rewards_available,
|
|
640
|
+
poolId: accountData.delegated_pool || null,
|
|
641
|
+
drepId: accountData.delegated_drep || null,
|
|
640
642
|
addresses: addresses,
|
|
641
643
|
};
|
|
642
644
|
}, this.name);
|
|
@@ -654,7 +654,8 @@ class OgmiosBackend {
|
|
|
654
654
|
// not in the ledger state; null = unavailable, as on Koios
|
|
655
655
|
blocksEpoch: null,
|
|
656
656
|
liveStake: pool.stake?.ada?.lovelace ? String(pool.stake.ada.lovelace) : '0',
|
|
657
|
-
|
|
657
|
+
// no total live stake to divide by; null = unavailable
|
|
658
|
+
liveSize: null,
|
|
658
659
|
// not in the ledger state; null = unavailable
|
|
659
660
|
liveDelegators: null,
|
|
660
661
|
liveSaturation: 0,
|
|
@@ -160,6 +160,8 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
|
|
|
160
160
|
* Pick the smallest ADA-only UTxO covering COLLATERAL_LOVELACE as collateral and return the
|
|
161
161
|
* rest as funding; excess above the floor goes back via collateralReturn when it meets min-ADA
|
|
162
162
|
* (Buildooor sets no collateralReturn for ADA-only collateral). Throws without an ADA-only UTxO.
|
|
163
|
+
* When the rest cannot pay `requiredLovelace` plus fee and change, the collateral UTxO is
|
|
164
|
+
* funding too. The ledger allows one UTxO as input and as collateral.
|
|
163
165
|
*/
|
|
164
166
|
private _setupCollateral;
|
|
165
167
|
/** Build a Ledger Value from lovelace + optional multi-asset array */
|
|
@@ -225,13 +225,15 @@ class BuildooorTxBuilder {
|
|
|
225
225
|
return this._buildResult(req, ctx, this._extractTxDetails(tx), { forcedInputsUsed: forcedInputs.length });
|
|
226
226
|
}
|
|
227
227
|
catch (err) {
|
|
228
|
-
|
|
228
|
+
// one requested output; Buildooor appends the change after it
|
|
229
|
+
(0, tx_build_helper_1.mapBuilderError)(err, undefined, undefined, 1);
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
232
|
async buildUnsignedMintTransaction(req, ctx) {
|
|
232
233
|
// Set once the collateral partition is known: it explains insufficient-funds rejections
|
|
233
234
|
// that the builder's own message cannot attribute.
|
|
234
235
|
let coinSelectionContext;
|
|
236
|
+
let requestedOutputs;
|
|
235
237
|
try {
|
|
236
238
|
this._ensureCurrentProtocolParameters(ctx);
|
|
237
239
|
const recipientAddress = cardano_ledger_ts_1.Address.fromString(req.recipientAddress);
|
|
@@ -251,11 +253,6 @@ class BuildooorTxBuilder {
|
|
|
251
253
|
// collateral and coin selection operate on the remainder only.
|
|
252
254
|
const { forced, rest } = this._partitionForcedInputs(ctx.utxos, req.forceInputs, this._referencedKeys(ctx, req.referenceInputs), req.protectInputs);
|
|
253
255
|
const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
|
|
254
|
-
// Collateral + funding separation (from candidates only — forced inputs cannot double as collateral)
|
|
255
|
-
const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest);
|
|
256
|
-
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
|
|
257
|
-
const fundingLedgerUtxos = fundingUtxos.map(utxo => this._mapMultiAssetUtxoToLedgerUtxo(utxo));
|
|
258
|
-
const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
|
|
259
256
|
// Funding must cover the lovelace plus, for extra outputs, their lovelace and any asset
|
|
260
257
|
// demand the mint itself does not cover.
|
|
261
258
|
let requiredFundingValue = cardano_ledger_ts_1.Value.lovelaces(BigInt(req.lovelaceAmount));
|
|
@@ -263,6 +260,11 @@ class BuildooorTxBuilder {
|
|
|
263
260
|
const { lovelace, assets } = this._extraOutputsFundingAfterMint(req.mintActions, req.extraOutputs);
|
|
264
261
|
requiredFundingValue = cardano_ledger_ts_1.Value.add(requiredFundingValue, this._buildLedgerValue(lovelace, assets));
|
|
265
262
|
}
|
|
263
|
+
// Collateral + funding separation (from candidates only — forced inputs cannot double as collateral)
|
|
264
|
+
const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest, requiredFundingValue.lovelaces);
|
|
265
|
+
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
|
|
266
|
+
const fundingLedgerUtxos = fundingUtxos.map(utxo => this._mapMultiAssetUtxoToLedgerUtxo(utxo));
|
|
267
|
+
const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
|
|
266
268
|
const selectedFunding = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
267
269
|
const inputs = [...forcedInputs, ...selectedFunding];
|
|
268
270
|
logger.debug(`Coin selection: ${selectedFunding.length}/${allFundingInputs.length} UTxOs selected (${forcedInputs.length} forced) for mint`);
|
|
@@ -289,6 +291,7 @@ class BuildooorTxBuilder {
|
|
|
289
291
|
const outputs = [this._buildTxOut(recipientAddress, outputValue, resolvedInlineDatum, refScript)];
|
|
290
292
|
// Append extra outputs, each independently min-ADA checked.
|
|
291
293
|
this._appendExtraOutputs(outputs, resolvedExtraOutputs);
|
|
294
|
+
requestedOutputs = outputs.length;
|
|
292
295
|
// Mint entries; Buildooor ignores caller-supplied execution units, the real ones are
|
|
293
296
|
// stamped post-build by _buildScriptTx.
|
|
294
297
|
const mints = this._buildMintEntries(req.mintActions, (a, i) => ({ inline: this._mintActionScript(a, script, i) }), resolvedMintRedeemer, resolveCtx);
|
|
@@ -316,12 +319,13 @@ class BuildooorTxBuilder {
|
|
|
316
319
|
return this._buildResult(req, ctx, this._extractTxDetails(tx), { scriptHash: script.hash.toString(), forcedInputsUsed: forcedInputs.length, referenceInputsUsed: readonlyRefInputs.length });
|
|
317
320
|
}
|
|
318
321
|
catch (err) {
|
|
319
|
-
(0, tx_build_helper_1.mapBuilderError)(err, undefined, coinSelectionContext);
|
|
322
|
+
(0, tx_build_helper_1.mapBuilderError)(err, undefined, coinSelectionContext, requestedOutputs);
|
|
320
323
|
}
|
|
321
324
|
}
|
|
322
325
|
async buildUnsignedPlutusSpendTransaction(req, ctx) {
|
|
323
326
|
// See buildUnsignedMintTransaction — same collateral-partition context for rejections.
|
|
324
327
|
let coinSelectionContext;
|
|
328
|
+
let requestedOutputs;
|
|
325
329
|
try {
|
|
326
330
|
this._ensureCurrentProtocolParameters(ctx);
|
|
327
331
|
const { plutusScriptExecution } = req;
|
|
@@ -344,19 +348,21 @@ class BuildooorTxBuilder {
|
|
|
344
348
|
const forceInputsFiltered = (req.forceInputs ?? []).filter(r => !(r.txHash === scriptUtxoRef.txHash && r.outputIndex === scriptUtxoRef.outputIndex));
|
|
345
349
|
const { forced, rest } = this._partitionForcedInputs(senderUtxos, forceInputsFiltered, this._referencedKeys(ctx, req.referenceInputs), req.protectInputs);
|
|
346
350
|
const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
|
|
347
|
-
// Collateral + funding separation (from candidates only — forced inputs cannot double as collateral)
|
|
348
|
-
const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest);
|
|
349
|
-
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
|
|
350
|
-
const fundingLedgerUtxos = fundingUtxos.map(utxo => this._mapMultiAssetUtxoToLedgerUtxo(utxo));
|
|
351
351
|
// Funding covers fee + min change (the script UTxO covers the output) plus extra outputs;
|
|
352
352
|
// assets the script UTxO already provides net out, so over-requesting is harmless.
|
|
353
|
-
const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
|
|
354
353
|
let requiredFundingValue = cardano_ledger_ts_1.Value.lovelaces(BigInt(req.lovelaceAmount || const_1.MIN_CHANGE_LOVELACE));
|
|
355
354
|
if (req.extraOutputs && req.extraOutputs.length > 0) {
|
|
356
355
|
for (const extra of req.extraOutputs) {
|
|
357
356
|
requiredFundingValue = cardano_ledger_ts_1.Value.add(requiredFundingValue, this._buildLedgerValue(BigInt(extra.lovelaceAmount), extra.assets));
|
|
358
357
|
}
|
|
359
358
|
}
|
|
359
|
+
// Collateral + funding separation (from candidates only — forced inputs cannot double as collateral).
|
|
360
|
+
// The script UTxO pays its part of the outputs, so the collateral check counts only the rest.
|
|
361
|
+
const fundingGap = requiredFundingValue.lovelaces - (0, tx_build_helper_1.getLovelace)(scriptOdatanoUtxo);
|
|
362
|
+
const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest, fundingGap > 0n ? fundingGap : 0n);
|
|
363
|
+
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
|
|
364
|
+
const fundingLedgerUtxos = fundingUtxos.map(utxo => this._mapMultiAssetUtxoToLedgerUtxo(utxo));
|
|
365
|
+
const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
|
|
360
366
|
const selectedFundingInputs = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
361
367
|
logger.debug(`Coin selection: ${selectedFundingInputs.length}/${allFundingInputs.length} UTxOs selected (${forcedInputs.length} forced) for Plutus spend`);
|
|
362
368
|
// Compute the final input order (Buildooor's lex sort) and resolve __INPUT_IDX__ placeholders
|
|
@@ -407,6 +413,7 @@ class BuildooorTxBuilder {
|
|
|
407
413
|
const outputs = [this._buildTxOut(recipientAddress, outputValue, resolvedPrimaryInlineDatum, primaryRefScript)];
|
|
408
414
|
// Append extra outputs, each independently min-ADA checked.
|
|
409
415
|
this._appendExtraOutputs(outputs, resolvedExtraOutputs);
|
|
416
|
+
requestedOutputs = outputs.length;
|
|
410
417
|
// Mint entries for the combined spend+mint; Buildooor ignores caller-supplied execution
|
|
411
418
|
// units, the real ones are stamped post-build by _buildScriptTx.
|
|
412
419
|
const mints = hasMint
|
|
@@ -441,7 +448,7 @@ class BuildooorTxBuilder {
|
|
|
441
448
|
});
|
|
442
449
|
}
|
|
443
450
|
catch (err) {
|
|
444
|
-
(0, tx_build_helper_1.mapBuilderError)(err, undefined, coinSelectionContext);
|
|
451
|
+
(0, tx_build_helper_1.mapBuilderError)(err, undefined, coinSelectionContext, requestedOutputs);
|
|
445
452
|
}
|
|
446
453
|
}
|
|
447
454
|
/**
|
|
@@ -450,6 +457,7 @@ class BuildooorTxBuilder {
|
|
|
450
457
|
*/
|
|
451
458
|
async buildUnsignedPlutusTransaction(req, ctx) {
|
|
452
459
|
let coinSelectionContext;
|
|
460
|
+
let requestedOutputs;
|
|
453
461
|
try {
|
|
454
462
|
this._ensureCurrentProtocolParameters(ctx);
|
|
455
463
|
const keyOf = (r) => `${r.txHash.toLowerCase()}#${r.outputIndex}`;
|
|
@@ -550,9 +558,6 @@ class BuildooorTxBuilder {
|
|
|
550
558
|
const { forced, rest } = this._partitionForcedInputs(senderUtxos, (req.forceInputs ?? []).filter(r => !scriptKeys.has(keyOf(r))), this._referencedKeys(ctx, req.referenceInputs, req.scriptInputs.flatMap(s => (s.referenceScript ? [s.referenceScript] : []))), req.protectInputs);
|
|
551
559
|
this._checkForeignForcedInputs(forced, req);
|
|
552
560
|
const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
|
|
553
|
-
const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest);
|
|
554
|
-
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
|
|
555
|
-
const allFundingInputs = fundingUtxos.map(utxo => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(utxo) }));
|
|
556
561
|
// Funding covers only what the outputs need beyond the script inputs, forced inputs, mints and
|
|
557
562
|
// withdrawals (keepRelevant adds its own lovelace margin for fee and change).
|
|
558
563
|
const need = new Map();
|
|
@@ -581,6 +586,14 @@ class BuildooorTxBuilder {
|
|
|
581
586
|
? cardano_ledger_ts_1.Value.lovelaces(qty)
|
|
582
587
|
: this._buildLedgerValue(0n, [{ unit, quantity: qty.toString() }]));
|
|
583
588
|
}
|
|
589
|
+
// Collateral only when a Plutus script runs; Buildooor writes given collaterals into any body.
|
|
590
|
+
const runsScript = scriptEntries.length > 0 || mintEntries.length > 0 ||
|
|
591
|
+
[...withdrawalEntries, ...certEntries].some(e => e.script || e.refLedgerUtxo);
|
|
592
|
+
const { collateralUtxos, fundingUtxos, collateralReturn } = runsScript
|
|
593
|
+
? this._setupCollateral(rest, requiredFundingValue.lovelaces)
|
|
594
|
+
: { collateralUtxos: [], fundingUtxos: rest, collateralReturn: undefined };
|
|
595
|
+
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
|
|
596
|
+
const allFundingInputs = fundingUtxos.map(utxo => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(utxo) }));
|
|
584
597
|
const selectedFundingInputs = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
585
598
|
// Reference inputs: the caller's, minus the reference-script UTxOs Buildooor adds itself
|
|
586
599
|
const refScriptKeys = new Set([...scriptEntries, ...withdrawalEntries, ...certEntries, ...mintEntries].filter(e => e.refLedgerUtxo).map(e => keyOf({ txHash: e.refLedgerUtxo.utxoRef.id.toString(), outputIndex: e.refLedgerUtxo.utxoRef.index })));
|
|
@@ -618,6 +631,7 @@ class BuildooorTxBuilder {
|
|
|
618
631
|
...o,
|
|
619
632
|
inlineDatum: o.inlineDatum !== undefined ? (0, plutus_placeholders_1.resolveIndexPlaceholders)(o.inlineDatum, resolveCtx) : undefined,
|
|
620
633
|
})));
|
|
634
|
+
requestedOutputs = outputs.length;
|
|
621
635
|
const mints = mintEntries.length > 0
|
|
622
636
|
? this._buildMintEntries(mintEntries.map(e => e.m), (_a, i) => (mintEntries[i].script ? { inline: mintEntries[i].script } : { ref: mintEntries[i].refLedgerUtxo }), undefined, resolveCtx)
|
|
623
637
|
: undefined;
|
|
@@ -655,7 +669,15 @@ class BuildooorTxBuilder {
|
|
|
655
669
|
throw new errors_1.TransactionValidationError(`transaction is ${details.sizeBytes} bytes, above the maximum of ${maxTxSize}` +
|
|
656
670
|
(inline > 0 ? `; ${inline} script input(s) carry their validator inline, a referenceScript would move it out of the transaction` : ''));
|
|
657
671
|
}
|
|
658
|
-
|
|
672
|
+
// the first script that runs: a spend, else a mint policy, else a withdrawal or certificate script
|
|
673
|
+
const scriptHashes = [
|
|
674
|
+
...scriptEntries.map(e => e.script ? e.script.hash.toString() : e.scriptHash),
|
|
675
|
+
...mintEntries.map(e => e.policyId),
|
|
676
|
+
...[...withdrawalEntries, ...certEntries].flatMap(e => {
|
|
677
|
+
const hash = e.script?.hash ?? e.refLedgerUtxo?.resolved.refScript?.hash;
|
|
678
|
+
return hash ? [hash.toString()] : [];
|
|
679
|
+
}),
|
|
680
|
+
];
|
|
659
681
|
logger.debug(`Built unsigned Plutus transaction with ${scriptInputs.length} script input(s), fee ${details.feeLovelace}`);
|
|
660
682
|
return this._buildResult(req, ctx, details, {
|
|
661
683
|
scriptHash: scriptHashes[0],
|
|
@@ -664,7 +686,7 @@ class BuildooorTxBuilder {
|
|
|
664
686
|
});
|
|
665
687
|
}
|
|
666
688
|
catch (err) {
|
|
667
|
-
(0, tx_build_helper_1.mapBuilderError)(err, undefined, coinSelectionContext);
|
|
689
|
+
(0, tx_build_helper_1.mapBuilderError)(err, undefined, coinSelectionContext, requestedOutputs);
|
|
668
690
|
}
|
|
669
691
|
}
|
|
670
692
|
/**
|
|
@@ -1200,17 +1222,25 @@ class BuildooorTxBuilder {
|
|
|
1200
1222
|
* message counts only the funding pool, so the reservation would otherwise be invisible.
|
|
1201
1223
|
*/
|
|
1202
1224
|
_collateralPartitionContext(collateralUtxos, fundingUtxos) {
|
|
1203
|
-
const collateralLovelace = collateralUtxos.reduce((s, u) => s + u.resolved.value.lovelaces, 0n);
|
|
1204
1225
|
const fundingLovelace = fundingUtxos.reduce((s, u) => s + (0, tx_build_helper_1.getLovelace)(u), 0n);
|
|
1205
|
-
|
|
1206
|
-
|
|
1226
|
+
if (collateralUtxos.length === 0) {
|
|
1227
|
+
return `no script runs, so no collateral; ${fundingUtxos.length} UTxO(s) with ${fundingLovelace} lovelace for coin selection`;
|
|
1228
|
+
}
|
|
1229
|
+
const collateralLovelace = collateralUtxos.reduce((s, u) => s + u.resolved.value.lovelaces, 0n);
|
|
1230
|
+
const collateralKeys = new Set(collateralUtxos.map(u => `${u.utxoRef.id.toString()}#${u.utxoRef.index}`));
|
|
1231
|
+
const alsoFunding = fundingUtxos.some(u => collateralKeys.has(`${u.txHash}#${u.outputIndex}`));
|
|
1232
|
+
return `${collateralUtxos.length} UTxO(s) with ${collateralLovelace} lovelace reserved as collateral` +
|
|
1233
|
+
`${alsoFunding ? ' and also offered as funding' : ''}; ` +
|
|
1234
|
+
`${fundingUtxos.length} UTxO(s) with ${fundingLovelace} lovelace for coin selection`;
|
|
1207
1235
|
}
|
|
1208
1236
|
/**
|
|
1209
1237
|
* Pick the smallest ADA-only UTxO covering COLLATERAL_LOVELACE as collateral and return the
|
|
1210
1238
|
* rest as funding; excess above the floor goes back via collateralReturn when it meets min-ADA
|
|
1211
1239
|
* (Buildooor sets no collateralReturn for ADA-only collateral). Throws without an ADA-only UTxO.
|
|
1240
|
+
* When the rest cannot pay `requiredLovelace` plus fee and change, the collateral UTxO is
|
|
1241
|
+
* funding too. The ledger allows one UTxO as input and as collateral.
|
|
1212
1242
|
*/
|
|
1213
|
-
_setupCollateral(utxos) {
|
|
1243
|
+
_setupCollateral(utxos, requiredLovelace) {
|
|
1214
1244
|
// ADA-only and without a reference script (a deployed script is not collateral); SetCollateral uses the same rule
|
|
1215
1245
|
const adaOnly = utxos.filter(tx_build_helper_1.isCollateralCandidate);
|
|
1216
1246
|
if (adaOnly.length === 0) {
|
|
@@ -1227,7 +1257,11 @@ class BuildooorTxBuilder {
|
|
|
1227
1257
|
`collateral floor — the node will reject the transaction if collateralPercentage × fee exceeds it`);
|
|
1228
1258
|
}
|
|
1229
1259
|
const collateralUtxos = [this._mapOdatanoUtxoToLedgerUtxo(chosen)];
|
|
1230
|
-
const
|
|
1260
|
+
const rest = utxos.filter(u => !(u.txHash === chosen.txHash && u.outputIndex === chosen.outputIndex));
|
|
1261
|
+
const restLovelace = rest.reduce((sum, u) => sum + (0, tx_build_helper_1.getLovelace)(u), 0n);
|
|
1262
|
+
const fundingUtxos = restLovelace >= requiredLovelace + const_1.FEE_BUFFER_LOVELACE + BigInt(const_1.MIN_CHANGE_LOVELACE)
|
|
1263
|
+
? rest
|
|
1264
|
+
: [...rest, chosen];
|
|
1231
1265
|
// Cap the at-risk amount at the floor: return the excess to the owner.
|
|
1232
1266
|
let collateralReturn;
|
|
1233
1267
|
const excess = (0, tx_build_helper_1.getLovelace)(chosen) - const_1.COLLATERAL_LOVELACE;
|
|
@@ -167,14 +167,7 @@ module.exports = (srv) => {
|
|
|
167
167
|
(0, errors_1.rejectInvalid)(req, 'VerifySignature', `Signing request status is '${current?.status ?? 'unknown'}', expected 'pending'`, 'signingRequestId');
|
|
168
168
|
}
|
|
169
169
|
// A CIP-30 wallet returns only the witness set; cardano-cli a full signed tx.
|
|
170
|
-
|
|
171
|
-
if ((0, signing_helper_1.isWitnessSetCbor)(signedTxCbor)) {
|
|
172
|
-
fullSignedTxCbor = (0, signing_helper_1.combineTransactionWithWitnesses)(signingRequest.unsignedTxCbor, signedTxCbor);
|
|
173
|
-
logger.debug({ signingRequestId }, 'Combined witness set with unsigned transaction for verification');
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
fullSignedTxCbor = signedTxCbor;
|
|
177
|
-
}
|
|
170
|
+
const fullSignedTxCbor = (0, signing_helper_1.toSignedTransaction)(signingRequest.unsignedTxCbor, signedTxCbor);
|
|
178
171
|
// Verification is bound to the keys that must witness this tx.
|
|
179
172
|
const requiredSigners = await resolveRequiredSigners(db, signingRequest, TransactionBuilds);
|
|
180
173
|
const signerModule = (0, external_signer_1.getExternalSignerModule)();
|
|
@@ -229,9 +222,7 @@ module.exports = (srv) => {
|
|
|
229
222
|
(0, errors_1.rejectInvalid)(req, 'SubmitVerifiedTransaction', 'Signing request has no associated build', 'signingRequestId');
|
|
230
223
|
}
|
|
231
224
|
// CIP-30 witness set or full signed tx
|
|
232
|
-
const fullSignedTxCbor = (0, signing_helper_1.
|
|
233
|
-
? (0, signing_helper_1.combineTransactionWithWitnesses)(signingRequest.unsignedTxCbor, signedTxCbor)
|
|
234
|
-
: signedTxCbor;
|
|
225
|
+
const fullSignedTxCbor = (0, signing_helper_1.toSignedTransaction)(signingRequest.unsignedTxCbor, signedTxCbor);
|
|
235
226
|
// Throws on failure; bound to the keys that must witness this tx.
|
|
236
227
|
const requiredSigners = await resolveRequiredSigners(db, signingRequest, TransactionBuilds);
|
|
237
228
|
const verificationResult = (0, external_signer_1.getExternalSignerModule)().verifyOrThrow(fullSignedTxCbor, signingRequest.txBodyHash, { requiredSigners });
|
|
@@ -268,7 +268,7 @@ service CardanoTransactionService @(impl: './cardano-tx-service') {
|
|
|
268
268
|
@description: 'The unique identifier of the transaction build'
|
|
269
269
|
buildId: UUID,
|
|
270
270
|
@title: 'Signed Transaction CBOR'
|
|
271
|
-
@description: 'The
|
|
271
|
+
@description: 'The signed transaction, or the witness set a CIP-30 wallet returns from signTx; a witness set is added to the build transaction'
|
|
272
272
|
signedTxCbor: String) returns TransactionSubmissions;
|
|
273
273
|
|
|
274
274
|
@title : 'Submit Signed Transaction'
|
|
@@ -355,7 +355,7 @@ service CardanoTransactionService @(impl: './cardano-tx-service') {
|
|
|
355
355
|
validityEndMs: String) returns TransactionBuilds;
|
|
356
356
|
|
|
357
357
|
@title : 'Build Plutus Transaction'
|
|
358
|
-
@description: 'Spend
|
|
358
|
+
@description: 'Spend script UTxOs, each with its own redeemer (inline validator or a reference-script UTxO), mint, withdraw and certify in one transaction; script inputs are optional, so a mint or a withdraw-zero alone works. Collateral is added only when a script runs. The outputs are built exactly in the given order, change comes after them. The execution units of every redeemer are returned under redeemers.'
|
|
359
359
|
action BuildPlutusTransaction(
|
|
360
360
|
@title: 'Sender Address'
|
|
361
361
|
@description: 'Pays the fee, funds the rest and provides the ADA-only collateral'
|
|
@@ -364,7 +364,7 @@ service CardanoTransactionService @(impl: './cardano-tx-service') {
|
|
|
364
364
|
@description: 'Receives the change; defaults to senderAddress'
|
|
365
365
|
changeAddress: Bech32,
|
|
366
366
|
@title: 'Script Inputs JSON'
|
|
367
|
-
@description: '
|
|
367
|
+
@description: 'Optional JSON array, 0..16 entries: {txHash, outputIndex, validatorScript (CBOR hex) | referenceScript: {txHash, outputIndex}, scriptParamsJson?, redeemerJson | redeemerCbor, datumJson | datumCbor (hash datums only)}. The *Cbor forms take PlutusData CBOR hex byte for byte. In any redeemer or datum JSON, __INPUT_IDX:<txHash>#<n>__ resolves to the index in the final sorted inputs, __REF_IDX:<txHash>#<n>__ to the index in the sorted reference inputs (reference-script UTxOs included) and __WDRL_IDX:<credential hash>__ to the index in the withdrawals in ledger order.'
|
|
368
368
|
scriptInputsJson: String,
|
|
369
369
|
@title: 'Outputs JSON'
|
|
370
370
|
@description: 'Required JSON array of outputs in this order: {address, lovelaceAmount, assets?: [{unit, quantity}], inlineDatumJson? | inlineDatumCbor? | datumHash?, referenceScriptHex?}. Each is min-ADA checked; change is appended after them and never merged into one.'
|
|
@@ -12,6 +12,7 @@ const tx_build_helper_1 = require("./utils/tx-build-helper");
|
|
|
12
12
|
const cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
|
|
13
13
|
const mappers_1 = require("./utils/mappers");
|
|
14
14
|
const server_1 = require("./server");
|
|
15
|
+
const signing_helper_1 = require("./utils/signing-helper");
|
|
15
16
|
const const_1 = require("./utils/const");
|
|
16
17
|
const tx_request_parsers_1 = require("./utils/tx-request-parsers");
|
|
17
18
|
const VALID_DERIVE_NETWORKS = ['mainnet', 'preview', 'preprod'];
|
|
@@ -825,14 +826,16 @@ module.exports = (srv) => {
|
|
|
825
826
|
// SubmitTransaction — submit the signed CBOR of a previous build.
|
|
826
827
|
srv.on('SubmitTransaction', async (req) => {
|
|
827
828
|
logger.debug('SubmitTransaction Action handler called');
|
|
828
|
-
const { buildId, signedTxCbor } = req.data;
|
|
829
|
-
const errors = (0, validators_1.validateTransactionInputs)({ buildId, signedTxCbor }, ['buildId', 'signedTxCbor']);
|
|
829
|
+
const { buildId, signedTxCbor: signedInput } = req.data;
|
|
830
|
+
const errors = (0, validators_1.validateTransactionInputs)({ buildId, signedTxCbor: signedInput }, ['buildId', 'signedTxCbor']);
|
|
830
831
|
(0, errors_1.throwIfValidationErrors)(req, 'SubmitTransaction', errors);
|
|
831
832
|
return (0, backend_request_handler_1.handleRequest)(req, async (db) => {
|
|
832
833
|
logger.debug({ buildId }, 'Submitting signed transaction');
|
|
833
834
|
const existing = await db.run(SELECT.one.from(TransactionBuilds).where({ id: buildId }));
|
|
834
835
|
if (!existing)
|
|
835
836
|
throw new errors_1.NotFoundError(`Build '${buildId}'`);
|
|
837
|
+
// A CIP-30 wallet returns only the witness set; cardano-cli a full signed tx.
|
|
838
|
+
const signedTxCbor = (0, signing_helper_1.toSignedTransaction)(existing.unsignedTxCbor, signedInput);
|
|
836
839
|
// The signed CBOR must belong to this build (audit-trail integrity)
|
|
837
840
|
const signedTxHash = (0, tx_build_helper_1.getTxHashFromCbor)(signedTxCbor);
|
|
838
841
|
if (signedTxHash !== existing.txBodyHash) {
|
package/srv/cbor/parse.js
CHANGED
|
@@ -96,7 +96,8 @@ function mapOutput(out) {
|
|
|
96
96
|
datumHash,
|
|
97
97
|
inlineDatumHex,
|
|
98
98
|
referenceScriptHex,
|
|
99
|
-
|
|
99
|
+
// the bytes as received; a re-encoding can be shorter
|
|
100
|
+
cborSize: out.cborRef ? out.cborRef.toBuffer().length : out.toCborBytes().length,
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
103
|
function mapCertificate(cert, index) {
|
package/srv/utils/mappers.js
CHANGED
|
@@ -499,7 +499,7 @@ function mapPoolSnapshot(providerPoolData, epoch, at, origin = { source: 'koios'
|
|
|
499
499
|
blocksMinted: providerPoolData.blocksMinted,
|
|
500
500
|
blocksEpoch: providerPoolData.blocksEpoch,
|
|
501
501
|
liveStake: providerPoolData.liveStake,
|
|
502
|
-
liveSize: Number(providerPoolData.liveSize),
|
|
502
|
+
liveSize: providerPoolData.liveSize == null ? null : Number(providerPoolData.liveSize),
|
|
503
503
|
liveSaturation: Number(providerPoolData.liveSaturation),
|
|
504
504
|
liveDelegators: providerPoolData.liveDelegators,
|
|
505
505
|
activeStake: providerPoolData.activeStake,
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
* @returns complete signed transaction CBOR (hex)
|
|
4
4
|
*/
|
|
5
5
|
export declare function combineTransactionWithWitnesses(unsignedTxCbor: string, witnessSetCbor: string): string;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* True when the CBOR is a CIP-30 witness set (map) rather than a full transaction (array).
|
|
8
|
+
* Reads the major type of the first byte only; a malformed map fails later in the combine step.
|
|
9
|
+
*/
|
|
7
10
|
export declare function isWitnessSetCbor(cborHex: string): boolean;
|
|
11
|
+
/** The signed transaction: as given, or the unsigned one plus a CIP-30 witness set. */
|
|
12
|
+
export declare function toSignedTransaction(unsignedTxCbor: string | null | undefined, signedTxOrWitnessSet: string): string;
|
|
8
13
|
//# sourceMappingURL=signing-helper.d.ts.map
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.combineTransactionWithWitnesses = combineTransactionWithWitnesses;
|
|
7
7
|
exports.isWitnessSetCbor = isWitnessSetCbor;
|
|
8
|
+
exports.toSignedTransaction = toSignedTransaction;
|
|
8
9
|
const cds_1 = __importDefault(require("@sap/cds"));
|
|
9
10
|
const cbor_1 = require("@harmoniclabs/cbor");
|
|
10
11
|
const uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
|
|
@@ -24,35 +25,27 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
24
25
|
const walletWsObj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(witnessSetCbor));
|
|
25
26
|
// txObj.array[0] = body, [1] = witness_set, [2] = is_valid, [3] = auxiliary_data
|
|
26
27
|
const origWs = txObj.array[1];
|
|
28
|
+
if (!(origWs instanceof cbor_1.CborMap) || !(walletWsObj instanceof cbor_1.CborMap)) {
|
|
29
|
+
throw new errors_1.TransactionValidationError('Witness set must be CBOR map per Cardano spec');
|
|
30
|
+
}
|
|
31
|
+
// The wallet signs with vkey witnesses (map key 0) or, for Byron addresses, bootstrap witnesses (key 2)
|
|
32
|
+
const isSignatureKey = (k) => k instanceof cbor_1.CborUInt && (Number(k.num) === 0 || Number(k.num) === 2);
|
|
33
|
+
const walletSignatures = walletWsObj.map.filter(e => isSignatureKey(e.k));
|
|
27
34
|
let witnessCount = 0;
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.filter(e => !(e.k instanceof cbor_1.CborUInt && Number(e.k.num) === 0))
|
|
35
|
-
.concat([walletVkeyEntry]);
|
|
36
|
-
// New witness set map preserving the original's encoding style
|
|
37
|
-
txObj.array[1] = new cbor_1.CborMap(mergedEntries, {
|
|
38
|
-
indefinite: origWs.indefinite,
|
|
39
|
-
});
|
|
40
|
-
// VKey witnesses: CborArray, or CborTag(258, CborArray) in Conway
|
|
41
|
-
const vkeyValue = walletVkeyEntry.v;
|
|
42
|
-
if (vkeyValue instanceof cbor_1.CborArray) {
|
|
43
|
-
witnessCount = vkeyValue.array.length;
|
|
44
|
-
}
|
|
45
|
-
else if (vkeyValue instanceof cbor_1.CborTag && vkeyValue.data instanceof cbor_1.CborArray) {
|
|
46
|
-
witnessCount = vkeyValue.data.array.length;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
throw new errors_1.TransactionValidationError('Unexpected VKey witness format in witness set');
|
|
50
|
-
}
|
|
51
|
-
}
|
|
35
|
+
for (const { v } of walletSignatures) {
|
|
36
|
+
// CborArray, or CborTag(258, CborArray) in Conway
|
|
37
|
+
const items = v instanceof cbor_1.CborArray ? v.array : v instanceof cbor_1.CborTag && v.data instanceof cbor_1.CborArray ? v.data.array : undefined;
|
|
38
|
+
if (!items)
|
|
39
|
+
throw new errors_1.TransactionValidationError('Unexpected witness format in witness set');
|
|
40
|
+
witnessCount += items.length;
|
|
52
41
|
}
|
|
53
|
-
|
|
54
|
-
throw new errors_1.TransactionValidationError('Witness set
|
|
42
|
+
if (witnessCount === 0) {
|
|
43
|
+
throw new errors_1.TransactionValidationError('Witness set carries no vkey or bootstrap witness; the wallet did not sign');
|
|
55
44
|
}
|
|
45
|
+
// Keep original entries (redeemers, datums, scripts at keys 3-7), take the signatures from the wallet
|
|
46
|
+
const mergedEntries = origWs.map.filter(e => !isSignatureKey(e.k)).concat(walletSignatures);
|
|
47
|
+
// New witness set map preserving the original's encoding style
|
|
48
|
+
txObj.array[1] = new cbor_1.CborMap(mergedEntries, { indefinite: origWs.indefinite });
|
|
56
49
|
// New outer CborArray so the encoder cannot reuse the stale outer subCborRef; the inner
|
|
57
50
|
// subCborRefs are kept so the body bytes (and thus the signed body hash) stay identical.
|
|
58
51
|
const signedTxCbor = (0, uint8array_utils_1.toHex)(cbor_1.Cbor.encode(new cbor_1.CborArray(txObj.array, { indefinite: txObj.indefinite })));
|
|
@@ -70,16 +63,21 @@ function combineTransactionWithWitnesses(unsignedTxCbor, witnessSetCbor) {
|
|
|
70
63
|
throw new errors_1.TransactionValidationError(`Failed to combine transaction with witnesses: ${msg}`);
|
|
71
64
|
}
|
|
72
65
|
}
|
|
73
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* True when the CBOR is a CIP-30 witness set (map) rather than a full transaction (array).
|
|
68
|
+
* Reads the major type of the first byte only; a malformed map fails later in the combine step.
|
|
69
|
+
*/
|
|
74
70
|
function isWitnessSetCbor(cborHex) {
|
|
75
|
-
|
|
76
|
-
const obj = cbor_1.Cbor.parse((0, uint8array_utils_1.fromHex)(cborHex));
|
|
77
|
-
if (obj instanceof cbor_1.CborArray)
|
|
78
|
-
return false;
|
|
79
|
-
return obj instanceof cbor_1.CborMap;
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
71
|
+
if (!/^[0-9a-f]{2}/i.test(cborHex))
|
|
82
72
|
return false;
|
|
83
|
-
|
|
73
|
+
return parseInt(cborHex.slice(0, 2), 16) >> 5 === 5;
|
|
74
|
+
}
|
|
75
|
+
/** The signed transaction: as given, or the unsigned one plus a CIP-30 witness set. */
|
|
76
|
+
function toSignedTransaction(unsignedTxCbor, signedTxOrWitnessSet) {
|
|
77
|
+
if (!isWitnessSetCbor(signedTxOrWitnessSet))
|
|
78
|
+
return signedTxOrWitnessSet;
|
|
79
|
+
if (!unsignedTxCbor)
|
|
80
|
+
throw new errors_1.TransactionValidationError('No unsigned transaction to add the witness set to');
|
|
81
|
+
return combineTransactionWithWitnesses(unsignedTxCbor, signedTxOrWitnessSet);
|
|
84
82
|
}
|
|
85
83
|
//# sourceMappingURL=signing-helper.js.map
|
|
@@ -30,8 +30,9 @@ export declare function extractTxCacheTargets(txCbor: string): TxCacheTargets;
|
|
|
30
30
|
/**
|
|
31
31
|
* Maps Buildooor errors to typed BackendErrors. Asset unit is parsed from "not enough <unit>" when not given;
|
|
32
32
|
* `context` (e.g. the collateral partition) is appended to the consumer-facing message.
|
|
33
|
+
* `requestedOutputs` is the number of outputs the caller asked for; Buildooor appends the change after them.
|
|
33
34
|
*/
|
|
34
|
-
export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string): never;
|
|
35
|
+
export declare function mapBuilderError(err: unknown, assetUnit?: string, context?: string, requestedOutputs?: number): never;
|
|
35
36
|
/** Split an asset unit into policyId (56 hex chars) and assetName (remaining hex). */
|
|
36
37
|
export declare function parseAssetUnit(assetUnit: string): {
|
|
37
38
|
policyId: string;
|
|
@@ -115,8 +115,9 @@ function extractTxCacheTargets(txCbor) {
|
|
|
115
115
|
/**
|
|
116
116
|
* Maps Buildooor errors to typed BackendErrors. Asset unit is parsed from "not enough <unit>" when not given;
|
|
117
117
|
* `context` (e.g. the collateral partition) is appended to the consumer-facing message.
|
|
118
|
+
* `requestedOutputs` is the number of outputs the caller asked for; Buildooor appends the change after them.
|
|
118
119
|
*/
|
|
119
|
-
function mapBuilderError(err, assetUnit, context) {
|
|
120
|
+
function mapBuilderError(err, assetUnit, context, requestedOutputs) {
|
|
120
121
|
// Typed errors keep their own status and payload
|
|
121
122
|
if (err instanceof errors_1.BackendError) {
|
|
122
123
|
throw err;
|
|
@@ -128,6 +129,11 @@ function mapBuilderError(err, assetUnit, context) {
|
|
|
128
129
|
const minAda = rawMsg.match(/tx output at index (\d+) did not have enough lovelaces[\s\S]*?minimum lovelaces required:\s*(\d+)[\s\S]*?output lovelaces\s*:\s*(\d+)/);
|
|
129
130
|
if (minAda) {
|
|
130
131
|
const [, index, minimum, actual] = minAda;
|
|
132
|
+
if (requestedOutputs !== undefined && Number(index) >= requestedOutputs) {
|
|
133
|
+
// the change output: the caller cannot raise it. The shortfall is unknown here, so no amounts
|
|
134
|
+
throw new errors_1.InsufficientFundsError('lovelace', 0n, 0n, err, `the change output needs at least ${minimum} lovelace (has ${actual}); the funding UTxOs cannot pay the fee and the change` +
|
|
135
|
+
(context ? ` (${context})` : ''));
|
|
136
|
+
}
|
|
131
137
|
const withAssets = /tx output:[\s\S]*"[0-9a-f]{56}"\s*:/i.test(rawMsg) ? ', it carries native assets' : '';
|
|
132
138
|
throw new errors_1.TransactionValidationError(`output ${index} needs at least ${minimum} lovelace (has ${actual}${withAssets}); raise its lovelace amount`, err);
|
|
133
139
|
}
|
|
@@ -85,7 +85,7 @@ export interface ParsedScriptInput {
|
|
|
85
85
|
/** Datum preimage as PlutusData CBOR hex (instead of datumJson). */
|
|
86
86
|
datumCbor?: string;
|
|
87
87
|
}
|
|
88
|
-
/** Parse and validate scriptInputsJson:
|
|
88
|
+
/** Parse and validate scriptInputsJson: 0..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
89
89
|
export declare function parseScriptInputs(json: string | undefined): {
|
|
90
90
|
parsed?: ParsedScriptInput[];
|
|
91
91
|
error?: string;
|
|
@@ -235,15 +235,15 @@ function parseMintActionPolicyFields(entry, i, byReference = false) {
|
|
|
235
235
|
}
|
|
236
236
|
/** Upper bound on script inputs per BuildPlutusTransaction. */
|
|
237
237
|
exports.MAX_SCRIPT_INPUTS = 16;
|
|
238
|
-
/** Parse and validate scriptInputsJson:
|
|
238
|
+
/** Parse and validate scriptInputsJson: 0..MAX_SCRIPT_INPUTS distinct script UTxOs, each with its own redeemer. */
|
|
239
239
|
function parseScriptInputs(json) {
|
|
240
240
|
if (!json)
|
|
241
|
-
return {
|
|
241
|
+
return { parsed: [] };
|
|
242
242
|
const jsonResult = (0, validators_1.validateJsonWithLimits)(json, 'scriptInputsJson');
|
|
243
243
|
if (!jsonResult.valid)
|
|
244
244
|
return { error: jsonResult.error };
|
|
245
|
-
if (!Array.isArray(jsonResult.parsed)
|
|
246
|
-
return { error: 'scriptInputsJson must be a
|
|
245
|
+
if (!Array.isArray(jsonResult.parsed)) {
|
|
246
|
+
return { error: 'scriptInputsJson must be a JSON array' };
|
|
247
247
|
}
|
|
248
248
|
if (jsonResult.parsed.length > exports.MAX_SCRIPT_INPUTS) {
|
|
249
249
|
return { error: `scriptInputsJson exceeds maximum of ${exports.MAX_SCRIPT_INPUTS} entries` };
|
package/srv/utils/types.d.ts
CHANGED
|
@@ -216,7 +216,8 @@ export interface PoolData {
|
|
|
216
216
|
/** Blocks minted in the current epoch; null when the backend has no such figure (Koios). */
|
|
217
217
|
blocksEpoch: number | null;
|
|
218
218
|
liveStake: string;
|
|
219
|
-
|
|
219
|
+
/** Share of the total live stake; null when the backend has no such figure (Koios). */
|
|
220
|
+
liveSize: number | null;
|
|
220
221
|
/** Fraction of the ideal (saturated) pool size, NOT percent: 0.7542 = 75.42 %. */
|
|
221
222
|
liveSaturation: number;
|
|
222
223
|
/** Null when the source cannot count delegators (Ogmios ledger state). */
|