@meshsdk/transaction 1.9.0-beta.99 → 1.9.0
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 +279 -11
- package/dist/index.d.cts +92 -2
- package/dist/index.d.ts +92 -2
- package/dist/index.js +286 -14
- package/package.json +7 -8
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
ForgeScript: () => ForgeScript,
|
|
34
34
|
LargestFirstInputSelector: () => LargestFirstInputSelector,
|
|
35
35
|
MeshTxBuilder: () => MeshTxBuilder,
|
|
36
|
+
MeshTxBuilderV2: () => MeshTxBuilderV2,
|
|
36
37
|
Transaction: () => Transaction,
|
|
37
38
|
TxParser: () => TxParser,
|
|
38
39
|
cloneOutput: () => cloneOutput,
|
|
@@ -1422,7 +1423,7 @@ var BuilderCallbacksSdkBridge = class {
|
|
|
1422
1423
|
change: selectionSkeleton.change.map(
|
|
1423
1424
|
(output) => CSDKOutputToMeshOutput(output)
|
|
1424
1425
|
),
|
|
1425
|
-
fee:
|
|
1426
|
+
fee: BigInt(1e9)
|
|
1426
1427
|
});
|
|
1427
1428
|
return {
|
|
1428
1429
|
fee: costs.fee,
|
|
@@ -1764,7 +1765,6 @@ var CSDKRedeemerTagToMeshRedeemerTag = (tag) => {
|
|
|
1764
1765
|
};
|
|
1765
1766
|
|
|
1766
1767
|
// src/mesh-tx-builder/coin-selection/largest-first-selector.ts
|
|
1767
|
-
var MAX_U64 = 18446744073709551615n;
|
|
1768
1768
|
var mergeValue = (a, b) => {
|
|
1769
1769
|
const merged = new Map(a);
|
|
1770
1770
|
b.forEach((quantity, unit) => {
|
|
@@ -1873,10 +1873,10 @@ var LargestFirstInputSelector = class {
|
|
|
1873
1873
|
computeChangeOutputs = (remainingValue, changeAddress, constraints) => {
|
|
1874
1874
|
let lovelaceAvailable = remainingValue.get("lovelace") || 0n;
|
|
1875
1875
|
let valueFulfilled = true;
|
|
1876
|
-
const valueAssets = remainingValue.entries().filter(([_, quantity]) => quantity > 0n).map(([unit, quantity]) => ({
|
|
1876
|
+
const valueAssets = Array.from(remainingValue.entries()).filter(([_, quantity]) => quantity > 0n).map(([unit, quantity]) => ({
|
|
1877
1877
|
unit,
|
|
1878
1878
|
quantity: String(quantity)
|
|
1879
|
-
}))
|
|
1879
|
+
}));
|
|
1880
1880
|
const changeOutputs = [];
|
|
1881
1881
|
let currentBundle = [
|
|
1882
1882
|
{
|
|
@@ -1952,9 +1952,11 @@ var LargestFirstInputSelector = class {
|
|
|
1952
1952
|
let remainingUtxos = [...availableUtxos];
|
|
1953
1953
|
const selectedUtxos = /* @__PURE__ */ new Set();
|
|
1954
1954
|
while (remainingUtxos.length > 0) {
|
|
1955
|
-
const assetToSelect = remainingValue.entries().find(
|
|
1956
|
-
|
|
1957
|
-
|
|
1955
|
+
const assetToSelect = Array.from(remainingValue.entries()).find(
|
|
1956
|
+
([_2, quantity]) => {
|
|
1957
|
+
return quantity < 0n;
|
|
1958
|
+
}
|
|
1959
|
+
);
|
|
1958
1960
|
if (!assetToSelect) {
|
|
1959
1961
|
break;
|
|
1960
1962
|
}
|
|
@@ -2009,7 +2011,7 @@ var LargestFirstInputSelector = class {
|
|
|
2009
2011
|
newInputs: selectedUtxos,
|
|
2010
2012
|
newOutputs: /* @__PURE__ */ new Set(),
|
|
2011
2013
|
change: changeOutputs,
|
|
2012
|
-
fee:
|
|
2014
|
+
fee: BigInt(1e9)
|
|
2013
2015
|
})).fee;
|
|
2014
2016
|
}
|
|
2015
2017
|
}
|
|
@@ -3140,9 +3142,12 @@ var MeshTxBuilderCore = class {
|
|
|
3140
3142
|
* @returns The MeshTxBuilder instance
|
|
3141
3143
|
*/
|
|
3142
3144
|
proposalRedeemerValue = (redeemer, type = "Mesh", exUnits = { ...import_common.DEFAULT_REDEEMER_BUDGET }) => {
|
|
3143
|
-
if (!this.proposalItem)
|
|
3145
|
+
if (!this.proposalItem)
|
|
3146
|
+
throw Error("proposalRedeemerValue: Undefined proposal");
|
|
3144
3147
|
if (!(this.proposalItem.type === "ScriptProposal"))
|
|
3145
|
-
throw Error(
|
|
3148
|
+
throw Error(
|
|
3149
|
+
"proposalRedeemerValue: Adding redeemer to non plutus proposal"
|
|
3150
|
+
);
|
|
3146
3151
|
this.proposalItem.redeemer = this.castBuilderDataToRedeemer(
|
|
3147
3152
|
redeemer,
|
|
3148
3153
|
type,
|
|
@@ -3530,6 +3535,15 @@ var MeshTxBuilderCore = class {
|
|
|
3530
3535
|
this.meshTxBuilderBody.network = network;
|
|
3531
3536
|
return this;
|
|
3532
3537
|
};
|
|
3538
|
+
/**
|
|
3539
|
+
* Alias for setNetwork for custom cost models
|
|
3540
|
+
* @param costModels
|
|
3541
|
+
* @returns The MeshTxBuilder instance
|
|
3542
|
+
*/
|
|
3543
|
+
setCostModels = (costModels) => {
|
|
3544
|
+
this.setNetwork(costModels);
|
|
3545
|
+
return this;
|
|
3546
|
+
};
|
|
3533
3547
|
/**
|
|
3534
3548
|
* Add a transaction that is used as input, but not yet reflected on the global blockchain
|
|
3535
3549
|
* @param txHex The transaction hex of chained transaction
|
|
@@ -4022,6 +4036,36 @@ var MeshTxBuilder = class _MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
4022
4036
|
this._protocolParams
|
|
4023
4037
|
);
|
|
4024
4038
|
};
|
|
4039
|
+
completeCostModels = async () => {
|
|
4040
|
+
if (Array.isArray(this.meshTxBuilderBody.network)) {
|
|
4041
|
+
return;
|
|
4042
|
+
}
|
|
4043
|
+
const defaults = [
|
|
4044
|
+
import_common3.DEFAULT_V1_COST_MODEL_LIST,
|
|
4045
|
+
import_common3.DEFAULT_V2_COST_MODEL_LIST,
|
|
4046
|
+
import_common3.DEFAULT_V3_COST_MODEL_LIST
|
|
4047
|
+
];
|
|
4048
|
+
if (this.fetcher) {
|
|
4049
|
+
try {
|
|
4050
|
+
console.log("fetching cost models from fetcher...");
|
|
4051
|
+
const costModels = await this.fetcher.fetchCostModels();
|
|
4052
|
+
if (Array.isArray(costModels) && costModels.length > 0) {
|
|
4053
|
+
this.meshTxBuilderBody.network = costModels;
|
|
4054
|
+
return;
|
|
4055
|
+
}
|
|
4056
|
+
console.warn(
|
|
4057
|
+
"fetchCostModels returned an invalid value, using default cost models:",
|
|
4058
|
+
costModels
|
|
4059
|
+
);
|
|
4060
|
+
} catch (error) {
|
|
4061
|
+
console.warn(
|
|
4062
|
+
"Failed to fetch cost models, using default cost models. Error: ",
|
|
4063
|
+
error
|
|
4064
|
+
);
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
4067
|
+
this.meshTxBuilderBody.network = defaults;
|
|
4068
|
+
};
|
|
4025
4069
|
/**
|
|
4026
4070
|
* It builds the transaction query the blockchain for missing information
|
|
4027
4071
|
* @param customizedTx The optional customized transaction body
|
|
@@ -4065,6 +4109,7 @@ var MeshTxBuilder = class _MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
4065
4109
|
this.setFee(customizedTx.fee);
|
|
4066
4110
|
}
|
|
4067
4111
|
}
|
|
4112
|
+
await this.completeCostModels();
|
|
4068
4113
|
this.queueAllLastItem();
|
|
4069
4114
|
if (this.verbose) {
|
|
4070
4115
|
console.log(
|
|
@@ -4122,7 +4167,15 @@ var MeshTxBuilder = class _MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
4122
4167
|
const selectionCallbacks = {
|
|
4123
4168
|
computeMinimumCost: async (selectionSkeleton) => {
|
|
4124
4169
|
const clonedBuilder = this.clone();
|
|
4125
|
-
|
|
4170
|
+
if (this.manualFee) {
|
|
4171
|
+
const newSelectionSkeleton = {
|
|
4172
|
+
...selectionSkeleton,
|
|
4173
|
+
fee: BigInt(this.manualFee)
|
|
4174
|
+
};
|
|
4175
|
+
await clonedBuilder.updateByTxPrototype(newSelectionSkeleton);
|
|
4176
|
+
} else {
|
|
4177
|
+
await clonedBuilder.updateByTxPrototype(selectionSkeleton);
|
|
4178
|
+
}
|
|
4126
4179
|
try {
|
|
4127
4180
|
await clonedBuilder.evaluateRedeemers();
|
|
4128
4181
|
} catch (error) {
|
|
@@ -6203,6 +6256,8 @@ var TxParser = class {
|
|
|
6203
6256
|
this.serializer = serializer;
|
|
6204
6257
|
this.fetcher = fetcher;
|
|
6205
6258
|
}
|
|
6259
|
+
serializer;
|
|
6260
|
+
fetcher;
|
|
6206
6261
|
parse = async (txHex, providedUtxos = []) => {
|
|
6207
6262
|
const resolvedUtxos = [...providedUtxos];
|
|
6208
6263
|
const resolvedUtxosSet = new Set(
|
|
@@ -6245,11 +6300,224 @@ var TxParser = class {
|
|
|
6245
6300
|
getBuilderBodyWithoutChange = () => this.serializer.parser.getBuilderBodyWithoutChange();
|
|
6246
6301
|
toTester = () => this.serializer.parser.toTester();
|
|
6247
6302
|
};
|
|
6303
|
+
|
|
6304
|
+
// src/mesh-tx-builder-v2/index.ts
|
|
6305
|
+
var import_common5 = require("@meshsdk/common");
|
|
6306
|
+
var SpendBuilderImpl = class {
|
|
6307
|
+
constructor(builder) {
|
|
6308
|
+
this.builder = builder;
|
|
6309
|
+
}
|
|
6310
|
+
builder;
|
|
6311
|
+
script(scriptCbor) {
|
|
6312
|
+
this.builder.txInScript(scriptCbor);
|
|
6313
|
+
return this;
|
|
6314
|
+
}
|
|
6315
|
+
referenceScript(refTxHash, refTxIndex, scriptSize, scriptHash) {
|
|
6316
|
+
this.builder.spendingTxInReference(
|
|
6317
|
+
refTxHash,
|
|
6318
|
+
refTxIndex,
|
|
6319
|
+
scriptSize,
|
|
6320
|
+
scriptHash
|
|
6321
|
+
);
|
|
6322
|
+
return this;
|
|
6323
|
+
}
|
|
6324
|
+
redeemerJson(redeemer, exUnits) {
|
|
6325
|
+
this.builder.txInRedeemerValue(
|
|
6326
|
+
redeemer,
|
|
6327
|
+
"JSON",
|
|
6328
|
+
exUnits ?? { ...import_common5.DEFAULT_REDEEMER_BUDGET }
|
|
6329
|
+
);
|
|
6330
|
+
return this;
|
|
6331
|
+
}
|
|
6332
|
+
redeemerCbor(redeemer, exUnits) {
|
|
6333
|
+
this.builder.txInRedeemerValue(
|
|
6334
|
+
redeemer,
|
|
6335
|
+
"CBOR",
|
|
6336
|
+
exUnits ?? { ...import_common5.DEFAULT_REDEEMER_BUDGET }
|
|
6337
|
+
);
|
|
6338
|
+
return this;
|
|
6339
|
+
}
|
|
6340
|
+
txOut(address, amount) {
|
|
6341
|
+
this.builder.txInInlineDatumPresent();
|
|
6342
|
+
this.builder.txOut(address, amount);
|
|
6343
|
+
return this;
|
|
6344
|
+
}
|
|
6345
|
+
datumJson(datum) {
|
|
6346
|
+
this.builder.txOutInlineDatumValue(datum, "JSON");
|
|
6347
|
+
return this.builder;
|
|
6348
|
+
}
|
|
6349
|
+
datumCbor(datum) {
|
|
6350
|
+
this.builder.txOutInlineDatumValue(datum, "CBOR");
|
|
6351
|
+
return this.builder;
|
|
6352
|
+
}
|
|
6353
|
+
datumHash(datumHash) {
|
|
6354
|
+
this.builder.txOutDatumHashValue(datumHash);
|
|
6355
|
+
return this.builder;
|
|
6356
|
+
}
|
|
6357
|
+
};
|
|
6358
|
+
var MintBuilderImpl = class {
|
|
6359
|
+
constructor(builder) {
|
|
6360
|
+
this.builder = builder;
|
|
6361
|
+
}
|
|
6362
|
+
builder;
|
|
6363
|
+
script(scriptCbor) {
|
|
6364
|
+
this.builder.mintingScript(scriptCbor);
|
|
6365
|
+
return this;
|
|
6366
|
+
}
|
|
6367
|
+
referenceScript(txHash, txIndex, scriptSize, scriptHash) {
|
|
6368
|
+
this.builder.mintTxInReference(txHash, txIndex, scriptSize, scriptHash);
|
|
6369
|
+
return this;
|
|
6370
|
+
}
|
|
6371
|
+
redeemerJson(redeemer, exUnits) {
|
|
6372
|
+
this.builder.mintRedeemerValue(
|
|
6373
|
+
redeemer,
|
|
6374
|
+
"JSON",
|
|
6375
|
+
exUnits ?? { ...import_common5.DEFAULT_REDEEMER_BUDGET }
|
|
6376
|
+
);
|
|
6377
|
+
return this;
|
|
6378
|
+
}
|
|
6379
|
+
redeemerCbor(redeemer, exUnits) {
|
|
6380
|
+
this.builder.mintRedeemerValue(
|
|
6381
|
+
redeemer,
|
|
6382
|
+
"CBOR",
|
|
6383
|
+
exUnits ?? { ...import_common5.DEFAULT_REDEEMER_BUDGET }
|
|
6384
|
+
);
|
|
6385
|
+
return this;
|
|
6386
|
+
}
|
|
6387
|
+
txOut(address, amount) {
|
|
6388
|
+
this.builder.txOut(address, amount);
|
|
6389
|
+
return this.builder;
|
|
6390
|
+
}
|
|
6391
|
+
};
|
|
6392
|
+
var WithdrawBuilderImpl = class {
|
|
6393
|
+
constructor(builder) {
|
|
6394
|
+
this.builder = builder;
|
|
6395
|
+
}
|
|
6396
|
+
builder;
|
|
6397
|
+
script(scriptCbor) {
|
|
6398
|
+
this.builder.withdrawalScript(scriptCbor);
|
|
6399
|
+
return this;
|
|
6400
|
+
}
|
|
6401
|
+
referenceScript(txHash, txIndex, scriptSize, scriptHash) {
|
|
6402
|
+
this.builder.withdrawalTxInReference(txHash, txIndex, scriptSize, scriptHash);
|
|
6403
|
+
return this;
|
|
6404
|
+
}
|
|
6405
|
+
redeemerJson(redeemer, exUnits) {
|
|
6406
|
+
this.builder.withdrawalRedeemerValue(
|
|
6407
|
+
redeemer,
|
|
6408
|
+
"JSON",
|
|
6409
|
+
exUnits ?? { ...import_common5.DEFAULT_REDEEMER_BUDGET }
|
|
6410
|
+
);
|
|
6411
|
+
return this.builder;
|
|
6412
|
+
}
|
|
6413
|
+
redeemerCbor(redeemer, exUnits) {
|
|
6414
|
+
this.builder.withdrawalRedeemerValue(
|
|
6415
|
+
redeemer,
|
|
6416
|
+
"CBOR",
|
|
6417
|
+
exUnits ?? { ...import_common5.DEFAULT_REDEEMER_BUDGET }
|
|
6418
|
+
);
|
|
6419
|
+
return this.builder;
|
|
6420
|
+
}
|
|
6421
|
+
};
|
|
6422
|
+
var VoteBuilderImpl = class {
|
|
6423
|
+
constructor(builder) {
|
|
6424
|
+
this.builder = builder;
|
|
6425
|
+
}
|
|
6426
|
+
builder;
|
|
6427
|
+
script(scriptCbor) {
|
|
6428
|
+
this.builder.voteScript(scriptCbor);
|
|
6429
|
+
return this;
|
|
6430
|
+
}
|
|
6431
|
+
referenceScript(txHash, txIndex, scriptSize, scriptHash) {
|
|
6432
|
+
this.builder.voteTxInReference(txHash, txIndex, scriptSize, scriptHash);
|
|
6433
|
+
return this;
|
|
6434
|
+
}
|
|
6435
|
+
redeemerJson(redeemer, exUnits) {
|
|
6436
|
+
this.builder.voteRedeemerValue(
|
|
6437
|
+
redeemer,
|
|
6438
|
+
"JSON",
|
|
6439
|
+
exUnits ?? { ...import_common5.DEFAULT_REDEEMER_BUDGET }
|
|
6440
|
+
);
|
|
6441
|
+
return this.builder;
|
|
6442
|
+
}
|
|
6443
|
+
redeemerCbor(redeemer, exUnits) {
|
|
6444
|
+
this.builder.voteRedeemerValue(
|
|
6445
|
+
redeemer,
|
|
6446
|
+
"CBOR",
|
|
6447
|
+
exUnits ?? { ...import_common5.DEFAULT_REDEEMER_BUDGET }
|
|
6448
|
+
);
|
|
6449
|
+
return this.builder;
|
|
6450
|
+
}
|
|
6451
|
+
};
|
|
6452
|
+
var TxBuilderV2 = class extends MeshTxBuilder {
|
|
6453
|
+
spendPlutusV1(txHash, txIndex) {
|
|
6454
|
+
this.spendingPlutusScriptV1();
|
|
6455
|
+
this.txIn(txHash, txIndex);
|
|
6456
|
+
return new SpendBuilderImpl(this);
|
|
6457
|
+
}
|
|
6458
|
+
spendPlutusV2(txHash, txIndex) {
|
|
6459
|
+
this.spendingPlutusScriptV2();
|
|
6460
|
+
this.txIn(txHash, txIndex);
|
|
6461
|
+
return new SpendBuilderImpl(this);
|
|
6462
|
+
}
|
|
6463
|
+
spendPlutusV3(txHash, txIndex) {
|
|
6464
|
+
this.spendingPlutusScriptV3();
|
|
6465
|
+
this.txIn(txHash, txIndex);
|
|
6466
|
+
return new SpendBuilderImpl(this);
|
|
6467
|
+
}
|
|
6468
|
+
mintPlutusV1(quantity, policyId, assetName) {
|
|
6469
|
+
this.mintPlutusScriptV1();
|
|
6470
|
+
this.mint(quantity, policyId, assetName);
|
|
6471
|
+
return new MintBuilderImpl(this);
|
|
6472
|
+
}
|
|
6473
|
+
mintPlutusV2(quantity, policyId, assetName) {
|
|
6474
|
+
this.mintPlutusScriptV2();
|
|
6475
|
+
this.mint(quantity, policyId, assetName);
|
|
6476
|
+
return new MintBuilderImpl(this);
|
|
6477
|
+
}
|
|
6478
|
+
mintPlutusV3(quantity, policyId, assetName) {
|
|
6479
|
+
this.mintPlutusScriptV3();
|
|
6480
|
+
this.mint(quantity, policyId, assetName);
|
|
6481
|
+
return new MintBuilderImpl(this);
|
|
6482
|
+
}
|
|
6483
|
+
withdrawPlutusV1(rewardAddress, amount) {
|
|
6484
|
+
this.withdrawalPlutusScriptV1();
|
|
6485
|
+
this.withdrawal(rewardAddress, amount);
|
|
6486
|
+
return new WithdrawBuilderImpl(this);
|
|
6487
|
+
}
|
|
6488
|
+
withdrawPlutusV2(rewardAddress, coin) {
|
|
6489
|
+
this.withdrawalPlutusScriptV2();
|
|
6490
|
+
this.withdrawal(rewardAddress, coin);
|
|
6491
|
+
return new WithdrawBuilderImpl(this);
|
|
6492
|
+
}
|
|
6493
|
+
withdrawPlutusV3(rewardAddress, coin) {
|
|
6494
|
+
this.withdrawalPlutusScriptV3();
|
|
6495
|
+
this.withdrawal(rewardAddress, coin);
|
|
6496
|
+
return new WithdrawBuilderImpl(this);
|
|
6497
|
+
}
|
|
6498
|
+
votePlutusV1(voter, govActionId, votingProcedure) {
|
|
6499
|
+
this.votePlutusScriptV1();
|
|
6500
|
+
this.vote(voter, govActionId, votingProcedure);
|
|
6501
|
+
return new VoteBuilderImpl(this);
|
|
6502
|
+
}
|
|
6503
|
+
votePlutusV2(voter, govActionId, votingProcedure) {
|
|
6504
|
+
this.votePlutusScriptV2();
|
|
6505
|
+
this.vote(voter, govActionId, votingProcedure);
|
|
6506
|
+
return new VoteBuilderImpl(this);
|
|
6507
|
+
}
|
|
6508
|
+
votePlutusV3(voter, govActionId, votingProcedure) {
|
|
6509
|
+
this.votePlutusScriptV3();
|
|
6510
|
+
this.vote(voter, govActionId, votingProcedure);
|
|
6511
|
+
return new VoteBuilderImpl(this);
|
|
6512
|
+
}
|
|
6513
|
+
};
|
|
6514
|
+
var MeshTxBuilderV2 = TxBuilderV2;
|
|
6248
6515
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6249
6516
|
0 && (module.exports = {
|
|
6250
6517
|
ForgeScript,
|
|
6251
6518
|
LargestFirstInputSelector,
|
|
6252
6519
|
MeshTxBuilder,
|
|
6520
|
+
MeshTxBuilderV2,
|
|
6253
6521
|
Transaction,
|
|
6254
6522
|
TxParser,
|
|
6255
6523
|
cloneOutput,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _meshsdk_common from '@meshsdk/common';
|
|
2
|
-
import { TxIn, Output, Asset, UTxO, TxOutput, Action, Protocol, MintItem, Withdrawal, Vote, Proposal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, BuilderData, LanguageVersion, Voter, VotingProcedure, GovernanceAction, Anchor, RewardAddress, PoolParams, DRep, Metadatum, Network, Redeemer, IFetcher, ISubmitter, IEvaluator,
|
|
2
|
+
import { TxIn, Output, Asset, UTxO, TxOutput, Action, Protocol, MintItem, Withdrawal, Vote, Proposal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, BuilderData, LanguageVersion, Voter, VotingProcedure, GovernanceAction, Anchor, RewardAddress, PoolParams, DRep, Metadatum, Network, Redeemer, IMeshTxSerializer, IFetcher, ISubmitter, IEvaluator, ScriptSource, SimpleScriptSourceInfo, Certificate, MintParam, NativeScript as NativeScript$1, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
|
|
3
3
|
import { CredentialCore, NativeScript } from '@meshsdk/core-cst';
|
|
4
4
|
|
|
5
5
|
interface TransactionPrototype {
|
|
@@ -582,6 +582,12 @@ declare class MeshTxBuilderCore {
|
|
|
582
582
|
* @returns The MeshTxBuilder instance
|
|
583
583
|
*/
|
|
584
584
|
setNetwork: (network: Network | number[][]) => this;
|
|
585
|
+
/**
|
|
586
|
+
* Alias for setNetwork for custom cost models
|
|
587
|
+
* @param costModels
|
|
588
|
+
* @returns The MeshTxBuilder instance
|
|
589
|
+
*/
|
|
590
|
+
setCostModels: (costModels: number[][]) => this;
|
|
585
591
|
/**
|
|
586
592
|
* Add a transaction that is used as input, but not yet reflected on the global blockchain
|
|
587
593
|
* @param txHex The transaction hex of chained transaction
|
|
@@ -652,6 +658,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
652
658
|
protected utxosWithRefScripts: UTxO[];
|
|
653
659
|
constructor({ serializer, selector, fetcher, submitter, evaluator, params, isHydra, verbose, }?: MeshTxBuilderOptions);
|
|
654
660
|
serializeMockTx: () => string;
|
|
661
|
+
completeCostModels: () => Promise<void>;
|
|
655
662
|
/**
|
|
656
663
|
* It builds the transaction query the blockchain for missing information
|
|
657
664
|
* @param customizedTx The optional customized transaction body
|
|
@@ -1053,4 +1060,87 @@ declare class TxParser {
|
|
|
1053
1060
|
toTester: () => _meshsdk_common.TxTester;
|
|
1054
1061
|
}
|
|
1055
1062
|
|
|
1056
|
-
|
|
1063
|
+
interface _MeshTxBuilderV2 extends Omit<MeshTxBuilder, ScriptMethodsToDrop> {
|
|
1064
|
+
spendPlutusV1(txHash: string, txIndex: number): SpendScriptBuilder;
|
|
1065
|
+
spendPlutusV2(txHash: string, txIndex: number): SpendScriptBuilder;
|
|
1066
|
+
spendPlutusV3(txHash: string, txIndex: number): SpendScriptBuilder;
|
|
1067
|
+
mintPlutusV1(quantity: string, policyId: string, assetName: string): MintScriptBuilder;
|
|
1068
|
+
mintPlutusV2(quantity: string, policyId: string, assetName: string): MintScriptBuilder;
|
|
1069
|
+
mintPlutusV3(quantity: string, policyId: string, assetName: string): MintScriptBuilder;
|
|
1070
|
+
withdrawPlutusV1(rewardAddress: string, amount: string): WithdrawScriptBuilder;
|
|
1071
|
+
withdrawPlutusV2(rewardAddress: string, amount: string): WithdrawScriptBuilder;
|
|
1072
|
+
withdrawPlutusV3(rewardAddress: string, amount: string): WithdrawScriptBuilder;
|
|
1073
|
+
votePlutusV1(voter: Voter, govActionId: RefTxIn, votingProcedure: VotingProcedure): VoteScriptBuilder;
|
|
1074
|
+
votePlutusV2(voter: Voter, govActionId: RefTxIn, votingProcedure: VotingProcedure): VoteScriptBuilder;
|
|
1075
|
+
votePlutusV3(voter: Voter, govActionId: RefTxIn, votingProcedure: VotingProcedure): VoteScriptBuilder;
|
|
1076
|
+
}
|
|
1077
|
+
type ScriptMethodsToDrop = "spendingPlutusScript" | "spendingPlutusScriptV1" | "spendingPlutusScriptV2" | "spendingPlutusScriptV3" | "spendingTxInReference" | "spendingReferenceTxInInlineDatumPresent" | "spendingReferenceTxInRedeemerValue" | "mintPlutusScript" | "mintPlutusScriptV1" | "mintPlutusScriptV2" | "mintPlutusScriptV3" | "mintingScript" | "mintTxInReference" | "mintReferenceTxInRedeemerValue" | "mintRedeemerValue" | "withdrawalPlutusScript" | "withdrawalPlutusScriptV1" | "withdrawalPlutusScriptV2" | "withdrawalPlutusScriptV3" | "withdrawalScript" | "withdrawalTxInReference" | "withdrawalReferenceTxInRedeemerValue" | "withdrawalRedeemerValue" | "votePlutusScript" | "votePlutusScriptV1" | "votePlutusScriptV2" | "votePlutusScriptV3" | "voteScript" | "voteTxInReference" | "voteReferenceTxInRedeemerValue" | "voteRedeemerValue" | "txInScript" | "txInDatumValue" | "txInInlineDatumPresent" | "txInRedeemerValue";
|
|
1078
|
+
interface SpendScriptBuilder {
|
|
1079
|
+
script(scriptCbor: string): SpendRedeemerBuilder;
|
|
1080
|
+
referenceScript(refTxHash: string, refTxIndex: number, scriptSize?: string, scriptHash?: string): SpendRedeemerBuilder;
|
|
1081
|
+
}
|
|
1082
|
+
interface SpendRedeemerBuilder {
|
|
1083
|
+
redeemerJson(redeemer: BuilderData["content"], exUnits?: Budget): SpendTxOutBuilder;
|
|
1084
|
+
redeemerCbor(redeemer: BuilderData["content"], exUnits?: Budget): SpendTxOutBuilder;
|
|
1085
|
+
}
|
|
1086
|
+
interface SpendTxOutBuilder {
|
|
1087
|
+
txOut(address: string, amount: Asset[]): SpendDatumBuilder;
|
|
1088
|
+
}
|
|
1089
|
+
interface SpendDatumBuilder {
|
|
1090
|
+
datumHash(datumHash: string): _MeshTxBuilderV2;
|
|
1091
|
+
datumCbor(datumCbor: BuilderData["content"]): _MeshTxBuilderV2;
|
|
1092
|
+
datumJson(datumJson: BuilderData["content"]): _MeshTxBuilderV2;
|
|
1093
|
+
}
|
|
1094
|
+
interface MintScriptBuilder {
|
|
1095
|
+
script(scriptCbor: string): MintRedeemerBuilder;
|
|
1096
|
+
referenceScript(txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string): MintRedeemerBuilder;
|
|
1097
|
+
}
|
|
1098
|
+
interface MintRedeemerBuilder {
|
|
1099
|
+
redeemerJson(redeemer: BuilderData["content"], exUnits?: Budget): MintTxOutBuilder;
|
|
1100
|
+
redeemerCbor(redeemer: BuilderData["content"], exUnits?: Budget): MintTxOutBuilder;
|
|
1101
|
+
}
|
|
1102
|
+
interface MintTxOutBuilder {
|
|
1103
|
+
txOut(address: string, amount: Asset[]): _MeshTxBuilderV2;
|
|
1104
|
+
}
|
|
1105
|
+
interface VoteScriptBuilder {
|
|
1106
|
+
script(scriptCbor: string): VoteRedeemerBuilder;
|
|
1107
|
+
referenceScript(txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string): VoteRedeemerBuilder;
|
|
1108
|
+
}
|
|
1109
|
+
interface VoteRedeemerBuilder {
|
|
1110
|
+
redeemerJson(redeemer: BuilderData["content"], exUnits?: Budget): _MeshTxBuilderV2;
|
|
1111
|
+
redeemerCbor(redeemer: BuilderData["content"], exUnits?: Budget): _MeshTxBuilderV2;
|
|
1112
|
+
}
|
|
1113
|
+
interface WithdrawScriptBuilder {
|
|
1114
|
+
script(scriptCbor: string): WithdrawRedeemerBuilder;
|
|
1115
|
+
referenceScript(txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string): WithdrawRedeemerBuilder;
|
|
1116
|
+
}
|
|
1117
|
+
interface WithdrawRedeemerBuilder {
|
|
1118
|
+
redeemerJson(redeemer: BuilderData["content"], exUnits?: Budget): _MeshTxBuilderV2;
|
|
1119
|
+
redeemerCbor(redeemer: BuilderData["content"], exUnits?: Budget): _MeshTxBuilderV2;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* \`MeshTxBuilderV2\` is a strongly-typed wrapper around the core \`MeshTxBuilder\`
|
|
1124
|
+
* that enforces a rigid Type-State machine for Plutus operations.
|
|
1125
|
+
*
|
|
1126
|
+
* It natively provides TypeScript autocomplete restrictions (Script -> Redeemer -> TxOut -> Datum)
|
|
1127
|
+
* for transactions like spending, minting, withdrawing, and voting, dropping standalone
|
|
1128
|
+
* script methods to prevent incorrect chained execution ordering.
|
|
1129
|
+
*
|
|
1130
|
+
* @example
|
|
1131
|
+
* ```typescript
|
|
1132
|
+
* const tx = new MeshTxBuilderV2({
|
|
1133
|
+
* fetcher: provider,
|
|
1134
|
+
* evaluator: provider,
|
|
1135
|
+
* });
|
|
1136
|
+
*
|
|
1137
|
+
* tx.spendPlutusV3(txHash, index)
|
|
1138
|
+
* .script(scriptCbor)
|
|
1139
|
+
* .redeemerJson(redeemerValue)
|
|
1140
|
+
* .txOut(address, assets)
|
|
1141
|
+
* .datumJson(datumValue); // Drops you back into the main builder methods
|
|
1142
|
+
* ```
|
|
1143
|
+
*/
|
|
1144
|
+
declare const MeshTxBuilderV2: new (options?: MeshTxBuilderOptions) => _MeshTxBuilderV2;
|
|
1145
|
+
|
|
1146
|
+
export { ForgeScript, LargestFirstInputSelector, MeshTxBuilder, type MeshTxBuilderOptions, MeshTxBuilderV2, type MetadataMergeLevel, Transaction, type TransactionOptions, TxParser, cloneOutput, getLovelace, getOutputMinLovelace, getUtxoMinLovelace, mergeContents, metadataObjToMap, setLoveLace, utxoToTxIn };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _meshsdk_common from '@meshsdk/common';
|
|
2
|
-
import { TxIn, Output, Asset, UTxO, TxOutput, Action, Protocol, MintItem, Withdrawal, Vote, Proposal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, BuilderData, LanguageVersion, Voter, VotingProcedure, GovernanceAction, Anchor, RewardAddress, PoolParams, DRep, Metadatum, Network, Redeemer, IFetcher, ISubmitter, IEvaluator,
|
|
2
|
+
import { TxIn, Output, Asset, UTxO, TxOutput, Action, Protocol, MintItem, Withdrawal, Vote, Proposal, PubKeyTxIn, RefTxIn, MeshTxBuilderBody, BuilderData, LanguageVersion, Voter, VotingProcedure, GovernanceAction, Anchor, RewardAddress, PoolParams, DRep, Metadatum, Network, Redeemer, IMeshTxSerializer, IFetcher, ISubmitter, IEvaluator, ScriptSource, SimpleScriptSourceInfo, Certificate, MintParam, NativeScript as NativeScript$1, IInitiator, Recipient, Token, PlutusScript, Budget, Data, Mint } from '@meshsdk/common';
|
|
3
3
|
import { CredentialCore, NativeScript } from '@meshsdk/core-cst';
|
|
4
4
|
|
|
5
5
|
interface TransactionPrototype {
|
|
@@ -582,6 +582,12 @@ declare class MeshTxBuilderCore {
|
|
|
582
582
|
* @returns The MeshTxBuilder instance
|
|
583
583
|
*/
|
|
584
584
|
setNetwork: (network: Network | number[][]) => this;
|
|
585
|
+
/**
|
|
586
|
+
* Alias for setNetwork for custom cost models
|
|
587
|
+
* @param costModels
|
|
588
|
+
* @returns The MeshTxBuilder instance
|
|
589
|
+
*/
|
|
590
|
+
setCostModels: (costModels: number[][]) => this;
|
|
585
591
|
/**
|
|
586
592
|
* Add a transaction that is used as input, but not yet reflected on the global blockchain
|
|
587
593
|
* @param txHex The transaction hex of chained transaction
|
|
@@ -652,6 +658,7 @@ declare class MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
652
658
|
protected utxosWithRefScripts: UTxO[];
|
|
653
659
|
constructor({ serializer, selector, fetcher, submitter, evaluator, params, isHydra, verbose, }?: MeshTxBuilderOptions);
|
|
654
660
|
serializeMockTx: () => string;
|
|
661
|
+
completeCostModels: () => Promise<void>;
|
|
655
662
|
/**
|
|
656
663
|
* It builds the transaction query the blockchain for missing information
|
|
657
664
|
* @param customizedTx The optional customized transaction body
|
|
@@ -1053,4 +1060,87 @@ declare class TxParser {
|
|
|
1053
1060
|
toTester: () => _meshsdk_common.TxTester;
|
|
1054
1061
|
}
|
|
1055
1062
|
|
|
1056
|
-
|
|
1063
|
+
interface _MeshTxBuilderV2 extends Omit<MeshTxBuilder, ScriptMethodsToDrop> {
|
|
1064
|
+
spendPlutusV1(txHash: string, txIndex: number): SpendScriptBuilder;
|
|
1065
|
+
spendPlutusV2(txHash: string, txIndex: number): SpendScriptBuilder;
|
|
1066
|
+
spendPlutusV3(txHash: string, txIndex: number): SpendScriptBuilder;
|
|
1067
|
+
mintPlutusV1(quantity: string, policyId: string, assetName: string): MintScriptBuilder;
|
|
1068
|
+
mintPlutusV2(quantity: string, policyId: string, assetName: string): MintScriptBuilder;
|
|
1069
|
+
mintPlutusV3(quantity: string, policyId: string, assetName: string): MintScriptBuilder;
|
|
1070
|
+
withdrawPlutusV1(rewardAddress: string, amount: string): WithdrawScriptBuilder;
|
|
1071
|
+
withdrawPlutusV2(rewardAddress: string, amount: string): WithdrawScriptBuilder;
|
|
1072
|
+
withdrawPlutusV3(rewardAddress: string, amount: string): WithdrawScriptBuilder;
|
|
1073
|
+
votePlutusV1(voter: Voter, govActionId: RefTxIn, votingProcedure: VotingProcedure): VoteScriptBuilder;
|
|
1074
|
+
votePlutusV2(voter: Voter, govActionId: RefTxIn, votingProcedure: VotingProcedure): VoteScriptBuilder;
|
|
1075
|
+
votePlutusV3(voter: Voter, govActionId: RefTxIn, votingProcedure: VotingProcedure): VoteScriptBuilder;
|
|
1076
|
+
}
|
|
1077
|
+
type ScriptMethodsToDrop = "spendingPlutusScript" | "spendingPlutusScriptV1" | "spendingPlutusScriptV2" | "spendingPlutusScriptV3" | "spendingTxInReference" | "spendingReferenceTxInInlineDatumPresent" | "spendingReferenceTxInRedeemerValue" | "mintPlutusScript" | "mintPlutusScriptV1" | "mintPlutusScriptV2" | "mintPlutusScriptV3" | "mintingScript" | "mintTxInReference" | "mintReferenceTxInRedeemerValue" | "mintRedeemerValue" | "withdrawalPlutusScript" | "withdrawalPlutusScriptV1" | "withdrawalPlutusScriptV2" | "withdrawalPlutusScriptV3" | "withdrawalScript" | "withdrawalTxInReference" | "withdrawalReferenceTxInRedeemerValue" | "withdrawalRedeemerValue" | "votePlutusScript" | "votePlutusScriptV1" | "votePlutusScriptV2" | "votePlutusScriptV3" | "voteScript" | "voteTxInReference" | "voteReferenceTxInRedeemerValue" | "voteRedeemerValue" | "txInScript" | "txInDatumValue" | "txInInlineDatumPresent" | "txInRedeemerValue";
|
|
1078
|
+
interface SpendScriptBuilder {
|
|
1079
|
+
script(scriptCbor: string): SpendRedeemerBuilder;
|
|
1080
|
+
referenceScript(refTxHash: string, refTxIndex: number, scriptSize?: string, scriptHash?: string): SpendRedeemerBuilder;
|
|
1081
|
+
}
|
|
1082
|
+
interface SpendRedeemerBuilder {
|
|
1083
|
+
redeemerJson(redeemer: BuilderData["content"], exUnits?: Budget): SpendTxOutBuilder;
|
|
1084
|
+
redeemerCbor(redeemer: BuilderData["content"], exUnits?: Budget): SpendTxOutBuilder;
|
|
1085
|
+
}
|
|
1086
|
+
interface SpendTxOutBuilder {
|
|
1087
|
+
txOut(address: string, amount: Asset[]): SpendDatumBuilder;
|
|
1088
|
+
}
|
|
1089
|
+
interface SpendDatumBuilder {
|
|
1090
|
+
datumHash(datumHash: string): _MeshTxBuilderV2;
|
|
1091
|
+
datumCbor(datumCbor: BuilderData["content"]): _MeshTxBuilderV2;
|
|
1092
|
+
datumJson(datumJson: BuilderData["content"]): _MeshTxBuilderV2;
|
|
1093
|
+
}
|
|
1094
|
+
interface MintScriptBuilder {
|
|
1095
|
+
script(scriptCbor: string): MintRedeemerBuilder;
|
|
1096
|
+
referenceScript(txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string): MintRedeemerBuilder;
|
|
1097
|
+
}
|
|
1098
|
+
interface MintRedeemerBuilder {
|
|
1099
|
+
redeemerJson(redeemer: BuilderData["content"], exUnits?: Budget): MintTxOutBuilder;
|
|
1100
|
+
redeemerCbor(redeemer: BuilderData["content"], exUnits?: Budget): MintTxOutBuilder;
|
|
1101
|
+
}
|
|
1102
|
+
interface MintTxOutBuilder {
|
|
1103
|
+
txOut(address: string, amount: Asset[]): _MeshTxBuilderV2;
|
|
1104
|
+
}
|
|
1105
|
+
interface VoteScriptBuilder {
|
|
1106
|
+
script(scriptCbor: string): VoteRedeemerBuilder;
|
|
1107
|
+
referenceScript(txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string): VoteRedeemerBuilder;
|
|
1108
|
+
}
|
|
1109
|
+
interface VoteRedeemerBuilder {
|
|
1110
|
+
redeemerJson(redeemer: BuilderData["content"], exUnits?: Budget): _MeshTxBuilderV2;
|
|
1111
|
+
redeemerCbor(redeemer: BuilderData["content"], exUnits?: Budget): _MeshTxBuilderV2;
|
|
1112
|
+
}
|
|
1113
|
+
interface WithdrawScriptBuilder {
|
|
1114
|
+
script(scriptCbor: string): WithdrawRedeemerBuilder;
|
|
1115
|
+
referenceScript(txHash: string, txIndex: number, scriptSize?: string, scriptHash?: string): WithdrawRedeemerBuilder;
|
|
1116
|
+
}
|
|
1117
|
+
interface WithdrawRedeemerBuilder {
|
|
1118
|
+
redeemerJson(redeemer: BuilderData["content"], exUnits?: Budget): _MeshTxBuilderV2;
|
|
1119
|
+
redeemerCbor(redeemer: BuilderData["content"], exUnits?: Budget): _MeshTxBuilderV2;
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* \`MeshTxBuilderV2\` is a strongly-typed wrapper around the core \`MeshTxBuilder\`
|
|
1124
|
+
* that enforces a rigid Type-State machine for Plutus operations.
|
|
1125
|
+
*
|
|
1126
|
+
* It natively provides TypeScript autocomplete restrictions (Script -> Redeemer -> TxOut -> Datum)
|
|
1127
|
+
* for transactions like spending, minting, withdrawing, and voting, dropping standalone
|
|
1128
|
+
* script methods to prevent incorrect chained execution ordering.
|
|
1129
|
+
*
|
|
1130
|
+
* @example
|
|
1131
|
+
* ```typescript
|
|
1132
|
+
* const tx = new MeshTxBuilderV2({
|
|
1133
|
+
* fetcher: provider,
|
|
1134
|
+
* evaluator: provider,
|
|
1135
|
+
* });
|
|
1136
|
+
*
|
|
1137
|
+
* tx.spendPlutusV3(txHash, index)
|
|
1138
|
+
* .script(scriptCbor)
|
|
1139
|
+
* .redeemerJson(redeemerValue)
|
|
1140
|
+
* .txOut(address, assets)
|
|
1141
|
+
* .datumJson(datumValue); // Drops you back into the main builder methods
|
|
1142
|
+
* ```
|
|
1143
|
+
*/
|
|
1144
|
+
declare const MeshTxBuilderV2: new (options?: MeshTxBuilderOptions) => _MeshTxBuilderV2;
|
|
1145
|
+
|
|
1146
|
+
export { ForgeScript, LargestFirstInputSelector, MeshTxBuilder, type MeshTxBuilderOptions, MeshTxBuilderV2, type MetadataMergeLevel, Transaction, type TransactionOptions, TxParser, cloneOutput, getLovelace, getOutputMinLovelace, getUtxoMinLovelace, mergeContents, metadataObjToMap, setLoveLace, utxoToTxIn };
|
package/dist/index.js
CHANGED
|
@@ -1345,7 +1345,10 @@ var bignumber_default = BigNumber;
|
|
|
1345
1345
|
// src/mesh-tx-builder/index.ts
|
|
1346
1346
|
import JSONBig3 from "json-bigint";
|
|
1347
1347
|
import {
|
|
1348
|
-
DEFAULT_PROTOCOL_PARAMETERS as DEFAULT_PROTOCOL_PARAMETERS3
|
|
1348
|
+
DEFAULT_PROTOCOL_PARAMETERS as DEFAULT_PROTOCOL_PARAMETERS3,
|
|
1349
|
+
DEFAULT_V1_COST_MODEL_LIST,
|
|
1350
|
+
DEFAULT_V2_COST_MODEL_LIST,
|
|
1351
|
+
DEFAULT_V3_COST_MODEL_LIST
|
|
1349
1352
|
} from "@meshsdk/common";
|
|
1350
1353
|
import {
|
|
1351
1354
|
CardanoSDKSerializer,
|
|
@@ -1390,7 +1393,7 @@ var BuilderCallbacksSdkBridge = class {
|
|
|
1390
1393
|
change: selectionSkeleton.change.map(
|
|
1391
1394
|
(output) => CSDKOutputToMeshOutput(output)
|
|
1392
1395
|
),
|
|
1393
|
-
fee:
|
|
1396
|
+
fee: BigInt(1e9)
|
|
1394
1397
|
});
|
|
1395
1398
|
return {
|
|
1396
1399
|
fee: costs.fee,
|
|
@@ -1732,7 +1735,6 @@ var CSDKRedeemerTagToMeshRedeemerTag = (tag) => {
|
|
|
1732
1735
|
};
|
|
1733
1736
|
|
|
1734
1737
|
// src/mesh-tx-builder/coin-selection/largest-first-selector.ts
|
|
1735
|
-
var MAX_U64 = 18446744073709551615n;
|
|
1736
1738
|
var mergeValue = (a, b) => {
|
|
1737
1739
|
const merged = new Map(a);
|
|
1738
1740
|
b.forEach((quantity, unit) => {
|
|
@@ -1841,10 +1843,10 @@ var LargestFirstInputSelector = class {
|
|
|
1841
1843
|
computeChangeOutputs = (remainingValue, changeAddress, constraints) => {
|
|
1842
1844
|
let lovelaceAvailable = remainingValue.get("lovelace") || 0n;
|
|
1843
1845
|
let valueFulfilled = true;
|
|
1844
|
-
const valueAssets = remainingValue.entries().filter(([_, quantity]) => quantity > 0n).map(([unit, quantity]) => ({
|
|
1846
|
+
const valueAssets = Array.from(remainingValue.entries()).filter(([_, quantity]) => quantity > 0n).map(([unit, quantity]) => ({
|
|
1845
1847
|
unit,
|
|
1846
1848
|
quantity: String(quantity)
|
|
1847
|
-
}))
|
|
1849
|
+
}));
|
|
1848
1850
|
const changeOutputs = [];
|
|
1849
1851
|
let currentBundle = [
|
|
1850
1852
|
{
|
|
@@ -1920,9 +1922,11 @@ var LargestFirstInputSelector = class {
|
|
|
1920
1922
|
let remainingUtxos = [...availableUtxos];
|
|
1921
1923
|
const selectedUtxos = /* @__PURE__ */ new Set();
|
|
1922
1924
|
while (remainingUtxos.length > 0) {
|
|
1923
|
-
const assetToSelect = remainingValue.entries().find(
|
|
1924
|
-
|
|
1925
|
-
|
|
1925
|
+
const assetToSelect = Array.from(remainingValue.entries()).find(
|
|
1926
|
+
([_2, quantity]) => {
|
|
1927
|
+
return quantity < 0n;
|
|
1928
|
+
}
|
|
1929
|
+
);
|
|
1926
1930
|
if (!assetToSelect) {
|
|
1927
1931
|
break;
|
|
1928
1932
|
}
|
|
@@ -1977,7 +1981,7 @@ var LargestFirstInputSelector = class {
|
|
|
1977
1981
|
newInputs: selectedUtxos,
|
|
1978
1982
|
newOutputs: /* @__PURE__ */ new Set(),
|
|
1979
1983
|
change: changeOutputs,
|
|
1980
|
-
fee:
|
|
1984
|
+
fee: BigInt(1e9)
|
|
1981
1985
|
})).fee;
|
|
1982
1986
|
}
|
|
1983
1987
|
}
|
|
@@ -2031,8 +2035,8 @@ import {
|
|
|
2031
2035
|
DEFAULT_PROTOCOL_PARAMETERS,
|
|
2032
2036
|
DEFAULT_REDEEMER_BUDGET,
|
|
2033
2037
|
DREP_DEPOSIT,
|
|
2034
|
-
|
|
2035
|
-
|
|
2038
|
+
emptyTxBuilderBody,
|
|
2039
|
+
VOTING_PROPOSAL_DEPOSIT
|
|
2036
2040
|
} from "@meshsdk/common";
|
|
2037
2041
|
import { Address, CredentialType } from "@meshsdk/core-cst";
|
|
2038
2042
|
|
|
@@ -3115,9 +3119,12 @@ var MeshTxBuilderCore = class {
|
|
|
3115
3119
|
* @returns The MeshTxBuilder instance
|
|
3116
3120
|
*/
|
|
3117
3121
|
proposalRedeemerValue = (redeemer, type = "Mesh", exUnits = { ...DEFAULT_REDEEMER_BUDGET }) => {
|
|
3118
|
-
if (!this.proposalItem)
|
|
3122
|
+
if (!this.proposalItem)
|
|
3123
|
+
throw Error("proposalRedeemerValue: Undefined proposal");
|
|
3119
3124
|
if (!(this.proposalItem.type === "ScriptProposal"))
|
|
3120
|
-
throw Error(
|
|
3125
|
+
throw Error(
|
|
3126
|
+
"proposalRedeemerValue: Adding redeemer to non plutus proposal"
|
|
3127
|
+
);
|
|
3121
3128
|
this.proposalItem.redeemer = this.castBuilderDataToRedeemer(
|
|
3122
3129
|
redeemer,
|
|
3123
3130
|
type,
|
|
@@ -3505,6 +3512,15 @@ var MeshTxBuilderCore = class {
|
|
|
3505
3512
|
this.meshTxBuilderBody.network = network;
|
|
3506
3513
|
return this;
|
|
3507
3514
|
};
|
|
3515
|
+
/**
|
|
3516
|
+
* Alias for setNetwork for custom cost models
|
|
3517
|
+
* @param costModels
|
|
3518
|
+
* @returns The MeshTxBuilder instance
|
|
3519
|
+
*/
|
|
3520
|
+
setCostModels = (costModels) => {
|
|
3521
|
+
this.setNetwork(costModels);
|
|
3522
|
+
return this;
|
|
3523
|
+
};
|
|
3508
3524
|
/**
|
|
3509
3525
|
* Add a transaction that is used as input, but not yet reflected on the global blockchain
|
|
3510
3526
|
* @param txHex The transaction hex of chained transaction
|
|
@@ -3999,6 +4015,36 @@ var MeshTxBuilder = class _MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
3999
4015
|
this._protocolParams
|
|
4000
4016
|
);
|
|
4001
4017
|
};
|
|
4018
|
+
completeCostModels = async () => {
|
|
4019
|
+
if (Array.isArray(this.meshTxBuilderBody.network)) {
|
|
4020
|
+
return;
|
|
4021
|
+
}
|
|
4022
|
+
const defaults = [
|
|
4023
|
+
DEFAULT_V1_COST_MODEL_LIST,
|
|
4024
|
+
DEFAULT_V2_COST_MODEL_LIST,
|
|
4025
|
+
DEFAULT_V3_COST_MODEL_LIST
|
|
4026
|
+
];
|
|
4027
|
+
if (this.fetcher) {
|
|
4028
|
+
try {
|
|
4029
|
+
console.log("fetching cost models from fetcher...");
|
|
4030
|
+
const costModels = await this.fetcher.fetchCostModels();
|
|
4031
|
+
if (Array.isArray(costModels) && costModels.length > 0) {
|
|
4032
|
+
this.meshTxBuilderBody.network = costModels;
|
|
4033
|
+
return;
|
|
4034
|
+
}
|
|
4035
|
+
console.warn(
|
|
4036
|
+
"fetchCostModels returned an invalid value, using default cost models:",
|
|
4037
|
+
costModels
|
|
4038
|
+
);
|
|
4039
|
+
} catch (error) {
|
|
4040
|
+
console.warn(
|
|
4041
|
+
"Failed to fetch cost models, using default cost models. Error: ",
|
|
4042
|
+
error
|
|
4043
|
+
);
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
this.meshTxBuilderBody.network = defaults;
|
|
4047
|
+
};
|
|
4002
4048
|
/**
|
|
4003
4049
|
* It builds the transaction query the blockchain for missing information
|
|
4004
4050
|
* @param customizedTx The optional customized transaction body
|
|
@@ -4042,6 +4088,7 @@ var MeshTxBuilder = class _MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
4042
4088
|
this.setFee(customizedTx.fee);
|
|
4043
4089
|
}
|
|
4044
4090
|
}
|
|
4091
|
+
await this.completeCostModels();
|
|
4045
4092
|
this.queueAllLastItem();
|
|
4046
4093
|
if (this.verbose) {
|
|
4047
4094
|
console.log(
|
|
@@ -4099,7 +4146,15 @@ var MeshTxBuilder = class _MeshTxBuilder extends MeshTxBuilderCore {
|
|
|
4099
4146
|
const selectionCallbacks = {
|
|
4100
4147
|
computeMinimumCost: async (selectionSkeleton) => {
|
|
4101
4148
|
const clonedBuilder = this.clone();
|
|
4102
|
-
|
|
4149
|
+
if (this.manualFee) {
|
|
4150
|
+
const newSelectionSkeleton = {
|
|
4151
|
+
...selectionSkeleton,
|
|
4152
|
+
fee: BigInt(this.manualFee)
|
|
4153
|
+
};
|
|
4154
|
+
await clonedBuilder.updateByTxPrototype(newSelectionSkeleton);
|
|
4155
|
+
} else {
|
|
4156
|
+
await clonedBuilder.updateByTxPrototype(selectionSkeleton);
|
|
4157
|
+
}
|
|
4103
4158
|
try {
|
|
4104
4159
|
await clonedBuilder.evaluateRedeemers();
|
|
4105
4160
|
} catch (error) {
|
|
@@ -6203,6 +6258,8 @@ var TxParser = class {
|
|
|
6203
6258
|
this.serializer = serializer;
|
|
6204
6259
|
this.fetcher = fetcher;
|
|
6205
6260
|
}
|
|
6261
|
+
serializer;
|
|
6262
|
+
fetcher;
|
|
6206
6263
|
parse = async (txHex, providedUtxos = []) => {
|
|
6207
6264
|
const resolvedUtxos = [...providedUtxos];
|
|
6208
6265
|
const resolvedUtxosSet = new Set(
|
|
@@ -6245,10 +6302,225 @@ var TxParser = class {
|
|
|
6245
6302
|
getBuilderBodyWithoutChange = () => this.serializer.parser.getBuilderBodyWithoutChange();
|
|
6246
6303
|
toTester = () => this.serializer.parser.toTester();
|
|
6247
6304
|
};
|
|
6305
|
+
|
|
6306
|
+
// src/mesh-tx-builder-v2/index.ts
|
|
6307
|
+
import {
|
|
6308
|
+
DEFAULT_REDEEMER_BUDGET as DEFAULT_REDEEMER_BUDGET3
|
|
6309
|
+
} from "@meshsdk/common";
|
|
6310
|
+
var SpendBuilderImpl = class {
|
|
6311
|
+
constructor(builder) {
|
|
6312
|
+
this.builder = builder;
|
|
6313
|
+
}
|
|
6314
|
+
builder;
|
|
6315
|
+
script(scriptCbor) {
|
|
6316
|
+
this.builder.txInScript(scriptCbor);
|
|
6317
|
+
return this;
|
|
6318
|
+
}
|
|
6319
|
+
referenceScript(refTxHash, refTxIndex, scriptSize, scriptHash) {
|
|
6320
|
+
this.builder.spendingTxInReference(
|
|
6321
|
+
refTxHash,
|
|
6322
|
+
refTxIndex,
|
|
6323
|
+
scriptSize,
|
|
6324
|
+
scriptHash
|
|
6325
|
+
);
|
|
6326
|
+
return this;
|
|
6327
|
+
}
|
|
6328
|
+
redeemerJson(redeemer, exUnits) {
|
|
6329
|
+
this.builder.txInRedeemerValue(
|
|
6330
|
+
redeemer,
|
|
6331
|
+
"JSON",
|
|
6332
|
+
exUnits ?? { ...DEFAULT_REDEEMER_BUDGET3 }
|
|
6333
|
+
);
|
|
6334
|
+
return this;
|
|
6335
|
+
}
|
|
6336
|
+
redeemerCbor(redeemer, exUnits) {
|
|
6337
|
+
this.builder.txInRedeemerValue(
|
|
6338
|
+
redeemer,
|
|
6339
|
+
"CBOR",
|
|
6340
|
+
exUnits ?? { ...DEFAULT_REDEEMER_BUDGET3 }
|
|
6341
|
+
);
|
|
6342
|
+
return this;
|
|
6343
|
+
}
|
|
6344
|
+
txOut(address, amount) {
|
|
6345
|
+
this.builder.txInInlineDatumPresent();
|
|
6346
|
+
this.builder.txOut(address, amount);
|
|
6347
|
+
return this;
|
|
6348
|
+
}
|
|
6349
|
+
datumJson(datum) {
|
|
6350
|
+
this.builder.txOutInlineDatumValue(datum, "JSON");
|
|
6351
|
+
return this.builder;
|
|
6352
|
+
}
|
|
6353
|
+
datumCbor(datum) {
|
|
6354
|
+
this.builder.txOutInlineDatumValue(datum, "CBOR");
|
|
6355
|
+
return this.builder;
|
|
6356
|
+
}
|
|
6357
|
+
datumHash(datumHash) {
|
|
6358
|
+
this.builder.txOutDatumHashValue(datumHash);
|
|
6359
|
+
return this.builder;
|
|
6360
|
+
}
|
|
6361
|
+
};
|
|
6362
|
+
var MintBuilderImpl = class {
|
|
6363
|
+
constructor(builder) {
|
|
6364
|
+
this.builder = builder;
|
|
6365
|
+
}
|
|
6366
|
+
builder;
|
|
6367
|
+
script(scriptCbor) {
|
|
6368
|
+
this.builder.mintingScript(scriptCbor);
|
|
6369
|
+
return this;
|
|
6370
|
+
}
|
|
6371
|
+
referenceScript(txHash, txIndex, scriptSize, scriptHash) {
|
|
6372
|
+
this.builder.mintTxInReference(txHash, txIndex, scriptSize, scriptHash);
|
|
6373
|
+
return this;
|
|
6374
|
+
}
|
|
6375
|
+
redeemerJson(redeemer, exUnits) {
|
|
6376
|
+
this.builder.mintRedeemerValue(
|
|
6377
|
+
redeemer,
|
|
6378
|
+
"JSON",
|
|
6379
|
+
exUnits ?? { ...DEFAULT_REDEEMER_BUDGET3 }
|
|
6380
|
+
);
|
|
6381
|
+
return this;
|
|
6382
|
+
}
|
|
6383
|
+
redeemerCbor(redeemer, exUnits) {
|
|
6384
|
+
this.builder.mintRedeemerValue(
|
|
6385
|
+
redeemer,
|
|
6386
|
+
"CBOR",
|
|
6387
|
+
exUnits ?? { ...DEFAULT_REDEEMER_BUDGET3 }
|
|
6388
|
+
);
|
|
6389
|
+
return this;
|
|
6390
|
+
}
|
|
6391
|
+
txOut(address, amount) {
|
|
6392
|
+
this.builder.txOut(address, amount);
|
|
6393
|
+
return this.builder;
|
|
6394
|
+
}
|
|
6395
|
+
};
|
|
6396
|
+
var WithdrawBuilderImpl = class {
|
|
6397
|
+
constructor(builder) {
|
|
6398
|
+
this.builder = builder;
|
|
6399
|
+
}
|
|
6400
|
+
builder;
|
|
6401
|
+
script(scriptCbor) {
|
|
6402
|
+
this.builder.withdrawalScript(scriptCbor);
|
|
6403
|
+
return this;
|
|
6404
|
+
}
|
|
6405
|
+
referenceScript(txHash, txIndex, scriptSize, scriptHash) {
|
|
6406
|
+
this.builder.withdrawalTxInReference(txHash, txIndex, scriptSize, scriptHash);
|
|
6407
|
+
return this;
|
|
6408
|
+
}
|
|
6409
|
+
redeemerJson(redeemer, exUnits) {
|
|
6410
|
+
this.builder.withdrawalRedeemerValue(
|
|
6411
|
+
redeemer,
|
|
6412
|
+
"JSON",
|
|
6413
|
+
exUnits ?? { ...DEFAULT_REDEEMER_BUDGET3 }
|
|
6414
|
+
);
|
|
6415
|
+
return this.builder;
|
|
6416
|
+
}
|
|
6417
|
+
redeemerCbor(redeemer, exUnits) {
|
|
6418
|
+
this.builder.withdrawalRedeemerValue(
|
|
6419
|
+
redeemer,
|
|
6420
|
+
"CBOR",
|
|
6421
|
+
exUnits ?? { ...DEFAULT_REDEEMER_BUDGET3 }
|
|
6422
|
+
);
|
|
6423
|
+
return this.builder;
|
|
6424
|
+
}
|
|
6425
|
+
};
|
|
6426
|
+
var VoteBuilderImpl = class {
|
|
6427
|
+
constructor(builder) {
|
|
6428
|
+
this.builder = builder;
|
|
6429
|
+
}
|
|
6430
|
+
builder;
|
|
6431
|
+
script(scriptCbor) {
|
|
6432
|
+
this.builder.voteScript(scriptCbor);
|
|
6433
|
+
return this;
|
|
6434
|
+
}
|
|
6435
|
+
referenceScript(txHash, txIndex, scriptSize, scriptHash) {
|
|
6436
|
+
this.builder.voteTxInReference(txHash, txIndex, scriptSize, scriptHash);
|
|
6437
|
+
return this;
|
|
6438
|
+
}
|
|
6439
|
+
redeemerJson(redeemer, exUnits) {
|
|
6440
|
+
this.builder.voteRedeemerValue(
|
|
6441
|
+
redeemer,
|
|
6442
|
+
"JSON",
|
|
6443
|
+
exUnits ?? { ...DEFAULT_REDEEMER_BUDGET3 }
|
|
6444
|
+
);
|
|
6445
|
+
return this.builder;
|
|
6446
|
+
}
|
|
6447
|
+
redeemerCbor(redeemer, exUnits) {
|
|
6448
|
+
this.builder.voteRedeemerValue(
|
|
6449
|
+
redeemer,
|
|
6450
|
+
"CBOR",
|
|
6451
|
+
exUnits ?? { ...DEFAULT_REDEEMER_BUDGET3 }
|
|
6452
|
+
);
|
|
6453
|
+
return this.builder;
|
|
6454
|
+
}
|
|
6455
|
+
};
|
|
6456
|
+
var TxBuilderV2 = class extends MeshTxBuilder {
|
|
6457
|
+
spendPlutusV1(txHash, txIndex) {
|
|
6458
|
+
this.spendingPlutusScriptV1();
|
|
6459
|
+
this.txIn(txHash, txIndex);
|
|
6460
|
+
return new SpendBuilderImpl(this);
|
|
6461
|
+
}
|
|
6462
|
+
spendPlutusV2(txHash, txIndex) {
|
|
6463
|
+
this.spendingPlutusScriptV2();
|
|
6464
|
+
this.txIn(txHash, txIndex);
|
|
6465
|
+
return new SpendBuilderImpl(this);
|
|
6466
|
+
}
|
|
6467
|
+
spendPlutusV3(txHash, txIndex) {
|
|
6468
|
+
this.spendingPlutusScriptV3();
|
|
6469
|
+
this.txIn(txHash, txIndex);
|
|
6470
|
+
return new SpendBuilderImpl(this);
|
|
6471
|
+
}
|
|
6472
|
+
mintPlutusV1(quantity, policyId, assetName) {
|
|
6473
|
+
this.mintPlutusScriptV1();
|
|
6474
|
+
this.mint(quantity, policyId, assetName);
|
|
6475
|
+
return new MintBuilderImpl(this);
|
|
6476
|
+
}
|
|
6477
|
+
mintPlutusV2(quantity, policyId, assetName) {
|
|
6478
|
+
this.mintPlutusScriptV2();
|
|
6479
|
+
this.mint(quantity, policyId, assetName);
|
|
6480
|
+
return new MintBuilderImpl(this);
|
|
6481
|
+
}
|
|
6482
|
+
mintPlutusV3(quantity, policyId, assetName) {
|
|
6483
|
+
this.mintPlutusScriptV3();
|
|
6484
|
+
this.mint(quantity, policyId, assetName);
|
|
6485
|
+
return new MintBuilderImpl(this);
|
|
6486
|
+
}
|
|
6487
|
+
withdrawPlutusV1(rewardAddress, amount) {
|
|
6488
|
+
this.withdrawalPlutusScriptV1();
|
|
6489
|
+
this.withdrawal(rewardAddress, amount);
|
|
6490
|
+
return new WithdrawBuilderImpl(this);
|
|
6491
|
+
}
|
|
6492
|
+
withdrawPlutusV2(rewardAddress, coin) {
|
|
6493
|
+
this.withdrawalPlutusScriptV2();
|
|
6494
|
+
this.withdrawal(rewardAddress, coin);
|
|
6495
|
+
return new WithdrawBuilderImpl(this);
|
|
6496
|
+
}
|
|
6497
|
+
withdrawPlutusV3(rewardAddress, coin) {
|
|
6498
|
+
this.withdrawalPlutusScriptV3();
|
|
6499
|
+
this.withdrawal(rewardAddress, coin);
|
|
6500
|
+
return new WithdrawBuilderImpl(this);
|
|
6501
|
+
}
|
|
6502
|
+
votePlutusV1(voter, govActionId, votingProcedure) {
|
|
6503
|
+
this.votePlutusScriptV1();
|
|
6504
|
+
this.vote(voter, govActionId, votingProcedure);
|
|
6505
|
+
return new VoteBuilderImpl(this);
|
|
6506
|
+
}
|
|
6507
|
+
votePlutusV2(voter, govActionId, votingProcedure) {
|
|
6508
|
+
this.votePlutusScriptV2();
|
|
6509
|
+
this.vote(voter, govActionId, votingProcedure);
|
|
6510
|
+
return new VoteBuilderImpl(this);
|
|
6511
|
+
}
|
|
6512
|
+
votePlutusV3(voter, govActionId, votingProcedure) {
|
|
6513
|
+
this.votePlutusScriptV3();
|
|
6514
|
+
this.vote(voter, govActionId, votingProcedure);
|
|
6515
|
+
return new VoteBuilderImpl(this);
|
|
6516
|
+
}
|
|
6517
|
+
};
|
|
6518
|
+
var MeshTxBuilderV2 = TxBuilderV2;
|
|
6248
6519
|
export {
|
|
6249
6520
|
ForgeScript,
|
|
6250
6521
|
LargestFirstInputSelector,
|
|
6251
6522
|
MeshTxBuilder,
|
|
6523
|
+
MeshTxBuilderV2,
|
|
6252
6524
|
Transaction,
|
|
6253
6525
|
TxParser,
|
|
6254
6526
|
cloneOutput,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/transaction",
|
|
3
|
-
"version": "1.9.0
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Transactions - https://meshjs.dev/apis/transaction",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
@@ -35,13 +35,12 @@
|
|
|
35
35
|
"typescript": "^5.3.3"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@meshsdk/common": "1.9.0
|
|
39
|
-
"@meshsdk/core-cst": "1.9.0
|
|
40
|
-
"@cardano-sdk/core": "
|
|
41
|
-
"@cardano-sdk/util": "
|
|
42
|
-
"@cardano-sdk/input-selection": "
|
|
43
|
-
"json-bigint": "^1.0.0"
|
|
44
|
-
"libsodium-wrappers-sumo": "0.7.15"
|
|
38
|
+
"@meshsdk/common": "1.9.0",
|
|
39
|
+
"@meshsdk/core-cst": "1.9.0",
|
|
40
|
+
"@cardano-sdk/core": "0.46.12",
|
|
41
|
+
"@cardano-sdk/util": "0.17.1",
|
|
42
|
+
"@cardano-sdk/input-selection": "0.14.28",
|
|
43
|
+
"json-bigint": "^1.0.0"
|
|
45
44
|
},
|
|
46
45
|
"prettier": "@meshsdk/configs/prettier",
|
|
47
46
|
"publishConfig": {
|