@meshsdk/transaction 1.6.7 → 1.6.9

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
@@ -366,10 +366,11 @@ var MeshTxBuilderCore = class {
366
366
  * Set the reference input where it would also be spent in the transaction
367
367
  * @param txHash The transaction hash of the reference UTxO
368
368
  * @param txIndex The transaction index of the reference UTxO
369
- * @param spendingScriptHash The script hash of the spending script
369
+ * @param scriptSize The script size in bytes of the spending script (can be obtained by script hex length / 2)
370
+ * @param scriptHash The script hash of the spending script
370
371
  * @returns The MeshTxBuilder instance
371
372
  */
372
- spendingTxInReference = (txHash, txIndex, spendingScriptHash) => {
373
+ spendingTxInReference = (txHash, txIndex, scriptSize, scriptHash) => {
373
374
  if (!this.txInQueueItem) throw Error("Undefined input");
374
375
  if (this.txInQueueItem.type === "PubKey")
375
376
  throw Error(
@@ -383,10 +384,9 @@ var MeshTxBuilderCore = class {
383
384
  type: "Inline",
384
385
  txHash,
385
386
  txIndex,
386
- scriptHash: spendingScriptHash,
387
+ scriptHash,
387
388
  version: this.plutusSpendingScriptVersion || "V2",
388
- scriptSize: "0"
389
- // TODO
389
+ scriptSize
390
390
  };
391
391
  return this;
392
392
  };
@@ -498,9 +498,11 @@ var MeshTxBuilderCore = class {
498
498
  * Use reference script for minting
499
499
  * @param txHash The transaction hash of the UTxO
500
500
  * @param txIndex The transaction index of the UTxO
501
+ * @param scriptSize The script size in bytes of the script (can be obtained by script hex length / 2)
502
+ * @param scriptHash The script hash of the script
501
503
  * @returns The MeshTxBuilder instance
502
504
  */
503
- mintTxInReference = (txHash, txIndex) => {
505
+ mintTxInReference = (txHash, txIndex, scriptSize, scriptHash) => {
504
506
  if (!this.mintItem) throw Error("Undefined mint");
505
507
  if (!this.mintItem.type) throw Error("Mint information missing");
506
508
  if (this.mintItem.type == "Native") {
@@ -515,10 +517,8 @@ var MeshTxBuilderCore = class {
515
517
  txHash,
516
518
  txIndex,
517
519
  version: this.plutusMintingScriptVersion,
518
- scriptSize: "0",
519
- // TODO
520
- scriptHash: ""
521
- // TODO
520
+ scriptSize,
521
+ scriptHash
522
522
  };
523
523
  return this;
524
524
  };
@@ -676,11 +676,11 @@ var MeshTxBuilderCore = class {
676
676
  * Add a withdrawal reference to the MeshTxBuilder instance
677
677
  * @param txHash The transaction hash of reference UTxO
678
678
  * @param txIndex The transaction index of reference UTxO
679
- * @param withdrawalScriptHash The script hash of the withdrawal script
680
- * @param scriptSize The script size of the withdrawal script
679
+ * @param scriptSize The script size in bytes of the withdrawal script (can be obtained by script hex length / 2)
680
+ * @param scriptHash The script hash of the withdrawal script
681
681
  * @returns The MeshTxBuilder instance
682
682
  */
683
- withdrawalTxInReference = (txHash, txIndex, withdrawalScriptHash, scriptSize) => {
683
+ withdrawalTxInReference = (txHash, txIndex, scriptSize, scriptHash) => {
684
684
  if (!this.withdrawalItem)
685
685
  throw Error("withdrawalTxInReference: Undefined withdrawal");
686
686
  if (this.withdrawalItem.type === "PubKeyWithdrawal")
@@ -691,9 +691,9 @@ var MeshTxBuilderCore = class {
691
691
  type: "Inline",
692
692
  txHash,
693
693
  txIndex,
694
- scriptHash: withdrawalScriptHash,
694
+ scriptHash,
695
695
  version: this.plutusWithdrawalScriptVersion || "V2",
696
- scriptSize: scriptSize || "0"
696
+ scriptSize
697
697
  };
698
698
  return this;
699
699
  };
@@ -839,11 +839,11 @@ var MeshTxBuilderCore = class {
839
839
  * Adds a script witness to the certificate
840
840
  * @param txHash The transaction hash of the reference UTxO
841
841
  * @param txIndex The transaction index of the reference UTxO
842
- * @param spendingScriptHash The script hash of the spending script
843
- * @param version Optional - The plutus version of the script, null version implies Native Script
844
- * @param scriptSize The size of the plutus script referenced
842
+ * @param scriptSize The size of the plutus script in bytes referenced (can be obtained by script hex length / 2)
843
+ * @param scriptHash The script hash of the spending script
844
+ * @param version The plutus version of the script, null version implies Native Script
845
845
  */
846
- certificateTxInReference = (txHash, txIndex, spendingScriptHash, version, scriptSize = "0") => {
846
+ certificateTxInReference = (txHash, txIndex, scriptSize, scriptHash, version) => {
847
847
  const currentCert = this.meshTxBuilderBody.certificates.pop();
848
848
  if (!currentCert) {
849
849
  throw Error(
@@ -858,7 +858,7 @@ var MeshTxBuilderCore = class {
858
858
  type: "Inline",
859
859
  txHash,
860
860
  txIndex,
861
- simpleScriptHash: spendingScriptHash
861
+ simpleScriptHash: scriptHash
862
862
  }
863
863
  });
864
864
  } else {
@@ -869,7 +869,7 @@ var MeshTxBuilderCore = class {
869
869
  type: "Inline",
870
870
  txHash,
871
871
  txIndex,
872
- scriptHash: spendingScriptHash,
872
+ scriptHash,
873
873
  scriptSize
874
874
  },
875
875
  redeemer: currentCert.type === "ScriptCertificate" ? currentCert.redeemer : void 0
@@ -974,6 +974,15 @@ var MeshTxBuilderCore = class {
974
974
  this._protocolParams = updatedParams;
975
975
  return this;
976
976
  };
977
+ /**
978
+ * Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
979
+ * @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
980
+ * @returns The MeshTxBuilder instance
981
+ */
982
+ setNetwork = (network) => {
983
+ this.meshTxBuilderBody.network = network;
984
+ return this;
985
+ };
977
986
  queueAllLastItem = () => {
978
987
  if (this.txOutput) {
979
988
  this.meshTxBuilderBody.outputs.push(this.txOutput);
@@ -1326,7 +1335,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1326
1335
  );
1327
1336
  if (this.evaluator) {
1328
1337
  const txEvaluation = await this.evaluator.evaluateTx(txHex).catch((error) => {
1329
- throw Error(`Tx evaluation failed: ${error}`);
1338
+ throw Error(`Tx evaluation failed: ${error}
1339
+ For txHex: ${txHex}`);
1330
1340
  });
1331
1341
  this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
1332
1342
  txHex = this.serializer.serializeTxBody(
@@ -1438,6 +1448,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1438
1448
  `Couldn't find script reference utxo for ${scriptSource.txHash}#${scriptSource.txIndex}`
1439
1449
  );
1440
1450
  scriptSource.scriptHash = scriptRefUtxo?.output.scriptHash;
1451
+ scriptSource.scriptSize = (scriptRefUtxo?.output.scriptRef.length / 2).toString();
1441
1452
  }
1442
1453
  };
1443
1454
  isInputComplete = (txIn) => {
@@ -1457,8 +1468,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1457
1468
  };
1458
1469
  isRefScriptInfoComplete = (scriptTxIn) => {
1459
1470
  const { scriptSource } = scriptTxIn.scriptTxIn;
1460
- if (scriptSource?.type === "Inline" && !scriptSource?.scriptHash)
1461
- return false;
1471
+ if (scriptSource?.type === "Inline") {
1472
+ if (scriptSource?.scriptHash || scriptSource?.scriptSize) return false;
1473
+ }
1462
1474
  return true;
1463
1475
  };
1464
1476
  };
@@ -1691,6 +1703,7 @@ var Transaction = class {
1691
1703
  ).spendingTxInReference(
1692
1704
  script.input.txHash,
1693
1705
  script.input.outputIndex,
1706
+ (script.output.scriptRef.length / 2).toString(),
1694
1707
  script.output.scriptHash
1695
1708
  ).txInRedeemerValue(red.data, "Mesh", red.budget);
1696
1709
  }
@@ -1748,12 +1761,16 @@ var Transaction = class {
1748
1761
  this.isCollateralNeeded = true;
1749
1762
  this.mintPlutusScript(script).mint(assetQuantity, policyId, assetNameHex).mintTxInReference(
1750
1763
  forgeScript.input.txHash,
1751
- forgeScript.input.outputIndex
1764
+ forgeScript.input.outputIndex,
1765
+ (forgeScript.output.scriptRef.length / 2).toString(),
1766
+ forgeScript.output.scriptHash
1752
1767
  ).mintRedeemerValue(redeemer.data, "Mesh", redeemer.budget);
1753
1768
  if (mint.cip68ScriptAddress) {
1754
1769
  this.mintPlutusScript(script).mint(assetQuantity, policyId, referenceAssetNameHex).mintTxInReference(
1755
1770
  forgeScript.input.txHash,
1756
- forgeScript.input.outputIndex
1771
+ forgeScript.input.outputIndex,
1772
+ (forgeScript.output.scriptRef.length / 2).toString(),
1773
+ forgeScript.output.scriptHash
1757
1774
  ).mintRedeemerValue(redeemer.data, "Mesh", redeemer.budget);
1758
1775
  break;
1759
1776
  }
@@ -1790,8 +1807,9 @@ var Transaction = class {
1790
1807
  this.setMetadata(Number(mint.label), {
1791
1808
  [policyId]: { [mint.assetName]: mint.metadata }
1792
1809
  });
1810
+ } else {
1811
+ this.setMetadata(Number(mint.label), mint.metadata);
1793
1812
  }
1794
- this.setMetadata(Number(mint.label), mint.metadata);
1795
1813
  }
1796
1814
  return this;
1797
1815
  }
@@ -1837,6 +1855,15 @@ var Transaction = class {
1837
1855
  });
1838
1856
  return this;
1839
1857
  }
1858
+ /**
1859
+ * Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
1860
+ * @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
1861
+ * @returns The Transaction object.
1862
+ */
1863
+ setNetwork = (network) => {
1864
+ this.txBuilder.setNetwork(network);
1865
+ return this;
1866
+ };
1840
1867
  /**
1841
1868
  * Sets the required signers for the transaction.
1842
1869
  *
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
1
+ import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Network, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
2
2
 
3
3
  declare class MeshTxBuilderCore {
4
4
  txEvaluationMultiplier: number;
@@ -103,10 +103,11 @@ declare class MeshTxBuilderCore {
103
103
  * Set the reference input where it would also be spent in the transaction
104
104
  * @param txHash The transaction hash of the reference UTxO
105
105
  * @param txIndex The transaction index of the reference UTxO
106
- * @param spendingScriptHash The script hash of the spending script
106
+ * @param scriptSize The script size in bytes of the spending script (can be obtained by script hex length / 2)
107
+ * @param scriptHash The script hash of the spending script
107
108
  * @returns The MeshTxBuilder instance
108
109
  */
109
- spendingTxInReference: (txHash: string, txIndex: number, spendingScriptHash?: string) => this;
110
+ spendingTxInReference: (txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string) => this;
110
111
  /**
111
112
  * [Alias of txInInlineDatumPresent] Set the instruction that the reference input has inline datum
112
113
  * @returns The MeshTxBuilder instance
@@ -164,9 +165,11 @@ declare class MeshTxBuilderCore {
164
165
  * Use reference script for minting
165
166
  * @param txHash The transaction hash of the UTxO
166
167
  * @param txIndex The transaction index of the UTxO
168
+ * @param scriptSize The script size in bytes of the script (can be obtained by script hex length / 2)
169
+ * @param scriptHash The script hash of the script
167
170
  * @returns The MeshTxBuilder instance
168
171
  */
169
- mintTxInReference: (txHash: string, txIndex: number) => this;
172
+ mintTxInReference: (txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string) => this;
170
173
  /**
171
174
  * Set the redeemer for minting
172
175
  * @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
@@ -236,11 +239,11 @@ declare class MeshTxBuilderCore {
236
239
  * Add a withdrawal reference to the MeshTxBuilder instance
237
240
  * @param txHash The transaction hash of reference UTxO
238
241
  * @param txIndex The transaction index of reference UTxO
239
- * @param withdrawalScriptHash The script hash of the withdrawal script
240
- * @param scriptSize The script size of the withdrawal script
242
+ * @param scriptSize The script size in bytes of the withdrawal script (can be obtained by script hex length / 2)
243
+ * @param scriptHash The script hash of the withdrawal script
241
244
  * @returns The MeshTxBuilder instance
242
245
  */
243
- withdrawalTxInReference: (txHash: string, txIndex: number, withdrawalScriptHash?: string, scriptSize?: string) => this;
246
+ withdrawalTxInReference: (txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string) => this;
244
247
  /**
245
248
  * Set the transaction withdrawal redeemer value in the MeshTxBuilder instance
246
249
  * @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
@@ -295,11 +298,11 @@ declare class MeshTxBuilderCore {
295
298
  * Adds a script witness to the certificate
296
299
  * @param txHash The transaction hash of the reference UTxO
297
300
  * @param txIndex The transaction index of the reference UTxO
298
- * @param spendingScriptHash The script hash of the spending script
299
- * @param version Optional - The plutus version of the script, null version implies Native Script
300
- * @param scriptSize The size of the plutus script referenced
301
+ * @param scriptSize The size of the plutus script in bytes referenced (can be obtained by script hex length / 2)
302
+ * @param scriptHash The script hash of the spending script
303
+ * @param version The plutus version of the script, null version implies Native Script
301
304
  */
302
- certificateTxInReference: (txHash: string, txIndex: number, spendingScriptHash: string, version?: LanguageVersion, scriptSize?: string) => this;
305
+ certificateTxInReference: (txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string, version?: LanguageVersion) => this;
303
306
  certificateRedeemerValue: (redeemer: BuilderData["content"], type?: BuilderData["type"], exUnits?: {
304
307
  mem: number;
305
308
  steps: number;
@@ -348,6 +351,12 @@ declare class MeshTxBuilderCore {
348
351
  * @returns The MeshTxBuilder instance
349
352
  */
350
353
  protocolParams: (params: Partial<Protocol>) => this;
354
+ /**
355
+ * Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
356
+ * @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
357
+ * @returns The MeshTxBuilder instance
358
+ */
359
+ setNetwork: (network: Network) => this;
351
360
  protected queueAllLastItem: () => void;
352
361
  private queueInput;
353
362
  private queueMint;
@@ -541,6 +550,12 @@ declare class Transaction {
541
550
  * @returns {Transaction} The Transaction object.
542
551
  */
543
552
  setCollateral(collateral: UTxO[]): Transaction;
553
+ /**
554
+ * Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
555
+ * @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
556
+ * @returns The Transaction object.
557
+ */
558
+ setNetwork: (network: Network) => this;
544
559
  /**
545
560
  * Sets the required signers for the transaction.
546
561
  *
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
1
+ import { Protocol, MintItem, TxIn, Withdrawal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, Asset, BuilderData, LanguageVersion, PoolParams, UTxO, UtxoSelectionStrategy, Network, Redeemer, Action, IFetcher, ISubmitter, IEvaluator, IMeshTxSerializer, NativeScript, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
2
2
 
3
3
  declare class MeshTxBuilderCore {
4
4
  txEvaluationMultiplier: number;
@@ -103,10 +103,11 @@ declare class MeshTxBuilderCore {
103
103
  * Set the reference input where it would also be spent in the transaction
104
104
  * @param txHash The transaction hash of the reference UTxO
105
105
  * @param txIndex The transaction index of the reference UTxO
106
- * @param spendingScriptHash The script hash of the spending script
106
+ * @param scriptSize The script size in bytes of the spending script (can be obtained by script hex length / 2)
107
+ * @param scriptHash The script hash of the spending script
107
108
  * @returns The MeshTxBuilder instance
108
109
  */
109
- spendingTxInReference: (txHash: string, txIndex: number, spendingScriptHash?: string) => this;
110
+ spendingTxInReference: (txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string) => this;
110
111
  /**
111
112
  * [Alias of txInInlineDatumPresent] Set the instruction that the reference input has inline datum
112
113
  * @returns The MeshTxBuilder instance
@@ -164,9 +165,11 @@ declare class MeshTxBuilderCore {
164
165
  * Use reference script for minting
165
166
  * @param txHash The transaction hash of the UTxO
166
167
  * @param txIndex The transaction index of the UTxO
168
+ * @param scriptSize The script size in bytes of the script (can be obtained by script hex length / 2)
169
+ * @param scriptHash The script hash of the script
167
170
  * @returns The MeshTxBuilder instance
168
171
  */
169
- mintTxInReference: (txHash: string, txIndex: number) => this;
172
+ mintTxInReference: (txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string) => this;
170
173
  /**
171
174
  * Set the redeemer for minting
172
175
  * @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
@@ -236,11 +239,11 @@ declare class MeshTxBuilderCore {
236
239
  * Add a withdrawal reference to the MeshTxBuilder instance
237
240
  * @param txHash The transaction hash of reference UTxO
238
241
  * @param txIndex The transaction index of reference UTxO
239
- * @param withdrawalScriptHash The script hash of the withdrawal script
240
- * @param scriptSize The script size of the withdrawal script
242
+ * @param scriptSize The script size in bytes of the withdrawal script (can be obtained by script hex length / 2)
243
+ * @param scriptHash The script hash of the withdrawal script
241
244
  * @returns The MeshTxBuilder instance
242
245
  */
243
- withdrawalTxInReference: (txHash: string, txIndex: number, withdrawalScriptHash?: string, scriptSize?: string) => this;
246
+ withdrawalTxInReference: (txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string) => this;
244
247
  /**
245
248
  * Set the transaction withdrawal redeemer value in the MeshTxBuilder instance
246
249
  * @param redeemer The redeemer in Mesh Data type, JSON in raw constructor like format, or CBOR hex string
@@ -295,11 +298,11 @@ declare class MeshTxBuilderCore {
295
298
  * Adds a script witness to the certificate
296
299
  * @param txHash The transaction hash of the reference UTxO
297
300
  * @param txIndex The transaction index of the reference UTxO
298
- * @param spendingScriptHash The script hash of the spending script
299
- * @param version Optional - The plutus version of the script, null version implies Native Script
300
- * @param scriptSize The size of the plutus script referenced
301
+ * @param scriptSize The size of the plutus script in bytes referenced (can be obtained by script hex length / 2)
302
+ * @param scriptHash The script hash of the spending script
303
+ * @param version The plutus version of the script, null version implies Native Script
301
304
  */
302
- certificateTxInReference: (txHash: string, txIndex: number, spendingScriptHash: string, version?: LanguageVersion, scriptSize?: string) => this;
305
+ certificateTxInReference: (txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string, version?: LanguageVersion) => this;
303
306
  certificateRedeemerValue: (redeemer: BuilderData["content"], type?: BuilderData["type"], exUnits?: {
304
307
  mem: number;
305
308
  steps: number;
@@ -348,6 +351,12 @@ declare class MeshTxBuilderCore {
348
351
  * @returns The MeshTxBuilder instance
349
352
  */
350
353
  protocolParams: (params: Partial<Protocol>) => this;
354
+ /**
355
+ * Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
356
+ * @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
357
+ * @returns The MeshTxBuilder instance
358
+ */
359
+ setNetwork: (network: Network) => this;
351
360
  protected queueAllLastItem: () => void;
352
361
  private queueInput;
353
362
  private queueMint;
@@ -541,6 +550,12 @@ declare class Transaction {
541
550
  * @returns {Transaction} The Transaction object.
542
551
  */
543
552
  setCollateral(collateral: UTxO[]): Transaction;
553
+ /**
554
+ * Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
555
+ * @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
556
+ * @returns The Transaction object.
557
+ */
558
+ setNetwork: (network: Network) => this;
544
559
  /**
545
560
  * Sets the required signers for the transaction.
546
561
  *
package/dist/index.js CHANGED
@@ -332,10 +332,11 @@ var MeshTxBuilderCore = class {
332
332
  * Set the reference input where it would also be spent in the transaction
333
333
  * @param txHash The transaction hash of the reference UTxO
334
334
  * @param txIndex The transaction index of the reference UTxO
335
- * @param spendingScriptHash The script hash of the spending script
335
+ * @param scriptSize The script size in bytes of the spending script (can be obtained by script hex length / 2)
336
+ * @param scriptHash The script hash of the spending script
336
337
  * @returns The MeshTxBuilder instance
337
338
  */
338
- spendingTxInReference = (txHash, txIndex, spendingScriptHash) => {
339
+ spendingTxInReference = (txHash, txIndex, scriptSize, scriptHash) => {
339
340
  if (!this.txInQueueItem) throw Error("Undefined input");
340
341
  if (this.txInQueueItem.type === "PubKey")
341
342
  throw Error(
@@ -349,10 +350,9 @@ var MeshTxBuilderCore = class {
349
350
  type: "Inline",
350
351
  txHash,
351
352
  txIndex,
352
- scriptHash: spendingScriptHash,
353
+ scriptHash,
353
354
  version: this.plutusSpendingScriptVersion || "V2",
354
- scriptSize: "0"
355
- // TODO
355
+ scriptSize
356
356
  };
357
357
  return this;
358
358
  };
@@ -464,9 +464,11 @@ var MeshTxBuilderCore = class {
464
464
  * Use reference script for minting
465
465
  * @param txHash The transaction hash of the UTxO
466
466
  * @param txIndex The transaction index of the UTxO
467
+ * @param scriptSize The script size in bytes of the script (can be obtained by script hex length / 2)
468
+ * @param scriptHash The script hash of the script
467
469
  * @returns The MeshTxBuilder instance
468
470
  */
469
- mintTxInReference = (txHash, txIndex) => {
471
+ mintTxInReference = (txHash, txIndex, scriptSize, scriptHash) => {
470
472
  if (!this.mintItem) throw Error("Undefined mint");
471
473
  if (!this.mintItem.type) throw Error("Mint information missing");
472
474
  if (this.mintItem.type == "Native") {
@@ -481,10 +483,8 @@ var MeshTxBuilderCore = class {
481
483
  txHash,
482
484
  txIndex,
483
485
  version: this.plutusMintingScriptVersion,
484
- scriptSize: "0",
485
- // TODO
486
- scriptHash: ""
487
- // TODO
486
+ scriptSize,
487
+ scriptHash
488
488
  };
489
489
  return this;
490
490
  };
@@ -642,11 +642,11 @@ var MeshTxBuilderCore = class {
642
642
  * Add a withdrawal reference to the MeshTxBuilder instance
643
643
  * @param txHash The transaction hash of reference UTxO
644
644
  * @param txIndex The transaction index of reference UTxO
645
- * @param withdrawalScriptHash The script hash of the withdrawal script
646
- * @param scriptSize The script size of the withdrawal script
645
+ * @param scriptSize The script size in bytes of the withdrawal script (can be obtained by script hex length / 2)
646
+ * @param scriptHash The script hash of the withdrawal script
647
647
  * @returns The MeshTxBuilder instance
648
648
  */
649
- withdrawalTxInReference = (txHash, txIndex, withdrawalScriptHash, scriptSize) => {
649
+ withdrawalTxInReference = (txHash, txIndex, scriptSize, scriptHash) => {
650
650
  if (!this.withdrawalItem)
651
651
  throw Error("withdrawalTxInReference: Undefined withdrawal");
652
652
  if (this.withdrawalItem.type === "PubKeyWithdrawal")
@@ -657,9 +657,9 @@ var MeshTxBuilderCore = class {
657
657
  type: "Inline",
658
658
  txHash,
659
659
  txIndex,
660
- scriptHash: withdrawalScriptHash,
660
+ scriptHash,
661
661
  version: this.plutusWithdrawalScriptVersion || "V2",
662
- scriptSize: scriptSize || "0"
662
+ scriptSize
663
663
  };
664
664
  return this;
665
665
  };
@@ -805,11 +805,11 @@ var MeshTxBuilderCore = class {
805
805
  * Adds a script witness to the certificate
806
806
  * @param txHash The transaction hash of the reference UTxO
807
807
  * @param txIndex The transaction index of the reference UTxO
808
- * @param spendingScriptHash The script hash of the spending script
809
- * @param version Optional - The plutus version of the script, null version implies Native Script
810
- * @param scriptSize The size of the plutus script referenced
808
+ * @param scriptSize The size of the plutus script in bytes referenced (can be obtained by script hex length / 2)
809
+ * @param scriptHash The script hash of the spending script
810
+ * @param version The plutus version of the script, null version implies Native Script
811
811
  */
812
- certificateTxInReference = (txHash, txIndex, spendingScriptHash, version, scriptSize = "0") => {
812
+ certificateTxInReference = (txHash, txIndex, scriptSize, scriptHash, version) => {
813
813
  const currentCert = this.meshTxBuilderBody.certificates.pop();
814
814
  if (!currentCert) {
815
815
  throw Error(
@@ -824,7 +824,7 @@ var MeshTxBuilderCore = class {
824
824
  type: "Inline",
825
825
  txHash,
826
826
  txIndex,
827
- simpleScriptHash: spendingScriptHash
827
+ simpleScriptHash: scriptHash
828
828
  }
829
829
  });
830
830
  } else {
@@ -835,7 +835,7 @@ var MeshTxBuilderCore = class {
835
835
  type: "Inline",
836
836
  txHash,
837
837
  txIndex,
838
- scriptHash: spendingScriptHash,
838
+ scriptHash,
839
839
  scriptSize
840
840
  },
841
841
  redeemer: currentCert.type === "ScriptCertificate" ? currentCert.redeemer : void 0
@@ -940,6 +940,15 @@ var MeshTxBuilderCore = class {
940
940
  this._protocolParams = updatedParams;
941
941
  return this;
942
942
  };
943
+ /**
944
+ * Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
945
+ * @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
946
+ * @returns The MeshTxBuilder instance
947
+ */
948
+ setNetwork = (network) => {
949
+ this.meshTxBuilderBody.network = network;
950
+ return this;
951
+ };
943
952
  queueAllLastItem = () => {
944
953
  if (this.txOutput) {
945
954
  this.meshTxBuilderBody.outputs.push(this.txOutput);
@@ -1292,7 +1301,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1292
1301
  );
1293
1302
  if (this.evaluator) {
1294
1303
  const txEvaluation = await this.evaluator.evaluateTx(txHex).catch((error) => {
1295
- throw Error(`Tx evaluation failed: ${error}`);
1304
+ throw Error(`Tx evaluation failed: ${error}
1305
+ For txHex: ${txHex}`);
1296
1306
  });
1297
1307
  this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
1298
1308
  txHex = this.serializer.serializeTxBody(
@@ -1404,6 +1414,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1404
1414
  `Couldn't find script reference utxo for ${scriptSource.txHash}#${scriptSource.txIndex}`
1405
1415
  );
1406
1416
  scriptSource.scriptHash = scriptRefUtxo?.output.scriptHash;
1417
+ scriptSource.scriptSize = (scriptRefUtxo?.output.scriptRef.length / 2).toString();
1407
1418
  }
1408
1419
  };
1409
1420
  isInputComplete = (txIn) => {
@@ -1423,8 +1434,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1423
1434
  };
1424
1435
  isRefScriptInfoComplete = (scriptTxIn) => {
1425
1436
  const { scriptSource } = scriptTxIn.scriptTxIn;
1426
- if (scriptSource?.type === "Inline" && !scriptSource?.scriptHash)
1427
- return false;
1437
+ if (scriptSource?.type === "Inline") {
1438
+ if (scriptSource?.scriptHash || scriptSource?.scriptSize) return false;
1439
+ }
1428
1440
  return true;
1429
1441
  };
1430
1442
  };
@@ -1675,6 +1687,7 @@ var Transaction = class {
1675
1687
  ).spendingTxInReference(
1676
1688
  script.input.txHash,
1677
1689
  script.input.outputIndex,
1690
+ (script.output.scriptRef.length / 2).toString(),
1678
1691
  script.output.scriptHash
1679
1692
  ).txInRedeemerValue(red.data, "Mesh", red.budget);
1680
1693
  }
@@ -1732,12 +1745,16 @@ var Transaction = class {
1732
1745
  this.isCollateralNeeded = true;
1733
1746
  this.mintPlutusScript(script).mint(assetQuantity, policyId, assetNameHex).mintTxInReference(
1734
1747
  forgeScript.input.txHash,
1735
- forgeScript.input.outputIndex
1748
+ forgeScript.input.outputIndex,
1749
+ (forgeScript.output.scriptRef.length / 2).toString(),
1750
+ forgeScript.output.scriptHash
1736
1751
  ).mintRedeemerValue(redeemer.data, "Mesh", redeemer.budget);
1737
1752
  if (mint.cip68ScriptAddress) {
1738
1753
  this.mintPlutusScript(script).mint(assetQuantity, policyId, referenceAssetNameHex).mintTxInReference(
1739
1754
  forgeScript.input.txHash,
1740
- forgeScript.input.outputIndex
1755
+ forgeScript.input.outputIndex,
1756
+ (forgeScript.output.scriptRef.length / 2).toString(),
1757
+ forgeScript.output.scriptHash
1741
1758
  ).mintRedeemerValue(redeemer.data, "Mesh", redeemer.budget);
1742
1759
  break;
1743
1760
  }
@@ -1774,8 +1791,9 @@ var Transaction = class {
1774
1791
  this.setMetadata(Number(mint.label), {
1775
1792
  [policyId]: { [mint.assetName]: mint.metadata }
1776
1793
  });
1794
+ } else {
1795
+ this.setMetadata(Number(mint.label), mint.metadata);
1777
1796
  }
1778
- this.setMetadata(Number(mint.label), mint.metadata);
1779
1797
  }
1780
1798
  return this;
1781
1799
  }
@@ -1821,6 +1839,15 @@ var Transaction = class {
1821
1839
  });
1822
1840
  return this;
1823
1841
  }
1842
+ /**
1843
+ * Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
1844
+ * @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
1845
+ * @returns The Transaction object.
1846
+ */
1847
+ setNetwork = (network) => {
1848
+ this.txBuilder.setNetwork(network);
1849
+ return this;
1850
+ };
1824
1851
  /**
1825
1852
  * Sets the required signers for the transaction.
1826
1853
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/transaction",
3
- "version": "1.6.7",
3
+ "version": "1.6.9",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",