@meshsdk/transaction 1.6.8 → 1.6.10
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 +145 -65
- package/dist/index.d.cts +44 -22
- package/dist/index.d.ts +44 -22
- package/dist/index.js +145 -65
- package/package.json +1 -1
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
|
|
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,
|
|
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
|
|
387
|
+
scriptHash,
|
|
387
388
|
version: this.plutusSpendingScriptVersion || "V2",
|
|
388
|
-
scriptSize
|
|
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
|
|
519
|
-
|
|
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
|
|
680
|
-
* @param
|
|
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,
|
|
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
|
|
694
|
+
scriptHash,
|
|
695
695
|
version: this.plutusWithdrawalScriptVersion || "V2",
|
|
696
|
-
scriptSize
|
|
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
|
|
843
|
-
* @param
|
|
844
|
-
* @param
|
|
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,
|
|
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:
|
|
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
|
|
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);
|
|
@@ -1277,7 +1286,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1277
1286
|
submitter,
|
|
1278
1287
|
evaluator,
|
|
1279
1288
|
params,
|
|
1280
|
-
isHydra = false
|
|
1289
|
+
isHydra = false,
|
|
1290
|
+
verbose = false
|
|
1281
1291
|
} = {}) {
|
|
1282
1292
|
super();
|
|
1283
1293
|
if (serializer) {
|
|
@@ -1285,6 +1295,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1285
1295
|
} else {
|
|
1286
1296
|
this.serializer = new import_core_csl.CSLSerializer();
|
|
1287
1297
|
}
|
|
1298
|
+
this.serializer.verbose = verbose;
|
|
1288
1299
|
if (fetcher) this.fetcher = fetcher;
|
|
1289
1300
|
if (submitter) this.submitter = submitter;
|
|
1290
1301
|
if (evaluator) this.evaluator = evaluator;
|
|
@@ -1311,14 +1322,25 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1311
1322
|
this.queueAllLastItem();
|
|
1312
1323
|
}
|
|
1313
1324
|
this.removeDuplicateInputs();
|
|
1314
|
-
const { inputs, collaterals } = this.meshTxBuilderBody;
|
|
1325
|
+
const { inputs, collaterals, mints } = this.meshTxBuilderBody;
|
|
1315
1326
|
const incompleteTxIns = [...inputs, ...collaterals].filter(
|
|
1316
1327
|
(txIn) => !this.isInputComplete(txIn)
|
|
1317
1328
|
);
|
|
1318
|
-
|
|
1329
|
+
const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
|
|
1330
|
+
await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
|
|
1319
1331
|
incompleteTxIns.forEach((txIn) => {
|
|
1320
1332
|
this.completeTxInformation(txIn);
|
|
1321
1333
|
});
|
|
1334
|
+
incompleteMints.forEach((mint) => {
|
|
1335
|
+
if (mint.type === "Plutus") {
|
|
1336
|
+
const scriptSource = mint.scriptSource;
|
|
1337
|
+
this.completeScriptInfo(scriptSource);
|
|
1338
|
+
}
|
|
1339
|
+
if (mint.type === "Native") {
|
|
1340
|
+
const scriptSource = mint.scriptSource;
|
|
1341
|
+
this.completeSimpleScriptInfo(scriptSource);
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1322
1344
|
this.addUtxosFromSelection();
|
|
1323
1345
|
let txHex = this.serializer.serializeTxBody(
|
|
1324
1346
|
this.meshTxBuilderBody,
|
|
@@ -1326,7 +1348,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1326
1348
|
);
|
|
1327
1349
|
if (this.evaluator) {
|
|
1328
1350
|
const txEvaluation = await this.evaluator.evaluateTx(txHex).catch((error) => {
|
|
1329
|
-
throw Error(`Tx evaluation failed: ${error}
|
|
1351
|
+
throw Error(`Tx evaluation failed: ${error}
|
|
1352
|
+
For txHex: ${txHex}`);
|
|
1330
1353
|
});
|
|
1331
1354
|
this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
|
|
1332
1355
|
txHex = this.serializer.serializeTxBody(
|
|
@@ -1377,7 +1400,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1377
1400
|
};
|
|
1378
1401
|
/**
|
|
1379
1402
|
* Get the UTxO information from the blockchain
|
|
1380
|
-
* @param
|
|
1403
|
+
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
1381
1404
|
*/
|
|
1382
1405
|
getUTxOInfo = async (txHash) => {
|
|
1383
1406
|
let utxos = [];
|
|
@@ -1387,9 +1410,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1387
1410
|
this.queriedUTxOs[txHash] = utxos;
|
|
1388
1411
|
}
|
|
1389
1412
|
};
|
|
1390
|
-
queryAllTxInfo = (incompleteTxIns) => {
|
|
1413
|
+
queryAllTxInfo = (incompleteTxIns, incompleteMints) => {
|
|
1391
1414
|
const queryUTxOPromises = [];
|
|
1392
|
-
if (incompleteTxIns.length > 0 && !this.fetcher)
|
|
1415
|
+
if ((incompleteTxIns.length > 0 || incompleteMints.length > 0) && !this.fetcher)
|
|
1393
1416
|
throw Error(
|
|
1394
1417
|
"Transaction information is incomplete while no fetcher instance is provided"
|
|
1395
1418
|
);
|
|
@@ -1398,67 +1421,109 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1398
1421
|
if (!this.isInputInfoComplete(currentTxIn)) {
|
|
1399
1422
|
queryUTxOPromises.push(this.getUTxOInfo(currentTxIn.txIn.txHash));
|
|
1400
1423
|
}
|
|
1401
|
-
if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn)) {
|
|
1424
|
+
if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn.scriptTxIn.scriptSource)) {
|
|
1402
1425
|
queryUTxOPromises.push(
|
|
1403
1426
|
this.getUTxOInfo(currentTxIn.scriptTxIn.scriptSource.txHash)
|
|
1404
1427
|
);
|
|
1405
1428
|
}
|
|
1406
1429
|
}
|
|
1430
|
+
for (let i = 0; i < incompleteMints.length; i++) {
|
|
1431
|
+
const currentMint = incompleteMints[i];
|
|
1432
|
+
if (currentMint.type === "Plutus") {
|
|
1433
|
+
const scriptSource = currentMint.scriptSource;
|
|
1434
|
+
if (scriptSource.type === "Inline") {
|
|
1435
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
1436
|
+
queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1407
1441
|
return Promise.all(queryUTxOPromises);
|
|
1408
1442
|
};
|
|
1409
1443
|
completeTxInformation = (input) => {
|
|
1410
1444
|
if (!this.isInputInfoComplete(input)) {
|
|
1411
|
-
|
|
1412
|
-
const utxo = utxos?.find(
|
|
1413
|
-
(utxo2) => utxo2.input.outputIndex === input.txIn.txIndex
|
|
1414
|
-
);
|
|
1415
|
-
const amount = utxo?.output.amount;
|
|
1416
|
-
const address = utxo?.output.address;
|
|
1417
|
-
if (!amount || amount.length === 0)
|
|
1418
|
-
throw Error(
|
|
1419
|
-
`Couldn't find value information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1420
|
-
);
|
|
1421
|
-
input.txIn.amount = amount;
|
|
1422
|
-
if (input.type === "PubKey") {
|
|
1423
|
-
if (!address || address === "")
|
|
1424
|
-
throw Error(
|
|
1425
|
-
`Couldn't find address information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1426
|
-
);
|
|
1427
|
-
input.txIn.address = address;
|
|
1428
|
-
}
|
|
1445
|
+
this.completeInputInfo(input);
|
|
1429
1446
|
}
|
|
1430
|
-
if (input.type === "Script" &&
|
|
1447
|
+
if (input.type === "Script" && !this.isRefScriptInfoComplete(input.scriptTxIn.scriptSource)) {
|
|
1431
1448
|
const scriptSource = input.scriptTxIn.scriptSource;
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1449
|
+
this.completeScriptInfo(scriptSource);
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
completeInputInfo = (input) => {
|
|
1453
|
+
const utxos = this.queriedUTxOs[input.txIn.txHash];
|
|
1454
|
+
const utxo = utxos?.find(
|
|
1455
|
+
(utxo2) => utxo2.input.outputIndex === input.txIn.txIndex
|
|
1456
|
+
);
|
|
1457
|
+
const amount = utxo?.output.amount;
|
|
1458
|
+
const address = utxo?.output.address;
|
|
1459
|
+
if (!amount || amount.length === 0)
|
|
1460
|
+
throw Error(
|
|
1461
|
+
`Couldn't find value information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1435
1462
|
);
|
|
1436
|
-
|
|
1463
|
+
input.txIn.amount = amount;
|
|
1464
|
+
if (input.type === "PubKey") {
|
|
1465
|
+
if (!address || address === "")
|
|
1437
1466
|
throw Error(
|
|
1438
|
-
`Couldn't find
|
|
1467
|
+
`Couldn't find address information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1439
1468
|
);
|
|
1440
|
-
|
|
1469
|
+
input.txIn.address = address;
|
|
1441
1470
|
}
|
|
1442
1471
|
};
|
|
1472
|
+
completeScriptInfo = (scriptSource) => {
|
|
1473
|
+
if (scriptSource?.type != "Inline") return;
|
|
1474
|
+
const refUtxos = this.queriedUTxOs[scriptSource.txHash];
|
|
1475
|
+
const scriptRefUtxo = refUtxos.find(
|
|
1476
|
+
(utxo) => utxo.input.outputIndex === scriptSource.txIndex
|
|
1477
|
+
);
|
|
1478
|
+
if (!scriptRefUtxo)
|
|
1479
|
+
throw Error(
|
|
1480
|
+
`Couldn't find script reference utxo for ${scriptSource.txHash}#${scriptSource.txIndex}`
|
|
1481
|
+
);
|
|
1482
|
+
scriptSource.scriptHash = scriptRefUtxo?.output.scriptHash;
|
|
1483
|
+
scriptSource.scriptSize = (scriptRefUtxo?.output.scriptRef.length / 2).toString();
|
|
1484
|
+
};
|
|
1485
|
+
completeSimpleScriptInfo = (simpleScript) => {
|
|
1486
|
+
if (simpleScript.type !== "Inline") return;
|
|
1487
|
+
const refUtxos = this.queriedUTxOs[simpleScript.txHash];
|
|
1488
|
+
const scriptRefUtxo = refUtxos.find(
|
|
1489
|
+
(utxo) => utxo.input.outputIndex === simpleScript.txIndex
|
|
1490
|
+
);
|
|
1491
|
+
if (!scriptRefUtxo)
|
|
1492
|
+
throw Error(
|
|
1493
|
+
`Couldn't find script reference utxo for ${simpleScript.txHash}#${simpleScript.txIndex}`
|
|
1494
|
+
);
|
|
1495
|
+
simpleScript.simpleScriptHash = scriptRefUtxo?.output.scriptHash;
|
|
1496
|
+
};
|
|
1443
1497
|
isInputComplete = (txIn) => {
|
|
1444
1498
|
if (txIn.type === "PubKey") return this.isInputInfoComplete(txIn);
|
|
1445
1499
|
if (txIn.type === "Script") {
|
|
1446
|
-
|
|
1500
|
+
const { scriptSource } = txIn.scriptTxIn;
|
|
1501
|
+
return this.isInputInfoComplete(txIn) && this.isRefScriptInfoComplete(scriptSource);
|
|
1447
1502
|
}
|
|
1448
1503
|
return true;
|
|
1449
1504
|
};
|
|
1450
1505
|
isInputInfoComplete = (txIn) => {
|
|
1451
1506
|
const { amount, address } = txIn.txIn;
|
|
1452
|
-
if (
|
|
1453
|
-
|
|
1454
|
-
|
|
1507
|
+
if (!amount || !address) return false;
|
|
1508
|
+
return true;
|
|
1509
|
+
};
|
|
1510
|
+
isMintComplete = (mint) => {
|
|
1511
|
+
if (mint.type === "Plutus") {
|
|
1512
|
+
const scriptSource = mint.scriptSource;
|
|
1513
|
+
return this.isRefScriptInfoComplete(scriptSource);
|
|
1514
|
+
}
|
|
1515
|
+
if (mint.type === "Native") {
|
|
1516
|
+
const scriptSource = mint.scriptSource;
|
|
1517
|
+
if (scriptSource.type === "Inline") {
|
|
1518
|
+
if (!scriptSource?.simpleScriptHash) return false;
|
|
1519
|
+
}
|
|
1455
1520
|
}
|
|
1456
1521
|
return true;
|
|
1457
1522
|
};
|
|
1458
|
-
isRefScriptInfoComplete = (
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1523
|
+
isRefScriptInfoComplete = (scriptSource) => {
|
|
1524
|
+
if (scriptSource?.type === "Inline") {
|
|
1525
|
+
if (!scriptSource?.scriptHash || !scriptSource?.scriptSize) return false;
|
|
1526
|
+
}
|
|
1462
1527
|
return true;
|
|
1463
1528
|
};
|
|
1464
1529
|
};
|
|
@@ -1691,6 +1756,7 @@ var Transaction = class {
|
|
|
1691
1756
|
).spendingTxInReference(
|
|
1692
1757
|
script.input.txHash,
|
|
1693
1758
|
script.input.outputIndex,
|
|
1759
|
+
(script.output.scriptRef.length / 2).toString(),
|
|
1694
1760
|
script.output.scriptHash
|
|
1695
1761
|
).txInRedeemerValue(red.data, "Mesh", red.budget);
|
|
1696
1762
|
}
|
|
@@ -1748,12 +1814,16 @@ var Transaction = class {
|
|
|
1748
1814
|
this.isCollateralNeeded = true;
|
|
1749
1815
|
this.mintPlutusScript(script).mint(assetQuantity, policyId, assetNameHex).mintTxInReference(
|
|
1750
1816
|
forgeScript.input.txHash,
|
|
1751
|
-
forgeScript.input.outputIndex
|
|
1817
|
+
forgeScript.input.outputIndex,
|
|
1818
|
+
(forgeScript.output.scriptRef.length / 2).toString(),
|
|
1819
|
+
forgeScript.output.scriptHash
|
|
1752
1820
|
).mintRedeemerValue(redeemer.data, "Mesh", redeemer.budget);
|
|
1753
1821
|
if (mint.cip68ScriptAddress) {
|
|
1754
1822
|
this.mintPlutusScript(script).mint(assetQuantity, policyId, referenceAssetNameHex).mintTxInReference(
|
|
1755
1823
|
forgeScript.input.txHash,
|
|
1756
|
-
forgeScript.input.outputIndex
|
|
1824
|
+
forgeScript.input.outputIndex,
|
|
1825
|
+
(forgeScript.output.scriptRef.length / 2).toString(),
|
|
1826
|
+
forgeScript.output.scriptHash
|
|
1757
1827
|
).mintRedeemerValue(redeemer.data, "Mesh", redeemer.budget);
|
|
1758
1828
|
break;
|
|
1759
1829
|
}
|
|
@@ -1790,8 +1860,9 @@ var Transaction = class {
|
|
|
1790
1860
|
this.setMetadata(Number(mint.label), {
|
|
1791
1861
|
[policyId]: { [mint.assetName]: mint.metadata }
|
|
1792
1862
|
});
|
|
1863
|
+
} else {
|
|
1864
|
+
this.setMetadata(Number(mint.label), mint.metadata);
|
|
1793
1865
|
}
|
|
1794
|
-
this.setMetadata(Number(mint.label), mint.metadata);
|
|
1795
1866
|
}
|
|
1796
1867
|
return this;
|
|
1797
1868
|
}
|
|
@@ -1837,6 +1908,15 @@ var Transaction = class {
|
|
|
1837
1908
|
});
|
|
1838
1909
|
return this;
|
|
1839
1910
|
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
|
|
1913
|
+
* @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
|
|
1914
|
+
* @returns The Transaction object.
|
|
1915
|
+
*/
|
|
1916
|
+
setNetwork = (network) => {
|
|
1917
|
+
this.txBuilder.setNetwork(network);
|
|
1918
|
+
return this;
|
|
1919
|
+
};
|
|
1840
1920
|
/**
|
|
1841
1921
|
* Sets the required signers for the transaction.
|
|
1842
1922
|
*
|
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, ScriptSource, SimpleScriptSourceInfo, 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
|
|
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,
|
|
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
|
|
240
|
-
* @param
|
|
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,
|
|
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
|
|
299
|
-
* @param
|
|
300
|
-
* @param
|
|
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,
|
|
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;
|
|
@@ -378,6 +387,7 @@ interface MeshTxBuilderOptions {
|
|
|
378
387
|
serializer?: IMeshTxSerializer;
|
|
379
388
|
isHydra?: boolean;
|
|
380
389
|
params?: Partial<Protocol>;
|
|
390
|
+
verbose?: boolean;
|
|
381
391
|
}
|
|
382
392
|
declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
383
393
|
serializer: IMeshTxSerializer;
|
|
@@ -385,9 +395,11 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
385
395
|
submitter?: ISubmitter;
|
|
386
396
|
evaluator?: IEvaluator;
|
|
387
397
|
txHex: string;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
398
|
+
protected queriedTxHashes: Set<string>;
|
|
399
|
+
protected queriedUTxOs: {
|
|
400
|
+
[x: string]: UTxO[];
|
|
401
|
+
};
|
|
402
|
+
constructor({ serializer, fetcher, submitter, evaluator, params, isHydra, verbose, }?: MeshTxBuilderOptions);
|
|
391
403
|
/**
|
|
392
404
|
* It builds the transaction and query the blockchain for missing information
|
|
393
405
|
* @param customizedTx The optional customized transaction body
|
|
@@ -413,14 +425,18 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
413
425
|
submitTx: (txHex: string) => Promise<string | undefined>;
|
|
414
426
|
/**
|
|
415
427
|
* Get the UTxO information from the blockchain
|
|
416
|
-
* @param
|
|
417
|
-
*/
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
428
|
+
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
429
|
+
*/
|
|
430
|
+
protected getUTxOInfo: (txHash: string) => Promise<void>;
|
|
431
|
+
protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteMints: MintItem[]) => Promise<void[]>;
|
|
432
|
+
protected completeTxInformation: (input: TxIn) => void;
|
|
433
|
+
protected completeInputInfo: (input: TxIn) => void;
|
|
434
|
+
protected completeScriptInfo: (scriptSource: ScriptSource) => void;
|
|
435
|
+
protected completeSimpleScriptInfo: (simpleScript: SimpleScriptSourceInfo) => void;
|
|
436
|
+
protected isInputComplete: (txIn: TxIn) => boolean;
|
|
437
|
+
protected isInputInfoComplete: (txIn: TxIn) => boolean;
|
|
438
|
+
protected isMintComplete: (mint: MintItem) => boolean;
|
|
439
|
+
protected isRefScriptInfoComplete: (scriptSource: ScriptSource) => boolean;
|
|
424
440
|
}
|
|
425
441
|
|
|
426
442
|
declare class ForgeScript {
|
|
@@ -541,6 +557,12 @@ declare class Transaction {
|
|
|
541
557
|
* @returns {Transaction} The Transaction object.
|
|
542
558
|
*/
|
|
543
559
|
setCollateral(collateral: UTxO[]): Transaction;
|
|
560
|
+
/**
|
|
561
|
+
* Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
|
|
562
|
+
* @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
|
|
563
|
+
* @returns The Transaction object.
|
|
564
|
+
*/
|
|
565
|
+
setNetwork: (network: Network) => this;
|
|
544
566
|
/**
|
|
545
567
|
* Sets the required signers for the transaction.
|
|
546
568
|
*
|
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, ScriptSource, SimpleScriptSourceInfo, 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
|
|
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,
|
|
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
|
|
240
|
-
* @param
|
|
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,
|
|
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
|
|
299
|
-
* @param
|
|
300
|
-
* @param
|
|
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,
|
|
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;
|
|
@@ -378,6 +387,7 @@ interface MeshTxBuilderOptions {
|
|
|
378
387
|
serializer?: IMeshTxSerializer;
|
|
379
388
|
isHydra?: boolean;
|
|
380
389
|
params?: Partial<Protocol>;
|
|
390
|
+
verbose?: boolean;
|
|
381
391
|
}
|
|
382
392
|
declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
383
393
|
serializer: IMeshTxSerializer;
|
|
@@ -385,9 +395,11 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
385
395
|
submitter?: ISubmitter;
|
|
386
396
|
evaluator?: IEvaluator;
|
|
387
397
|
txHex: string;
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
398
|
+
protected queriedTxHashes: Set<string>;
|
|
399
|
+
protected queriedUTxOs: {
|
|
400
|
+
[x: string]: UTxO[];
|
|
401
|
+
};
|
|
402
|
+
constructor({ serializer, fetcher, submitter, evaluator, params, isHydra, verbose, }?: MeshTxBuilderOptions);
|
|
391
403
|
/**
|
|
392
404
|
* It builds the transaction and query the blockchain for missing information
|
|
393
405
|
* @param customizedTx The optional customized transaction body
|
|
@@ -413,14 +425,18 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
413
425
|
submitTx: (txHex: string) => Promise<string | undefined>;
|
|
414
426
|
/**
|
|
415
427
|
* Get the UTxO information from the blockchain
|
|
416
|
-
* @param
|
|
417
|
-
*/
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
428
|
+
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
429
|
+
*/
|
|
430
|
+
protected getUTxOInfo: (txHash: string) => Promise<void>;
|
|
431
|
+
protected queryAllTxInfo: (incompleteTxIns: TxIn[], incompleteMints: MintItem[]) => Promise<void[]>;
|
|
432
|
+
protected completeTxInformation: (input: TxIn) => void;
|
|
433
|
+
protected completeInputInfo: (input: TxIn) => void;
|
|
434
|
+
protected completeScriptInfo: (scriptSource: ScriptSource) => void;
|
|
435
|
+
protected completeSimpleScriptInfo: (simpleScript: SimpleScriptSourceInfo) => void;
|
|
436
|
+
protected isInputComplete: (txIn: TxIn) => boolean;
|
|
437
|
+
protected isInputInfoComplete: (txIn: TxIn) => boolean;
|
|
438
|
+
protected isMintComplete: (mint: MintItem) => boolean;
|
|
439
|
+
protected isRefScriptInfoComplete: (scriptSource: ScriptSource) => boolean;
|
|
424
440
|
}
|
|
425
441
|
|
|
426
442
|
declare class ForgeScript {
|
|
@@ -541,6 +557,12 @@ declare class Transaction {
|
|
|
541
557
|
* @returns {Transaction} The Transaction object.
|
|
542
558
|
*/
|
|
543
559
|
setCollateral(collateral: UTxO[]): Transaction;
|
|
560
|
+
/**
|
|
561
|
+
* Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
|
|
562
|
+
* @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
|
|
563
|
+
* @returns The Transaction object.
|
|
564
|
+
*/
|
|
565
|
+
setNetwork: (network: Network) => this;
|
|
544
566
|
/**
|
|
545
567
|
* Sets the required signers for the transaction.
|
|
546
568
|
*
|
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
|
|
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,
|
|
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
|
|
353
|
+
scriptHash,
|
|
353
354
|
version: this.plutusSpendingScriptVersion || "V2",
|
|
354
|
-
scriptSize
|
|
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
|
|
485
|
-
|
|
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
|
|
646
|
-
* @param
|
|
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,
|
|
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
|
|
660
|
+
scriptHash,
|
|
661
661
|
version: this.plutusWithdrawalScriptVersion || "V2",
|
|
662
|
-
scriptSize
|
|
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
|
|
809
|
-
* @param
|
|
810
|
-
* @param
|
|
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,
|
|
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:
|
|
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
|
|
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);
|
|
@@ -1243,7 +1252,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1243
1252
|
submitter,
|
|
1244
1253
|
evaluator,
|
|
1245
1254
|
params,
|
|
1246
|
-
isHydra = false
|
|
1255
|
+
isHydra = false,
|
|
1256
|
+
verbose = false
|
|
1247
1257
|
} = {}) {
|
|
1248
1258
|
super();
|
|
1249
1259
|
if (serializer) {
|
|
@@ -1251,6 +1261,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1251
1261
|
} else {
|
|
1252
1262
|
this.serializer = new CSLSerializer();
|
|
1253
1263
|
}
|
|
1264
|
+
this.serializer.verbose = verbose;
|
|
1254
1265
|
if (fetcher) this.fetcher = fetcher;
|
|
1255
1266
|
if (submitter) this.submitter = submitter;
|
|
1256
1267
|
if (evaluator) this.evaluator = evaluator;
|
|
@@ -1277,14 +1288,25 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1277
1288
|
this.queueAllLastItem();
|
|
1278
1289
|
}
|
|
1279
1290
|
this.removeDuplicateInputs();
|
|
1280
|
-
const { inputs, collaterals } = this.meshTxBuilderBody;
|
|
1291
|
+
const { inputs, collaterals, mints } = this.meshTxBuilderBody;
|
|
1281
1292
|
const incompleteTxIns = [...inputs, ...collaterals].filter(
|
|
1282
1293
|
(txIn) => !this.isInputComplete(txIn)
|
|
1283
1294
|
);
|
|
1284
|
-
|
|
1295
|
+
const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
|
|
1296
|
+
await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
|
|
1285
1297
|
incompleteTxIns.forEach((txIn) => {
|
|
1286
1298
|
this.completeTxInformation(txIn);
|
|
1287
1299
|
});
|
|
1300
|
+
incompleteMints.forEach((mint) => {
|
|
1301
|
+
if (mint.type === "Plutus") {
|
|
1302
|
+
const scriptSource = mint.scriptSource;
|
|
1303
|
+
this.completeScriptInfo(scriptSource);
|
|
1304
|
+
}
|
|
1305
|
+
if (mint.type === "Native") {
|
|
1306
|
+
const scriptSource = mint.scriptSource;
|
|
1307
|
+
this.completeSimpleScriptInfo(scriptSource);
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1288
1310
|
this.addUtxosFromSelection();
|
|
1289
1311
|
let txHex = this.serializer.serializeTxBody(
|
|
1290
1312
|
this.meshTxBuilderBody,
|
|
@@ -1292,7 +1314,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1292
1314
|
);
|
|
1293
1315
|
if (this.evaluator) {
|
|
1294
1316
|
const txEvaluation = await this.evaluator.evaluateTx(txHex).catch((error) => {
|
|
1295
|
-
throw Error(`Tx evaluation failed: ${error}
|
|
1317
|
+
throw Error(`Tx evaluation failed: ${error}
|
|
1318
|
+
For txHex: ${txHex}`);
|
|
1296
1319
|
});
|
|
1297
1320
|
this.updateRedeemer(this.meshTxBuilderBody, txEvaluation);
|
|
1298
1321
|
txHex = this.serializer.serializeTxBody(
|
|
@@ -1343,7 +1366,7 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1343
1366
|
};
|
|
1344
1367
|
/**
|
|
1345
1368
|
* Get the UTxO information from the blockchain
|
|
1346
|
-
* @param
|
|
1369
|
+
* @param txHash The TxIn object that contains the txHash and txIndex, while missing amount and address information
|
|
1347
1370
|
*/
|
|
1348
1371
|
getUTxOInfo = async (txHash) => {
|
|
1349
1372
|
let utxos = [];
|
|
@@ -1353,9 +1376,9 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1353
1376
|
this.queriedUTxOs[txHash] = utxos;
|
|
1354
1377
|
}
|
|
1355
1378
|
};
|
|
1356
|
-
queryAllTxInfo = (incompleteTxIns) => {
|
|
1379
|
+
queryAllTxInfo = (incompleteTxIns, incompleteMints) => {
|
|
1357
1380
|
const queryUTxOPromises = [];
|
|
1358
|
-
if (incompleteTxIns.length > 0 && !this.fetcher)
|
|
1381
|
+
if ((incompleteTxIns.length > 0 || incompleteMints.length > 0) && !this.fetcher)
|
|
1359
1382
|
throw Error(
|
|
1360
1383
|
"Transaction information is incomplete while no fetcher instance is provided"
|
|
1361
1384
|
);
|
|
@@ -1364,67 +1387,109 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
|
|
|
1364
1387
|
if (!this.isInputInfoComplete(currentTxIn)) {
|
|
1365
1388
|
queryUTxOPromises.push(this.getUTxOInfo(currentTxIn.txIn.txHash));
|
|
1366
1389
|
}
|
|
1367
|
-
if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn)) {
|
|
1390
|
+
if (currentTxIn.type === "Script" && currentTxIn.scriptTxIn.scriptSource?.type === "Inline" && !this.isRefScriptInfoComplete(currentTxIn.scriptTxIn.scriptSource)) {
|
|
1368
1391
|
queryUTxOPromises.push(
|
|
1369
1392
|
this.getUTxOInfo(currentTxIn.scriptTxIn.scriptSource.txHash)
|
|
1370
1393
|
);
|
|
1371
1394
|
}
|
|
1372
1395
|
}
|
|
1396
|
+
for (let i = 0; i < incompleteMints.length; i++) {
|
|
1397
|
+
const currentMint = incompleteMints[i];
|
|
1398
|
+
if (currentMint.type === "Plutus") {
|
|
1399
|
+
const scriptSource = currentMint.scriptSource;
|
|
1400
|
+
if (scriptSource.type === "Inline") {
|
|
1401
|
+
if (!this.isRefScriptInfoComplete(scriptSource)) {
|
|
1402
|
+
queryUTxOPromises.push(this.getUTxOInfo(scriptSource.txHash));
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1373
1407
|
return Promise.all(queryUTxOPromises);
|
|
1374
1408
|
};
|
|
1375
1409
|
completeTxInformation = (input) => {
|
|
1376
1410
|
if (!this.isInputInfoComplete(input)) {
|
|
1377
|
-
|
|
1378
|
-
const utxo = utxos?.find(
|
|
1379
|
-
(utxo2) => utxo2.input.outputIndex === input.txIn.txIndex
|
|
1380
|
-
);
|
|
1381
|
-
const amount = utxo?.output.amount;
|
|
1382
|
-
const address = utxo?.output.address;
|
|
1383
|
-
if (!amount || amount.length === 0)
|
|
1384
|
-
throw Error(
|
|
1385
|
-
`Couldn't find value information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1386
|
-
);
|
|
1387
|
-
input.txIn.amount = amount;
|
|
1388
|
-
if (input.type === "PubKey") {
|
|
1389
|
-
if (!address || address === "")
|
|
1390
|
-
throw Error(
|
|
1391
|
-
`Couldn't find address information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1392
|
-
);
|
|
1393
|
-
input.txIn.address = address;
|
|
1394
|
-
}
|
|
1411
|
+
this.completeInputInfo(input);
|
|
1395
1412
|
}
|
|
1396
|
-
if (input.type === "Script" &&
|
|
1413
|
+
if (input.type === "Script" && !this.isRefScriptInfoComplete(input.scriptTxIn.scriptSource)) {
|
|
1397
1414
|
const scriptSource = input.scriptTxIn.scriptSource;
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1415
|
+
this.completeScriptInfo(scriptSource);
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
completeInputInfo = (input) => {
|
|
1419
|
+
const utxos = this.queriedUTxOs[input.txIn.txHash];
|
|
1420
|
+
const utxo = utxos?.find(
|
|
1421
|
+
(utxo2) => utxo2.input.outputIndex === input.txIn.txIndex
|
|
1422
|
+
);
|
|
1423
|
+
const amount = utxo?.output.amount;
|
|
1424
|
+
const address = utxo?.output.address;
|
|
1425
|
+
if (!amount || amount.length === 0)
|
|
1426
|
+
throw Error(
|
|
1427
|
+
`Couldn't find value information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1401
1428
|
);
|
|
1402
|
-
|
|
1429
|
+
input.txIn.amount = amount;
|
|
1430
|
+
if (input.type === "PubKey") {
|
|
1431
|
+
if (!address || address === "")
|
|
1403
1432
|
throw Error(
|
|
1404
|
-
`Couldn't find
|
|
1433
|
+
`Couldn't find address information for ${input.txIn.txHash}#${input.txIn.txIndex}`
|
|
1405
1434
|
);
|
|
1406
|
-
|
|
1435
|
+
input.txIn.address = address;
|
|
1407
1436
|
}
|
|
1408
1437
|
};
|
|
1438
|
+
completeScriptInfo = (scriptSource) => {
|
|
1439
|
+
if (scriptSource?.type != "Inline") return;
|
|
1440
|
+
const refUtxos = this.queriedUTxOs[scriptSource.txHash];
|
|
1441
|
+
const scriptRefUtxo = refUtxos.find(
|
|
1442
|
+
(utxo) => utxo.input.outputIndex === scriptSource.txIndex
|
|
1443
|
+
);
|
|
1444
|
+
if (!scriptRefUtxo)
|
|
1445
|
+
throw Error(
|
|
1446
|
+
`Couldn't find script reference utxo for ${scriptSource.txHash}#${scriptSource.txIndex}`
|
|
1447
|
+
);
|
|
1448
|
+
scriptSource.scriptHash = scriptRefUtxo?.output.scriptHash;
|
|
1449
|
+
scriptSource.scriptSize = (scriptRefUtxo?.output.scriptRef.length / 2).toString();
|
|
1450
|
+
};
|
|
1451
|
+
completeSimpleScriptInfo = (simpleScript) => {
|
|
1452
|
+
if (simpleScript.type !== "Inline") return;
|
|
1453
|
+
const refUtxos = this.queriedUTxOs[simpleScript.txHash];
|
|
1454
|
+
const scriptRefUtxo = refUtxos.find(
|
|
1455
|
+
(utxo) => utxo.input.outputIndex === simpleScript.txIndex
|
|
1456
|
+
);
|
|
1457
|
+
if (!scriptRefUtxo)
|
|
1458
|
+
throw Error(
|
|
1459
|
+
`Couldn't find script reference utxo for ${simpleScript.txHash}#${simpleScript.txIndex}`
|
|
1460
|
+
);
|
|
1461
|
+
simpleScript.simpleScriptHash = scriptRefUtxo?.output.scriptHash;
|
|
1462
|
+
};
|
|
1409
1463
|
isInputComplete = (txIn) => {
|
|
1410
1464
|
if (txIn.type === "PubKey") return this.isInputInfoComplete(txIn);
|
|
1411
1465
|
if (txIn.type === "Script") {
|
|
1412
|
-
|
|
1466
|
+
const { scriptSource } = txIn.scriptTxIn;
|
|
1467
|
+
return this.isInputInfoComplete(txIn) && this.isRefScriptInfoComplete(scriptSource);
|
|
1413
1468
|
}
|
|
1414
1469
|
return true;
|
|
1415
1470
|
};
|
|
1416
1471
|
isInputInfoComplete = (txIn) => {
|
|
1417
1472
|
const { amount, address } = txIn.txIn;
|
|
1418
|
-
if (
|
|
1419
|
-
|
|
1420
|
-
|
|
1473
|
+
if (!amount || !address) return false;
|
|
1474
|
+
return true;
|
|
1475
|
+
};
|
|
1476
|
+
isMintComplete = (mint) => {
|
|
1477
|
+
if (mint.type === "Plutus") {
|
|
1478
|
+
const scriptSource = mint.scriptSource;
|
|
1479
|
+
return this.isRefScriptInfoComplete(scriptSource);
|
|
1480
|
+
}
|
|
1481
|
+
if (mint.type === "Native") {
|
|
1482
|
+
const scriptSource = mint.scriptSource;
|
|
1483
|
+
if (scriptSource.type === "Inline") {
|
|
1484
|
+
if (!scriptSource?.simpleScriptHash) return false;
|
|
1485
|
+
}
|
|
1421
1486
|
}
|
|
1422
1487
|
return true;
|
|
1423
1488
|
};
|
|
1424
|
-
isRefScriptInfoComplete = (
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1489
|
+
isRefScriptInfoComplete = (scriptSource) => {
|
|
1490
|
+
if (scriptSource?.type === "Inline") {
|
|
1491
|
+
if (!scriptSource?.scriptHash || !scriptSource?.scriptSize) return false;
|
|
1492
|
+
}
|
|
1428
1493
|
return true;
|
|
1429
1494
|
};
|
|
1430
1495
|
};
|
|
@@ -1675,6 +1740,7 @@ var Transaction = class {
|
|
|
1675
1740
|
).spendingTxInReference(
|
|
1676
1741
|
script.input.txHash,
|
|
1677
1742
|
script.input.outputIndex,
|
|
1743
|
+
(script.output.scriptRef.length / 2).toString(),
|
|
1678
1744
|
script.output.scriptHash
|
|
1679
1745
|
).txInRedeemerValue(red.data, "Mesh", red.budget);
|
|
1680
1746
|
}
|
|
@@ -1732,12 +1798,16 @@ var Transaction = class {
|
|
|
1732
1798
|
this.isCollateralNeeded = true;
|
|
1733
1799
|
this.mintPlutusScript(script).mint(assetQuantity, policyId, assetNameHex).mintTxInReference(
|
|
1734
1800
|
forgeScript.input.txHash,
|
|
1735
|
-
forgeScript.input.outputIndex
|
|
1801
|
+
forgeScript.input.outputIndex,
|
|
1802
|
+
(forgeScript.output.scriptRef.length / 2).toString(),
|
|
1803
|
+
forgeScript.output.scriptHash
|
|
1736
1804
|
).mintRedeemerValue(redeemer.data, "Mesh", redeemer.budget);
|
|
1737
1805
|
if (mint.cip68ScriptAddress) {
|
|
1738
1806
|
this.mintPlutusScript(script).mint(assetQuantity, policyId, referenceAssetNameHex).mintTxInReference(
|
|
1739
1807
|
forgeScript.input.txHash,
|
|
1740
|
-
forgeScript.input.outputIndex
|
|
1808
|
+
forgeScript.input.outputIndex,
|
|
1809
|
+
(forgeScript.output.scriptRef.length / 2).toString(),
|
|
1810
|
+
forgeScript.output.scriptHash
|
|
1741
1811
|
).mintRedeemerValue(redeemer.data, "Mesh", redeemer.budget);
|
|
1742
1812
|
break;
|
|
1743
1813
|
}
|
|
@@ -1774,8 +1844,9 @@ var Transaction = class {
|
|
|
1774
1844
|
this.setMetadata(Number(mint.label), {
|
|
1775
1845
|
[policyId]: { [mint.assetName]: mint.metadata }
|
|
1776
1846
|
});
|
|
1847
|
+
} else {
|
|
1848
|
+
this.setMetadata(Number(mint.label), mint.metadata);
|
|
1777
1849
|
}
|
|
1778
|
-
this.setMetadata(Number(mint.label), mint.metadata);
|
|
1779
1850
|
}
|
|
1780
1851
|
return this;
|
|
1781
1852
|
}
|
|
@@ -1821,6 +1892,15 @@ var Transaction = class {
|
|
|
1821
1892
|
});
|
|
1822
1893
|
return this;
|
|
1823
1894
|
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Sets the network to use, this is mainly to know the cost models to be used to calculate script integrity hash
|
|
1897
|
+
* @param network The specific network this transaction is being built for ("testnet" | "preview" | "preprod" | "mainnet")
|
|
1898
|
+
* @returns The Transaction object.
|
|
1899
|
+
*/
|
|
1900
|
+
setNetwork = (network) => {
|
|
1901
|
+
this.txBuilder.setNetwork(network);
|
|
1902
|
+
return this;
|
|
1903
|
+
};
|
|
1824
1904
|
/**
|
|
1825
1905
|
* Sets the required signers for the transaction.
|
|
1826
1906
|
*
|