@harmoniclabs/buildooor 0.1.0 → 0.1.2

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.
@@ -19,6 +19,7 @@ export declare class TxBuilder {
19
19
  calcLinearFee(tx: Tx | CborString): bigint;
20
20
  calcMinFee(tx: Tx): bigint;
21
21
  getMinimumOutputLovelaces(tx_out: TxOut | CanBeCborString): bigint;
22
+ addMinLovelacesIfMissing(txOut: TxOut): TxOut;
22
23
  minimizeLovelaces(out: ITxOut): TxOut;
23
24
  /**
24
25
  *
@@ -215,6 +215,16 @@ var TxBuilder = /** @class */ (function () {
215
215
  size = BigInt(tx_out.length);
216
216
  return BigInt(this.protocolParamters.utxoCostPerByte) * size;
217
217
  };
218
+ TxBuilder.prototype.addMinLovelacesIfMissing = function (txOut) {
219
+ if (txOut.value.lovelaces > 0)
220
+ return txOut.clone();
221
+ return this.minimizeLovelaces({
222
+ address: txOut.address,
223
+ value: cardano_ledger_ts_1.Value.add(cardano_ledger_ts_1.Value.lovelaces(this.getMinimumOutputLovelaces(txOut) + BigInt(1000000)), txOut.value),
224
+ datum: txOut.datum,
225
+ refScript: txOut.refScript
226
+ });
227
+ };
218
228
  TxBuilder.prototype.minimizeLovelaces = function (out) {
219
229
  var o = out instanceof cardano_ledger_ts_1.TxOut ? out : (0, txBuild_1.txBuildOutToTxOut)(out);
220
230
  var minLovelaces = this.getMinimumOutputLovelaces(o);
@@ -411,7 +421,7 @@ var TxBuilder = /** @class */ (function () {
411
421
  if (round === maxRound - 1)
412
422
  return "break";
413
423
  for (var i = 0; i < outs.length; i++) {
414
- txOuts[i] = outs[i].clone();
424
+ txOuts[i] = this_1.addMinLovelacesIfMissing(outs[i]);
415
425
  }
416
426
  txOuts[txOuts.length - 1] = (new cardano_ledger_ts_1.TxOut({
417
427
  address: change.address,
@@ -456,6 +466,7 @@ var TxBuilder = /** @class */ (function () {
456
466
  * this is all that either `build` or `buildSync` needs to do
457
467
  **/
458
468
  TxBuilder.prototype.initTxBuild = function (buildArgs) {
469
+ var _this = this;
459
470
  var _a = (0, txBuild_1.normalizeITxBuildArgs)(buildArgs), outputs = _a.outputs, requiredSigners = _a.requiredSigners, mints = _a.mints, invalidAfter = _a.invalidAfter, certificates = _a.certificates, withdrawals = _a.withdrawals, memo = _a.memo, metadata = _a.metadata, votingProcedures = _a.votingProcedures, proposalProcedures = _a.proposalProcedures, currentTreasuryValue = _a.currentTreasuryValue, paymentToTreasury = _a.paymentToTreasury, args = __rest(_a, ["outputs", "requiredSigners", "mints", "invalidAfter", "certificates", "withdrawals", "memo", "metadata", "votingProcedures", "proposalProcedures", "currentTreasuryValue", "paymentToTreasury"]);
460
471
  // mutable args
461
472
  var inputs = args.inputs, changeAddress = args.changeAddress, change = args.change, invalidBefore = args.invalidBefore, readonlyRefInputs = args.readonlyRefInputs, collaterals = args.collaterals, collateralReturn = args.collateralReturn;
@@ -703,7 +714,7 @@ var TxBuilder = /** @class */ (function () {
703
714
  // however now we are not able to calculate it
704
715
  // because we are missing the minted value and eventual
705
716
  // values associated with certificates
706
- value: cardano_ledger_ts_1.Value.lovelaces(totInputValue.lovelaces),
717
+ value: totInputValue.clone(),
707
718
  datum: change.datum ? (change.datum instanceof cardano_ledger_ts_1.Hash32 ?
708
719
  change.datum :
709
720
  (0, CanBeData_1.forceData)(change.datum)) : undef,
@@ -933,7 +944,7 @@ var TxBuilder = /** @class */ (function () {
933
944
  });
934
945
  var minFee = this.calcMinFee(dummyTx);
935
946
  var txOuts = new Array(outs.length + 1);
936
- outs.forEach(function (txO, i) { return txOuts[i] = txO.clone(); });
947
+ outs.forEach(function (txO, i) { return txOuts[i] = _this.addMinLovelacesIfMissing(txO); });
937
948
  var changeOutput = new cardano_ledger_ts_1.TxOut({
938
949
  address: change.address,
939
950
  value: cardano_ledger_ts_1.Value.sub(totInputValue, cardano_ledger_ts_1.Value.add(requiredOutputValue, cardano_ledger_ts_1.Value.lovelaces(minFee))),
@@ -954,7 +965,7 @@ var TxBuilder = /** @class */ (function () {
954
965
  totInputValue: totInputValue,
955
966
  requiredOutputValue: requiredOutputValue,
956
967
  outs: outs,
957
- change: change
968
+ change: change,
958
969
  };
959
970
  };
960
971
  TxBuilder.prototype.assertCorrectChangeOutput = function (changeOutput) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harmoniclabs/buildooor",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Cardano transaction builder in typescript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",