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

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
@@ -40,6 +40,7 @@ __export(index_exports, {
40
40
  module.exports = __toCommonJS(index_exports);
41
41
 
42
42
  // src/mesh-tx-builder/index.ts
43
+ var import_common2 = require("@meshsdk/common");
43
44
  var import_core_cst = require("@meshsdk/core-cst");
44
45
 
45
46
  // src/mesh-tx-builder/tx-builder-core.ts
@@ -1256,7 +1257,8 @@ var MeshTxBuilderCore = class {
1256
1257
  txHash,
1257
1258
  txIndex,
1258
1259
  scriptHash,
1259
- scriptSize
1260
+ scriptSize,
1261
+ version
1260
1262
  },
1261
1263
  redeemer: currentCert.type === "ScriptCertificate" ? currentCert.redeemer : void 0
1262
1264
  });
@@ -1470,7 +1472,6 @@ var MeshTxBuilderCore = class {
1470
1472
  }
1471
1473
  }
1472
1474
  this.meshTxBuilderBody.inputs.push(this.txInQueueItem);
1473
- this.inputForEvaluation((0, import_common.txInToUtxo)(this.txInQueueItem.txIn));
1474
1475
  this.txInQueueItem = void 0;
1475
1476
  };
1476
1477
  queueMint = () => {
@@ -1766,16 +1767,16 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1766
1767
  verbose = false
1767
1768
  } = {}) {
1768
1769
  super();
1770
+ if (fetcher) this.fetcher = fetcher;
1771
+ if (submitter) this.submitter = submitter;
1772
+ if (evaluator) this.evaluator = evaluator;
1773
+ if (params) this.protocolParams(params);
1769
1774
  if (serializer) {
1770
1775
  this.serializer = serializer;
1771
1776
  } else {
1772
- this.serializer = new import_core_cst.CardanoSDKSerializer();
1777
+ this.serializer = new import_core_cst.CardanoSDKSerializer(this._protocolParams);
1773
1778
  }
1774
1779
  this.serializer.verbose = verbose;
1775
- if (fetcher) this.fetcher = fetcher;
1776
- if (submitter) this.submitter = submitter;
1777
- if (evaluator) this.evaluator = evaluator;
1778
- if (params) this.protocolParams(params);
1779
1780
  if (isHydra)
1780
1781
  this.protocolParams({
1781
1782
  minFeeA: 0,
@@ -1791,7 +1792,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1791
1792
  * @param customizedTx The optional customized transaction body
1792
1793
  * @returns The signed transaction in hex ready to submit / signed by client
1793
1794
  */
1794
- complete = async (customizedTx) => {
1795
+ complete = async (customizedTx, balanced = true) => {
1795
1796
  if (customizedTx) {
1796
1797
  this.meshTxBuilderBody = { ...this.meshTxBuilderBody, ...customizedTx };
1797
1798
  } else {
@@ -1801,25 +1802,93 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1801
1802
  for (let collateral of this.meshTxBuilderBody.collaterals) {
1802
1803
  collateral.txIn.scriptSize = 0;
1803
1804
  }
1804
- const { inputs, collaterals, mints } = this.meshTxBuilderBody;
1805
+ const { inputs, collaterals, mints, withdrawals, votes, certificates } = this.meshTxBuilderBody;
1805
1806
  const incompleteTxIns = [...inputs, ...collaterals].filter(
1806
1807
  (txIn) => !this.isInputComplete(txIn)
1807
1808
  );
1808
- const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
1809
- await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
1810
- incompleteTxIns.forEach((txIn) => {
1811
- this.completeTxInformation(txIn);
1809
+ let incompleteScriptSources = [];
1810
+ let incompleteSimpleScriptSources = [];
1811
+ inputs.forEach((txIn) => {
1812
+ if (txIn.type === "Script" && txIn.scriptTxIn.scriptSource?.type === "Inline") {
1813
+ if (!this.isRefScriptInfoComplete(txIn.scriptTxIn.scriptSource)) {
1814
+ incompleteScriptSources.push(txIn.scriptTxIn.scriptSource);
1815
+ }
1816
+ } else if (txIn.type === "SimpleScript" && txIn.simpleScriptTxIn?.scriptSource?.type === "Inline") {
1817
+ if (!this.isSimpleRefScriptInfoComplete(
1818
+ txIn.simpleScriptTxIn.scriptSource
1819
+ )) {
1820
+ incompleteSimpleScriptSources.push(
1821
+ txIn.simpleScriptTxIn.scriptSource
1822
+ );
1823
+ }
1824
+ }
1812
1825
  });
1813
- incompleteMints.forEach((mint) => {
1826
+ mints.forEach((mint) => {
1814
1827
  if (mint.type === "Plutus") {
1815
1828
  const scriptSource = mint.scriptSource;
1816
- this.completeScriptInfo(scriptSource);
1817
- }
1818
- if (mint.type === "Native") {
1829
+ if (!this.isRefScriptInfoComplete(scriptSource)) {
1830
+ incompleteScriptSources.push(scriptSource);
1831
+ }
1832
+ } else if (mint.type === "Native") {
1819
1833
  const scriptSource = mint.scriptSource;
1820
- this.completeSimpleScriptInfo(scriptSource);
1834
+ if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
1835
+ incompleteSimpleScriptSources.push(scriptSource);
1836
+ }
1821
1837
  }
1822
1838
  });
1839
+ withdrawals.forEach((withdrawal) => {
1840
+ if (withdrawal.type === "ScriptWithdrawal") {
1841
+ const scriptSource = withdrawal.scriptSource;
1842
+ if (!this.isRefScriptInfoComplete(scriptSource)) {
1843
+ incompleteScriptSources.push(scriptSource);
1844
+ }
1845
+ } else if (withdrawal.type === "SimpleScriptWithdrawal") {
1846
+ const scriptSource = withdrawal.scriptSource;
1847
+ if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
1848
+ incompleteSimpleScriptSources.push(scriptSource);
1849
+ }
1850
+ }
1851
+ });
1852
+ votes.forEach((vote) => {
1853
+ if (vote.type === "ScriptVote") {
1854
+ const scriptSource = vote.scriptSource;
1855
+ if (!this.isRefScriptInfoComplete(scriptSource)) {
1856
+ incompleteScriptSources.push(scriptSource);
1857
+ }
1858
+ } else if (vote.type === "SimpleScriptVote") {
1859
+ const scriptSource = vote.simpleScriptSource;
1860
+ if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
1861
+ incompleteSimpleScriptSources.push(scriptSource);
1862
+ }
1863
+ }
1864
+ });
1865
+ certificates.forEach((certificate) => {
1866
+ if (certificate.type === "ScriptCertificate") {
1867
+ const scriptSource = certificate.scriptSource;
1868
+ if (!this.isRefScriptInfoComplete(scriptSource)) {
1869
+ incompleteScriptSources.push(scriptSource);
1870
+ }
1871
+ } else if (certificate.type === "SimpleScriptCertificate") {
1872
+ const scriptSource = certificate.simpleScriptSource;
1873
+ if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
1874
+ incompleteSimpleScriptSources.push(scriptSource);
1875
+ }
1876
+ }
1877
+ });
1878
+ await this.queryAllTxInfo(
1879
+ incompleteTxIns,
1880
+ incompleteScriptSources,
1881
+ incompleteSimpleScriptSources
1882
+ );
1883
+ incompleteTxIns.forEach((txIn) => {
1884
+ this.completeTxInformation(txIn);
1885
+ });
1886
+ incompleteScriptSources.forEach((scriptSource) => {
1887
+ this.completeScriptInfo(scriptSource);
1888
+ });
1889
+ incompleteSimpleScriptSources.forEach((simpleScriptSource) => {
1890
+ this.completeSimpleScriptInfo(simpleScriptSource);
1891
+ });
1823
1892
  this.meshTxBuilderBody.inputs.forEach((input) => {
1824
1893
  if (input.txIn.scriptSize && input.txIn.scriptSize > 0) {
1825
1894
  if (this.meshTxBuilderBody.referenceInputs.find((refTxIn) => {
@@ -1850,21 +1919,27 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1850
1919
  });
1851
1920
  let txHex = this.serializer.serializeTxBody(
1852
1921
  this.meshTxBuilderBody,
1853
- this._protocolParams
1922
+ this._protocolParams,
1923
+ balanced
1854
1924
  );
1855
1925
  if (this.evaluator) {
1856
1926
  const txEvaluation = await this.evaluator.evaluateTx(
1857
1927
  txHex,
1858
- Object.values(this.meshTxBuilderBody.inputsForEvaluation),
1928
+ Object.values(this.meshTxBuilderBody.inputsForEvaluation).concat(
1929
+ this.meshTxBuilderBody.inputs.map((val) => (0, import_common2.txInToUtxo)(val.txIn))
1930
+ ),
1859
1931
  this.meshTxBuilderBody.chainedTxs
1860
1932
  ).catch((error) => {
1861
- throw Error(`Tx evaluation failed: ${error}
1862
- For txHex: ${txHex}`);
1933
+ throw new Error(
1934
+ `Tx evaluation failed: ${JSON.stringify(error)}
1935
+ For txHex: ${txHex}`
1936
+ );
1863
1937
  });
1864
1938
  this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
1865
1939
  txHex = this.serializer.serializeTxBody(
1866
1940
  this.meshTxBuilderBody,
1867
- this._protocolParams
1941
+ this._protocolParams,
1942
+ balanced
1868
1943
  );
1869
1944
  }
1870
1945
  this.txHex = txHex;
@@ -1875,7 +1950,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1875
1950
  * @param customizedTx The optional customized transaction body
1876
1951
  * @returns The signed transaction in hex ready to submit / signed by client
1877
1952
  */
1878
- completeSync = (customizedTx) => {
1953
+ completeSync = (customizedTx, balanced = true) => {
1879
1954
  if (customizedTx) {
1880
1955
  this.meshTxBuilderBody = customizedTx;
1881
1956
  } else {
@@ -1884,7 +1959,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1884
1959
  this.addUtxosFromSelection();
1885
1960
  return this.serializer.serializeTxBody(
1886
1961
  this.meshTxBuilderBody,
1887
- this._protocolParams
1962
+ this._protocolParams,
1963
+ balanced
1888
1964
  );
1889
1965
  };
1890
1966
  /**
@@ -1920,9 +1996,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1920
1996
  this.queriedUTxOs[txHash] = utxos;
1921
1997
  }
1922
1998
  };
1923
- queryAllTxInfo = (incompleteTxIns, incompleteMints) => {
1999
+ queryAllTxInfo = (incompleteTxIns, incompleteScriptSources, incompleteSimpleScriptSources) => {
1924
2000
  const queryUTxOPromises = [];
1925
- if ((incompleteTxIns.length > 0 || incompleteMints.length > 0) && !this.fetcher)
2001
+ if ((incompleteTxIns.length > 0 || incompleteScriptSources.length > 0 || incompleteSimpleScriptSources.length) && !this.fetcher)
1926
2002
  throw Error(
1927
2003
  "Transaction information is incomplete while no fetcher instance is provided. Provide a `fetcher`."
1928
2004
  );
@@ -1931,21 +2007,11 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1931
2007
  if (!this.isInputInfoComplete(currentTxIn)) {
1932
2008
  queryUTxOPromises.push(this.getUTxOInfo(currentTxIn.txIn.txHash));
1933
2009
  }
1934
- if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn.scriptTxIn.scriptSource)) {
1935
- queryUTxOPromises.push(
1936
- this.getUTxOInfo(currentTxIn.scriptTxIn.scriptSource.txHash)
1937
- );
1938
- }
1939
2010
  }
1940
- for (let i = 0; i < incompleteMints.length; i++) {
1941
- const currentMint = incompleteMints[i];
1942
- if (currentMint.type === "Plutus") {
1943
- const scriptSource = currentMint.scriptSource;
1944
- if (scriptSource.type === "Inline") {
1945
- if (!this.isRefScriptInfoComplete(scriptSource)) {
1946
- queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
1947
- }
1948
- }
2011
+ for (let i = 0; i < incompleteScriptSources.length; i++) {
2012
+ const scriptSource = incompleteScriptSources[i];
2013
+ if (scriptSource.type === "Inline") {
2014
+ queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
1949
2015
  }
1950
2016
  }
1951
2017
  return Promise.all(queryUTxOPromises);
@@ -2039,6 +2105,13 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
2039
2105
  }
2040
2106
  return true;
2041
2107
  };
2108
+ isSimpleRefScriptInfoComplete = (simpleScriptSource) => {
2109
+ if (simpleScriptSource.type === "Inline") {
2110
+ if (!simpleScriptSource.simpleScriptHash || !simpleScriptSource.scriptSize)
2111
+ return false;
2112
+ }
2113
+ return true;
2114
+ };
2042
2115
  };
2043
2116
 
2044
2117
  // src/scripts/forge.script.ts
@@ -2089,7 +2162,7 @@ var ForgeScript = class {
2089
2162
  };
2090
2163
 
2091
2164
  // src/transaction/index.ts
2092
- var import_common2 = require("@meshsdk/common");
2165
+ var import_common3 = require("@meshsdk/common");
2093
2166
  var import_core_cst3 = require("@meshsdk/core-cst");
2094
2167
  var Transaction = class {
2095
2168
  txBuilder;
@@ -2213,7 +2286,7 @@ var Transaction = class {
2213
2286
  * @see {@link https://meshjs.dev/apis/transaction#sendToken}
2214
2287
  */
2215
2288
  sendToken(recipient, ticker, amount) {
2216
- const assets = [{ unit: import_common2.SUPPORTED_TOKENS[ticker], quantity: amount }];
2289
+ const assets = [{ unit: import_common3.SUPPORTED_TOKENS[ticker], quantity: amount }];
2217
2290
  return this.sendAssets(recipient, assets);
2218
2291
  }
2219
2292
  /**
@@ -2290,7 +2363,7 @@ var Transaction = class {
2290
2363
  const { value, script, datum, redeemer } = options;
2291
2364
  const red = redeemer || {
2292
2365
  data: { alternative: 0, fields: ["mesh"] },
2293
- budget: import_common2.DEFAULT_REDEEMER_BUDGET
2366
+ budget: import_common3.DEFAULT_REDEEMER_BUDGET
2294
2367
  };
2295
2368
  if ("code" in script) {
2296
2369
  this.isCollateralNeeded = true;
@@ -2298,7 +2371,8 @@ var Transaction = class {
2298
2371
  value.input.txHash,
2299
2372
  value.input.outputIndex,
2300
2373
  value.output.amount,
2301
- value.output.address
2374
+ value.output.address,
2375
+ value.output.scriptRef ? value.output.scriptRef.length / 2 : 0
2302
2376
  ).txInScript(script.code).txInRedeemerValue(red.data, "Mesh", red.budget);
2303
2377
  }
2304
2378
  if ("output" in script) {
@@ -2332,10 +2406,10 @@ var Transaction = class {
2332
2406
  // TODO: nuke this probably as the input type is too confusing
2333
2407
  mintAsset(forgeScript, mint, redeemer) {
2334
2408
  const assetQuantity = mint.assetQuantity;
2335
- let assetNameHex = (0, import_common2.stringToHex)(mint.assetName);
2336
- const referenceAssetNameHex = (0, import_common2.CIP68_100)(assetNameHex);
2409
+ let assetNameHex = (0, import_common3.stringToHex)(mint.assetName);
2410
+ const referenceAssetNameHex = (0, import_common3.CIP68_100)(assetNameHex);
2337
2411
  if (mint.cip68ScriptAddress) {
2338
- assetNameHex = (0, import_common2.CIP68_222)(assetNameHex);
2412
+ assetNameHex = (0, import_common3.CIP68_222)(assetNameHex);
2339
2413
  }
2340
2414
  let policyId = "";
2341
2415
  switch (typeof forgeScript) {
@@ -2407,7 +2481,7 @@ var Transaction = class {
2407
2481
  this.sendAssets(
2408
2482
  {
2409
2483
  address: mint.cip68ScriptAddress,
2410
- datum: { inline: true, value: (0, import_common2.metadataToCip68)(mint.metadata) }
2484
+ datum: { inline: true, value: (0, import_common3.metadataToCip68)(mint.metadata) }
2411
2485
  },
2412
2486
  [
2413
2487
  {
@@ -2446,7 +2520,7 @@ var Transaction = class {
2446
2520
  burnAsset(forgeScript, asset, redeemer) {
2447
2521
  const assetQuantity = "-" + asset.quantity;
2448
2522
  const mint = {
2449
- assetName: (0, import_common2.hexToString)(asset.unit.slice(import_common2.POLICY_ID_LENGTH)),
2523
+ assetName: (0, import_common3.hexToString)(asset.unit.slice(import_common3.POLICY_ID_LENGTH)),
2450
2524
  assetQuantity
2451
2525
  };
2452
2526
  try {
@@ -2546,7 +2620,7 @@ var Transaction = class {
2546
2620
  delegateStake(rewardAddress, poolId) {
2547
2621
  this.txBuilder.delegateStakeCertificate(
2548
2622
  rewardAddress,
2549
- this.txBuilder.serializer.resolver.keys.resolveEd25519KeyHash(poolId)
2623
+ this.txBuilder.serializer.deserializer.cert.deserializePoolId(poolId)
2550
2624
  );
2551
2625
  return this;
2552
2626
  }
@@ -2568,12 +2642,12 @@ var Transaction = class {
2568
2642
  this.txBuilder.retirePoolCertificate(poolId, epochNo);
2569
2643
  return this;
2570
2644
  }
2571
- async build() {
2645
+ async build(balanced = true) {
2572
2646
  try {
2573
2647
  await this.addCollateralIfNeeded();
2574
2648
  await this.addTxInputsAsNeeded();
2575
2649
  await this.addChangeAddress();
2576
- return this.txBuilder.complete();
2650
+ return this.txBuilder.complete(void 0, balanced);
2577
2651
  } catch (error) {
2578
2652
  throw new Error(
2579
2653
  `[Transaction] An error occurred during build: ${error}.`
package/dist/index.d.cts CHANGED
@@ -546,13 +546,13 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
546
546
  * @param customizedTx The optional customized transaction body
547
547
  * @returns The signed transaction in hex ready to submit / signed by client
548
548
  */
549
- complete: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
549
+ complete: (customizedTx?: Partial<MeshTxBuilderBody>, balanced?: Boolean) => Promise<string>;
550
550
  /**
551
551
  * It builds the transaction without dependencies
552
552
  * @param customizedTx The optional customized transaction body
553
553
  * @returns The signed transaction in hex ready to submit / signed by client
554
554
  */
555
- completeSync: (customizedTx?: MeshTxBuilderBody) => string;
555
+ completeSync: (customizedTx?: MeshTxBuilderBody, balanced?: Boolean) => string;
556
556
  /**
557
557
  * Complete the signing process
558
558
  * @returns The signed transaction in hex
@@ -569,7 +569,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
569
569
  * @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
570
570
  */
571
571
  protected getUTxOInfo: (txHash: string) => Promise<void>;
572
- protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteMints: MintItem[]) => Promise<void[]>;
572
+ protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteScriptSources: ScriptSource[], incompleteSimpleScriptSources: SimpleScriptSourceInfo[]) => Promise<void[]>;
573
573
  protected completeTxInformation: (input: TxIn) => void;
574
574
  protected completeInputInfo: (input: TxIn) => void;
575
575
  protected completeScriptInfo: (scriptSource: ScriptSource) => void;
@@ -578,6 +578,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
578
578
  protected isInputInfoComplete: (txIn: TxIn) => boolean;
579
579
  protected isMintComplete: (mint: MintItem) => boolean;
580
580
  protected isRefScriptInfoComplete: (scriptSource: ScriptSource) => boolean;
581
+ protected isSimpleRefScriptInfoComplete: (simpleScriptSource: SimpleScriptSourceInfo) => boolean;
581
582
  }
582
583
 
583
584
  declare class ForgeScript {
@@ -747,7 +748,7 @@ declare class Transaction {
747
748
  registerStake(rewardAddress: string): Transaction;
748
749
  registerPool(params: PoolParams): Transaction;
749
750
  retirePool(poolId: string, epochNo: number): Transaction;
750
- build(): Promise<string>;
751
+ build(balanced?: Boolean): Promise<string>;
751
752
  protected mintPlutusScript(script: PlutusScript): MeshTxBuilder;
752
753
  protected spendingPlutusScript(script: PlutusScript): MeshTxBuilder;
753
754
  private addCollateralIfNeeded;
package/dist/index.d.ts CHANGED
@@ -546,13 +546,13 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
546
546
  * @param customizedTx The optional customized transaction body
547
547
  * @returns The signed transaction in hex ready to submit / signed by client
548
548
  */
549
- complete: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
549
+ complete: (customizedTx?: Partial<MeshTxBuilderBody>, balanced?: Boolean) => Promise<string>;
550
550
  /**
551
551
  * It builds the transaction without dependencies
552
552
  * @param customizedTx The optional customized transaction body
553
553
  * @returns The signed transaction in hex ready to submit / signed by client
554
554
  */
555
- completeSync: (customizedTx?: MeshTxBuilderBody) => string;
555
+ completeSync: (customizedTx?: MeshTxBuilderBody, balanced?: Boolean) => string;
556
556
  /**
557
557
  * Complete the signing process
558
558
  * @returns The signed transaction in hex
@@ -569,7 +569,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
569
569
  * @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
570
570
  */
571
571
  protected getUTxOInfo: (txHash: string) => Promise<void>;
572
- protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteMints: MintItem[]) => Promise<void[]>;
572
+ protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteScriptSources: ScriptSource[], incompleteSimpleScriptSources: SimpleScriptSourceInfo[]) => Promise<void[]>;
573
573
  protected completeTxInformation: (input: TxIn) => void;
574
574
  protected completeInputInfo: (input: TxIn) => void;
575
575
  protected completeScriptInfo: (scriptSource: ScriptSource) => void;
@@ -578,6 +578,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
578
578
  protected isInputInfoComplete: (txIn: TxIn) => boolean;
579
579
  protected isMintComplete: (mint: MintItem) => boolean;
580
580
  protected isRefScriptInfoComplete: (scriptSource: ScriptSource) => boolean;
581
+ protected isSimpleRefScriptInfoComplete: (simpleScriptSource: SimpleScriptSourceInfo) => boolean;
581
582
  }
582
583
 
583
584
  declare class ForgeScript {
@@ -747,7 +748,7 @@ declare class Transaction {
747
748
  registerStake(rewardAddress: string): Transaction;
748
749
  registerPool(params: PoolParams): Transaction;
749
750
  retirePool(poolId: string, epochNo: number): Transaction;
750
- build(): Promise<string>;
751
+ build(balanced?: Boolean): Promise<string>;
751
752
  protected mintPlutusScript(script: PlutusScript): MeshTxBuilder;
752
753
  protected spendingPlutusScript(script: PlutusScript): MeshTxBuilder;
753
754
  private addCollateralIfNeeded;
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  // src/mesh-tx-builder/index.ts
2
+ import {
3
+ txInToUtxo
4
+ } from "@meshsdk/common";
2
5
  import { CardanoSDKSerializer } from "@meshsdk/core-cst";
3
6
 
4
7
  // src/mesh-tx-builder/tx-builder-core.ts
@@ -8,7 +11,6 @@ import {
8
11
  DEFAULT_REDEEMER_BUDGET,
9
12
  DREP_DEPOSIT,
10
13
  emptyTxBuilderBody,
11
- txInToUtxo,
12
14
  UtxoSelection
13
15
  } from "@meshsdk/common";
14
16
 
@@ -1222,7 +1224,8 @@ var MeshTxBuilderCore = class {
1222
1224
  txHash,
1223
1225
  txIndex,
1224
1226
  scriptHash,
1225
- scriptSize
1227
+ scriptSize,
1228
+ version
1226
1229
  },
1227
1230
  redeemer: currentCert.type === "ScriptCertificate" ? currentCert.redeemer : void 0
1228
1231
  });
@@ -1436,7 +1439,6 @@ var MeshTxBuilderCore = class {
1436
1439
  }
1437
1440
  }
1438
1441
  this.meshTxBuilderBody.inputs.push(this.txInQueueItem);
1439
- this.inputForEvaluation(txInToUtxo(this.txInQueueItem.txIn));
1440
1442
  this.txInQueueItem = void 0;
1441
1443
  };
1442
1444
  queueMint = () => {
@@ -1732,16 +1734,16 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1732
1734
  verbose = false
1733
1735
  } = {}) {
1734
1736
  super();
1737
+ if (fetcher) this.fetcher = fetcher;
1738
+ if (submitter) this.submitter = submitter;
1739
+ if (evaluator) this.evaluator = evaluator;
1740
+ if (params) this.protocolParams(params);
1735
1741
  if (serializer) {
1736
1742
  this.serializer = serializer;
1737
1743
  } else {
1738
- this.serializer = new CardanoSDKSerializer();
1744
+ this.serializer = new CardanoSDKSerializer(this._protocolParams);
1739
1745
  }
1740
1746
  this.serializer.verbose = verbose;
1741
- if (fetcher) this.fetcher = fetcher;
1742
- if (submitter) this.submitter = submitter;
1743
- if (evaluator) this.evaluator = evaluator;
1744
- if (params) this.protocolParams(params);
1745
1747
  if (isHydra)
1746
1748
  this.protocolParams({
1747
1749
  minFeeA: 0,
@@ -1757,7 +1759,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1757
1759
  * @param customizedTx The optional customized transaction body
1758
1760
  * @returns The signed transaction in hex ready to submit / signed by client
1759
1761
  */
1760
- complete = async (customizedTx) => {
1762
+ complete = async (customizedTx, balanced = true) => {
1761
1763
  if (customizedTx) {
1762
1764
  this.meshTxBuilderBody = { ...this.meshTxBuilderBody, ...customizedTx };
1763
1765
  } else {
@@ -1767,25 +1769,93 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1767
1769
  for (let collateral of this.meshTxBuilderBody.collaterals) {
1768
1770
  collateral.txIn.scriptSize = 0;
1769
1771
  }
1770
- const { inputs, collaterals, mints } = this.meshTxBuilderBody;
1772
+ const { inputs, collaterals, mints, withdrawals, votes, certificates } = this.meshTxBuilderBody;
1771
1773
  const incompleteTxIns = [...inputs, ...collaterals].filter(
1772
1774
  (txIn) => !this.isInputComplete(txIn)
1773
1775
  );
1774
- const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
1775
- await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
1776
- incompleteTxIns.forEach((txIn) => {
1777
- this.completeTxInformation(txIn);
1776
+ let incompleteScriptSources = [];
1777
+ let incompleteSimpleScriptSources = [];
1778
+ inputs.forEach((txIn) => {
1779
+ if (txIn.type === "Script" && txIn.scriptTxIn.scriptSource?.type === "Inline") {
1780
+ if (!this.isRefScriptInfoComplete(txIn.scriptTxIn.scriptSource)) {
1781
+ incompleteScriptSources.push(txIn.scriptTxIn.scriptSource);
1782
+ }
1783
+ } else if (txIn.type === "SimpleScript" && txIn.simpleScriptTxIn?.scriptSource?.type === "Inline") {
1784
+ if (!this.isSimpleRefScriptInfoComplete(
1785
+ txIn.simpleScriptTxIn.scriptSource
1786
+ )) {
1787
+ incompleteSimpleScriptSources.push(
1788
+ txIn.simpleScriptTxIn.scriptSource
1789
+ );
1790
+ }
1791
+ }
1778
1792
  });
1779
- incompleteMints.forEach((mint) => {
1793
+ mints.forEach((mint) => {
1780
1794
  if (mint.type === "Plutus") {
1781
1795
  const scriptSource = mint.scriptSource;
1782
- this.completeScriptInfo(scriptSource);
1783
- }
1784
- if (mint.type === "Native") {
1796
+ if (!this.isRefScriptInfoComplete(scriptSource)) {
1797
+ incompleteScriptSources.push(scriptSource);
1798
+ }
1799
+ } else if (mint.type === "Native") {
1785
1800
  const scriptSource = mint.scriptSource;
1786
- this.completeSimpleScriptInfo(scriptSource);
1801
+ if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
1802
+ incompleteSimpleScriptSources.push(scriptSource);
1803
+ }
1804
+ }
1805
+ });
1806
+ withdrawals.forEach((withdrawal) => {
1807
+ if (withdrawal.type === "ScriptWithdrawal") {
1808
+ const scriptSource = withdrawal.scriptSource;
1809
+ if (!this.isRefScriptInfoComplete(scriptSource)) {
1810
+ incompleteScriptSources.push(scriptSource);
1811
+ }
1812
+ } else if (withdrawal.type === "SimpleScriptWithdrawal") {
1813
+ const scriptSource = withdrawal.scriptSource;
1814
+ if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
1815
+ incompleteSimpleScriptSources.push(scriptSource);
1816
+ }
1787
1817
  }
1788
1818
  });
1819
+ votes.forEach((vote) => {
1820
+ if (vote.type === "ScriptVote") {
1821
+ const scriptSource = vote.scriptSource;
1822
+ if (!this.isRefScriptInfoComplete(scriptSource)) {
1823
+ incompleteScriptSources.push(scriptSource);
1824
+ }
1825
+ } else if (vote.type === "SimpleScriptVote") {
1826
+ const scriptSource = vote.simpleScriptSource;
1827
+ if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
1828
+ incompleteSimpleScriptSources.push(scriptSource);
1829
+ }
1830
+ }
1831
+ });
1832
+ certificates.forEach((certificate) => {
1833
+ if (certificate.type === "ScriptCertificate") {
1834
+ const scriptSource = certificate.scriptSource;
1835
+ if (!this.isRefScriptInfoComplete(scriptSource)) {
1836
+ incompleteScriptSources.push(scriptSource);
1837
+ }
1838
+ } else if (certificate.type === "SimpleScriptCertificate") {
1839
+ const scriptSource = certificate.simpleScriptSource;
1840
+ if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
1841
+ incompleteSimpleScriptSources.push(scriptSource);
1842
+ }
1843
+ }
1844
+ });
1845
+ await this.queryAllTxInfo(
1846
+ incompleteTxIns,
1847
+ incompleteScriptSources,
1848
+ incompleteSimpleScriptSources
1849
+ );
1850
+ incompleteTxIns.forEach((txIn) => {
1851
+ this.completeTxInformation(txIn);
1852
+ });
1853
+ incompleteScriptSources.forEach((scriptSource) => {
1854
+ this.completeScriptInfo(scriptSource);
1855
+ });
1856
+ incompleteSimpleScriptSources.forEach((simpleScriptSource) => {
1857
+ this.completeSimpleScriptInfo(simpleScriptSource);
1858
+ });
1789
1859
  this.meshTxBuilderBody.inputs.forEach((input) => {
1790
1860
  if (input.txIn.scriptSize && input.txIn.scriptSize > 0) {
1791
1861
  if (this.meshTxBuilderBody.referenceInputs.find((refTxIn) => {
@@ -1816,21 +1886,27 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1816
1886
  });
1817
1887
  let txHex = this.serializer.serializeTxBody(
1818
1888
  this.meshTxBuilderBody,
1819
- this._protocolParams
1889
+ this._protocolParams,
1890
+ balanced
1820
1891
  );
1821
1892
  if (this.evaluator) {
1822
1893
  const txEvaluation = await this.evaluator.evaluateTx(
1823
1894
  txHex,
1824
- Object.values(this.meshTxBuilderBody.inputsForEvaluation),
1895
+ Object.values(this.meshTxBuilderBody.inputsForEvaluation).concat(
1896
+ this.meshTxBuilderBody.inputs.map((val) => txInToUtxo(val.txIn))
1897
+ ),
1825
1898
  this.meshTxBuilderBody.chainedTxs
1826
1899
  ).catch((error) => {
1827
- throw Error(`Tx evaluation failed: ${error}
1828
- For txHex: ${txHex}`);
1900
+ throw new Error(
1901
+ `Tx evaluation failed: ${JSON.stringify(error)}
1902
+ For txHex: ${txHex}`
1903
+ );
1829
1904
  });
1830
1905
  this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
1831
1906
  txHex = this.serializer.serializeTxBody(
1832
1907
  this.meshTxBuilderBody,
1833
- this._protocolParams
1908
+ this._protocolParams,
1909
+ balanced
1834
1910
  );
1835
1911
  }
1836
1912
  this.txHex = txHex;
@@ -1841,7 +1917,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1841
1917
  * @param customizedTx The optional customized transaction body
1842
1918
  * @returns The signed transaction in hex ready to submit / signed by client
1843
1919
  */
1844
- completeSync = (customizedTx) => {
1920
+ completeSync = (customizedTx, balanced = true) => {
1845
1921
  if (customizedTx) {
1846
1922
  this.meshTxBuilderBody = customizedTx;
1847
1923
  } else {
@@ -1850,7 +1926,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1850
1926
  this.addUtxosFromSelection();
1851
1927
  return this.serializer.serializeTxBody(
1852
1928
  this.meshTxBuilderBody,
1853
- this._protocolParams
1929
+ this._protocolParams,
1930
+ balanced
1854
1931
  );
1855
1932
  };
1856
1933
  /**
@@ -1886,9 +1963,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1886
1963
  this.queriedUTxOs[txHash] = utxos;
1887
1964
  }
1888
1965
  };
1889
- queryAllTxInfo = (incompleteTxIns, incompleteMints) => {
1966
+ queryAllTxInfo = (incompleteTxIns, incompleteScriptSources, incompleteSimpleScriptSources) => {
1890
1967
  const queryUTxOPromises = [];
1891
- if ((incompleteTxIns.length > 0 || incompleteMints.length > 0) && !this.fetcher)
1968
+ if ((incompleteTxIns.length > 0 || incompleteScriptSources.length > 0 || incompleteSimpleScriptSources.length) && !this.fetcher)
1892
1969
  throw Error(
1893
1970
  "Transaction information is incomplete while no fetcher instance is provided. Provide a `fetcher`."
1894
1971
  );
@@ -1897,21 +1974,11 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1897
1974
  if (!this.isInputInfoComplete(currentTxIn)) {
1898
1975
  queryUTxOPromises.push(this.getUTxOInfo(currentTxIn.txIn.txHash));
1899
1976
  }
1900
- if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn.scriptTxIn.scriptSource)) {
1901
- queryUTxOPromises.push(
1902
- this.getUTxOInfo(currentTxIn.scriptTxIn.scriptSource.txHash)
1903
- );
1904
- }
1905
1977
  }
1906
- for (let i = 0; i < incompleteMints.length; i++) {
1907
- const currentMint = incompleteMints[i];
1908
- if (currentMint.type === "Plutus") {
1909
- const scriptSource = currentMint.scriptSource;
1910
- if (scriptSource.type === "Inline") {
1911
- if (!this.isRefScriptInfoComplete(scriptSource)) {
1912
- queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
1913
- }
1914
- }
1978
+ for (let i = 0; i < incompleteScriptSources.length; i++) {
1979
+ const scriptSource = incompleteScriptSources[i];
1980
+ if (scriptSource.type === "Inline") {
1981
+ queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
1915
1982
  }
1916
1983
  }
1917
1984
  return Promise.all(queryUTxOPromises);
@@ -2005,6 +2072,13 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
2005
2072
  }
2006
2073
  return true;
2007
2074
  };
2075
+ isSimpleRefScriptInfoComplete = (simpleScriptSource) => {
2076
+ if (simpleScriptSource.type === "Inline") {
2077
+ if (!simpleScriptSource.simpleScriptHash || !simpleScriptSource.scriptSize)
2078
+ return false;
2079
+ }
2080
+ return true;
2081
+ };
2008
2082
  };
2009
2083
 
2010
2084
  // src/scripts/forge.script.ts
@@ -2287,7 +2361,8 @@ var Transaction = class {
2287
2361
  value.input.txHash,
2288
2362
  value.input.outputIndex,
2289
2363
  value.output.amount,
2290
- value.output.address
2364
+ value.output.address,
2365
+ value.output.scriptRef ? value.output.scriptRef.length / 2 : 0
2291
2366
  ).txInScript(script.code).txInRedeemerValue(red.data, "Mesh", red.budget);
2292
2367
  }
2293
2368
  if ("output" in script) {
@@ -2535,7 +2610,7 @@ var Transaction = class {
2535
2610
  delegateStake(rewardAddress, poolId) {
2536
2611
  this.txBuilder.delegateStakeCertificate(
2537
2612
  rewardAddress,
2538
- this.txBuilder.serializer.resolver.keys.resolveEd25519KeyHash(poolId)
2613
+ this.txBuilder.serializer.deserializer.cert.deserializePoolId(poolId)
2539
2614
  );
2540
2615
  return this;
2541
2616
  }
@@ -2557,12 +2632,12 @@ var Transaction = class {
2557
2632
  this.txBuilder.retirePoolCertificate(poolId, epochNo);
2558
2633
  return this;
2559
2634
  }
2560
- async build() {
2635
+ async build(balanced = true) {
2561
2636
  try {
2562
2637
  await this.addCollateralIfNeeded();
2563
2638
  await this.addTxInputsAsNeeded();
2564
2639
  await this.addChangeAddress();
2565
- return this.txBuilder.complete();
2640
+ return this.txBuilder.complete(void 0, balanced);
2566
2641
  } catch (error) {
2567
2642
  throw new Error(
2568
2643
  `[Transaction] An error occurred during build: ${error}.`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/transaction",
3
- "version": "1.9.0-beta.3",
3
+ "version": "1.9.0-beta.5",
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.3",
39
- "@meshsdk/core-cst": "1.9.0-beta.3",
38
+ "@meshsdk/common": "1.9.0-beta.5",
39
+ "@meshsdk/core-cst": "1.9.0-beta.5",
40
40
  "json-bigint": "^1.0.0"
41
41
  },
42
42
  "prettier": "@meshsdk/configs/prettier",