@meshsdk/transaction 1.9.0-beta.1 → 1.9.0-beta.3

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/dist/index.cjs CHANGED
@@ -1383,6 +1383,48 @@ var MeshTxBuilderCore = class {
1383
1383
  this.meshTxBuilderBody.network = network;
1384
1384
  return this;
1385
1385
  };
1386
+ /**
1387
+ * Add a transaction that is used as input, but not yet reflected on the global blockchain
1388
+ * @param txHex The transaction hex of chained transaction
1389
+ * @returns The MeshTxBuilderCore instance
1390
+ */
1391
+ chainTx(txHex) {
1392
+ this.meshTxBuilderBody.chainedTxs.push(txHex);
1393
+ return this;
1394
+ }
1395
+ /**
1396
+ * Add a transaction input to provide information for offline evaluation
1397
+ * @param input The input to be added
1398
+ * @returns The MeshTxBuilderCore instance
1399
+ */
1400
+ inputForEvaluation(input) {
1401
+ const utxoId = `${input.input.txHash}${input.input.outputIndex}`;
1402
+ const currentUtxo = this.meshTxBuilderBody.inputsForEvaluation[utxoId];
1403
+ if (currentUtxo) {
1404
+ const { address, amount, dataHash, plutusData, scriptRef, scriptHash } = input.output;
1405
+ const {
1406
+ dataHash: currentDataHash,
1407
+ plutusData: currentPlutusData,
1408
+ scriptRef: currentScriptRef,
1409
+ scriptHash: currentScriptHash
1410
+ } = currentUtxo.output;
1411
+ const updatedUtxo = {
1412
+ ...input,
1413
+ output: {
1414
+ address,
1415
+ amount,
1416
+ dataHash: dataHash ?? currentDataHash,
1417
+ plutusData: plutusData ?? currentPlutusData,
1418
+ scriptRef: scriptRef ?? currentScriptRef,
1419
+ scriptHash: scriptHash ?? currentScriptHash
1420
+ }
1421
+ };
1422
+ this.meshTxBuilderBody.inputsForEvaluation[utxoId] = updatedUtxo;
1423
+ } else {
1424
+ this.meshTxBuilderBody.inputsForEvaluation[utxoId] = input;
1425
+ }
1426
+ return this;
1427
+ }
1386
1428
  queueAllLastItem = () => {
1387
1429
  if (this.txOutput) {
1388
1430
  this.meshTxBuilderBody.outputs.push(this.txOutput);
@@ -1428,6 +1470,7 @@ var MeshTxBuilderCore = class {
1428
1470
  }
1429
1471
  }
1430
1472
  this.meshTxBuilderBody.inputs.push(this.txInQueueItem);
1473
+ this.inputForEvaluation((0, import_common.txInToUtxo)(this.txInQueueItem.txIn));
1431
1474
  this.txInQueueItem = void 0;
1432
1475
  };
1433
1476
  queueMint = () => {
@@ -1648,6 +1691,7 @@ var MeshTxBuilderCore = class {
1648
1691
  scriptSize: input.output.scriptRef.length / 2
1649
1692
  });
1650
1693
  }
1694
+ this.inputForEvaluation(input);
1651
1695
  });
1652
1696
  };
1653
1697
  removeDuplicateInputs = () => {
@@ -1809,7 +1853,11 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1809
1853
  this._protocolParams
1810
1854
  );
