@meshsdk/transaction 1.9.0-beta.3 → 1.9.0-beta.30
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 +252 -114
- package/dist/index.d.cts +19 -4
- package/dist/index.d.ts +19 -4
- package/dist/index.js +252 -115
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -800,6 +800,7 @@ var MeshTxBuilderCore = class {
|
|
|
800
800
|
coin
|
|
801
801
|
};
|
|
802
802
|
this.withdrawalItem = withdrawal2;
|
|
803
|
+
this.addingPlutusWithdrawal = false;
|
|
803
804
|
return this;
|
|
804
805
|
}
|
|
805
806
|
const withdrawal = {
|
|
@@ -943,6 +944,7 @@ var MeshTxBuilderCore = class {
|
|
|
943
944
|
}
|
|
944
945
|
};
|
|
945
946
|
this.voteItem = vote;
|
|
947
|
+
this.addingPlutusVote = false;
|
|
946
948
|
} else {
|
|
947
949
|
const vote = {
|
|
948
950
|
type: "BasicVote",
|
|
@@ -1256,7 +1258,8 @@ var MeshTxBuilderCore = class {
|
|
|
1256
1258
|
txHash,
|
|
1257
1259
|
txIndex,
|
|
1258
1260
|
scriptHash,
|
|
1259
|
-
scriptSize
|
|
1261
|
+
scriptSize,
|
|
1262
|
+
version
|
|
1260
1263
|
},
|
|
1261
1264
|
redeemer: currentCert.type === "ScriptCertificate" ? currentCert.redeemer : void 0
|
|
1262
1265
|
});
|
|
@@ -1401,24 +1404,17 @@ var MeshTxBuilderCore = class {
|
|
|
1401
1404
|
const utxoId = `${input.input.txHash}${input.input.outputIndex}`;
|
|
1402
1405
|
const currentUtxo = this.meshTxBuilderBody.inputsForEvaluation[utxoId];
|
|
1403
1406
|
if (currentUtxo) {
|
|
1404
|
-
const { address, amount, dataHash, plutusData, scriptRef, scriptHash } = input.output;
|
|
1405
1407
|
const {
|
|
1406
1408
|
dataHash: currentDataHash,
|
|
1407
1409
|
plutusData: currentPlutusData,
|
|
1408
1410
|
scriptRef: currentScriptRef,
|
|
1409
1411
|
scriptHash: currentScriptHash
|
|
1410
1412
|
} = currentUtxo.output;
|
|
1411
|
-
const updatedUtxo = {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
dataHash: dataHash ?? currentDataHash,
|
|
1417
|
-
plutusData: plutusData ?? currentPlutusData,
|
|
1418
|
-
scriptRef: scriptRef ?? currentScriptRef,
|
|
1419
|
-
scriptHash: scriptHash ?? currentScriptHash
|
|
1420
|
-
}
|
|
1421
|
-
};
|
|
1413
|
+
const updatedUtxo = { ...currentUtxo };
|
|
1414
|
+
if (currentDataHash) updatedUtxo.output.dataHash = currentDataHash;
|
|
1415
|
+
if (currentPlutusData) updatedUtxo.output.plutusData = currentPlutusData;
|
|
1416
|
+
if (currentScriptRef) updatedUtxo.output.scriptRef = currentScriptRef;
|
|
1417
|
+
if (currentScriptHash) updatedUtxo.output.scriptHash = currentScriptHash;
|
|
1422
1418
|
this.meshTxBuilderBody.inputsForEvaluation[utxoId] = updatedUtxo;
|
|
1423
1419
|
} else {
|
|
1424
1420
|
this.meshTxBuilderBody.inputsForEvaluation[utxoId] = input;
|
|
@@ -1470,7 +1466,6 @@ var MeshTxBuilderCore = class {
|
|
|
1470
1466
|
}
|
|
1471
1467
|
}
|
|
1472
1468
|
this.meshTxBuilderBody.inputs.push(this.txInQueueItem);
|
|
1473
|
-
this.inputForEvaluation((0, import_common.txInToUtxo)(this.txInQueueItem.txIn));
|
|
1474
1469
|
this.txInQueueItem = void 0;
|
|
1475
1470
|
};
|
|
1476
1471
|
queueMint = () => {
|
|
@@ -1550,6 +1545,7 @@ var MeshTxBuilderCore = class {
|
|
|
1550
1545
|
return red;
|
|
1551
1546
|
};
|
|
1552
1547
|
updateRedeemer = (meshTxBuilderBody, txEvaluation) => {
|
|
1548
|
+
let mintIndex = 0;
|
|
1553
1549
|
txEvaluation.forEach((redeemerEvaluation) => {
|
|
1554
1550
|
switch (redeemerEvaluation.tag) {
|
|
1555
1551
|
case "SPEND": {
|
|
@@ -1565,7 +1561,7 @@ var MeshTxBuilderCore = class {
|
|
|
1565
1561
|
break;
|
|
1566
1562
|
}
|
|
1567
1563
|
case "MINT": {
|
|
1568
|
-
const mint = meshTxBuilderBody.mints[
|
|
1564
|
+
const mint = meshTxBuilderBody.mints[mintIndex];
|
|
1569
1565
|
if (mint.type == "Plutus" && mint.redeemer) {
|
|
1570
1566
|
let newExUnits = {
|
|
1571
1567
|
mem: Math.floor(
|
|
@@ -1578,6 +1574,7 @@ var MeshTxBuilderCore = class {
|
|
|
1578
1574
|
for (let i = redeemerEvaluation.index; i < meshTxBuilderBody.mints.length; i++) {
|
|
1579
1575
|
if (meshTxBuilderBody.mints[i].policyId === mint.policyId) {
|
|
1580
1576
|
meshTxBuilderBody.mints[i].redeemer.exUnits = newExUnits;
|
|
1577
|
+
mintIndex++;
|
|
1581
1578
|
}
|
|
1582
1579
|
}
|
|
1583
1580
|
}
|
|
@@ -1711,6 +1708,23 @@ var MeshTxBuilderCore = class {
|
|
|
1711
1708
|
}
|
|
1712
1709
|
this.meshTxBuilderBody.inputs = addedInputs;
|
|
1713
1710
|
};
|
|
1711
|
+
removeDuplicateRefInputs = () => {
|
|
1712
|
+
const { referenceInputs } = this.meshTxBuilderBody;
|
|
1713
|
+
const getTxInId = (txIn) => `${txIn.txHash}#${txIn.txIndex}`;
|
|
1714
|
+
const currentTxInIds = [];
|
|
1715
|
+
const addedInputs = [];
|
|
1716
|
+
for (let i = 0; i < referenceInputs.length; i += 1) {
|
|
1717
|
+
const currentInput = referenceInputs[i];
|
|
1718
|
+
const currentTxInId = getTxInId(currentInput);
|
|
1719
|
+
if (currentTxInIds.includes(currentTxInId)) {
|
|
1720
|
+
referenceInputs.splice(i, 1);
|
|
1721
|
+
i -= 1;
|
|
1722
|
+
} else {
|
|
1723
|
+
addedInputs.push(currentInput);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
this.meshTxBuilderBody.referenceInputs = addedInputs;
|
|
1727
|
+
};
|
|
1714
1728
|
emptyTxBuilderBody = () => {
|
|
1715
1729
|
this.meshTxBuilderBody = (0, import_common.emptyTxBuilderBody)();
|
|
1716
1730
|
return import_common.emptyTxBuilderBody;
|
|
@@ -1766,16 +1780,16 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1766
1780
|
verbose = false
|
|
1767
1781
|
} = {}) {
|
|
1768
1782
|
super();
|
|
1783
|
+
if (fetcher) this.fetcher = fetcher;
|
|
1784
|
+
if (submitter) this.submitter = submitter;
|
|
1785
|
+
if (evaluator) this.evaluator = evaluator;
|
|
1786
|
+
if (params) this.protocolParams(params);
|
|
1769
1787
|
if (serializer) {
|
|
1770
1788
|
this.serializer = serializer;
|
|
1771
1789
|
} else {
|
|
1772
|
-
this.serializer = new import_core_cst.CardanoSDKSerializer();
|
|
1790
|
+
this.serializer = new import_core_cst.CardanoSDKSerializer(this._protocolParams);
|
|
1773
1791
|
}
|
|
1774
1792
|
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
1793
|
if (isHydra)
|
|
1780
1794
|
this.protocolParams({
|
|
1781
1795
|
minFeeA: 0,
|
|
@@ -1789,93 +1803,45 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1789
1803
|
/**
|
|
1790
1804
|
* It builds the transaction and query the blockchain for missing information
|
|
1791
1805
|
* @param customizedTx The optional customized transaction body
|
|
1792
|
-
* @returns The
|
|
1806
|
+
* @returns The transaction in hex ready to submit / signed by client
|
|
1793
1807
|
*/
|
|
1794
1808
|
complete = async (customizedTx) => {
|
|
1809
|
+
const txHex = await this.completeSerialization(customizedTx, true);
|
|
1810
|
+
return txHex;
|
|
1811
|
+
};
|
|
1812
|
+
/**
|
|
1813
|
+
* It builds the transaction query the blockchain for missing information
|
|
1814
|
+
* @param customizedTx The optional customized transaction body
|
|
1815
|
+
* @returns The transaction in hex, unbalanced
|
|
1816
|
+
*/
|
|
1817
|
+
completeUnbalanced = async (customizedTx) => {
|
|
1818
|
+
const txHex = await this.completeSerialization(customizedTx, false);
|
|
1819
|
+
return txHex;
|
|
1820
|
+
};
|
|
1821
|
+
/**
|
|
1822
|
+
* It builds the transaction without dependencies
|
|
1823
|
+
* @param customizedTx The optional customized transaction body
|
|
1824
|
+
* @returns The transaction in hex ready to submit / signed by client
|
|
1825
|
+
*/
|
|
1826
|
+
completeSync = (customizedTx) => {
|
|
1795
1827
|
if (customizedTx) {
|
|
1796
|
-
this.meshTxBuilderBody =
|
|
1828
|
+
this.meshTxBuilderBody = customizedTx;
|
|
1797
1829
|
} else {
|
|
1798
1830
|
this.queueAllLastItem();
|
|
1799
1831
|
}
|
|
1800
|
-
this.removeDuplicateInputs();
|
|
1801
|
-
for (let collateral of this.meshTxBuilderBody.collaterals) {
|
|
1802
|
-
collateral.txIn.scriptSize = 0;
|
|
1803
|
-
}
|
|
1804
|
-
const { inputs, collaterals, mints } = this.meshTxBuilderBody;
|
|
1805
|
-
const incompleteTxIns = [...inputs, ...collaterals].filter(
|
|
1806
|
-
(txIn) => !this.isInputComplete(txIn)
|
|
1807
|
-
);
|
|
1808
|
-
const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
|
|
1809
|
-
await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
|
|
1810
|
-
incompleteTxIns.forEach((txIn) => {
|
|
1811
|
-
this.completeTxInformation(txIn);
|
|
1812
|
-
});
|
|
1813
|
-
incompleteMints.forEach((mint) => {
|
|
1814
|
-
if (mint.type === "Plutus") {
|
|
1815
|
-
const scriptSource = mint.scriptSource;
|
|
1816
|
-
this.completeScriptInfo(scriptSource);
|
|
1817
|
-
}
|
|
1818
|
-
if (mint.type === "Native") {
|
|
1819
|
-
const scriptSource = mint.scriptSource;
|
|
1820
|
-
this.completeSimpleScriptInfo(scriptSource);
|
|
1821
|
-
}
|
|
1822
|
-
});
|
|
1823
|
-
this.meshTxBuilderBody.inputs.forEach((input) => {
|
|
1824
|
-
if (input.txIn.scriptSize && input.txIn.scriptSize > 0) {
|
|
1825
|
-
if (this.meshTxBuilderBody.referenceInputs.find((refTxIn) => {
|
|
1826
|
-
refTxIn.txHash === input.txIn.txHash && refTxIn.txIndex === input.txIn.txIndex;
|
|
1827
|
-
}) === void 0) {
|
|
1828
|
-
this.meshTxBuilderBody.referenceInputs.push({
|
|
1829
|
-
txHash: input.txIn.txHash,
|
|
1830
|
-
txIndex: input.txIn.txIndex,
|
|
1831
|
-
scriptSize: input.txIn.scriptSize
|
|
1832
|
-
});
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
});
|
|
1836
1832
|
this.addUtxosFromSelection();
|
|
1837
|
-
this.
|
|
1838
|
-
if (a.txIn.txHash < b.txIn.txHash) return -1;
|
|
1839
|
-
if (a.txIn.txHash > b.txIn.txHash) return 1;
|
|
1840
|
-
if (a.txIn.txIndex < b.txIn.txIndex) return -1;
|
|
1841
|
-
if (a.txIn.txIndex > b.txIn.txIndex) return 1;
|
|
1842
|
-
return 0;
|
|
1843
|
-
});
|
|
1844
|
-
this.meshTxBuilderBody.mints.sort((a, b) => {
|
|
1845
|
-
if (a.policyId < b.policyId) return -1;
|
|
1846
|
-
if (a.policyId > b.policyId) return 1;
|
|
1847
|
-
if (a.assetName < b.assetName) return -1;
|
|
1848
|
-
if (a.assetName > b.assetName) return 1;
|
|
1849
|
-
return 0;
|
|
1850
|
-
});
|
|
1851
|
-
let txHex = this.serializer.serializeTxBody(
|
|
1833
|
+
return this.serializer.serializeTxBody(
|
|
1852
1834
|
this.meshTxBuilderBody,
|
|
1853
|
-
this._protocolParams
|
|
1835
|
+
this._protocolParams,
|
|
1836
|
+
true
|
|
1854
1837
|
);
|
|
1855
|
-
if (this.evaluator) {
|
|
1856
|
-
const txEvaluation = await this.evaluator.evaluateTx(
|
|
1857
|
-
txHex,
|
|
1858
|
-
Object.values(this.meshTxBuilderBody.inputsForEvaluation),
|
|
1859
|
-
this.meshTxBuilderBody.chainedTxs
|
|
1860
|
-
).catch((error) => {
|
|
1861
|
-
throw Error(`Tx evaluation failed: ${error}
|
|
1862
|
-
For txHex: ${txHex}`);
|
|
1863
|
-
});
|
|
1864
|
-
this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
|
|
1865
|
-
txHex = this.serializer.serializeTxBody(
|
|
1866
|
-
this.meshTxBuilderBody,
|
|
1867
|
-
this._protocolParams
|
|
1868
|
-
);
|
|
1869
|
-
}
|
|
1870
|
-
this.txHex = txHex;
|
|
1871
|
-
return txHex;
|
|
1872
1838
|
};
|
|
1873
1839
|
/**
|
|
1874
1840
|
* It builds the transaction without dependencies
|
|
1875
1841
|
* @param customizedTx The optional customized transaction body
|
|
1876
|
-
* @returns The
|
|
1842
|
+
* @returns The transaction in hex, unbalanced
|
|
1877
1843
|
*/
|
|
1878
|
-
|
|
1844
|
+
completeUnbalancedSync = (customizedTx) => {
|
|
1879
1845
|
if (customizedTx) {
|
|
1880
1846
|
this.meshTxBuilderBody = customizedTx;
|
|
1881
1847
|
} else {
|
|
@@ -1884,7 +1850,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1884
1850
|
this.addUtxosFromSelection();
|
|
1885
1851
|
return this.serializer.serializeTxBody(
|
|
1886
1852
|
this.meshTxBuilderBody,
|
|
1887
|
-
this._protocolParams
|
|
1853
|
+
this._protocolParams,
|
|
1854
|
+
false
|
|
1888
1855
|
);
|
|
1889
1856
|
};
|
|
1890
1857
|
/**
|
|
@@ -1920,9 +1887,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1920
1887
|
this.queriedUTxOs[txHash] = utxos;
|
|
1921
1888
|
}
|
|
1922
1889
|
};
|
|
1923
|
-
queryAllTxInfo = (incompleteTxIns,
|
|
1890
|
+
queryAllTxInfo = (incompleteTxIns, incompleteScriptSources, incompleteSimpleScriptSources) => {
|
|
1924
1891
|
const queryUTxOPromises = [];
|
|
1925
|
-
if ((incompleteTxIns.length > 0 ||
|
|
1892
|
+
if ((incompleteTxIns.length > 0 || incompleteScriptSources.length > 0 || incompleteSimpleScriptSources.length) && !this.fetcher)
|
|
1926
1893
|
throw Error(
|
|
1927
1894
|
"Transaction information is incomplete while no fetcher instance is provided. Provide a `fetcher`."
|
|
1928
1895
|
);
|
|
@@ -1931,21 +1898,11 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1931
1898
|
if (!this.isInputInfoComplete(currentTxIn)) {
|
|
1932
1899
|
queryUTxOPromises.push(this.getUTxOInfo(currentTxIn.txIn.txHash));
|
|
1933
1900
|
}
|
|
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
1901
|
}
|
|
1940
|
-
for (let i = 0; i <
|
|
1941
|
-
const
|
|
1942
|
-
if (
|
|
1943
|
-
|
|
1944
|
-
if (scriptSource.type === "Inline") {
|
|
1945
|
-
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
1946
|
-
queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
|
|
1947
|
-
}
|
|
1948
|
-
}
|
|
1902
|
+
for (let i = 0; i < incompleteScriptSources.length; i++) {
|
|
1903
|
+
const scriptSource = incompleteScriptSources[i];
|
|
1904
|
+
if (scriptSource.type === "Inline") {
|
|
1905
|
+
queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
|
|
1949
1906
|
}
|
|
1950
1907
|
}
|
|
1951
1908
|
return Promise.all(queryUTxOPromises);
|
|
@@ -2039,6 +1996,182 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
2039
1996
|
}
|
|
2040
1997
|
return true;
|
|
2041
1998
|
};
|
|
1999
|
+
isSimpleRefScriptInfoComplete = (simpleScriptSource) => {
|
|
2000
|
+
if (simpleScriptSource.type === "Inline") {
|
|
2001
|
+
if (!simpleScriptSource.simpleScriptHash || !simpleScriptSource.scriptSize)
|
|
2002
|
+
return false;
|
|
2003
|
+
}
|
|
2004
|
+
return true;
|
|
2005
|
+
};
|
|
2006
|
+
completeSerialization = async (customizedTx, balanced = true) => {
|
|
2007
|
+
if (customizedTx) {
|
|
2008
|
+
this.meshTxBuilderBody = { ...this.meshTxBuilderBody, ...customizedTx };
|
|
2009
|
+
} else {
|
|
2010
|
+
this.queueAllLastItem();
|
|
2011
|
+
}
|
|
2012
|
+
this.removeDuplicateInputs();
|
|
2013
|
+
this.removeDuplicateRefInputs();
|
|
2014
|
+
for (let collateral of this.meshTxBuilderBody.collaterals) {
|
|
2015
|
+
collateral.txIn.scriptSize = 0;
|
|
2016
|
+
}
|
|
2017
|
+
const { inputs, collaterals, mints, withdrawals, votes, certificates } = this.meshTxBuilderBody;
|
|
2018
|
+
const incompleteTxIns = [...inputs, ...collaterals].filter(
|
|
2019
|
+
(txIn) => !this.isInputComplete(txIn)
|
|
2020
|
+
);
|
|
2021
|
+
let incompleteScriptSources = [];
|
|
2022
|
+
let incompleteSimpleScriptSources = [];
|
|
2023
|
+
inputs.forEach((txIn) => {
|
|
2024
|
+
if (txIn.type === "Script" && txIn.scriptTxIn.scriptSource?.type === "Inline") {
|
|
2025
|
+
if (!this.isRefScriptInfoComplete(txIn.scriptTxIn.scriptSource)) {
|
|
2026
|
+
incompleteScriptSources.push(txIn.scriptTxIn.scriptSource);
|
|
2027
|
+
}
|
|
2028
|
+
} else if (txIn.type === "SimpleScript" && txIn.simpleScriptTxIn?.scriptSource?.type === "Inline") {
|
|
2029
|
+
if (!this.isSimpleRefScriptInfoComplete(
|
|
2030
|
+
txIn.simpleScriptTxIn.scriptSource
|
|
2031
|
+
)) {
|
|
2032
|
+
incompleteSimpleScriptSources.push(
|
|
2033
|
+
txIn.simpleScriptTxIn.scriptSource
|
|
2034
|
+
);
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
});
|
|
2038
|
+
mints.forEach((mint) => {
|
|
2039
|
+
if (mint.type === "Plutus") {
|
|
2040
|
+
const scriptSource = mint.scriptSource;
|
|
2041
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
2042
|
+
incompleteScriptSources.push(scriptSource);
|
|
2043
|
+
}
|
|
2044
|
+
} else if (mint.type === "Native") {
|
|
2045
|
+
const scriptSource = mint.scriptSource;
|
|
2046
|
+
if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
|
|
2047
|
+
incompleteSimpleScriptSources.push(scriptSource);
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
});
|
|
2051
|
+
withdrawals.forEach((withdrawal) => {
|
|
2052
|
+
if (withdrawal.type === "ScriptWithdrawal") {
|
|
2053
|
+
const scriptSource = withdrawal.scriptSource;
|
|
2054
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
2055
|
+
incompleteScriptSources.push(scriptSource);
|
|
2056
|
+
}
|
|
2057
|
+
} else if (withdrawal.type === "SimpleScriptWithdrawal") {
|
|
2058
|
+
const scriptSource = withdrawal.scriptSource;
|
|
2059
|
+
if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
|
|
2060
|
+
incompleteSimpleScriptSources.push(scriptSource);
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
});
|
|
2064
|
+
votes.forEach((vote) => {
|
|
2065
|
+
if (vote.type === "ScriptVote") {
|
|
2066
|
+
const scriptSource = vote.scriptSource;
|
|
2067
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
2068
|
+
incompleteScriptSources.push(scriptSource);
|
|
2069
|
+
}
|
|
2070
|
+
} else if (vote.type === "SimpleScriptVote") {
|
|
2071
|
+
const scriptSource = vote.simpleScriptSource;
|
|
2072
|
+
if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
|
|
2073
|
+
incompleteSimpleScriptSources.push(scriptSource);
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
});
|
|
2077
|
+
certificates.forEach((certificate) => {
|
|
2078
|
+
if (certificate.type === "ScriptCertificate") {
|
|
2079
|
+
const scriptSource = certificate.scriptSource;
|
|
2080
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
2081
|
+
incompleteScriptSources.push(scriptSource);
|
|
2082
|
+
}
|
|
2083
|
+
} else if (certificate.type === "SimpleScriptCertificate") {
|
|
2084
|
+
const scriptSource = certificate.simpleScriptSource;
|
|
2085
|
+
if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
|
|
2086
|
+
incompleteSimpleScriptSources.push(scriptSource);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
});
|
|
2090
|
+
await this.queryAllTxInfo(
|
|
2091
|
+
incompleteTxIns,
|
|
2092
|
+
incompleteScriptSources,
|
|
2093
|
+
incompleteSimpleScriptSources
|
|
2094
|
+
);
|
|
2095
|
+
incompleteTxIns.forEach((txIn) => {
|
|
2096
|
+
this.completeTxInformation(txIn);
|
|
2097
|
+
});
|
|
2098
|
+
incompleteScriptSources.forEach((scriptSource) => {
|
|
2099
|
+
this.completeScriptInfo(scriptSource);
|
|
2100
|
+
});
|
|
2101
|
+
incompleteSimpleScriptSources.forEach((simpleScriptSource) => {
|
|
2102
|
+
this.completeSimpleScriptInfo(simpleScriptSource);
|
|
2103
|
+
});
|
|
2104
|
+
this.meshTxBuilderBody.inputs.forEach((input) => {
|
|
2105
|
+
if (input.txIn.scriptSize && input.txIn.scriptSize > 0) {
|
|
2106
|
+
if (this.meshTxBuilderBody.referenceInputs.find((refTxIn) => {
|
|
2107
|
+
refTxIn.txHash === input.txIn.txHash && refTxIn.txIndex === input.txIn.txIndex;
|
|
2108
|
+
}) === void 0) {
|
|
2109
|
+
this.meshTxBuilderBody.referenceInputs.push({
|
|
2110
|
+
txHash: input.txIn.txHash,
|
|
2111
|
+
txIndex: input.txIn.txIndex,
|
|
2112
|
+
scriptSize: input.txIn.scriptSize
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
});
|
|
2117
|
+
this.addUtxosFromSelection();
|
|
2118
|
+
this.meshTxBuilderBody.inputs.sort((a, b) => {
|
|
2119
|
+
if (a.txIn.txHash < b.txIn.txHash) return -1;
|
|
2120
|
+
if (a.txIn.txHash > b.txIn.txHash) return 1;
|
|
2121
|
+
if (a.txIn.txIndex < b.txIn.txIndex) return -1;
|
|
2122
|
+
if (a.txIn.txIndex > b.txIn.txIndex) return 1;
|
|
2123
|
+
return 0;
|
|
2124
|
+
});
|
|
2125
|
+
this.meshTxBuilderBody.mints.sort((a, b) => {
|
|
2126
|
+
if (a.policyId < b.policyId) return -1;
|
|
2127
|
+
if (a.policyId > b.policyId) return 1;
|
|
2128
|
+
if (a.assetName < b.assetName) return -1;
|
|
2129
|
+
if (a.assetName > b.assetName) return 1;
|
|
2130
|
+
return 0;
|
|
2131
|
+
});
|
|
2132
|
+
let txHex = this.serializer.serializeTxBody(
|
|
2133
|
+
this.meshTxBuilderBody,
|
|
2134
|
+
this._protocolParams,
|
|
2135
|
+
balanced
|
|
2136
|
+
);
|
|
2137
|
+
if (this.evaluator) {
|
|
2138
|
+
const txEvaluation = await this.evaluator.evaluateTx(
|
|
2139
|
+
txHex,
|
|
2140
|
+
Object.values(this.meshTxBuilderBody.inputsForEvaluation),
|
|
2141
|
+
this.meshTxBuilderBody.chainedTxs
|
|
2142
|
+
).catch((error) => {
|
|
2143
|
+
if (error instanceof Error) {
|
|
2144
|
+
throw new Error(
|
|
2145
|
+
`Tx evaluation failed: ${error.message}
|
|
2146
|
+
For txHex: ${txHex}`
|
|
2147
|
+
);
|
|
2148
|
+
} else if (typeof error === "string") {
|
|
2149
|
+
throw new Error(
|
|
2150
|
+
`Tx evaluation failed: ${error}
|
|
2151
|
+
For txHex: ${txHex}`
|
|
2152
|
+
);
|
|
2153
|
+
} else if (typeof error === "object") {
|
|
2154
|
+
throw new Error(
|
|
2155
|
+
`Tx evaluation failed: ${JSON.stringify(error)}
|
|
2156
|
+
For txHex: ${txHex}`
|
|
2157
|
+
);
|
|
2158
|
+
} else {
|
|
2159
|
+
throw new Error(
|
|
2160
|
+
`Tx evaluation failed: ${String(error)}
|
|
2161
|
+
For txHex: ${txHex}`
|
|
2162
|
+
);
|
|
2163
|
+
}
|
|
2164
|
+
});
|
|
2165
|
+
this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
|
|
2166
|
+
txHex = this.serializer.serializeTxBody(
|
|
2167
|
+
this.meshTxBuilderBody,
|
|
2168
|
+
this._protocolParams,
|
|
2169
|
+
balanced
|
|
2170
|
+
);
|
|
2171
|
+
}
|
|
2172
|
+
this.txHex = txHex;
|
|
2173
|
+
return txHex;
|
|
2174
|
+
};
|
|
2042
2175
|
};
|
|
2043
2176
|
|
|
2044
2177
|
// src/scripts/forge.script.ts
|
|
@@ -2298,7 +2431,8 @@ var Transaction = class {
|
|
|
2298
2431
|
value.input.txHash,
|
|
2299
2432
|
value.input.outputIndex,
|
|
2300
2433
|
value.output.amount,
|
|
2301
|
-
value.output.address
|
|
2434
|
+
value.output.address,
|
|
2435
|
+
value.output.scriptRef ? value.output.scriptRef.length / 2 : 0
|
|
2302
2436
|
).txInScript(script.code).txInRedeemerValue(red.data, "Mesh", red.budget);
|
|
2303
2437
|
}
|
|
2304
2438
|
if ("output" in script) {
|
|
@@ -2546,7 +2680,7 @@ var Transaction = class {
|
|
|
2546
2680
|
delegateStake(rewardAddress, poolId) {
|
|
2547
2681
|
this.txBuilder.delegateStakeCertificate(
|
|
2548
2682
|
rewardAddress,
|
|
2549
|
-
this.txBuilder.serializer.
|
|
2683
|
+
this.txBuilder.serializer.deserializer.cert.deserializePoolId(poolId)
|
|
2550
2684
|
);
|
|
2551
2685
|
return this;
|
|
2552
2686
|
}
|
|
@@ -2568,12 +2702,16 @@ var Transaction = class {
|
|
|
2568
2702
|
this.txBuilder.retirePoolCertificate(poolId, epochNo);
|
|
2569
2703
|
return this;
|
|
2570
2704
|
}
|
|
2571
|
-
async build() {
|
|
2705
|
+
async build(balanced = true) {
|
|
2572
2706
|
try {
|
|
2573
2707
|
await this.addCollateralIfNeeded();
|
|
2574
2708
|
await this.addTxInputsAsNeeded();
|
|
2575
2709
|
await this.addChangeAddress();
|
|
2576
|
-
|
|
2710
|
+
if (balanced) {
|
|
2711
|
+
return this.txBuilder.complete();
|
|
2712
|
+
} else {
|
|
2713
|
+
return this.txBuilder.completeUnbalanced();
|
|
2714
|
+
}
|
|
2577
2715
|
} catch (error) {
|
|
2578
2716
|
throw new Error(
|
|
2579
2717
|
`[Transaction] An error occurred during build: ${error}.`
|
package/dist/index.d.cts
CHANGED
|
@@ -509,6 +509,7 @@ declare class MeshTxBuilderCore {
|
|
|
509
509
|
protected updateRedeemer: (meshTxBuilderBody: MeshTxBuilderBody, txEvaluation: Omit<Action, "data">[]) => void;
|
|
510
510
|
addUtxosFromSelection: () => void;
|
|
511
511
|
removeDuplicateInputs: () => void;
|
|
512
|
+
removeDuplicateRefInputs: () => void;
|
|
512
513
|
emptyTxBuilderBody: () => () => MeshTxBuilderBody;
|
|
513
514
|
reset: () => void;
|
|
514
515
|
}
|
|
@@ -544,15 +545,27 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
544
545
|
/**
|
|
545
546
|
* It builds the transaction and query the blockchain for missing information
|
|
546
547
|
* @param customizedTx The optional customized transaction body
|
|
547
|
-
* @returns The
|
|
548
|
+
* @returns The transaction in hex ready to submit / signed by client
|
|
548
549
|
*/
|
|
549
550
|
complete: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
|
|
551
|
+
/**
|
|
552
|
+
* It builds the transaction query the blockchain for missing information
|
|
553
|
+
* @param customizedTx The optional customized transaction body
|
|
554
|
+
* @returns The transaction in hex, unbalanced
|
|
555
|
+
*/
|
|
556
|
+
completeUnbalanced: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
|
|
550
557
|
/**
|
|
551
558
|
* It builds the transaction without dependencies
|
|
552
559
|
* @param customizedTx The optional customized transaction body
|
|
553
|
-
* @returns The
|
|
560
|
+
* @returns The transaction in hex ready to submit / signed by client
|
|
554
561
|
*/
|
|
555
562
|
completeSync: (customizedTx?: MeshTxBuilderBody) => string;
|
|
563
|
+
/**
|
|
564
|
+
* It builds the transaction without dependencies
|
|
565
|
+
* @param customizedTx The optional customized transaction body
|
|
566
|
+
* @returns The transaction in hex, unbalanced
|
|
567
|
+
*/
|
|
568
|
+
completeUnbalancedSync: (customizedTx?: MeshTxBuilderBody) => string;
|
|
556
569
|
/**
|
|
557
570
|
* Complete the signing process
|
|
558
571
|
* @returns The signed transaction in hex
|
|
@@ -569,7 +582,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
569
582
|
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
570
583
|
*/
|
|
571
584
|
protected getUTxOInfo: (txHash: string) => Promise<void>;
|
|
572
|
-
protected queryAllTxInfo: (incompleteTxIns: TxIn[],
|
|
585
|
+
protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteScriptSources: ScriptSource[], incompleteSimpleScriptSources: SimpleScriptSourceInfo[]) => Promise<void[]>;
|
|
573
586
|
protected completeTxInformation: (input: TxIn) => void;
|
|
574
587
|
protected completeInputInfo: (input: TxIn) => void;
|
|
575
588
|
protected completeScriptInfo: (scriptSource: ScriptSource) => void;
|
|
@@ -578,6 +591,8 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
578
591
|
protected isInputInfoComplete: (txIn: TxIn) => boolean;
|
|
579
592
|
protected isMintComplete: (mint: MintItem) => boolean;
|
|
580
593
|
protected isRefScriptInfoComplete: (scriptSource: ScriptSource) => boolean;
|
|
594
|
+
protected isSimpleRefScriptInfoComplete: (simpleScriptSource: SimpleScriptSourceInfo) => boolean;
|
|
595
|
+
protected completeSerialization: (customizedTx?: Partial<MeshTxBuilderBody>, balanced?: Boolean) => Promise<string>;
|
|
581
596
|
}
|
|
582
597
|
|
|
583
598
|
declare class ForgeScript {
|
|
@@ -747,7 +762,7 @@ declare class Transaction {
|
|
|
747
762
|
registerStake(rewardAddress: string): Transaction;
|
|
748
763
|
registerPool(params: PoolParams): Transaction;
|
|
749
764
|
retirePool(poolId: string, epochNo: number): Transaction;
|
|
750
|
-
build(): Promise<string>;
|
|
765
|
+
build(balanced?: Boolean): Promise<string>;
|
|
751
766
|
protected mintPlutusScript(script: PlutusScript): MeshTxBuilder;
|
|
752
767
|
protected spendingPlutusScript(script: PlutusScript): MeshTxBuilder;
|
|
753
768
|
private addCollateralIfNeeded;
|
package/dist/index.d.ts
CHANGED
|
@@ -509,6 +509,7 @@ declare class MeshTxBuilderCore {
|
|
|
509
509
|
protected updateRedeemer: (meshTxBuilderBody: MeshTxBuilderBody, txEvaluation: Omit<Action, "data">[]) => void;
|
|
510
510
|
addUtxosFromSelection: () => void;
|
|
511
511
|
removeDuplicateInputs: () => void;
|
|
512
|
+
removeDuplicateRefInputs: () => void;
|
|
512
513
|
emptyTxBuilderBody: () => () => MeshTxBuilderBody;
|
|
513
514
|
reset: () => void;
|
|
514
515
|
}
|
|
@@ -544,15 +545,27 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
544
545
|
/**
|
|
545
546
|
* It builds the transaction and query the blockchain for missing information
|
|
546
547
|
* @param customizedTx The optional customized transaction body
|
|
547
|
-
* @returns The
|
|
548
|
+
* @returns The transaction in hex ready to submit / signed by client
|
|
548
549
|
*/
|
|
549
550
|
complete: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
|
|
551
|
+
/**
|
|
552
|
+
* It builds the transaction query the blockchain for missing information
|
|
553
|
+
* @param customizedTx The optional customized transaction body
|
|
554
|
+
* @returns The transaction in hex, unbalanced
|
|
555
|
+
*/
|
|
556
|
+
completeUnbalanced: (customizedTx?: Partial<MeshTxBuilderBody>) => Promise<string>;
|
|
550
557
|
/**
|
|
551
558
|
* It builds the transaction without dependencies
|
|
552
559
|
* @param customizedTx The optional customized transaction body
|
|
553
|
-
* @returns The
|
|
560
|
+
* @returns The transaction in hex ready to submit / signed by client
|
|
554
561
|
*/
|
|
555
562
|
completeSync: (customizedTx?: MeshTxBuilderBody) => string;
|
|
563
|
+
/**
|
|
564
|
+
* It builds the transaction without dependencies
|
|
565
|
+
* @param customizedTx The optional customized transaction body
|
|
566
|
+
* @returns The transaction in hex, unbalanced
|
|
567
|
+
*/
|
|
568
|
+
completeUnbalancedSync: (customizedTx?: MeshTxBuilderBody) => string;
|
|
556
569
|
/**
|
|
557
570
|
* Complete the signing process
|
|
558
571
|
* @returns The signed transaction in hex
|
|
@@ -569,7 +582,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
569
582
|
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
570
583
|
*/
|
|
571
584
|
protected getUTxOInfo: (txHash: string) => Promise<void>;
|
|
572
|
-
protected queryAllTxInfo: (incompleteTxIns: TxIn[],
|
|
585
|
+
protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteScriptSources: ScriptSource[], incompleteSimpleScriptSources: SimpleScriptSourceInfo[]) => Promise<void[]>;
|
|
573
586
|
protected completeTxInformation: (input: TxIn) => void;
|
|
574
587
|
protected completeInputInfo: (input: TxIn) => void;
|
|
575
588
|
protected completeScriptInfo: (scriptSource: ScriptSource) => void;
|
|
@@ -578,6 +591,8 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
578
591
|
protected isInputInfoComplete: (txIn: TxIn) => boolean;
|
|
579
592
|
protected isMintComplete: (mint: MintItem) => boolean;
|
|
580
593
|
protected isRefScriptInfoComplete: (scriptSource: ScriptSource) => boolean;
|
|
594
|
+
protected isSimpleRefScriptInfoComplete: (simpleScriptSource: SimpleScriptSourceInfo) => boolean;
|
|
595
|
+
protected completeSerialization: (customizedTx?: Partial<MeshTxBuilderBody>, balanced?: Boolean) => Promise<string>;
|
|
581
596
|
}
|
|
582
597
|
|
|
583
598
|
declare class ForgeScript {
|
|
@@ -747,7 +762,7 @@ declare class Transaction {
|
|
|
747
762
|
registerStake(rewardAddress: string): Transaction;
|
|
748
763
|
registerPool(params: PoolParams): Transaction;
|
|
749
764
|
retirePool(poolId: string, epochNo: number): Transaction;
|
|
750
|
-
build(): Promise<string>;
|
|
765
|
+
build(balanced?: Boolean): Promise<string>;
|
|
751
766
|
protected mintPlutusScript(script: PlutusScript): MeshTxBuilder;
|
|
752
767
|
protected spendingPlutusScript(script: PlutusScript): MeshTxBuilder;
|
|
753
768
|
private addCollateralIfNeeded;
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
DEFAULT_REDEEMER_BUDGET,
|
|
9
9
|
DREP_DEPOSIT,
|
|
10
10
|
emptyTxBuilderBody,
|
|
11
|
-
txInToUtxo,
|
|
12
11
|
UtxoSelection
|
|
13
12
|
} from "@meshsdk/common";
|
|
14
13
|
|
|
@@ -766,6 +765,7 @@ var MeshTxBuilderCore = class {
|
|
|
766
765
|
coin
|
|
767
766
|
};
|
|
768
767
|
this.withdrawalItem = withdrawal2;
|
|
768
|
+
this.addingPlutusWithdrawal = false;
|
|
769
769
|
return this;
|
|
770
770
|
}
|
|
771
771
|
const withdrawal = {
|
|
@@ -909,6 +909,7 @@ var MeshTxBuilderCore = class {
|
|
|
909
909
|
}
|
|
910
910
|
};
|
|
911
911
|
this.voteItem = vote;
|
|
912
|
+
this.addingPlutusVote = false;
|
|
912
913
|
} else {
|
|
913
914
|
const vote = {
|
|
914
915
|
type: "BasicVote",
|
|
@@ -1222,7 +1223,8 @@ var MeshTxBuilderCore = class {
|
|
|
1222
1223
|
txHash,
|
|
1223
1224
|
txIndex,
|
|
1224
1225
|
scriptHash,
|
|
1225
|
-
scriptSize
|
|
1226
|
+
scriptSize,
|
|
1227
|
+
version
|
|
1226
1228
|
},
|
|
1227
1229
|
redeemer: currentCert.type === "ScriptCertificate" ? currentCert.redeemer : void 0
|
|
1228
1230
|
});
|
|
@@ -1367,24 +1369,17 @@ var MeshTxBuilderCore = class {
|
|
|
1367
1369
|
const utxoId = `${input.input.txHash}${input.input.outputIndex}`;
|
|
1368
1370
|
const currentUtxo = this.meshTxBuilderBody.inputsForEvaluation[utxoId];
|
|
1369
1371
|
if (currentUtxo) {
|
|
1370
|
-
const { address, amount, dataHash, plutusData, scriptRef, scriptHash } = input.output;
|
|
1371
1372
|
const {
|
|
1372
1373
|
dataHash: currentDataHash,
|
|
1373
1374
|
plutusData: currentPlutusData,
|
|
1374
1375
|
scriptRef: currentScriptRef,
|
|
1375
1376
|
scriptHash: currentScriptHash
|
|
1376
1377
|
} = currentUtxo.output;
|
|
1377
|
-
const updatedUtxo = {
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
dataHash: dataHash ?? currentDataHash,
|
|
1383
|
-
plutusData: plutusData ?? currentPlutusData,
|
|
1384
|
-
scriptRef: scriptRef ?? currentScriptRef,
|
|
1385
|
-
scriptHash: scriptHash ?? currentScriptHash
|
|
1386
|
-
}
|
|
1387
|
-
};
|
|
1378
|
+
const updatedUtxo = { ...currentUtxo };
|
|
1379
|
+
if (currentDataHash) updatedUtxo.output.dataHash = currentDataHash;
|
|
1380
|
+
if (currentPlutusData) updatedUtxo.output.plutusData = currentPlutusData;
|
|
1381
|
+
if (currentScriptRef) updatedUtxo.output.scriptRef = currentScriptRef;
|
|
1382
|
+
if (currentScriptHash) updatedUtxo.output.scriptHash = currentScriptHash;
|
|
1388
1383
|
this.meshTxBuilderBody.inputsForEvaluation[utxoId] = updatedUtxo;
|
|
1389
1384
|
} else {
|
|
1390
1385
|
this.meshTxBuilderBody.inputsForEvaluation[utxoId] = input;
|
|
@@ -1436,7 +1431,6 @@ var MeshTxBuilderCore = class {
|
|
|
1436
1431
|
}
|
|
1437
1432
|
}
|
|
1438
1433
|
this.meshTxBuilderBody.inputs.push(this.txInQueueItem);
|
|
1439
|
-
this.inputForEvaluation(txInToUtxo(this.txInQueueItem.txIn));
|
|
1440
1434
|
this.txInQueueItem = void 0;
|
|
1441
1435
|
};
|
|
1442
1436
|
queueMint = () => {
|
|
@@ -1516,6 +1510,7 @@ var MeshTxBuilderCore = class {
|
|
|
1516
1510
|
return red;
|
|
1517
1511
|
};
|
|
1518
1512
|
updateRedeemer = (meshTxBuilderBody, txEvaluation) => {
|
|
1513
|
+
let mintIndex = 0;
|
|
1519
1514
|
txEvaluation.forEach((redeemerEvaluation) => {
|
|
1520
1515
|
switch (redeemerEvaluation.tag) {
|
|
1521
1516
|
case "SPEND": {
|
|
@@ -1531,7 +1526,7 @@ var MeshTxBuilderCore = class {
|
|
|
1531
1526
|
break;
|
|
1532
1527
|
}
|
|
1533
1528
|
case "MINT": {
|
|
1534
|
-
const mint = meshTxBuilderBody.mints[
|
|
1529
|
+
const mint = meshTxBuilderBody.mints[mintIndex];
|
|
1535
1530
|
if (mint.type == "Plutus" && mint.redeemer) {
|
|
1536
1531
|
let newExUnits = {
|
|
1537
1532
|
mem: Math.floor(
|
|
@@ -1544,6 +1539,7 @@ var MeshTxBuilderCore = class {
|
|
|
1544
1539
|
for (let i = redeemerEvaluation.index; i < meshTxBuilderBody.mints.length; i++) {
|
|
1545
1540
|
if (meshTxBuilderBody.mints[i].policyId === mint.policyId) {
|
|
1546
1541
|
meshTxBuilderBody.mints[i].redeemer.exUnits = newExUnits;
|
|
1542
|
+
mintIndex++;
|
|
1547
1543
|
}
|
|
1548
1544
|
}
|
|
1549
1545
|
}
|
|
@@ -1677,6 +1673,23 @@ var MeshTxBuilderCore = class {
|
|
|
1677
1673
|
}
|
|
1678
1674
|
this.meshTxBuilderBody.inputs = addedInputs;
|
|
1679
1675
|
};
|
|
1676
|
+
removeDuplicateRefInputs = () => {
|
|
1677
|
+
const { referenceInputs } = this.meshTxBuilderBody;
|
|
1678
|
+
const getTxInId = (txIn) => `${txIn.txHash}#${txIn.txIndex}`;
|
|
1679
|
+
const currentTxInIds = [];
|
|
1680
|
+
const addedInputs = [];
|
|
1681
|
+
for (let i = 0; i < referenceInputs.length; i += 1) {
|
|
1682
|
+
const currentInput = referenceInputs[i];
|
|
1683
|
+
const currentTxInId = getTxInId(currentInput);
|
|
1684
|
+
if (currentTxInIds.includes(currentTxInId)) {
|
|
1685
|
+
referenceInputs.splice(i, 1);
|
|
1686
|
+
i -= 1;
|
|
1687
|
+
} else {
|
|
1688
|
+
addedInputs.push(currentInput);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
this.meshTxBuilderBody.referenceInputs = addedInputs;
|
|
1692
|
+
};
|
|
1680
1693
|
emptyTxBuilderBody = () => {
|
|
1681
1694
|
this.meshTxBuilderBody = emptyTxBuilderBody();
|
|
1682
1695
|
return emptyTxBuilderBody;
|
|
@@ -1732,16 +1745,16 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1732
1745
|
verbose = false
|
|
1733
1746
|
} = {}) {
|
|
1734
1747
|
super();
|
|
1748
|
+
if (fetcher) this.fetcher = fetcher;
|
|
1749
|
+
if (submitter) this.submitter = submitter;
|
|
1750
|
+
if (evaluator) this.evaluator = evaluator;
|
|
1751
|
+
if (params) this.protocolParams(params);
|
|
1735
1752
|
if (serializer) {
|
|
1736
1753
|
this.serializer = serializer;
|
|
1737
1754
|
} else {
|
|
1738
|
-
this.serializer = new CardanoSDKSerializer();
|
|
1755
|
+
this.serializer = new CardanoSDKSerializer(this._protocolParams);
|
|
1739
1756
|
}
|
|
1740
1757
|
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
1758
|
if (isHydra)
|
|
1746
1759
|
this.protocolParams({
|
|
1747
1760
|
minFeeA: 0,
|
|
@@ -1755,93 +1768,45 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1755
1768
|
/**
|
|
1756
1769
|
* It builds the transaction and query the blockchain for missing information
|
|
1757
1770
|
* @param customizedTx The optional customized transaction body
|
|
1758
|
-
* @returns The
|
|
1771
|
+
* @returns The transaction in hex ready to submit / signed by client
|
|
1759
1772
|
*/
|
|
1760
1773
|
complete = async (customizedTx) => {
|
|
1774
|
+
const txHex = await this.completeSerialization(customizedTx, true);
|
|
1775
|
+
return txHex;
|
|
1776
|
+
};
|
|
1777
|
+
/**
|
|
1778
|
+
* It builds the transaction query the blockchain for missing information
|
|
1779
|
+
* @param customizedTx The optional customized transaction body
|
|
1780
|
+
* @returns The transaction in hex, unbalanced
|
|
1781
|
+
*/
|
|
1782
|
+
completeUnbalanced = async (customizedTx) => {
|
|
1783
|
+
const txHex = await this.completeSerialization(customizedTx, false);
|
|
1784
|
+
return txHex;
|
|
1785
|
+
};
|
|
1786
|
+
/**
|
|
1787
|
+
* It builds the transaction without dependencies
|
|
1788
|
+
* @param customizedTx The optional customized transaction body
|
|
1789
|
+
* @returns The transaction in hex ready to submit / signed by client
|
|
1790
|
+
*/
|
|
1791
|
+
completeSync = (customizedTx) => {
|
|
1761
1792
|
if (customizedTx) {
|
|
1762
|
-
this.meshTxBuilderBody =
|
|
1793
|
+
this.meshTxBuilderBody = customizedTx;
|
|
1763
1794
|
} else {
|
|
1764
1795
|
this.queueAllLastItem();
|
|
1765
1796
|
}
|
|
1766
|
-
this.removeDuplicateInputs();
|
|
1767
|
-
for (let collateral of this.meshTxBuilderBody.collaterals) {
|
|
1768
|
-
collateral.txIn.scriptSize = 0;
|
|
1769
|
-
}
|
|
1770
|
-
const { inputs, collaterals, mints } = this.meshTxBuilderBody;
|
|
1771
|
-
const incompleteTxIns = [...inputs, ...collaterals].filter(
|
|
1772
|
-
(txIn) => !this.isInputComplete(txIn)
|
|
1773
|
-
);
|
|
1774
|
-
const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
|
|
1775
|
-
await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
|
|
1776
|
-
incompleteTxIns.forEach((txIn) => {
|
|
1777
|
-
this.completeTxInformation(txIn);
|
|
1778
|
-
});
|
|
1779
|
-
incompleteMints.forEach((mint) => {
|
|
1780
|
-
if (mint.type === "Plutus") {
|
|
1781
|
-
const scriptSource = mint.scriptSource;
|
|
1782
|
-
this.completeScriptInfo(scriptSource);
|
|
1783
|
-
}
|
|
1784
|
-
if (mint.type === "Native") {
|
|
1785
|
-
const scriptSource = mint.scriptSource;
|
|
1786
|
-
this.completeSimpleScriptInfo(scriptSource);
|
|
1787
|
-
}
|
|
1788
|
-
});
|
|
1789
|
-
this.meshTxBuilderBody.inputs.forEach((input) => {
|
|
1790
|
-
if (input.txIn.scriptSize && input.txIn.scriptSize > 0) {
|
|
1791
|
-
if (this.meshTxBuilderBody.referenceInputs.find((refTxIn) => {
|
|
1792
|
-
refTxIn.txHash === input.txIn.txHash && refTxIn.txIndex === input.txIn.txIndex;
|
|
1793
|
-
}) === void 0) {
|
|
1794
|
-
this.meshTxBuilderBody.referenceInputs.push({
|
|
1795
|
-
txHash: input.txIn.txHash,
|
|
1796
|
-
txIndex: input.txIn.txIndex,
|
|
1797
|
-
scriptSize: input.txIn.scriptSize
|
|
1798
|
-
});
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
});
|
|
1802
1797
|
this.addUtxosFromSelection();
|
|
1803
|
-
this.
|
|
1804
|
-
if (a.txIn.txHash < b.txIn.txHash) return -1;
|
|
1805
|
-
if (a.txIn.txHash > b.txIn.txHash) return 1;
|
|
1806
|
-
if (a.txIn.txIndex < b.txIn.txIndex) return -1;
|
|
1807
|
-
if (a.txIn.txIndex > b.txIn.txIndex) return 1;
|
|
1808
|
-
return 0;
|
|
1809
|
-
});
|
|
1810
|
-
this.meshTxBuilderBody.mints.sort((a, b) => {
|
|
1811
|
-
if (a.policyId < b.policyId) return -1;
|
|
1812
|
-
if (a.policyId > b.policyId) return 1;
|
|
1813
|
-
if (a.assetName < b.assetName) return -1;
|
|
1814
|
-
if (a.assetName > b.assetName) return 1;
|
|
1815
|
-
return 0;
|
|
1816
|
-
});
|
|
1817
|
-
let txHex = this.serializer.serializeTxBody(
|
|
1798
|
+
return this.serializer.serializeTxBody(
|
|
1818
1799
|
this.meshTxBuilderBody,
|
|
1819
|
-
this._protocolParams
|
|
1800
|
+
this._protocolParams,
|
|
1801
|
+
true
|
|
1820
1802
|
);
|
|
1821
|
-
if (this.evaluator) {
|
|
1822
|
-
const txEvaluation = await this.evaluator.evaluateTx(
|
|
1823
|
-
txHex,
|
|
1824
|
-
Object.values(this.meshTxBuilderBody.inputsForEvaluation),
|
|
1825
|
-
this.meshTxBuilderBody.chainedTxs
|
|
1826
|
-
).catch((error) => {
|
|
1827
|
-
throw Error(`Tx evaluation failed: ${error}
|
|
1828
|
-
For txHex: ${txHex}`);
|
|
1829
|
-
});
|
|
1830
|
-
this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
|
|
1831
|
-
txHex = this.serializer.serializeTxBody(
|
|
1832
|
-
this.meshTxBuilderBody,
|
|
1833
|
-
this._protocolParams
|
|
1834
|
-
);
|
|
1835
|
-
}
|
|
1836
|
-
this.txHex = txHex;
|
|
1837
|
-
return txHex;
|
|
1838
1803
|
};
|
|
1839
1804
|
/**
|
|
1840
1805
|
* It builds the transaction without dependencies
|
|
1841
1806
|
* @param customizedTx The optional customized transaction body
|
|
1842
|
-
* @returns The
|
|
1807
|
+
* @returns The transaction in hex, unbalanced
|
|
1843
1808
|
*/
|
|
1844
|
-
|
|
1809
|
+
completeUnbalancedSync = (customizedTx) => {
|
|
1845
1810
|
if (customizedTx) {
|
|
1846
1811
|
this.meshTxBuilderBody = customizedTx;
|
|
1847
1812
|
} else {
|
|
@@ -1850,7 +1815,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1850
1815
|
this.addUtxosFromSelection();
|
|
1851
1816
|
return this.serializer.serializeTxBody(
|
|
1852
1817
|
this.meshTxBuilderBody,
|
|
1853
|
-
this._protocolParams
|
|
1818
|
+
this._protocolParams,
|
|
1819
|
+
false
|
|
1854
1820
|
);
|
|
1855
1821
|
};
|
|
1856
1822
|
/**
|
|
@@ -1886,9 +1852,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1886
1852
|
this.queriedUTxOs[txHash] = utxos;
|
|
1887
1853
|
}
|
|
1888
1854
|
};
|
|
1889
|
-
queryAllTxInfo = (incompleteTxIns,
|
|
1855
|
+
queryAllTxInfo = (incompleteTxIns, incompleteScriptSources, incompleteSimpleScriptSources) => {
|
|
1890
1856
|
const queryUTxOPromises = [];
|
|
1891
|
-
if ((incompleteTxIns.length > 0 ||
|
|
1857
|
+
if ((incompleteTxIns.length > 0 || incompleteScriptSources.length > 0 || incompleteSimpleScriptSources.length) && !this.fetcher)
|
|
1892
1858
|
throw Error(
|
|
1893
1859
|
"Transaction information is incomplete while no fetcher instance is provided. Provide a `fetcher`."
|
|
1894
1860
|
);
|
|
@@ -1897,21 +1863,11 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1897
1863
|
if (!this.isInputInfoComplete(currentTxIn)) {
|
|
1898
1864
|
queryUTxOPromises.push(this.getUTxOInfo(currentTxIn.txIn.txHash));
|
|
1899
1865
|
}
|
|
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
1866
|
}
|
|
1906
|
-
for (let i = 0; i <
|
|
1907
|
-
const
|
|
1908
|
-
if (
|
|
1909
|
-
|
|
1910
|
-
if (scriptSource.type === "Inline") {
|
|
1911
|
-
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
1912
|
-
queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1867
|
+
for (let i = 0; i < incompleteScriptSources.length; i++) {
|
|
1868
|
+
const scriptSource = incompleteScriptSources[i];
|
|
1869
|
+
if (scriptSource.type === "Inline") {
|
|
1870
|
+
queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
|
|
1915
1871
|
}
|
|
1916
1872
|
}
|
|
1917
1873
|
return Promise.all(queryUTxOPromises);
|
|
@@ -2005,6 +1961,182 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
2005
1961
|
}
|
|
2006
1962
|
return true;
|
|
2007
1963
|
};
|
|
1964
|
+
isSimpleRefScriptInfoComplete = (simpleScriptSource) => {
|
|
1965
|
+
if (simpleScriptSource.type === "Inline") {
|
|
1966
|
+
if (!simpleScriptSource.simpleScriptHash || !simpleScriptSource.scriptSize)
|
|
1967
|
+
return false;
|
|
1968
|
+
}
|
|
1969
|
+
return true;
|
|
1970
|
+
};
|
|
1971
|
+
completeSerialization = async (customizedTx, balanced = true) => {
|
|
1972
|
+
if (customizedTx) {
|
|
1973
|
+
this.meshTxBuilderBody = { ...this.meshTxBuilderBody, ...customizedTx };
|
|
1974
|
+
} else {
|
|
1975
|
+
this.queueAllLastItem();
|
|
1976
|
+
}
|
|
1977
|
+
this.removeDuplicateInputs();
|
|
1978
|
+
this.removeDuplicateRefInputs();
|
|
1979
|
+
for (let collateral of this.meshTxBuilderBody.collaterals) {
|
|
1980
|
+
collateral.txIn.scriptSize = 0;
|
|
1981
|
+
}
|
|
1982
|
+
const { inputs, collaterals, mints, withdrawals, votes, certificates } = this.meshTxBuilderBody;
|
|
1983
|
+
const incompleteTxIns = [...inputs, ...collaterals].filter(
|
|
1984
|
+
(txIn) => !this.isInputComplete(txIn)
|
|
1985
|
+
);
|
|
1986
|
+
let incompleteScriptSources = [];
|
|
1987
|
+
let incompleteSimpleScriptSources = [];
|
|
1988
|
+
inputs.forEach((txIn) => {
|
|
1989
|
+
if (txIn.type === "Script" && txIn.scriptTxIn.scriptSource?.type === "Inline") {
|
|
1990
|
+
if (!this.isRefScriptInfoComplete(txIn.scriptTxIn.scriptSource)) {
|
|
1991
|
+
incompleteScriptSources.push(txIn.scriptTxIn.scriptSource);
|
|
1992
|
+
}
|
|
1993
|
+
} else if (txIn.type === "SimpleScript" && txIn.simpleScriptTxIn?.scriptSource?.type === "Inline") {
|
|
1994
|
+
if (!this.isSimpleRefScriptInfoComplete(
|
|
1995
|
+
txIn.simpleScriptTxIn.scriptSource
|
|
1996
|
+
)) {
|
|
1997
|
+
incompleteSimpleScriptSources.push(
|
|
1998
|
+
txIn.simpleScriptTxIn.scriptSource
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
});
|
|
2003
|
+
mints.forEach((mint) => {
|
|
2004
|
+
if (mint.type === "Plutus") {
|
|
2005
|
+
const scriptSource = mint.scriptSource;
|
|
2006
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
2007
|
+
incompleteScriptSources.push(scriptSource);
|
|
2008
|
+
}
|
|
2009
|
+
} else if (mint.type === "Native") {
|
|
2010
|
+
const scriptSource = mint.scriptSource;
|
|
2011
|
+
if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
|
|
2012
|
+
incompleteSimpleScriptSources.push(scriptSource);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
});
|
|
2016
|
+
withdrawals.forEach((withdrawal) => {
|
|
2017
|
+
if (withdrawal.type === "ScriptWithdrawal") {
|
|
2018
|
+
const scriptSource = withdrawal.scriptSource;
|
|
2019
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
2020
|
+
incompleteScriptSources.push(scriptSource);
|
|
2021
|
+
}
|
|
2022
|
+
} else if (withdrawal.type === "SimpleScriptWithdrawal") {
|
|
2023
|
+
const scriptSource = withdrawal.scriptSource;
|
|
2024
|
+
if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
|
|
2025
|
+
incompleteSimpleScriptSources.push(scriptSource);
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
});
|
|
2029
|
+
votes.forEach((vote) => {
|
|
2030
|
+
if (vote.type === "ScriptVote") {
|
|
2031
|
+
const scriptSource = vote.scriptSource;
|
|
2032
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
2033
|
+
incompleteScriptSources.push(scriptSource);
|
|
2034
|
+
}
|
|
2035
|
+
} else if (vote.type === "SimpleScriptVote") {
|
|
2036
|
+
const scriptSource = vote.simpleScriptSource;
|
|
2037
|
+
if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
|
|
2038
|
+
incompleteSimpleScriptSources.push(scriptSource);
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
certificates.forEach((certificate) => {
|
|
2043
|
+
if (certificate.type === "ScriptCertificate") {
|
|
2044
|
+
const scriptSource = certificate.scriptSource;
|
|
2045
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
2046
|
+
incompleteScriptSources.push(scriptSource);
|
|
2047
|
+
}
|
|
2048
|
+
} else if (certificate.type === "SimpleScriptCertificate") {
|
|
2049
|
+
const scriptSource = certificate.simpleScriptSource;
|
|
2050
|
+
if (!this.isSimpleRefScriptInfoComplete(scriptSource)) {
|
|
2051
|
+
incompleteSimpleScriptSources.push(scriptSource);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
});
|
|
2055
|
+
await this.queryAllTxInfo(
|
|
2056
|
+
incompleteTxIns,
|
|
2057
|
+
incompleteScriptSources,
|
|
2058
|
+
incompleteSimpleScriptSources
|
|
2059
|
+
);
|
|
2060
|
+
incompleteTxIns.forEach((txIn) => {
|
|
2061
|
+
this.completeTxInformation(txIn);
|
|
2062
|
+
});
|
|
2063
|
+
incompleteScriptSources.forEach((scriptSource) => {
|
|
2064
|
+
this.completeScriptInfo(scriptSource);
|
|
2065
|
+
});
|
|
2066
|
+
incompleteSimpleScriptSources.forEach((simpleScriptSource) => {
|
|
2067
|
+
this.completeSimpleScriptInfo(simpleScriptSource);
|
|
2068
|
+
});
|
|
2069
|
+
this.meshTxBuilderBody.inputs.forEach((input) => {
|
|
2070
|
+
if (input.txIn.scriptSize && input.txIn.scriptSize > 0) {
|
|
2071
|
+
if (this.meshTxBuilderBody.referenceInputs.find((refTxIn) => {
|
|
2072
|
+
refTxIn.txHash === input.txIn.txHash && refTxIn.txIndex === input.txIn.txIndex;
|
|
2073
|
+
}) === void 0) {
|
|
2074
|
+
this.meshTxBuilderBody.referenceInputs.push({
|
|
2075
|
+
txHash: input.txIn.txHash,
|
|
2076
|
+
txIndex: input.txIn.txIndex,
|
|
2077
|
+
scriptSize: input.txIn.scriptSize
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
});
|
|
2082
|
+
this.addUtxosFromSelection();
|
|
2083
|
+
this.meshTxBuilderBody.inputs.sort((a, b) => {
|
|
2084
|
+
if (a.txIn.txHash < b.txIn.txHash) return -1;
|
|
2085
|
+
if (a.txIn.txHash > b.txIn.txHash) return 1;
|
|
2086
|
+
if (a.txIn.txIndex < b.txIn.txIndex) return -1;
|
|
2087
|
+
if (a.txIn.txIndex > b.txIn.txIndex) return 1;
|
|
2088
|
+
return 0;
|
|
2089
|
+
});
|
|
2090
|
+
this.meshTxBuilderBody.mints.sort((a, b) => {
|
|
2091
|
+
if (a.policyId < b.policyId) return -1;
|
|
2092
|
+
if (a.policyId > b.policyId) return 1;
|
|
2093
|
+
if (a.assetName < b.assetName) return -1;
|
|
2094
|
+
if (a.assetName > b.assetName) return 1;
|
|
2095
|
+
return 0;
|
|
2096
|
+
});
|
|
2097
|
+
let txHex = this.serializer.serializeTxBody(
|
|
2098
|
+
this.meshTxBuilderBody,
|
|
2099
|
+
this._protocolParams,
|
|
2100
|
+
balanced
|
|
2101
|
+
);
|
|
2102
|
+
if (this.evaluator) {
|
|
2103
|
+
const txEvaluation = await this.evaluator.evaluateTx(
|
|
2104
|
+
txHex,
|
|
2105
|
+
Object.values(this.meshTxBuilderBody.inputsForEvaluation),
|
|
2106
|
+
this.meshTxBuilderBody.chainedTxs
|
|
2107
|
+
).catch((error) => {
|
|
2108
|
+
if (error instanceof Error) {
|
|
2109
|
+
throw new Error(
|
|
2110
|
+
`Tx evaluation failed: ${error.message}
|
|
2111
|
+
For txHex: ${txHex}`
|
|
2112
|
+
);
|
|
2113
|
+
} else if (typeof error === "string") {
|
|
2114
|
+
throw new Error(
|
|
2115
|
+
`Tx evaluation failed: ${error}
|
|
2116
|
+
For txHex: ${txHex}`
|
|
2117
|
+
);
|
|
2118
|
+
} else if (typeof error === "object") {
|
|
2119
|
+
throw new Error(
|
|
2120
|
+
`Tx evaluation failed: ${JSON.stringify(error)}
|
|
2121
|
+
For txHex: ${txHex}`
|
|
2122
|
+
);
|
|
2123
|
+
} else {
|
|
2124
|
+
throw new Error(
|
|
2125
|
+
`Tx evaluation failed: ${String(error)}
|
|
2126
|
+
For txHex: ${txHex}`
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
});
|
|
2130
|
+
this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
|
|
2131
|
+
txHex = this.serializer.serializeTxBody(
|
|
2132
|
+
this.meshTxBuilderBody,
|
|
2133
|
+
this._protocolParams,
|
|
2134
|
+
balanced
|
|
2135
|
+
);
|
|
2136
|
+
}
|
|
2137
|
+
this.txHex = txHex;
|
|
2138
|
+
return txHex;
|
|
2139
|
+
};
|
|
2008
2140
|
};
|
|
2009
2141
|
|
|
2010
2142
|
// src/scripts/forge.script.ts
|
|
@@ -2287,7 +2419,8 @@ var Transaction = class {
|
|
|
2287
2419
|
value.input.txHash,
|
|
2288
2420
|
value.input.outputIndex,
|
|
2289
2421
|
value.output.amount,
|
|
2290
|
-
value.output.address
|
|
2422
|
+
value.output.address,
|
|
2423
|
+
value.output.scriptRef ? value.output.scriptRef.length / 2 : 0
|
|
2291
2424
|
).txInScript(script.code).txInRedeemerValue(red.data, "Mesh", red.budget);
|
|
2292
2425
|
}
|
|
2293
2426
|
if ("output" in script) {
|
|
@@ -2535,7 +2668,7 @@ var Transaction = class {
|
|
|
2535
2668
|
delegateStake(rewardAddress, poolId) {
|
|
2536
2669
|
this.txBuilder.delegateStakeCertificate(
|
|
2537
2670
|
rewardAddress,
|
|
2538
|
-
this.txBuilder.serializer.
|
|
2671
|
+
this.txBuilder.serializer.deserializer.cert.deserializePoolId(poolId)
|
|
2539
2672
|
);
|
|
2540
2673
|
return this;
|
|
2541
2674
|
}
|
|
@@ -2557,12 +2690,16 @@ var Transaction = class {
|
|
|
2557
2690
|
this.txBuilder.retirePoolCertificate(poolId, epochNo);
|
|
2558
2691
|
return this;
|
|
2559
2692
|
}
|
|
2560
|
-
async build() {
|
|
2693
|
+
async build(balanced = true) {
|
|
2561
2694
|
try {
|
|
2562
2695
|
await this.addCollateralIfNeeded();
|
|
2563
2696
|
await this.addTxInputsAsNeeded();
|
|
2564
2697
|
await this.addChangeAddress();
|
|
2565
|
-
|
|
2698
|
+
if (balanced) {
|
|
2699
|
+
return this.txBuilder.complete();
|
|
2700
|
+
} else {
|
|
2701
|
+
return this.txBuilder.completeUnbalanced();
|
|
2702
|
+
}
|
|
2566
2703
|
} catch (error) {
|
|
2567
2704
|
throw new Error(
|
|
2568
2705
|
`[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
|
+
"version": "1.9.0-beta.30",
|
|
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.
|
|
39
|
-
"@meshsdk/core-cst": "1.9.0-beta.
|
|
38
|
+
"@meshsdk/common": "1.9.0-beta.30",
|
|
39
|
+
"@meshsdk/core-cst": "1.9.0-beta.30",
|
|
40
40
|
"json-bigint": "^1.0.0"
|
|
41
41
|
},
|
|
42
42
|
"prettier": "@meshsdk/configs/prettier",
|
|
@@ -51,4 +51,4 @@
|
|
|
51
51
|
"blockchain",
|
|
52
52
|
"sdk"
|
|
53
53
|
]
|
|
54
|
-
}
|
|
54
|
+
}
|