@odatano/core 2.0.0-rc.26 → 2.0.0-rc.28

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.
@@ -413,11 +413,11 @@ export class UTxOAssets extends Array<UTxOAsset> {
413
413
 
414
414
  export declare const BuildSimpleAdaTransaction: {
415
415
  // positional
416
- (senderAddress: _.Bech32 | null, recipientAddress: _.Bech32 | null, lovelaceAmount: _.Lovelace | null, changeAddress: _.Bech32 | null, outputDatumJson: string | null, assetsJson: string | null, forceInputsJson: string | null, validatorScript: string | null, scriptParamsJson: string | null, lockOnScript: boolean | null, referenceScriptHex: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
416
+ (senderAddress: _.Bech32 | null, recipientAddress: _.Bech32 | null, lovelaceAmount: _.Lovelace | null, changeAddress: _.Bech32 | null, outputDatumJson: string | null, assetsJson: string | null, forceInputsJson: string | null, protectInputsJson: string | null, validatorScript: string | null, scriptParamsJson: string | null, lockOnScript: boolean | null, referenceScriptHex: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
417
417
  // named
418
- ({senderAddress, recipientAddress, lovelaceAmount, changeAddress, outputDatumJson, assetsJson, forceInputsJson, validatorScript, scriptParamsJson, lockOnScript, referenceScriptHex, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, changeAddress?: _.Bech32 | null, outputDatumJson?: string | null, assetsJson?: string | null, forceInputsJson?: string | null, validatorScript?: string | null, scriptParamsJson?: string | null, lockOnScript?: boolean | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
418
+ ({senderAddress, recipientAddress, lovelaceAmount, changeAddress, outputDatumJson, assetsJson, forceInputsJson, protectInputsJson, validatorScript, scriptParamsJson, lockOnScript, referenceScriptHex, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, changeAddress?: _.Bech32 | null, outputDatumJson?: string | null, assetsJson?: string | null, forceInputsJson?: string | null, protectInputsJson?: string | null, validatorScript?: string | null, scriptParamsJson?: string | null, lockOnScript?: boolean | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
419
419
  // metadata (do not use)
420
- __parameters: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, changeAddress?: _.Bech32 | null, outputDatumJson?: string | null, assetsJson?: string | null, forceInputsJson?: string | null, validatorScript?: string | null, scriptParamsJson?: string | null, lockOnScript?: boolean | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
420
+ __parameters: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, changeAddress?: _.Bech32 | null, outputDatumJson?: string | null, assetsJson?: string | null, forceInputsJson?: string | null, protectInputsJson?: string | null, validatorScript?: string | null, scriptParamsJson?: string | null, lockOnScript?: boolean | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
421
421
  kind: 'action'
422
422
  }
423
423
 
@@ -443,11 +443,11 @@ export declare const BuildMultiAssetTransaction: {
443
443
 
444
444
  export declare const BuildMintTransaction: {
445
445
  // positional
446
- (senderAddress: _.Bech32 | null, recipientAddress: _.Bech32 | null, lovelaceAmount: _.Lovelace | null, mintActionsJson: string | null, mintingPolicyScript: string | null, changeAddress: _.Bech32 | null, requiredSignersJson: string | null, scriptParamsJson: string | null, inlineDatumJson: string | null, mintRedeemerJson: string | null, lockOnScript: boolean | null, forceInputsJson: string | null, referenceInputsJson: string | null, extraOutputsJson: string | null, metadataJson: string | null, referenceScriptHex: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
446
+ (senderAddress: _.Bech32 | null, recipientAddress: _.Bech32 | null, lovelaceAmount: _.Lovelace | null, mintActionsJson: string | null, mintingPolicyScript: string | null, changeAddress: _.Bech32 | null, requiredSignersJson: string | null, scriptParamsJson: string | null, inlineDatumJson: string | null, mintRedeemerJson: string | null, lockOnScript: boolean | null, forceInputsJson: string | null, protectInputsJson: string | null, referenceInputsJson: string | null, extraOutputsJson: string | null, metadataJson: string | null, referenceScriptHex: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
447
447
  // named
448
- ({senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, changeAddress, requiredSignersJson, scriptParamsJson, inlineDatumJson, mintRedeemerJson, lockOnScript, forceInputsJson, referenceInputsJson, extraOutputsJson, metadataJson, referenceScriptHex, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, mintRedeemerJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, referenceInputsJson?: string | null, extraOutputsJson?: string | null, metadataJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
448
+ ({senderAddress, recipientAddress, lovelaceAmount, mintActionsJson, mintingPolicyScript, changeAddress, requiredSignersJson, scriptParamsJson, inlineDatumJson, mintRedeemerJson, lockOnScript, forceInputsJson, protectInputsJson, referenceInputsJson, extraOutputsJson, metadataJson, referenceScriptHex, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, mintRedeemerJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, protectInputsJson?: string | null, referenceInputsJson?: string | null, extraOutputsJson?: string | null, metadataJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
449
449
  // metadata (do not use)
450
- __parameters: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, mintRedeemerJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, referenceInputsJson?: string | null, extraOutputsJson?: string | null, metadataJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
450
+ __parameters: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, mintRedeemerJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, protectInputsJson?: string | null, referenceInputsJson?: string | null, extraOutputsJson?: string | null, metadataJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
451
451
  kind: 'action'
452
452
  }
453
453
 
@@ -483,21 +483,21 @@ export declare const SubmitSignedTransaction: {
483
483
 
484
484
  export declare const BuildPlutusSpendTransaction: {
485
485
  // positional
486
- (senderAddress: _.Bech32 | null, recipientAddress: _.Bech32 | null, lovelaceAmount: _.Lovelace | null, validatorScript: string | null, scriptTxHash: string | null, scriptOutputIndex: number | null, redeemerJson: string | null, datumJson: string | null, changeAddress: _.Bech32 | null, requiredSignersJson: string | null, scriptParamsJson: string | null, inlineDatumJson: string | null, lockOnScript: boolean | null, forceInputsJson: string | null, extraOutputsJson: string | null, mintActionsJson: string | null, mintingPolicyScript: string | null, mintRedeemerJson: string | null, referenceInputsJson: string | null, referenceScriptHex: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
486
+ (senderAddress: _.Bech32 | null, recipientAddress: _.Bech32 | null, lovelaceAmount: _.Lovelace | null, validatorScript: string | null, scriptTxHash: string | null, scriptOutputIndex: number | null, redeemerJson: string | null, datumJson: string | null, changeAddress: _.Bech32 | null, requiredSignersJson: string | null, scriptParamsJson: string | null, inlineDatumJson: string | null, lockOnScript: boolean | null, forceInputsJson: string | null, protectInputsJson: string | null, extraOutputsJson: string | null, mintActionsJson: string | null, mintingPolicyScript: string | null, mintRedeemerJson: string | null, referenceInputsJson: string | null, referenceScriptHex: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
487
487
  // named
488
- ({senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, changeAddress, requiredSignersJson, scriptParamsJson, inlineDatumJson, lockOnScript, forceInputsJson, extraOutputsJson, mintActionsJson, mintingPolicyScript, mintRedeemerJson, referenceInputsJson, referenceScriptHex, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, validatorScript?: string | null, scriptTxHash?: string | null, scriptOutputIndex?: number | null, redeemerJson?: string | null, datumJson?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, extraOutputsJson?: string | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, mintRedeemerJson?: string | null, referenceInputsJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
488
+ ({senderAddress, recipientAddress, lovelaceAmount, validatorScript, scriptTxHash, scriptOutputIndex, redeemerJson, datumJson, changeAddress, requiredSignersJson, scriptParamsJson, inlineDatumJson, lockOnScript, forceInputsJson, protectInputsJson, extraOutputsJson, mintActionsJson, mintingPolicyScript, mintRedeemerJson, referenceInputsJson, referenceScriptHex, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, validatorScript?: string | null, scriptTxHash?: string | null, scriptOutputIndex?: number | null, redeemerJson?: string | null, datumJson?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, protectInputsJson?: string | null, extraOutputsJson?: string | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, mintRedeemerJson?: string | null, referenceInputsJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
489
489
  // metadata (do not use)
490
- __parameters: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, validatorScript?: string | null, scriptTxHash?: string | null, scriptOutputIndex?: number | null, redeemerJson?: string | null, datumJson?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, extraOutputsJson?: string | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, mintRedeemerJson?: string | null, referenceInputsJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
490
+ __parameters: {senderAddress?: _.Bech32 | null, recipientAddress?: _.Bech32 | null, lovelaceAmount?: _.Lovelace | null, validatorScript?: string | null, scriptTxHash?: string | null, scriptOutputIndex?: number | null, redeemerJson?: string | null, datumJson?: string | null, changeAddress?: _.Bech32 | null, requiredSignersJson?: string | null, scriptParamsJson?: string | null, inlineDatumJson?: string | null, lockOnScript?: boolean | null, forceInputsJson?: string | null, protectInputsJson?: string | null, extraOutputsJson?: string | null, mintActionsJson?: string | null, mintingPolicyScript?: string | null, mintRedeemerJson?: string | null, referenceInputsJson?: string | null, referenceScriptHex?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
491
491
  kind: 'action'
492
492
  }
493
493
 
494
494
  export declare const BuildPlutusTransaction: {
495
495
  // positional
496
- (senderAddress: _.Bech32 | null, changeAddress: _.Bech32 | null, scriptInputsJson: string | null, outputsJson: string | null, referenceInputsJson: string | null, forceInputsJson: string | null, requiredSignersJson: string | null, mintActionsJson: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
496
+ (senderAddress: _.Bech32 | null, changeAddress: _.Bech32 | null, scriptInputsJson: string | null, outputsJson: string | null, referenceInputsJson: string | null, forceInputsJson: string | null, protectInputsJson: string | null, withdrawalsJson: string | null, certificatesJson: string | null, requiredSignersJson: string | null, mintActionsJson: string | null, validityStartMs: string | null, validityEndMs: string | null): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
497
497
  // named
498
- ({senderAddress, changeAddress, scriptInputsJson, outputsJson, referenceInputsJson, forceInputsJson, requiredSignersJson, mintActionsJson, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, changeAddress?: _.Bech32 | null, scriptInputsJson?: string | null, outputsJson?: string | null, referenceInputsJson?: string | null, forceInputsJson?: string | null, requiredSignersJson?: string | null, mintActionsJson?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
498
+ ({senderAddress, changeAddress, scriptInputsJson, outputsJson, referenceInputsJson, forceInputsJson, protectInputsJson, withdrawalsJson, certificatesJson, requiredSignersJson, mintActionsJson, validityStartMs, validityEndMs}: {senderAddress?: _.Bech32 | null, changeAddress?: _.Bech32 | null, scriptInputsJson?: string | null, outputsJson?: string | null, referenceInputsJson?: string | null, forceInputsJson?: string | null, protectInputsJson?: string | null, withdrawalsJson?: string | null, certificatesJson?: string | null, requiredSignersJson?: string | null, mintActionsJson?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}): globalThis.Promise<TransactionBuild | null> | TransactionBuild | null
499
499
  // metadata (do not use)
500
- __parameters: {senderAddress?: _.Bech32 | null, changeAddress?: _.Bech32 | null, scriptInputsJson?: string | null, outputsJson?: string | null, referenceInputsJson?: string | null, forceInputsJson?: string | null, requiredSignersJson?: string | null, mintActionsJson?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
500
+ __parameters: {senderAddress?: _.Bech32 | null, changeAddress?: _.Bech32 | null, scriptInputsJson?: string | null, outputsJson?: string | null, referenceInputsJson?: string | null, forceInputsJson?: string | null, protectInputsJson?: string | null, withdrawalsJson?: string | null, certificatesJson?: string | null, requiredSignersJson?: string | null, mintActionsJson?: string | null, validityStartMs?: string | null, validityEndMs?: string | null}, __returns: globalThis.Promise<TransactionBuild | null> | TransactionBuild | null, __self: never
501
501
  kind: 'action'
502
502
  }
503
503
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odatano/core",
3
- "version": "2.0.0-rc.26",
3
+ "version": "2.0.0-rc.28",
4
4
  "description": "SAP CAP plugin for Cardano blockchain OData V4 integration",
5
5
  "imports": {
6
6
  "#cds-models/*": "./@cds-models/*/index.js"
@@ -75,7 +75,7 @@ export declare class KoiosBackend implements CardanoBackend, PaginatingBackend,
75
75
  init(): Promise<boolean>;
76
76
  /**
77
77
  * Retry (500 → 1000 → 2000 ms) when Koios transiently returns [] for a valid query.
78
- * Element type is `any` on purpose: only non-emptiness is checked; rows are narrowed at use sites.
78
+ * Only non-emptiness is checked here; rows keep the caller's element type.
79
79
  */
80
80
  private fetchWithRetryOnEmpty;
81
81
  /**
@@ -114,10 +114,9 @@ class KoiosBackend {
114
114
  }
115
115
  /**
116
116
  * Retry (500 → 1000 → 2000 ms) when Koios transiently returns [] for a valid query.
117
- * Element type is `any` on purpose: only non-emptiness is checked; rows are narrowed at use sites.
117
+ * Only non-emptiness is checked here; rows keep the caller's element type.
118
118
  */
119
- async fetchWithRetryOnEmpty(fn, // eslint-disable-line @typescript-eslint/no-explicit-any
120
- label) {
119
+ async fetchWithRetryOnEmpty(fn, label) {
121
120
  const maxRetries = 3;
122
121
  const baseDelayMs = 500;
123
122
  const result = await fn();
@@ -445,8 +444,8 @@ class KoiosBackend {
445
444
  _mapKoiosPool(poolData, fallbackId) {
446
445
  return {
447
446
  poolId: poolData.pool_id_bech32 || poolData.pool_id_hex || fallbackId,
448
- vrfKeyHash: poolData.vrf_key_hash,
449
- blocksMinted: poolData.block_count,
447
+ vrfKeyHash: poolData.vrf_key_hash || '',
448
+ blocksMinted: poolData.block_count || 0,
450
449
  // Koios pool_info has no blocks-in-current-epoch figure. null = not available;
451
450
  // a 0 would be indistinguishable from a real zero downstream.
452
451
  blocksEpoch: null,
@@ -461,7 +460,7 @@ class KoiosBackend {
461
460
  pledge: poolData.pledge || '0',
462
461
  margin: poolData.margin || 0,
463
462
  fixedCost: poolData.fixed_cost || '0',
464
- rewardAccount: poolData.reward_addr,
463
+ rewardAccount: poolData.reward_addr || '',
465
464
  };
466
465
  }
467
466
  /**
@@ -911,6 +910,9 @@ class KoiosBackend {
911
910
  const info = await this.fetchWithRetryOnEmpty(() => this.api.post('/block_info', { _block_hashes: [afterHash] }), `getNextBlocks/height(${afterHash})`);
912
911
  if (!info.length)
913
912
  throw new errors_1.NotFoundError('Block', this.name);
913
+ if (info[0].block_height == null) {
914
+ throw new errors_1.ProviderUnavailableError(`Block ${afterHash} has no height on Koios and cannot anchor pagination`, this.name);
915
+ }
914
916
  anchorHeight = info[0].block_height;
915
917
  }
916
918
  const rows = await this.fetchWithRetryOnEmpty(() => this.api.get(`/blocks?block_height=gt.${anchorHeight}&order=block_height.asc&limit=${count}`), `getNextBlocks(${afterHash})`);
@@ -361,7 +361,7 @@ export declare class CardanoIndexer {
361
361
  buildId?: string | null;
362
362
  }): Promise<TransactionSubmission>;
363
363
  /** Update a submission's status (two-phase submit: pending → submitted or failed). */
364
- updateSubmissionStatus(tx: CapTransaction, submissionId: string, status: string, errorMessage?: string): Promise<void>;
364
+ updateSubmissionStatus(tx: CapTransaction, submissionId: string, status: TransactionSubmission['status'], errorMessage?: string): Promise<void>;
365
365
  /** Persist a new signing request and link it to the build's sender address. */
366
366
  persistSigningRequest(tx: CapTransaction, params: {
367
367
  buildId: string;
@@ -37,6 +37,11 @@ export declare class CardanoTransactionBuilder {
37
37
  * UTxO (one ledger lookup each), plus the sender's UTxOs, forced and reference inputs.
38
38
  */
39
39
  buildPlutusTransaction(req: TxBuildPlutusRequest, protocolParameters: LedgerProtocolParameter): Promise<TxBuildResult>;
40
+ /**
41
+ * The ledger rejects a withdrawal from an unregistered reward account (also a zero one), so the
42
+ * build fails here with the account named. A provider failure is passed on as it is.
43
+ */
44
+ private _assertRewardAccountsRegistered;
40
45
  /**
41
46
  * Resolve the script UTxO of a Plutus spend from the node's ledger, otherwise from its producing
42
47
  * transaction. Spending an already-consumed script UTxO is the most common replay mistake —
@@ -186,9 +186,16 @@ class CardanoTransactionBuilder {
186
186
  const allUtxos = mergeUtxosUnique(senderUtxos, scriptUtxos);
187
187
  const forcedUtxos = await this._resolveForceInputs(req.forceInputs ?? [], allUtxos);
188
188
  // Reference-script UTxOs always from the ledger: a known sender UTxO may carry only the script hash
189
- const refScriptUtxos = await this._resolveInputRefs(req.scriptInputs.flatMap(s => (s.referenceScript ? [s.referenceScript] : [])), [], 'referenceScript');
189
+ const refScriptUtxos = await this._resolveInputRefs([
190
+ ...req.scriptInputs.flatMap(s => (s.referenceScript ? [s.referenceScript] : [])),
191
+ ...(req.withdrawals ?? []).flatMap(w => (w.referenceScript ? [w.referenceScript] : [])),
192
+ ...(req.certificates ?? []).flatMap(c => (c.referenceScript ? [c.referenceScript] : [])),
193
+ ], [], 'referenceScript');
190
194
  const callerRefUtxos = await this._resolveReferenceInputs(req.referenceInputs ?? [], allUtxos);
191
195
  const referenceInputUtxos = mergeUtxosUnique(callerRefUtxos, refScriptUtxos);
196
+ // A credential this transaction registers is withdrawable in the same transaction
197
+ const registeredHere = new Set((req.certificates ?? []).filter(c => c.type === 'registerStake').map(c => c.stakeAddress.toLowerCase()));
198
+ await this._assertRewardAccountsRegistered(req.withdrawals ?? [], registeredHere);
192
199
  const txContext = {
193
200
  utxos: mergeUtxosUnique(allUtxos, forcedUtxos),
194
201
  protocolParameters,
@@ -200,6 +207,28 @@ class CardanoTransactionBuilder {
200
207
  logger.debug(`Prepared multi-script build context: ${senderUtxos.length} sender + ${scriptUtxos.length} script + ${forcedUtxos.length} forced UTxOs, ${referenceInputUtxos.length} reference inputs`);
201
208
  return builder.buildUnsignedPlutusTransaction(req, txContext);
202
209
  }
210
+ /**
211
+ * The ledger rejects a withdrawal from an unregistered reward account (also a zero one), so the
212
+ * build fails here with the account named. A provider failure is passed on as it is.
213
+ */
214
+ async _assertRewardAccountsRegistered(withdrawals, registeredHere = new Set()) {
215
+ for (const [i, w] of withdrawals.entries()) {
216
+ if (registeredHere.has(w.rewardAddress.toLowerCase()))
217
+ continue;
218
+ let active;
219
+ try {
220
+ active = (await this.client.getAccount(w.rewardAddress)).active;
221
+ }
222
+ catch (err) {
223
+ if (!(err instanceof errors_1.NotFoundError))
224
+ throw err;
225
+ active = false;
226
+ }
227
+ if (!active) {
228
+ throw new errors_1.TransactionValidationError(`withdrawals[${i}] reward account ${w.rewardAddress} is not registered on chain; register the stake credential first`);
229
+ }
230
+ }
231
+ }
203
232
  /**
204
233
  * Resolve the script UTxO of a Plutus spend from the node's ledger, otherwise from its producing
205
234
  * transaction. Spending an already-consumed script UTxO is the most common replay mistake —
@@ -16,7 +16,6 @@ const logger = cds_1.default.log('SubmissionFinalizer');
16
16
  // Lazy require avoids the srv/server.ts <-> this-module import cycle; the app-context
17
17
  // getters are only needed at runtime.
18
18
  function server() {
19
- // eslint-disable-next-line @typescript-eslint/no-var-requires
20
19
  return require('../../server');
21
20
  }
22
21
  /**
@@ -96,6 +96,17 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
96
96
  * refs absent from utxos are ignored (existence is validated upstream).
97
97
  */
98
98
  private _partitionForcedInputs;
99
+ /**
100
+ * Staking script of a withdrawal or certificate: inline (swapped for a reference input that already
101
+ * carries the same hash), by reference, or none (key witness).
102
+ */
103
+ private _resolveStakingScript;
104
+ /**
105
+ * Forced inputs of other key addresses: the owner's payment key hash must be a required signer,
106
+ * and every unit they bring must be spent by the outputs, so none of it lands in the sender's change.
107
+ * Script addresses are refused; those UTxOs are script inputs.
108
+ */
109
+ private _checkForeignForcedInputs;
99
110
  /** Keys (`txhash#index`) of the reference inputs of a build, from the resolved UTxOs and the request refs. */
100
111
  private _referencedKeys;
101
112
  /** Map resolved CIP-31 reference input UTxOs to Buildooor LedgerUTxO; empty when none. */
@@ -192,7 +192,7 @@ class BuildooorTxBuilder {
192
192
  const refScript = this._parseReferenceScript(req.referenceScript);
193
193
  const outputs = [this._buildTxOut(recipientAddress, outputValue, req.outputDatum, refScript)];
194
194
  // Partition: forced UTxOs become fixed inputs; rest is the coin-selection pool
195
- const { forced, rest } = this._partitionForcedInputs(ctx.utxos, req.forceInputs, this._referencedKeys(ctx, req.referenceInputs));
195
+ const { forced, rest } = this._partitionForcedInputs(ctx.utxos, req.forceInputs, this._referencedKeys(ctx, req.referenceInputs), req.protectInputs);
196
196
  const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
197
197
  const candidateInputs = rest.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
198
198
  // Coin selection on candidates only; forced inputs are prepended unconditionally
@@ -232,7 +232,7 @@ class BuildooorTxBuilder {
232
232
  }
233
233
  // Partition forced vs candidate UTxOs. Forced inputs are already committed;
234
234
  // collateral and coin selection operate on the remainder only.
235
- const { forced, rest } = this._partitionForcedInputs(ctx.utxos, req.forceInputs, this._referencedKeys(ctx, req.referenceInputs));
235
+ const { forced, rest } = this._partitionForcedInputs(ctx.utxos, req.forceInputs, this._referencedKeys(ctx, req.referenceInputs), req.protectInputs);
236
236
  const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
237
237
  // Collateral + funding separation (from candidates only — forced inputs cannot double as collateral)
238
238
  const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest);
@@ -325,7 +325,7 @@ class BuildooorTxBuilder {
325
325
  const changeAddress = cardano_ledger_ts_1.Address.fromString(req.changeAddress ?? req.senderAddress);
326
326
  // Partition forced inputs (excluding any ref that matches the script UTxO — silently ignored)
327
327
  const forceInputsFiltered = (req.forceInputs ?? []).filter(r => !(r.txHash === scriptUtxoRef.txHash && r.outputIndex === scriptUtxoRef.outputIndex));
328
- const { forced, rest } = this._partitionForcedInputs(senderUtxos, forceInputsFiltered, this._referencedKeys(ctx, req.referenceInputs));
328
+ const { forced, rest } = this._partitionForcedInputs(senderUtxos, forceInputsFiltered, this._referencedKeys(ctx, req.referenceInputs), req.protectInputs);
329
329
  const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
330
330
  // Collateral + funding separation (from candidates only — forced inputs cannot double as collateral)
331
331
  const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest);
@@ -467,15 +467,52 @@ class BuildooorTxBuilder {
467
467
  }
468
468
  return { si, utxo, refLedgerUtxo, scriptHash: refLedgerUtxo.resolved.refScript.hash.toString() };
469
469
  });
470
+ // Withdrawals: the staking script inline, by reference, or the one a reference input carries
471
+ const withdrawalEntries = (req.withdrawals ?? []).map((w, i) => ({
472
+ w, rewardAccount: cardano_ledger_ts_1.StakeAddress.fromString(w.rewardAddress),
473
+ ...this._resolveStakingScript(w, `withdrawals[${i}]`, referencedByHash, refUtxoByKey),
474
+ }));
475
+ // Certificates: the credential from the stake address; a script runs under the Certifying purpose
476
+ const stakeDeposit = BigInt(String(this.txBuilder.protocolParamters.stakeAddressDeposit ?? cardano_ledger_ts_1.defaultProtocolParameters.stakeAddressDeposit));
477
+ const certEntries = (req.certificates ?? []).map((c, i) => {
478
+ const at = `certificates[${i}]`;
479
+ const stake = cardano_ledger_ts_1.StakeAddress.fromString(c.stakeAddress);
480
+ const credentialHash = stake.credentials.toString().toLowerCase();
481
+ const witness = this._resolveStakingScript(c, at, referencedByHash, refUtxoByKey);
482
+ const scripted = Boolean(witness.script || witness.refLedgerUtxo);
483
+ const witnessHash = (witness.script?.hash ?? witness.refLedgerUtxo?.resolved.refScript?.hash)?.toString().toLowerCase();
484
+ if (stake.type === 'script') {
485
+ if (scripted && witnessHash !== credentialHash) {
486
+ throw new errors_1.TransactionValidationError(`${at} staking script hash ${witnessHash} is not the credential of ${c.stakeAddress} (${credentialHash})`);
487
+ }
488
+ if (!scripted && c.type === 'deregisterStake') {
489
+ throw new errors_1.TransactionValidationError(`${at} deregisters the script credential ${c.stakeAddress}; its staking script and redeemer are needed`);
490
+ }
491
+ }
492
+ else if (scripted) {
493
+ throw new errors_1.TransactionValidationError(`${at} ${c.stakeAddress} is a key credential; it takes no staking script`);
494
+ }
495
+ const stakeCredential = stake.type === 'script' ? cardano_ledger_ts_1.Credential.script(stake.credentials) : cardano_ledger_ts_1.Credential.keyHash(stake.credentials);
496
+ const deposit = c.deposit ? BigInt(c.deposit) : stakeDeposit;
497
+ // Without a script the witness-free legacy registration; the deposit forms need the witness
498
+ const cert = c.type === 'registerStake'
499
+ ? (scripted ? new cardano_ledger_ts_1.CertRegistrationDeposit({ stakeCredential, deposit }) : new cardano_ledger_ts_1.CertStakeRegistration({ stakeCredential }))
500
+ : (c.deposit ? new cardano_ledger_ts_1.CertUnRegistrationDeposit({ stakeCredential, deposit }) : new cardano_ledger_ts_1.CertStakeDeRegistration({ stakeCredential }));
501
+ return { c, cert, deposit, ...witness };
502
+ });
470
503
  const senderUtxos = ctx.utxos.filter(u => !scriptKeys.has(keyOf(u)));
471
504
  const changeAddress = cardano_ledger_ts_1.Address.fromString(req.changeAddress ?? req.senderAddress);
472
- 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] : []))));
505
+ const scriptKeyClash = (req.protectInputs ?? []).map(keyOf).find(k => scriptKeys.has(k));
506
+ if (scriptKeyClash)
507
+ throw new errors_1.TransactionValidationError(`protectInputs ${scriptKeyClash} is also a script input`);
508
+ 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);
509
+ this._checkForeignForcedInputs(forced, req);
473
510
  const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
474
511
  const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest);
475
512
  coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
476
513
  const allFundingInputs = fundingUtxos.map(utxo => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(utxo) }));
477
- // Funding covers only what the outputs need beyond the script inputs, forced inputs and mints
478
- // (keepRelevant adds its own lovelace margin for fee and change).
514
+ // Funding covers only what the outputs need beyond the script inputs, forced inputs, mints and
515
+ // withdrawals (keepRelevant adds its own lovelace margin for fee and change).
479
516
  const need = new Map();
480
517
  const add = (unit, qty) => need.set(unit, (need.get(unit) ?? 0n) + qty);
481
518
  for (const o of req.outputs) {
@@ -489,6 +526,11 @@ class BuildooorTxBuilder {
489
526
  }
490
527
  for (const m of req.mintActions ?? [])
491
528
  add(m.assetUnit, -BigInt(m.quantity));
529
+ for (const { w } of withdrawalEntries)
530
+ add('lovelace', -BigInt(w.lovelace));
531
+ // a registration locks the deposit, a deregistration refunds it
532
+ for (const { c, deposit } of certEntries)
533
+ add('lovelace', c.type === 'registerStake' ? deposit : -deposit);
492
534
  let requiredFundingValue = cardano_ledger_ts_1.Value.lovelaces(0n);
493
535
  for (const [unit, qty] of need) {
494
536
  if (qty <= 0n)
@@ -518,8 +560,23 @@ class BuildooorTxBuilder {
518
560
  const mints = req.mintActions && req.mintActions.length > 0
519
561
  ? this._buildMintEntries(req.mintActions, this._parsePlutusV3Script(req.mintActions[0].mintingPolicyScript, 'mintActions[0].mintingPolicyScript'), undefined, resolveCtx)
520
562
  : undefined;
563
+ // Withdrawals: Buildooor sorts them by reward account and runs each script under the Reward purpose
564
+ const withdrawals = withdrawalEntries.map(({ w, script, refLedgerUtxo, rewardAccount }) => {
565
+ const withdrawal = { rewardAccount, amount: BigInt(w.lovelace) };
566
+ if (!script && !refLedgerUtxo)
567
+ return { withdrawal };
568
+ const redeemer = w.redeemerCbor ? (0, plutus_data_1.dataFromCbor)(w.redeemerCbor) : (0, tx_build_helper_1.jsonToPlutusData)((0, plutus_placeholders_1.resolveIndexPlaceholders)(w.redeemer ?? null, resolveCtx));
569
+ return { withdrawal, script: script ? { inline: script, redeemer } : { ref: refLedgerUtxo, redeemer } };
570
+ });
571
+ // Certificates in the given order; a scripted one carries its redeemer under the Cert purpose
572
+ const certificates = certEntries.map(({ c, cert, script, refLedgerUtxo }) => {
573
+ if (!script && !refLedgerUtxo)
574
+ return { cert };
575
+ const redeemer = c.redeemerCbor ? (0, plutus_data_1.dataFromCbor)(c.redeemerCbor) : (0, tx_build_helper_1.jsonToPlutusData)((0, plutus_placeholders_1.resolveIndexPlaceholders)(c.redeemer ?? null, resolveCtx));
576
+ return { cert, script: script ? { inline: script, redeemer } : { ref: refLedgerUtxo, redeemer } };
577
+ });
521
578
  // Reference inputs: the caller's, minus the reference-script UTxOs Buildooor adds itself
522
- const refScriptKeys = new Set(scriptEntries.filter(e => e.refLedgerUtxo).map(e => keyOf({ txHash: e.refLedgerUtxo.utxoRef.id.toString(), outputIndex: e.refLedgerUtxo.utxoRef.index })));
579
+ const refScriptKeys = new Set([...scriptEntries, ...withdrawalEntries, ...certEntries].filter(e => e.refLedgerUtxo).map(e => keyOf({ txHash: e.refLedgerUtxo.utxoRef.id.toString(), outputIndex: e.refLedgerUtxo.utxoRef.index })));
523
580
  const readonlyRefInputs = this._mapReferenceInputs((ctx.referenceInputUtxos ?? []).filter(u => !refScriptKeys.has(keyOf(u)) && (req.referenceInputs ?? []).some(r => keyOf(r) === keyOf(u))));
524
581
  const { invalidBefore, invalidAfter } = this._resolveValiditySlots(req, 'script');
525
582
  const buildParams = {
@@ -528,7 +585,9 @@ class BuildooorTxBuilder {
528
585
  collaterals: collateralUtxos, requiredSigners: req.requiredSigners,
529
586
  invalidBefore, invalidAfter,
530
587
  ...(collateralReturn && { collateralReturn }),
531
- ...(readonlyRefInputs.length > 0 && { readonlyRefInputs })
588
+ ...(readonlyRefInputs.length > 0 && { readonlyRefInputs }),
589
+ ...(withdrawals.length > 0 && { withdrawals }),
590
+ ...(certificates.length > 0 && { certificates })
532
591
  };
533
592
  const tx = await this._buildScriptTx(buildParams, ctx.evaluateTransaction);
534
593
  const details = this._extractTxDetails(tx);
@@ -826,28 +885,103 @@ class BuildooorTxBuilder {
826
885
  * Split UTxOs into forced inputs (must be consumed) and remaining candidates; forceInputs
827
886
  * refs absent from utxos are ignored (existence is validated upstream).
828
887
  */
829
- _partitionForcedInputs(utxos, forceInputs, referenced = new Set()) {
888
+ _partitionForcedInputs(utxos, forceInputs, referenced = new Set(), protectInputs) {
830
889
  const hasRefScript = (u) => Boolean(u.scriptRef || u.scriptRefCbor);
831
- if ((!forceInputs || forceInputs.length === 0) && referenced.size === 0 && !utxos.some(hasRefScript))
832
- return { forced: [], rest: utxos };
833
890
  const key = (r) => `${r.txHash.toLowerCase()}#${r.outputIndex}`;
891
+ const protectedKeys = new Set((protectInputs ?? []).map(key));
892
+ if ((!forceInputs || forceInputs.length === 0) && referenced.size === 0 && protectedKeys.size === 0 && !utxos.some(hasRefScript)) {
893
+ return { forced: [], rest: utxos };
894
+ }
834
895
  const forcedKeys = new Set((forceInputs ?? []).map(key));
835
896
  // a UTxO cannot be spent and referenced in one transaction
836
897
  const clash = [...forcedKeys].find(k => referenced.has(k));
837
898
  if (clash)
838
899
  throw new errors_1.TransactionValidationError(`forceInputs ${clash} is also a reference input — a UTxO cannot be spent and referenced in one transaction`);
900
+ const protectedClash = [...forcedKeys].find(k => protectedKeys.has(k));
901
+ if (protectedClash)
902
+ throw new errors_1.TransactionValidationError(`forceInputs ${protectedClash} is also in protectInputs`);
839
903
  const forced = [];
840
904
  const rest = [];
841
905
  for (const u of utxos) {
842
906
  if (forcedKeys.has(key(u)))
843
907
  forced.push(u);
844
- // reference inputs and UTxOs carrying a reference script stay out of coin selection and
845
- // collateral; a deployed script is spent only when forced
846
- else if (!referenced.has(key(u)) && !hasRefScript(u))
908
+ // reference inputs, protected UTxOs and UTxOs carrying a reference script stay out of coin
909
+ // selection and collateral; a deployed script is spent only when forced
910
+ else if (!referenced.has(key(u)) && !protectedKeys.has(key(u)) && !hasRefScript(u))
847
911
  rest.push(u);
848
912
  }
849
913
  return { forced, rest };
850
914
  }
915
+ /**
916
+ * Staking script of a withdrawal or certificate: inline (swapped for a reference input that already
917
+ * carries the same hash), by reference, or none (key witness).
918
+ */
919
+ _resolveStakingScript(w, at, referencedByHash, refUtxoByKey) {
920
+ if (w.stakingScript) {
921
+ const script = this._parsePlutusV3Script(w.stakingScript, `${at}.stakingScript`);
922
+ const referenced = referencedByHash.get(script.hash.toString());
923
+ return referenced ? { refLedgerUtxo: referenced } : { script };
924
+ }
925
+ if (!w.referenceScript)
926
+ return {};
927
+ const refKey = `${w.referenceScript.txHash.toLowerCase()}#${w.referenceScript.outputIndex}`;
928
+ const refUtxo = refUtxoByKey.get(refKey);
929
+ if (!refUtxo)
930
+ throw new errors_1.TransactionValidationError(`${at}.referenceScript ${refKey} not found on-chain or already spent`);
931
+ const refLedgerUtxo = this._mapMultiAssetUtxoToLedgerUtxo(refUtxo);
932
+ if (!refLedgerUtxo.resolved.refScript) {
933
+ throw new errors_1.TransactionValidationError(`${at}.referenceScript ${refKey} carries no reference script, or its bytes are not available ` +
934
+ `from the configured backends (Ogmios or Koios deliver them, Blockfrost only the hash)`);
935
+ }
936
+ return { refLedgerUtxo };
937
+ }
938
+ /**
939
+ * Forced inputs of other key addresses: the owner's payment key hash must be a required signer,
940
+ * and every unit they bring must be spent by the outputs, so none of it lands in the sender's change.
941
+ * Script addresses are refused; those UTxOs are script inputs.
942
+ */
943
+ _checkForeignForcedInputs(forced, req) {
944
+ const sender = req.senderAddress.toLowerCase();
945
+ const foreign = forced.filter(u => u.address.toLowerCase() !== sender);
946
+ if (foreign.length === 0)
947
+ return;
948
+ const signers = new Set((req.requiredSigners ?? []).map(s => s.toLowerCase()));
949
+ const keyOf = (u) => `${u.txHash}#${u.outputIndex}`;
950
+ const byAddress = new Map();
951
+ for (const u of foreign)
952
+ byAddress.set(u.address, [...(byAddress.get(u.address) ?? []), u]);
953
+ for (const [address, utxos] of byAddress) {
954
+ const creds = cardano_ledger_ts_1.Address.fromString(address).paymentCreds;
955
+ const refs = utxos.map(keyOf).join(', ');
956
+ if (creds.type !== cardano_ledger_ts_1.CredentialType.KeyHash) {
957
+ throw new errors_1.TransactionValidationError(`forceInputs ${refs} are at the script address ${address}; spend script UTxOs via scriptInputs`);
958
+ }
959
+ const keyHash = creds.hash.toString().toLowerCase();
960
+ if (!signers.has(keyHash)) {
961
+ throw new errors_1.TransactionValidationError(`forceInputs ${refs} belong to ${address}; its payment key hash ${keyHash} must be in requiredSigners (the owner co-signs)`);
962
+ }
963
+ }
964
+ const brought = new Map();
965
+ for (const u of foreign) {
966
+ for (const a of u.amount) {
967
+ const unit = a.unit.toLowerCase() === 'lovelace' ? 'lovelace' : a.unit;
968
+ brought.set(unit, (brought.get(unit) ?? 0n) + BigInt(a.quantity));
969
+ }
970
+ }
971
+ const spent = new Map();
972
+ for (const o of req.outputs) {
973
+ spent.set('lovelace', (spent.get('lovelace') ?? 0n) + BigInt(o.lovelaceAmount));
974
+ for (const a of o.assets ?? [])
975
+ spent.set(a.unit, (spent.get(a.unit) ?? 0n) + BigInt(a.quantity));
976
+ }
977
+ for (const [unit, qty] of brought) {
978
+ const out = spent.get(unit) ?? 0n;
979
+ if (qty > out) {
980
+ throw new errors_1.TransactionValidationError(`forceInputs of other addresses bring ${qty} ${unit} but the outputs spend only ${out}; ` +
981
+ `the difference would go to the sender's change, return it to its owner in outputs`);
982
+ }
983
+ }
984
+ }
851
985
  /** Keys (`txhash#index`) of the reference inputs of a build, from the resolved UTxOs and the request refs. */
852
986
  _referencedKeys(ctx, ...refs) {
853
987
  const keys = new Set();
@@ -114,6 +114,8 @@ function prepareSimpleAda(raw, network) {
114
114
  const clean = { ...raw };
115
115
  clean.forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
116
116
  delete clean.forceInputsJson;
117
+ clean.protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
118
+ delete clean.protectInputsJson;
117
119
  const outputDatum = parseJsonField(raw, 'outputDatumJson');
118
120
  if (outputDatum !== undefined)
119
121
  clean.outputDatum = outputDatum;
@@ -170,6 +172,7 @@ function prepareMint(raw, network) {
170
172
  const inlineDatum = parseJsonField(raw, 'inlineDatumJson');
171
173
  const mintRedeemer = parseJsonField(raw, 'mintRedeemerJson');
172
174
  const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
175
+ const protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
173
176
  const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
174
177
  const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
175
178
  if (raw.lockOnScript && (!scriptParams || scriptParams.length === 0)) {
@@ -190,6 +193,7 @@ function prepareMint(raw, network) {
190
193
  delete clean.mintRedeemerJson;
191
194
  delete clean.lockOnScript;
192
195
  delete clean.forceInputsJson;
196
+ delete clean.protectInputsJson;
193
197
  delete clean.referenceInputsJson;
194
198
  delete clean.extraOutputsJson;
195
199
  if (parsedMetadata)
@@ -237,6 +241,7 @@ function prepareMint(raw, network) {
237
241
  inlineDatum,
238
242
  mintRedeemer,
239
243
  forceInputs,
244
+ protectInputs,
240
245
  referenceInputs,
241
246
  extraOutputs,
242
247
  };
@@ -255,6 +260,7 @@ function preparePlutusSpend(raw, network) {
255
260
  fail('lockOnScript requires scriptParamsJson to derive script address');
256
261
  }
257
262
  const forceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.forceInputsJson, 'forceInputsJson'));
263
+ const protectInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.protectInputsJson, 'protectInputsJson'));
258
264
  const referenceInputs = takeParsed((0, tx_request_parsers_1.parseUtxoRefArray)(raw.referenceInputsJson, 'referenceInputsJson'));
259
265
  const extraOutputs = takeParsed((0, tx_request_parsers_1.parseExtraOutputs)(raw.extraOutputsJson));
260
266
  // Optional combined spend+mint.
@@ -317,6 +323,7 @@ function preparePlutusSpend(raw, network) {
317
323
  requiredSigners,
318
324
  inlineDatum,
319
325
  forceInputs,
326
+ protectInputs,
320
327
  referenceInputs,
321
328
  extraOutputs,
322
329
  mintActions,
@@ -329,6 +336,7 @@ function preparePlutusSpend(raw, network) {
329
336
  delete clean.scriptParamsJson;
330
337
  delete clean.inlineDatumJson;
331
338
  delete clean.forceInputsJson;
339
+ delete clean.protectInputsJson;
332
340
  delete clean.referenceInputsJson;
333
341
  delete clean.extraOutputsJson;
334
342
  delete clean.mintActionsJson;
@@ -9,6 +9,17 @@ const validators_1 = require("./utils/validators");
9
9
  const errors_1 = require("./utils/errors");
10
10
  const backend_request_handler_1 = require("./utils/backend-request-handler");
11
11
  const cbor_1 = require("./cbor");
12
+ /** Newest temporal slice per key; child tables keep one row per validFrom. */
13
+ function latestSlices(rows, keyOf) {
14
+ const seen = new Map();
15
+ for (const row of rows) {
16
+ const key = keyOf(row);
17
+ const prev = seen.get(key);
18
+ if (!prev || (row.validFrom ?? '') > (prev.validFrom ?? ''))
19
+ seen.set(key, row);
20
+ }
21
+ return Array.from(seen.values());
22
+ }
12
23
  const { SELECT } = cds_1.default.ql;
13
24
  const logger = cds_1.default.log(`CardanoService`);
14
25
  /** Upper bound of the temporal window; must outlast the slowest index-on-miss of one request. */
@@ -194,14 +205,7 @@ module.exports = (srv) => {
194
205
  if (!existing)
195
206
  await indexer().indexAddress(db, address);
196
207
  const assets = await db.run(SELECT.from(AddressAssets).where({ address_address: address }));
197
- // Keep the latest temporal slice per unit
198
- const seen = new Map();
199
- for (const asset of assets) {
200
- if (!seen.has(asset.unit) || asset.validFrom > seen.get(asset.unit).validFrom) {
201
- seen.set(asset.unit, asset);
202
- }
203
- }
204
- return Array.from(seen.values());
208
+ return latestSlices(assets, (asset) => asset.unit ?? '');
205
209
  });
206
210
  });
207
211
  // GetUTxOsByAddress — indexes the parent address if needed, then queries child UTxOs.
@@ -232,15 +236,7 @@ module.exports = (srv) => {
232
236
  const fresh = await db.run(SELECT.from(AddressUTxOs).where({ address_address: address }));
233
237
  return fresh;
234
238
  }
235
- // Keep the latest temporal slice per hash#index
236
- const seen = new Map();
237
- for (const utxo of existing) {
238
- const key = `${utxo.hash}#${utxo.index}`;
239
- if (!seen.has(key) || utxo.validFrom > seen.get(key).validFrom) {
240
- seen.set(key, utxo);
241
- }
242
- }
243
- return Array.from(seen.values());
239
+ return latestSlices(existing, (utxo) => `${utxo.hash}#${utxo.index}`);
244
240
  });
245
241
  });
246
242
  // GetUTxOsByCredential — always-fresh credential-keyed UTxO query (dApp state reads need current