1811
1855
  if (this.evaluator) {
1812
- const txEvaluation = await this.evaluator.evaluateTx(txHex).catch((error) => {
1856
+ const txEvaluation = await this.evaluator.evaluateTx(
1857
+ txHex,
1858
+ Object.values(this.meshTxBuilderBody.inputsForEvaluation),
1859
+ this.meshTxBuilderBody.chainedTxs
1860
+ ).catch((error) => {
1813
1861
  throw Error(`Tx evaluation failed: ${error}
1814
1862
  For txHex: ${txHex}`);
1815
1863
  });
package/dist/index.d.cts CHANGED
@@ -484,6 +484,18 @@ declare class MeshTxBuilderCore {
484
484
  * @returns The MeshTxBuilder instance
485
485
  */
486
486
  setNetwork: (network: Network | number[][]) => this;
487
+ /**
488
+ * Add a transaction that is used as input, but not yet reflected on the global blockchain
489
+ * @param txHex The transaction hex of chained transaction
490
+ * @returns The MeshTxBuilderCore instance
491
+ */
492
+ chainTx(txHex: string): this;
493
+ /**
494
+ * Add a transaction input to provide information for offline evaluation
495
+ * @param input The input to be added
496
+ * @returns The MeshTxBuilderCore instance
497
+ */
498
+ inputForEvaluation(input: UTxO): this;
487
499
  protected queueAllLastItem: () => void;
488
500
  private queueInput;
489
501
  private queueMint;
package/dist/index.d.ts CHANGED
@@ -484,6 +484,18 @@ declare class MeshTxBuilderCore {
484
484
  * @returns The MeshTxBuilder instance
485
485
  */
486
486
  setNetwork: (network: Network | number[][]) => this;
487
+ /**
488
+ * Add a transaction that is used as input, but not yet reflected on the global blockchain
489
+ * @param txHex The transaction hex of chained transaction
490
+ * @returns The MeshTxBuilderCore instance
491
+ */
492
+ chainTx(txHex: string): this;
493
+ /**
494
+ * Add a transaction input to provide information for offline evaluation
495
+ * @param input The input to be added
496
+ * @returns The MeshTxBuilderCore instance
497
+ */
498
+ inputForEvaluation(input: UTxO): this;
487
499
  protected queueAllLastItem: () => void;
488
500
  private queueInput;
489
501
  private queueMint;
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  DEFAULT_REDEEMER_BUDGET,
9
9
  DREP_DEPOSIT,
10
10
  emptyTxBuilderBody,
11
+ txInToUtxo,
11
12
  UtxoSelection
12
13
  } from "@meshsdk/common";
13
14
 
@@ -1348,6 +1349,48 @@ var MeshTxBuilderCore = class {
1348
1349
  this.meshTxBuilderBody.network = network;
1349
1350
  return this;
1350
1351
  };
1352
+ /**
1353
+ * Add a transaction that is used as input, but not yet reflected on the global blockchain
1354
+ * @param txHex The transaction hex of chained transaction
1355
+ * @returns The MeshTxBuilderCore instance
1356
+ */
1357
+ chainTx(txHex) {
1358
+ this.meshTxBuilderBody.chainedTxs.push(txHex);
1359
+ return this;
1360
+ }
1361
+ /**
1362
+ * Add a transaction input to provide information for offline evaluation
1363
+ * @param input The input to be added
1364
+ * @returns The MeshTxBuilderCore instance
1365
+ */
1366
+ inputForEvaluation(input) {
1367
+ const utxoId = `${input.input.txHash}${input.input.outputIndex}`;
1368
+ const currentUtxo = this.meshTxBuilderBody.inputsForEvaluation[utxoId];
1369
+ if (currentUtxo) {
1370
+ const { address, amount, dataHash, plutusData, scriptRef, scriptHash } = input.output;
1371
+ const {
1372
+ dataHash: currentDataHash,
1373
+ plutusData: currentPlutusData,
1374
+ scriptRef: currentScriptRef,
1375
+ scriptHash: currentScriptHash
1376
+ } = currentUtxo.output;
1377
+ const updatedUtxo = {
1378
+ ...input,
1379
+ output: {
1380
+ address,
1381
+ amount,
1382
+ dataHash: dataHash ?? currentDataHash,
1383
+ plutusData: plutusData ?? currentPlutusData,
1384
+ scriptRef: scriptRef ?? currentScriptRef,
1385
+ scriptHash: scriptHash ?? currentScriptHash
1386
+ }
1387
+ };
1388
+ this.meshTxBuilderBody.inputsForEvaluation[utxoId] = updatedUtxo;
1389
+ } else {
1390
+ this.meshTxBuilderBody.inputsForEvaluation[utxoId] = input;
1391
+ }
1392
+ return this;
1393
+ }
1351
1394
  queueAllLastItem = () => {
1352
1395
  if (this.txOutput) {
1353
1396
  this.meshTxBuilderBody.outputs.push(this.txOutput);
@@ -1393,6 +1436,7 @@ var MeshTxBuilderCore = class {
1393
1436
  }
1394
1437
  }
1395
1438
  this.meshTxBuilderBody.inputs.push(this.txInQueueItem);
1439
+ this.inputForEvaluation(txInToUtxo(this.txInQueueItem.txIn));
1396
1440
  this.txInQueueItem = void 0;
1397
1441
  };
1398
1442
  queueMint = () => {
@@ -1613,6 +1657,7 @@ var MeshTxBuilderCore = class {
1613
1657
  scriptSize: input.output.scriptRef.length / 2
1614
1658
  });
1615
1659
  }
1660
+ this.inputForEvaluation(input);
1616
1661
  });
1617
1662
  };
1618
1663
  removeDuplicateInputs = () => {
@@ -1774,7 +1819,11 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1774
1819
  this._protocolParams
1775
1820
  );
1776
1821
  if (this.evaluator) {
1777
- const txEvaluation = await this.evaluator.evaluateTx(txHex).catch((error) => {
1822
+ const txEvaluation = await this.evaluator.evaluateTx(
1823
+ txHex,
1824
+ Object.values(this.meshTxBuilderBody.inputsForEvaluation),
1825
+ this.meshTxBuilderBody.chainedTxs
1826
+ ).catch((error) => {
1778
1827
  throw Error(`Tx evaluation failed: ${error}
1779
1828
  For txHex: ${txHex}`);
1780
1829
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/transaction",
3
- "version": "1.9.0-beta.1",
3
+ "version": "1.9.0-beta.3",
4
4
  "description": "Transactions - https://meshjs.dev/apis/transaction",
5
5
  "main": "./dist/index.cjs",
6
6
  "browser": "./dist/index.js",
@@ -35,8 +35,8 @@
35
35
  "typescript": "^5.3.3"
36
36
  },
37
37
  "dependencies": {
38
- "@meshsdk/common": "1.9.0-beta.1",
39
- "@meshsdk/core-cst": "1.9.0-beta.1",
38
+ "@meshsdk/common": "1.9.0-beta.3",
39
+ "@meshsdk/core-cst": "1.9.0-beta.3",
40
40
  "json-bigint": "^1.0.0"
41
41
  },
42
42
  "prettier": "@meshsdk/configs/prettier",