@odatano/core 2.0.0-rc.33 → 2.0.0-rc.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@cds-models/index.d.ts +1 -0
- package/db/types.cds +4 -0
- package/package.json +1 -1
- package/srv/blockchain/transaction-building/buildooor-tx.d.ts +1 -0
- package/srv/blockchain/transaction-building/buildooor-tx.js +30 -21
- package/srv/cbor/parse.d.ts +2 -0
- package/srv/cbor/parse.js +1 -0
- package/srv/utils/agent-grants.js +1 -1
package/@cds-models/index.d.ts
CHANGED
|
@@ -359,6 +359,7 @@ export declare function _ParsedTransactionAspect<TBase extends new (...args: any
|
|
|
359
359
|
currentTreasuryValue?: Lovelace | null
|
|
360
360
|
requiredSigners?: Array<Blake2b224>
|
|
361
361
|
scriptDataHash?: Blake2b256 | null
|
|
362
|
+
isValid?: boolean | null
|
|
362
363
|
witnesses?: ParsedWitnesses | null
|
|
363
364
|
} & InstanceType<TBase>
|
|
364
365
|
readonly kind: 'type';
|
package/db/types.cds
CHANGED
|
@@ -399,6 +399,10 @@ type ParsedTransaction {
|
|
|
399
399
|
@description: 'Blake2b-256 hash over datum/redeemer/costmodels section; null if no Plutus data is present'
|
|
400
400
|
scriptDataHash : Blake2b256;
|
|
401
401
|
|
|
402
|
+
@title : 'Validity Flag'
|
|
403
|
+
@description: 'false when the transaction is flagged as failing its scripts; on chain it then spends only the collateral and creates no outputs'
|
|
404
|
+
isValid : Boolean;
|
|
405
|
+
|
|
402
406
|
@title : 'Witness Counts'
|
|
403
407
|
@description: 'Shape summary of the witness set (no secret material exposed)'
|
|
404
408
|
witnesses : ParsedWitnesses;
|
package/package.json
CHANGED
|
@@ -162,6 +162,7 @@ export declare class BuildooorTxBuilder implements CardanoTxBuilder {
|
|
|
162
162
|
* (Buildooor sets no collateralReturn for ADA-only collateral). Throws without an ADA-only UTxO.
|
|
163
163
|
* When the rest cannot pay `requiredLovelace` plus fee and change, the collateral UTxO is
|
|
164
164
|
* funding too. The ledger allows one UTxO as input and as collateral.
|
|
165
|
+
* When no UTxO in `utxos` covers the floor, a forced input of the sender that does is the collateral.
|
|
165
166
|
*/
|
|
166
167
|
private _setupCollateral;
|
|
167
168
|
/** Build a Ledger Value from lovelace + optional multi-asset array */
|
|
@@ -250,7 +250,7 @@ class BuildooorTxBuilder {
|
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
// Partition forced vs candidate UTxOs. Forced inputs are already committed;
|
|
253
|
-
//
|
|
253
|
+
// coin selection operates on the remainder only.
|
|
254
254
|
const { forced, rest } = this._partitionForcedInputs(ctx.utxos, req.forceInputs, this._referencedKeys(ctx, req.referenceInputs), req.protectInputs);
|
|
255
255
|
const forcedInputs = forced.map(u => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(u) }));
|
|
256
256
|
// Funding must cover the lovelace plus, for extra outputs, their lovelace and any asset
|
|
@@ -260,9 +260,9 @@ class BuildooorTxBuilder {
|
|
|
260
260
|
const { lovelace, assets } = this._extraOutputsFundingAfterMint(req.mintActions, req.extraOutputs);
|
|
261
261
|
requiredFundingValue = cardano_ledger_ts_1.Value.add(requiredFundingValue, this._buildLedgerValue(lovelace, assets));
|
|
262
262
|
}
|
|
263
|
-
// Collateral + funding separation
|
|
264
|
-
const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest, requiredFundingValue.lovelaces);
|
|
265
|
-
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
|
|
263
|
+
// Collateral + funding separation from the candidates; a forced input is collateral only as a fallback
|
|
264
|
+
const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest, requiredFundingValue.lovelaces, forced, req.senderAddress);
|
|
265
|
+
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos, forced);
|
|
266
266
|
const fundingLedgerUtxos = fundingUtxos.map(utxo => this._mapMultiAssetUtxoToLedgerUtxo(utxo));
|
|
267
267
|
const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
|
|
268
268
|
const selectedFunding = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
@@ -356,11 +356,11 @@ class BuildooorTxBuilder {
|
|
|
356
356
|
requiredFundingValue = cardano_ledger_ts_1.Value.add(requiredFundingValue, this._buildLedgerValue(BigInt(extra.lovelaceAmount), extra.assets));
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
|
-
// Collateral + funding separation
|
|
359
|
+
// Collateral + funding separation from the candidates; a forced input is collateral only as a fallback.
|
|
360
360
|
// The script UTxO pays its part of the outputs, so the collateral check counts only the rest.
|
|
361
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);
|
|
362
|
+
const { collateralUtxos, fundingUtxos, collateralReturn } = this._setupCollateral(rest, fundingGap > 0n ? fundingGap : 0n, forced, req.senderAddress);
|
|
363
|
+
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos, forced);
|
|
364
364
|
const fundingLedgerUtxos = fundingUtxos.map(utxo => this._mapMultiAssetUtxoToLedgerUtxo(utxo));
|
|
365
365
|
const allFundingInputs = fundingLedgerUtxos.map(utxo => ({ utxo }));
|
|
366
366
|
const selectedFundingInputs = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
@@ -590,9 +590,9 @@ class BuildooorTxBuilder {
|
|
|
590
590
|
const runsScript = scriptEntries.length > 0 || mintEntries.length > 0 ||
|
|
591
591
|
[...withdrawalEntries, ...certEntries].some(e => e.script || e.refLedgerUtxo);
|
|
592
592
|
const { collateralUtxos, fundingUtxos, collateralReturn } = runsScript
|
|
593
|
-
? this._setupCollateral(rest, requiredFundingValue.lovelaces)
|
|
593
|
+
? this._setupCollateral(rest, requiredFundingValue.lovelaces, forced, req.senderAddress)
|
|
594
594
|
: { collateralUtxos: [], fundingUtxos: rest, collateralReturn: undefined };
|
|
595
|
-
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos);
|
|
595
|
+
coinSelectionContext = this._collateralPartitionContext(collateralUtxos, fundingUtxos, forced);
|
|
596
596
|
const allFundingInputs = fundingUtxos.map(utxo => ({ utxo: this._mapMultiAssetUtxoToLedgerUtxo(utxo) }));
|
|
597
597
|
const selectedFundingInputs = this.txBuilder.keepRelevant(requiredFundingValue, allFundingInputs);
|
|
598
598
|
// Reference inputs: the caller's, minus the reference-script UTxOs Buildooor adds itself
|
|
@@ -1221,16 +1221,18 @@ class BuildooorTxBuilder {
|
|
|
1221
1221
|
* Context for insufficient-funds rejections after the collateral partition: the builder's
|
|
1222
1222
|
* message counts only the funding pool, so the reservation would otherwise be invisible.
|
|
1223
1223
|
*/
|
|
1224
|
-
_collateralPartitionContext(collateralUtxos, fundingUtxos) {
|
|
1224
|
+
_collateralPartitionContext(collateralUtxos, fundingUtxos, forced = []) {
|
|
1225
1225
|
const fundingLovelace = fundingUtxos.reduce((s, u) => s + (0, tx_build_helper_1.getLovelace)(u), 0n);
|
|
1226
1226
|
if (collateralUtxos.length === 0) {
|
|
1227
1227
|
return `no script runs, so no collateral; ${fundingUtxos.length} UTxO(s) with ${fundingLovelace} lovelace for coin selection`;
|
|
1228
1228
|
}
|
|
1229
1229
|
const collateralLovelace = collateralUtxos.reduce((s, u) => s + u.resolved.value.lovelaces, 0n);
|
|
1230
1230
|
const collateralKeys = new Set(collateralUtxos.map(u => `${u.utxoRef.id.toString()}#${u.utxoRef.index}`));
|
|
1231
|
-
const
|
|
1231
|
+
const isCollateral = (u) => collateralKeys.has(`${u.txHash}#${u.outputIndex}`);
|
|
1232
|
+
const alsoFunding = fundingUtxos.some(isCollateral);
|
|
1233
|
+
const alsoForced = forced.some(isCollateral);
|
|
1232
1234
|
return `${collateralUtxos.length} UTxO(s) with ${collateralLovelace} lovelace reserved as collateral` +
|
|
1233
|
-
`${alsoFunding ? ' and also offered as funding' : ''}; ` +
|
|
1235
|
+
`${alsoFunding ? ' and also offered as funding' : alsoForced ? ' and also spent as a forced input' : ''}; ` +
|
|
1234
1236
|
`${fundingUtxos.length} UTxO(s) with ${fundingLovelace} lovelace for coin selection`;
|
|
1235
1237
|
}
|
|
1236
1238
|
/**
|
|
@@ -1239,19 +1241,25 @@ class BuildooorTxBuilder {
|
|
|
1239
1241
|
* (Buildooor sets no collateralReturn for ADA-only collateral). Throws without an ADA-only UTxO.
|
|
1240
1242
|
* When the rest cannot pay `requiredLovelace` plus fee and change, the collateral UTxO is
|
|
1241
1243
|
* funding too. The ledger allows one UTxO as input and as collateral.
|
|
1244
|
+
* When no UTxO in `utxos` covers the floor, a forced input of the sender that does is the collateral.
|
|
1242
1245
|
*/
|
|
1243
|
-
_setupCollateral(utxos, requiredLovelace) {
|
|
1246
|
+
_setupCollateral(utxos, requiredLovelace, forced = [], senderAddress = '') {
|
|
1247
|
+
const byLovelace = (a, b) => {
|
|
1248
|
+
const diff = (0, tx_build_helper_1.getLovelace)(a) - (0, tx_build_helper_1.getLovelace)(b);
|
|
1249
|
+
return diff < 0n ? -1 : diff > 0n ? 1 : 0;
|
|
1250
|
+
};
|
|
1251
|
+
const coversFloor = (u) => (0, tx_build_helper_1.getLovelace)(u) >= const_1.COLLATERAL_LOVELACE;
|
|
1244
1252
|
// ADA-only and without a reference script (a deployed script is not collateral); SetCollateral uses the same rule
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1253
|
+
const sorted = utxos.filter(tx_build_helper_1.isCollateralCandidate).sort(byLovelace);
|
|
1254
|
+
const sender = senderAddress.toLowerCase();
|
|
1255
|
+
const forcedChoice = sorted.some(coversFloor)
|
|
1256
|
+
? undefined
|
|
1257
|
+
: forced.filter(u => u.address.toLowerCase() === sender && (0, tx_build_helper_1.isCollateralCandidate)(u) && coversFloor(u)).sort(byLovelace)[0];
|
|
1258
|
+
if (sorted.length === 0 && !forcedChoice) {
|
|
1247
1259
|
throw new errors_1.TransactionValidationError('No ADA-only UTxO available for collateral. Plutus scripts require ADA-only collateral; create one with SetCollateral.');
|
|
1248
1260
|
}
|
|
1249
|
-
const sorted = [...adaOnly].sort((a, b) => {
|
|
1250
|
-
const diff = (0, tx_build_helper_1.getLovelace)(a) - (0, tx_build_helper_1.getLovelace)(b);
|
|
1251
|
-
return diff < 0n ? -1 : diff > 0n ? 1 : 0;
|
|
1252
|
-
});
|
|
1253
1261
|
// smallest sufficient; if none reaches the floor, the largest available is the best bet
|
|
1254
|
-
const chosen = sorted.find(
|
|
1262
|
+
const chosen = forcedChoice ?? sorted.find(coversFloor) ?? sorted[sorted.length - 1];
|
|
1255
1263
|
if ((0, tx_build_helper_1.getLovelace)(chosen) < const_1.COLLATERAL_LOVELACE) {
|
|
1256
1264
|
logger.warn(`Largest ADA-only UTxO (${(0, tx_build_helper_1.getLovelace)(chosen)} lovelace) is below the ${const_1.COLLATERAL_LOVELACE} lovelace ` +
|
|
1257
1265
|
`collateral floor — the node will reject the transaction if collateralPercentage × fee exceeds it`);
|
|
@@ -1259,7 +1267,8 @@ class BuildooorTxBuilder {
|
|
|
1259
1267
|
const collateralUtxos = [this._mapOdatanoUtxoToLedgerUtxo(chosen)];
|
|
1260
1268
|
const rest = utxos.filter(u => !(u.txHash === chosen.txHash && u.outputIndex === chosen.outputIndex));
|
|
1261
1269
|
const restLovelace = rest.reduce((sum, u) => sum + (0, tx_build_helper_1.getLovelace)(u), 0n);
|
|
1262
|
-
|
|
1270
|
+
// a forced input is already spent, so it is never offered to coin selection as well
|
|
1271
|
+
const fundingUtxos = forcedChoice || restLovelace >= requiredLovelace + const_1.FEE_BUFFER_LOVELACE + BigInt(const_1.MIN_CHANGE_LOVELACE)
|
|
1263
1272
|
? rest
|
|
1264
1273
|
: [...rest, chosen];
|
|
1265
1274
|
// Cap the at-risk amount at the floor: return the excess to the owner.
|
package/srv/cbor/parse.d.ts
CHANGED
|
@@ -76,6 +76,8 @@ export interface ParsedTransaction {
|
|
|
76
76
|
/** 28-byte Ed25519 key hashes listed in the tx body's required_signers field. */
|
|
77
77
|
requiredSigners: string[];
|
|
78
78
|
scriptDataHash: string | null;
|
|
79
|
+
/** `false` when the transaction is flagged as failing its scripts. On chain it then spends only the collateral and creates no outputs. */
|
|
80
|
+
isValid: boolean;
|
|
79
81
|
witnesses: ParsedWitnesses;
|
|
80
82
|
}
|
|
81
83
|
/**
|
package/srv/cbor/parse.js
CHANGED
|
@@ -51,6 +51,7 @@ function parseTransaction(cborHex) {
|
|
|
51
51
|
currentTreasuryValue: raw.currentTreasuryValue,
|
|
52
52
|
requiredSigners: (body.requiredSigners ?? []).map((s) => s.toString()),
|
|
53
53
|
scriptDataHash: body.scriptDataHash ? body.scriptDataHash.toString() : null,
|
|
54
|
+
isValid: tx.isScriptValid,
|
|
54
55
|
witnesses: countWitnesses(tx.witnesses),
|
|
55
56
|
};
|
|
56
57
|
}
|
|
@@ -103,7 +103,7 @@ exports.AGENT_ALWAYS_ALLOWED_EVENTS = new Set([
|
|
|
103
103
|
// CardanoODataService: chain reads through the backends
|
|
104
104
|
'GetNetworkInformation', 'GetBlockByHash', 'GetEpochByNumber', 'GetPoolById', 'GetDrepById',
|
|
105
105
|
'GetAssetInfo', 'GetAssetHistory', 'GetAccountByStakeAddress', 'GetTransactionByHash',
|
|
106
|
-
'GetMetadataByTxHash', 'GetAddressByBech32', 'GetUTxOsByAddress', 'GetUTxOsByCredential',
|
|
106
|
+
'GetTransactionConfirmations', 'GetMetadataByTxHash', 'GetAddressByBech32', 'GetUTxOsByAddress', 'GetUTxOsByCredential',
|
|
107
107
|
'GetAssetsByAddress', 'GetLatestTransactionsByAddress', 'GetLatestBlock', 'GetLatestEpoch',
|
|
108
108
|
'GetLedgerProtocolParameters', 'ParseTransactionCbor',
|
|
109
109
|
// CardanoTransactionService: compute-only
|