@stellar/stellar-base 14.0.1 → 14.0.3

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.
@@ -72,6 +72,8 @@ function scValToBigInt(scv) {
72
72
  return BigInt(scv.value());
73
73
  case 'scvU64':
74
74
  case 'scvI64':
75
+ case 'scvTimepoint':
76
+ case 'scvDuration':
75
77
  return new _xdr_large_int.XdrLargeInt(scIntType, scv.value()).toBigInt();
76
78
  case 'scvU128':
77
79
  case 'scvI128':
@@ -65,6 +65,8 @@ var XdrLargeInt = exports.XdrLargeInt = /*#__PURE__*/function () {
65
65
  this["int"] = new _int2.Int256(values);
66
66
  break;
67
67
  case 'u64':
68
+ case 'timepoint':
69
+ case 'duration':
68
70
  this["int"] = new _jsXdr.UnsignedHyper(values);
69
71
  break;
70
72
  case 'u128':
@@ -121,6 +123,24 @@ var XdrLargeInt = exports.XdrLargeInt = /*#__PURE__*/function () {
121
123
  );
122
124
  }
123
125
 
126
+ /** @returns {xdr.ScVal} the integer encoded with `ScValType = Timepoint` */
127
+ }, {
128
+ key: "toTimepoint",
129
+ value: function toTimepoint() {
130
+ this._sizeCheck(64);
131
+ return _xdr["default"].ScVal.scvTimepoint(new _xdr["default"].Uint64(BigInt.asUintN(64, this.toBigInt())) // reiterpret as unsigned
132
+ );
133
+ }
134
+
135
+ /** @returns {xdr.ScVal} the integer encoded with `ScValType = Duration` */
136
+ }, {
137
+ key: "toDuration",
138
+ value: function toDuration() {
139
+ this._sizeCheck(64);
140
+ return _xdr["default"].ScVal.scvDuration(new _xdr["default"].Uint64(BigInt.asUintN(64, this.toBigInt())) // reiterpret as unsigned
141
+ );
142
+ }
143
+
124
144
  /**
125
145
  * @returns {xdr.ScVal} the integer encoded with `ScValType = I128`
126
146
  * @throws {RangeError} if the value cannot fit in 128 bits
@@ -205,6 +225,10 @@ var XdrLargeInt = exports.XdrLargeInt = /*#__PURE__*/function () {
205
225
  return this.toU128();
206
226
  case 'u256':
207
227
  return this.toU256();
228
+ case 'timepoint':
229
+ return this.toTimepoint();
230
+ case 'duration':
231
+ return this.toDuration();
208
232
  default:
209
233
  throw TypeError("invalid type: ".concat(this.type));
210
234
  }
@@ -244,6 +268,8 @@ var XdrLargeInt = exports.XdrLargeInt = /*#__PURE__*/function () {
244
268
  case 'u64':
245
269
  case 'u128':
246
270
  case 'u256':
271
+ case 'timepoint':
272
+ case 'duration':
247
273
  return true;
248
274
  default:
249
275
  return false;
package/lib/scval.js CHANGED
@@ -303,7 +303,7 @@ function nativeToScVal(val) {
303
303
  *
304
304
  * - void -> `null`
305
305
  * - u32, i32 -> `number`
306
- * - u64, i64, u128, i128, u256, i256 -> `bigint`
306
+ * - u64, i64, u128, i128, u256, i256, timepoint, duration -> `bigint`
307
307
  * - vec -> `Array` of any of the above (via recursion)
308
308
  * - map -> key-value object of any of the above (via recursion)
309
309
  * - bool -> `boolean`
@@ -694,14 +694,31 @@ var TransactionBuilder = exports.TransactionBuilder = /*#__PURE__*/function () {
694
694
  key: "buildFeeBumpTransaction",
695
695
  value: function buildFeeBumpTransaction(feeSource, baseFee, innerTx, networkPassphrase) {
696
696
  var innerOps = innerTx.operations.length;
697
- var innerBaseFeeRate = new _bignumber["default"](innerTx.fee).div(innerOps);
697
+ var minBaseFee = new _bignumber["default"](BASE_FEE);
698
+ var innerInclusionFee = new _bignumber["default"](innerTx.fee).div(innerOps);
699
+ var resourceFee = new _bignumber["default"](0);
700
+
701
+ // Do we need to do special Soroban fee handling? We only want the fee-bump
702
+ // requirement to match the inclusion fee, not the inclusion+resource fee.
703
+ var env = innerTx.toEnvelope();
704
+ switch (env["switch"]().value) {
705
+ case _xdr["default"].EnvelopeType.envelopeTypeTx().value:
706
+ {
707
+ var _sorobanData$resource;
708
+ var sorobanData = env.v1().tx().ext().value();
709
+ resourceFee = new _bignumber["default"]((_sorobanData$resource = sorobanData === null || sorobanData === void 0 ? void 0 : sorobanData.resourceFee()) !== null && _sorobanData$resource !== void 0 ? _sorobanData$resource : 0);
710
+ innerInclusionFee = _bignumber["default"].max(minBaseFee, innerInclusionFee.minus(resourceFee));
711
+ break;
712
+ }
713
+ default:
714
+ break;
715
+ }
698
716
  var base = new _bignumber["default"](baseFee);
699
717
 
700
718
  // The fee rate for fee bump is at least the fee rate of the inner transaction
701
- if (base.lt(innerBaseFeeRate)) {
702
- throw new Error("Invalid baseFee, it should be at least ".concat(innerBaseFeeRate, " stroops."));
719
+ if (base.lt(innerInclusionFee)) {
720
+ throw new Error("Invalid baseFee, it should be at least ".concat(innerInclusionFee, " stroops."));
703
721
  }
704
- var minBaseFee = new _bignumber["default"](BASE_FEE);
705
722
 
706
723
  // The fee rate is at least the minimum fee
707
724
  if (base.lt(minBaseFee)) {
@@ -732,7 +749,7 @@ var TransactionBuilder = exports.TransactionBuilder = /*#__PURE__*/function () {
732
749
  }
733
750
  var tx = new _xdr["default"].FeeBumpTransaction({
734
751
  feeSource: feeSourceAccount,
735
- fee: _xdr["default"].Int64.fromString(base.times(innerOps + 1).toString()),
752
+ fee: _xdr["default"].Int64.fromString(base.times(innerOps + 1).plus(resourceFee).toString()),
736
753
  innerTx: _xdr["default"].FeeBumpTransactionInnerTx.envelopeTypeTx(innerTxEnvelope.v1()),
737
754
  ext: new _xdr["default"].FeeBumpTransactionExt(0)
738
755
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar/stellar-base",
3
- "version": "14.0.1",
3
+ "version": "14.0.3",
4
4
  "description": "Low-level support library for the Stellar network.",
5
5
  "main": "./lib/index.js",
6
6
  "browser": {