@stellar/stellar-base 14.0.4 → 14.1.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/README.md +13 -15
- package/dist/stellar-base.js +2041 -1884
- package/dist/stellar-base.min.js +1 -1
- package/lib/auth.js +2 -4
- package/lib/transaction_builder.js +161 -3
- package/package.json +1 -1
- package/types/curr.d.ts +121 -146
- package/types/index.d.ts +24 -0
- package/types/next.d.ts +121 -145
- package/CHANGELOG.md +0 -1497
package/dist/stellar-base.js
CHANGED
|
@@ -22002,1197 +22002,762 @@ var SignerKey = /*#__PURE__*/function () {
|
|
|
22002
22002
|
}
|
|
22003
22003
|
}]);
|
|
22004
22004
|
}();
|
|
22005
|
-
;// ./src/
|
|
22006
|
-
function
|
|
22007
|
-
function
|
|
22008
|
-
function
|
|
22009
|
-
function
|
|
22010
|
-
function
|
|
22011
|
-
function
|
|
22012
|
-
function transaction_builder_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
22013
|
-
function transaction_builder_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22014
|
-
function transaction_builder_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? transaction_builder_ownKeys(Object(t), !0).forEach(function (r) { transaction_builder_defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : transaction_builder_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22015
|
-
function transaction_builder_defineProperty(e, r, t) { return (r = transaction_builder_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
22016
|
-
function transaction_builder_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22017
|
-
function transaction_builder_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, transaction_builder_toPropertyKey(o.key), o); } }
|
|
22018
|
-
function transaction_builder_createClass(e, r, t) { return r && transaction_builder_defineProperties(e.prototype, r), t && transaction_builder_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
22019
|
-
function transaction_builder_toPropertyKey(t) { var i = transaction_builder_toPrimitive(t, "string"); return "symbol" == transaction_builder_typeof(i) ? i : i + ""; }
|
|
22020
|
-
function transaction_builder_toPrimitive(t, r) { if ("object" != transaction_builder_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != transaction_builder_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22021
|
-
|
|
22022
|
-
|
|
22023
|
-
|
|
22024
|
-
|
|
22025
|
-
|
|
22026
|
-
|
|
22027
|
-
|
|
22028
|
-
|
|
22029
|
-
|
|
22030
|
-
|
|
22005
|
+
;// ./src/contract.js
|
|
22006
|
+
function contract_typeof(o) { "@babel/helpers - typeof"; return contract_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, contract_typeof(o); }
|
|
22007
|
+
function contract_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22008
|
+
function contract_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, contract_toPropertyKey(o.key), o); } }
|
|
22009
|
+
function contract_createClass(e, r, t) { return r && contract_defineProperties(e.prototype, r), t && contract_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
22010
|
+
function contract_toPropertyKey(t) { var i = contract_toPrimitive(t, "string"); return "symbol" == contract_typeof(i) ? i : i + ""; }
|
|
22011
|
+
function contract_toPrimitive(t, r) { if ("object" != contract_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != contract_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22031
22012
|
|
|
22032
22013
|
|
|
22033
22014
|
|
|
22034
|
-
/**
|
|
22035
|
-
* Minimum base fee for transactions. If this fee is below the network
|
|
22036
|
-
* minimum, the transaction will fail. The more operations in the
|
|
22037
|
-
* transaction, the greater the required fee. Use {@link
|
|
22038
|
-
* Server#fetchBaseFee} to get an accurate value of minimum transaction
|
|
22039
|
-
* fee on the network.
|
|
22040
|
-
*
|
|
22041
|
-
* @constant
|
|
22042
|
-
* @see [Fees](https://developers.stellar.org/docs/glossary/fees/)
|
|
22043
|
-
*/
|
|
22044
|
-
var BASE_FEE = '100'; // Stroops
|
|
22045
22015
|
|
|
22046
|
-
/**
|
|
22047
|
-
* @constant
|
|
22048
|
-
* @see {@link TransactionBuilder#setTimeout}
|
|
22049
|
-
* @see [Timeout](https://developers.stellar.org/api/resources/transactions/post/)
|
|
22050
|
-
*/
|
|
22051
|
-
var TimeoutInfinite = 0;
|
|
22052
22016
|
|
|
22053
22017
|
/**
|
|
22054
|
-
*
|
|
22055
|
-
* given {@link Account} as the transaction's "source account". The transaction
|
|
22056
|
-
* will use the current sequence number of the given account as its sequence
|
|
22057
|
-
* number and increment the given account's sequence number by one. The given
|
|
22058
|
-
* source account must include a private key for signing the transaction or an
|
|
22059
|
-
* error will be thrown.</p>
|
|
22060
|
-
*
|
|
22061
|
-
* <p>Operations can be added to the transaction via their corresponding builder
|
|
22062
|
-
* methods, and each returns the TransactionBuilder object so they can be
|
|
22063
|
-
* chained together. After adding the desired operations, call the `build()`
|
|
22064
|
-
* method on the `TransactionBuilder` to return a fully constructed `{@link
|
|
22065
|
-
* Transaction}` that can be signed. The returned transaction will contain the
|
|
22066
|
-
* sequence number of the source account and include the signature from the
|
|
22067
|
-
* source account.</p>
|
|
22068
|
-
*
|
|
22069
|
-
* <p><strong>Be careful about unsubmitted transactions!</strong> When you build
|
|
22070
|
-
* a transaction, `stellar-sdk` automatically increments the source account's
|
|
22071
|
-
* sequence number. If you end up not submitting this transaction and submitting
|
|
22072
|
-
* another one instead, it'll fail due to the sequence number being wrong. So if
|
|
22073
|
-
* you decide not to use a built transaction, make sure to update the source
|
|
22074
|
-
* account's sequence number with
|
|
22075
|
-
* [Server.loadAccount](https://stellar.github.io/js-stellar-sdk/Server.html#loadAccount)
|
|
22076
|
-
* before creating another transaction.</p>
|
|
22077
|
-
*
|
|
22078
|
-
* <p>The following code example creates a new transaction with {@link
|
|
22079
|
-
* Operation.createAccount} and {@link Operation.payment} operations. The
|
|
22080
|
-
* Transaction's source account first funds `destinationA`, then sends a payment
|
|
22081
|
-
* to `destinationB`. The built transaction is then signed by
|
|
22082
|
-
* `sourceKeypair`.</p>
|
|
22083
|
-
*
|
|
22084
|
-
* ```
|
|
22085
|
-
* var transaction = new TransactionBuilder(source, { fee, networkPassphrase: Networks.TESTNET })
|
|
22086
|
-
* .addOperation(Operation.createAccount({
|
|
22087
|
-
* destination: destinationA,
|
|
22088
|
-
* startingBalance: "20"
|
|
22089
|
-
* })) // <- funds and creates destinationA
|
|
22090
|
-
* .addOperation(Operation.payment({
|
|
22091
|
-
* destination: destinationB,
|
|
22092
|
-
* amount: "100",
|
|
22093
|
-
* asset: Asset.native()
|
|
22094
|
-
* })) // <- sends 100 XLM to destinationB
|
|
22095
|
-
* .setTimeout(30)
|
|
22096
|
-
* .build();
|
|
22018
|
+
* Create a new Contract object.
|
|
22097
22019
|
*
|
|
22098
|
-
*
|
|
22099
|
-
*
|
|
22020
|
+
* `Contract` represents a single contract in the Stellar network, embodying the
|
|
22021
|
+
* interface of the contract. See
|
|
22022
|
+
* [Contracts](https://soroban.stellar.org/docs/learn/interacting-with-contracts)
|
|
22023
|
+
* for more information about how contracts work in Stellar.
|
|
22100
22024
|
*
|
|
22101
22025
|
* @constructor
|
|
22102
22026
|
*
|
|
22103
|
-
* @param {
|
|
22104
|
-
*
|
|
22105
|
-
* @param {string} opts.fee - max fee you're willing to pay per
|
|
22106
|
-
* operation in this transaction (**in stroops**)
|
|
22107
|
-
*
|
|
22108
|
-
* @param {object} [opts.timebounds] - timebounds for the
|
|
22109
|
-
* validity of this transaction
|
|
22110
|
-
* @param {number|string|Date} [opts.timebounds.minTime] - 64-bit UNIX
|
|
22111
|
-
* timestamp or Date object
|
|
22112
|
-
* @param {number|string|Date} [opts.timebounds.maxTime] - 64-bit UNIX
|
|
22113
|
-
* timestamp or Date object
|
|
22114
|
-
* @param {object} [opts.ledgerbounds] - ledger bounds for the
|
|
22115
|
-
* validity of this transaction
|
|
22116
|
-
* @param {number} [opts.ledgerbounds.minLedger] - number of the minimum
|
|
22117
|
-
* ledger sequence
|
|
22118
|
-
* @param {number} [opts.ledgerbounds.maxLedger] - number of the maximum
|
|
22119
|
-
* ledger sequence
|
|
22120
|
-
* @param {string} [opts.minAccountSequence] - number for
|
|
22121
|
-
* the minimum account sequence
|
|
22122
|
-
* @param {number} [opts.minAccountSequenceAge] - number of
|
|
22123
|
-
* seconds for the minimum account sequence age
|
|
22124
|
-
* @param {number} [opts.minAccountSequenceLedgerGap] - number of
|
|
22125
|
-
* ledgers for the minimum account sequence ledger gap
|
|
22126
|
-
* @param {string[]} [opts.extraSigners] - list of the extra signers
|
|
22127
|
-
* required for this transaction
|
|
22128
|
-
* @param {Memo} [opts.memo] - memo for the transaction
|
|
22129
|
-
* @param {string} [opts.networkPassphrase] passphrase of the
|
|
22130
|
-
* target Stellar network (e.g. "Public Global Stellar Network ; September
|
|
22131
|
-
* 2015" for the pubnet)
|
|
22132
|
-
* @param {xdr.SorobanTransactionData | string} [opts.sorobanData] - an
|
|
22133
|
-
* optional instance of {@link xdr.SorobanTransactionData} to be set as the
|
|
22134
|
-
* internal `Transaction.Ext.SorobanData` field (either the xdr object or a
|
|
22135
|
-
* base64 string). In the case of Soroban transactions, this can be obtained
|
|
22136
|
-
* from a prior simulation of the transaction with a contract invocation and
|
|
22137
|
-
* provides necessary resource estimations. You can also use
|
|
22138
|
-
* {@link SorobanDataBuilder} to construct complicated combinations of
|
|
22139
|
-
* parameters without mucking with XDR directly. **Note:** For
|
|
22140
|
-
* non-contract(non-Soroban) transactions, this has no effect.
|
|
22027
|
+
* @param {string} contractId - ID of the contract (ex.
|
|
22028
|
+
* `CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE`).
|
|
22141
22029
|
*/
|
|
22142
|
-
var
|
|
22143
|
-
function
|
|
22144
|
-
|
|
22145
|
-
|
|
22146
|
-
|
|
22147
|
-
|
|
22148
|
-
}
|
|
22149
|
-
|
|
22150
|
-
throw new Error('must specify fee for the transaction (in stroops)');
|
|
22030
|
+
var Contract = /*#__PURE__*/function () {
|
|
22031
|
+
function Contract(contractId) {
|
|
22032
|
+
contract_classCallCheck(this, Contract);
|
|
22033
|
+
try {
|
|
22034
|
+
// First, try it as a strkey
|
|
22035
|
+
this._id = StrKey.decodeContract(contractId);
|
|
22036
|
+
} catch (_) {
|
|
22037
|
+
throw new Error("Invalid contract ID: ".concat(contractId));
|
|
22151
22038
|
}
|
|
22152
|
-
this.source = sourceAccount;
|
|
22153
|
-
this.operations = [];
|
|
22154
|
-
this.baseFee = opts.fee;
|
|
22155
|
-
this.timebounds = opts.timebounds ? transaction_builder_objectSpread({}, opts.timebounds) : null;
|
|
22156
|
-
this.ledgerbounds = opts.ledgerbounds ? transaction_builder_objectSpread({}, opts.ledgerbounds) : null;
|
|
22157
|
-
this.minAccountSequence = opts.minAccountSequence || null;
|
|
22158
|
-
this.minAccountSequenceAge = opts.minAccountSequenceAge || null;
|
|
22159
|
-
this.minAccountSequenceLedgerGap = opts.minAccountSequenceLedgerGap || null;
|
|
22160
|
-
this.extraSigners = opts.extraSigners ? _toConsumableArray(opts.extraSigners) : null;
|
|
22161
|
-
this.memo = opts.memo || Memo.none();
|
|
22162
|
-
this.networkPassphrase = opts.networkPassphrase || null;
|
|
22163
|
-
this.sorobanData = opts.sorobanData ? new SorobanDataBuilder(opts.sorobanData).build() : null;
|
|
22164
22039
|
}
|
|
22165
22040
|
|
|
22166
22041
|
/**
|
|
22167
|
-
*
|
|
22168
|
-
*
|
|
22169
|
-
*
|
|
22170
|
-
* Note that the sequence number WILL be cloned, so EITHER this transaction or
|
|
22171
|
-
* the one it was cloned from will be valid. This is useful in situations
|
|
22172
|
-
* where you are constructing a transaction in pieces and need to make
|
|
22173
|
-
* adjustments as you go (for example, when filling out Soroban resource
|
|
22174
|
-
* information).
|
|
22175
|
-
*
|
|
22176
|
-
* @param {Transaction} tx a "template" transaction to clone exactly
|
|
22177
|
-
* @param {object} [opts] additional options to override the clone, e.g.
|
|
22178
|
-
* {fee: '1000'} will override the existing base fee derived from `tx` (see
|
|
22179
|
-
* the {@link TransactionBuilder} constructor for detailed options)
|
|
22180
|
-
*
|
|
22181
|
-
* @returns {TransactionBuilder} a "prepared" builder instance with the same
|
|
22182
|
-
* configuration and operations as the given transaction
|
|
22183
|
-
*
|
|
22184
|
-
* @warning This does not clone the transaction's
|
|
22185
|
-
* {@link xdr.SorobanTransactionData} (if applicable), use
|
|
22186
|
-
* {@link SorobanDataBuilder} and {@link TransactionBuilder.setSorobanData}
|
|
22187
|
-
* as needed, instead..
|
|
22188
|
-
*
|
|
22189
|
-
* @todo This cannot clone {@link FeeBumpTransaction}s, yet.
|
|
22042
|
+
* Returns Stellar contract ID as a strkey, ex.
|
|
22043
|
+
* `CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE`.
|
|
22044
|
+
* @returns {string}
|
|
22190
22045
|
*/
|
|
22191
|
-
return
|
|
22192
|
-
key: "
|
|
22193
|
-
value:
|
|
22194
|
-
|
|
22195
|
-
* Adds an operation to the transaction.
|
|
22196
|
-
*
|
|
22197
|
-
* @param {xdr.Operation} operation The xdr operation object, use {@link
|
|
22198
|
-
* Operation} static methods.
|
|
22199
|
-
*
|
|
22200
|
-
* @returns {TransactionBuilder}
|
|
22201
|
-
*/
|
|
22202
|
-
function addOperation(operation) {
|
|
22203
|
-
this.operations.push(operation);
|
|
22204
|
-
return this;
|
|
22046
|
+
return contract_createClass(Contract, [{
|
|
22047
|
+
key: "contractId",
|
|
22048
|
+
value: function contractId() {
|
|
22049
|
+
return StrKey.encodeContract(this._id);
|
|
22205
22050
|
}
|
|
22206
22051
|
|
|
22207
|
-
/**
|
|
22208
|
-
* Adds an operation to the transaction at a specific index.
|
|
22209
|
-
*
|
|
22210
|
-
* @param {xdr.Operation} operation - The xdr operation object to add, use {@link Operation} static methods.
|
|
22211
|
-
* @param {number} index - The index at which to insert the operation.
|
|
22212
|
-
*
|
|
22213
|
-
* @returns {TransactionBuilder} - The TransactionBuilder instance for method chaining.
|
|
22214
|
-
*/
|
|
22052
|
+
/** @returns {string} the ID as a strkey (C...) */
|
|
22215
22053
|
}, {
|
|
22216
|
-
key: "
|
|
22217
|
-
value: function
|
|
22218
|
-
this.
|
|
22219
|
-
return this;
|
|
22054
|
+
key: "toString",
|
|
22055
|
+
value: function toString() {
|
|
22056
|
+
return this.contractId();
|
|
22220
22057
|
}
|
|
22221
22058
|
|
|
22222
|
-
/**
|
|
22223
|
-
* Removes the operations from the builder (useful when cloning).
|
|
22224
|
-
* @returns {TransactionBuilder} this builder instance
|
|
22225
|
-
*/
|
|
22059
|
+
/** @returns {Address} the wrapped address of this contract */
|
|
22226
22060
|
}, {
|
|
22227
|
-
key: "
|
|
22228
|
-
value: function
|
|
22229
|
-
this.
|
|
22230
|
-
return this;
|
|
22061
|
+
key: "address",
|
|
22062
|
+
value: function address() {
|
|
22063
|
+
return Address.contract(this._id);
|
|
22231
22064
|
}
|
|
22232
22065
|
|
|
22233
22066
|
/**
|
|
22234
|
-
*
|
|
22067
|
+
* Returns an operation that will invoke this contract call.
|
|
22235
22068
|
*
|
|
22236
|
-
* @param {
|
|
22069
|
+
* @param {string} method name of the method to call
|
|
22070
|
+
* @param {...xdr.ScVal} params arguments to pass to the function call
|
|
22237
22071
|
*
|
|
22238
|
-
* @returns {
|
|
22072
|
+
* @returns {xdr.Operation} an InvokeHostFunctionOp operation to call the
|
|
22073
|
+
* contract with the given method and parameters
|
|
22074
|
+
*
|
|
22075
|
+
* @see Operation.invokeHostFunction
|
|
22076
|
+
* @see Operation.invokeContractFunction
|
|
22077
|
+
* @see Operation.createCustomContract
|
|
22078
|
+
* @see Operation.createStellarAssetContract
|
|
22079
|
+
* @see Operation.uploadContractWasm
|
|
22239
22080
|
*/
|
|
22240
22081
|
}, {
|
|
22241
|
-
key: "
|
|
22242
|
-
value: function
|
|
22243
|
-
|
|
22244
|
-
|
|
22245
|
-
}
|
|
22246
|
-
|
|
22247
|
-
/**
|
|
22248
|
-
* Adds a memo to the transaction.
|
|
22249
|
-
* @param {Memo} memo {@link Memo} object
|
|
22250
|
-
* @returns {TransactionBuilder}
|
|
22251
|
-
*/
|
|
22252
|
-
}, {
|
|
22253
|
-
key: "addMemo",
|
|
22254
|
-
value: function addMemo(memo) {
|
|
22255
|
-
this.memo = memo;
|
|
22256
|
-
return this;
|
|
22257
|
-
}
|
|
22258
|
-
|
|
22259
|
-
/**
|
|
22260
|
-
* Sets a timeout precondition on the transaction.
|
|
22261
|
-
*
|
|
22262
|
-
* Because of the distributed nature of the Stellar network it is possible
|
|
22263
|
-
* that the status of your transaction will be determined after a long time
|
|
22264
|
-
* if the network is highly congested. If you want to be sure to receive the
|
|
22265
|
-
* status of the transaction within a given period you should set the {@link
|
|
22266
|
-
* TimeBounds} with `maxTime` on the transaction (this is what `setTimeout`
|
|
22267
|
-
* does internally; if there's `minTime` set but no `maxTime` it will be
|
|
22268
|
-
* added).
|
|
22269
|
-
*
|
|
22270
|
-
* A call to `TransactionBuilder.setTimeout` is **required** if Transaction
|
|
22271
|
-
* does not have `max_time` set. If you don't want to set timeout, use
|
|
22272
|
-
* `{@link TimeoutInfinite}`. In general you should set `{@link
|
|
22273
|
-
* TimeoutInfinite}` only in smart contracts.
|
|
22274
|
-
*
|
|
22275
|
-
* Please note that Horizon may still return <code>504 Gateway Timeout</code>
|
|
22276
|
-
* error, even for short timeouts. In such case you need to resubmit the same
|
|
22277
|
-
* transaction again without making any changes to receive a status. This
|
|
22278
|
-
* method is using the machine system time (UTC), make sure it is set
|
|
22279
|
-
* correctly.
|
|
22280
|
-
*
|
|
22281
|
-
* @param {number} timeoutSeconds Number of seconds the transaction is good.
|
|
22282
|
-
* Can't be negative. If the value is {@link TimeoutInfinite}, the
|
|
22283
|
-
* transaction is good indefinitely.
|
|
22284
|
-
*
|
|
22285
|
-
* @returns {TransactionBuilder}
|
|
22286
|
-
*
|
|
22287
|
-
* @see {@link TimeoutInfinite}
|
|
22288
|
-
* @see https://developers.stellar.org/docs/tutorials/handling-errors/
|
|
22289
|
-
*/
|
|
22290
|
-
}, {
|
|
22291
|
-
key: "setTimeout",
|
|
22292
|
-
value: function setTimeout(timeoutSeconds) {
|
|
22293
|
-
if (this.timebounds !== null && this.timebounds.maxTime > 0) {
|
|
22294
|
-
throw new Error('TimeBounds.max_time has been already set - setting timeout would overwrite it.');
|
|
22295
|
-
}
|
|
22296
|
-
if (timeoutSeconds < 0) {
|
|
22297
|
-
throw new Error('timeout cannot be negative');
|
|
22298
|
-
}
|
|
22299
|
-
if (timeoutSeconds > 0) {
|
|
22300
|
-
var timeoutTimestamp = Math.floor(Date.now() / 1000) + timeoutSeconds;
|
|
22301
|
-
if (this.timebounds === null) {
|
|
22302
|
-
this.timebounds = {
|
|
22303
|
-
minTime: 0,
|
|
22304
|
-
maxTime: timeoutTimestamp
|
|
22305
|
-
};
|
|
22306
|
-
} else {
|
|
22307
|
-
this.timebounds = {
|
|
22308
|
-
minTime: this.timebounds.minTime,
|
|
22309
|
-
maxTime: timeoutTimestamp
|
|
22310
|
-
};
|
|
22311
|
-
}
|
|
22312
|
-
} else {
|
|
22313
|
-
this.timebounds = {
|
|
22314
|
-
minTime: 0,
|
|
22315
|
-
maxTime: 0
|
|
22316
|
-
};
|
|
22082
|
+
key: "call",
|
|
22083
|
+
value: function call(method) {
|
|
22084
|
+
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
22085
|
+
params[_key - 1] = arguments[_key];
|
|
22317
22086
|
}
|
|
22318
|
-
return
|
|
22087
|
+
return Operation.invokeContractFunction({
|
|
22088
|
+
contract: this.address().toString(),
|
|
22089
|
+
"function": method,
|
|
22090
|
+
args: params
|
|
22091
|
+
});
|
|
22319
22092
|
}
|
|
22320
22093
|
|
|
22321
22094
|
/**
|
|
22322
|
-
*
|
|
22323
|
-
*
|
|
22324
|
-
*
|
|
22325
|
-
* preconditions. Conflicts with `setTimeout`, so use one or the other.
|
|
22326
|
-
*
|
|
22327
|
-
* @param {Date|number} minEpochOrDate Either a JS Date object, or a number
|
|
22328
|
-
* of UNIX epoch seconds. The transaction is valid after this timestamp.
|
|
22329
|
-
* Can't be negative. If the value is `0`, the transaction is valid
|
|
22330
|
-
* immediately.
|
|
22331
|
-
* @param {Date|number} maxEpochOrDate Either a JS Date object, or a number
|
|
22332
|
-
* of UNIX epoch seconds. The transaction is valid until this timestamp.
|
|
22333
|
-
* Can't be negative. If the value is `0`, the transaction is valid
|
|
22334
|
-
* indefinitely.
|
|
22095
|
+
* Returns the read-only footprint entries necessary for any invocations to
|
|
22096
|
+
* this contract, for convenience when manually adding it to your
|
|
22097
|
+
* transaction's overall footprint or doing bump/restore operations.
|
|
22335
22098
|
*
|
|
22336
|
-
* @returns {
|
|
22099
|
+
* @returns {xdr.LedgerKey} the ledger key for the deployed contract instance
|
|
22337
22100
|
*/
|
|
22338
22101
|
}, {
|
|
22339
|
-
key: "
|
|
22340
|
-
value: function
|
|
22341
|
-
|
|
22342
|
-
|
|
22343
|
-
|
|
22344
|
-
|
|
22345
|
-
|
|
22346
|
-
maxEpochOrDate = new Date(maxEpochOrDate * 1000);
|
|
22347
|
-
}
|
|
22348
|
-
if (this.timebounds !== null) {
|
|
22349
|
-
throw new Error('TimeBounds has been already set - setting timebounds would overwrite it.');
|
|
22350
|
-
}
|
|
22351
|
-
|
|
22352
|
-
// Convert that date to the epoch seconds
|
|
22353
|
-
var minTime = Math.floor(minEpochOrDate.valueOf() / 1000);
|
|
22354
|
-
var maxTime = Math.floor(maxEpochOrDate.valueOf() / 1000);
|
|
22355
|
-
if (minTime < 0) {
|
|
22356
|
-
throw new Error('min_time cannot be negative');
|
|
22357
|
-
}
|
|
22358
|
-
if (maxTime < 0) {
|
|
22359
|
-
throw new Error('max_time cannot be negative');
|
|
22360
|
-
}
|
|
22361
|
-
if (maxTime > 0 && minTime > maxTime) {
|
|
22362
|
-
throw new Error('min_time cannot be greater than max_time');
|
|
22363
|
-
}
|
|
22364
|
-
this.timebounds = {
|
|
22365
|
-
minTime: minTime,
|
|
22366
|
-
maxTime: maxTime
|
|
22367
|
-
};
|
|
22368
|
-
return this;
|
|
22102
|
+
key: "getFootprint",
|
|
22103
|
+
value: function getFootprint() {
|
|
22104
|
+
return src_xdr.LedgerKey.contractData(new src_xdr.LedgerKeyContractData({
|
|
22105
|
+
contract: this.address().toScAddress(),
|
|
22106
|
+
key: src_xdr.ScVal.scvLedgerKeyContractInstance(),
|
|
22107
|
+
durability: src_xdr.ContractDataDurability.persistent()
|
|
22108
|
+
}));
|
|
22369
22109
|
}
|
|
22110
|
+
}]);
|
|
22111
|
+
}();
|
|
22112
|
+
;// ./src/numbers/uint128.js
|
|
22113
|
+
function uint128_typeof(o) { "@babel/helpers - typeof"; return uint128_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, uint128_typeof(o); }
|
|
22114
|
+
function uint128_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22115
|
+
function uint128_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, uint128_toPropertyKey(o.key), o); } }
|
|
22116
|
+
function uint128_createClass(e, r, t) { return r && uint128_defineProperties(e.prototype, r), t && uint128_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
22117
|
+
function uint128_toPropertyKey(t) { var i = uint128_toPrimitive(t, "string"); return "symbol" == uint128_typeof(i) ? i : i + ""; }
|
|
22118
|
+
function uint128_toPrimitive(t, r) { if ("object" != uint128_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != uint128_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22119
|
+
function uint128_callSuper(t, o, e) { return o = uint128_getPrototypeOf(o), uint128_possibleConstructorReturn(t, uint128_isNativeReflectConstruct() ? Reflect.construct(o, e || [], uint128_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
22120
|
+
function uint128_possibleConstructorReturn(t, e) { if (e && ("object" == uint128_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return uint128_assertThisInitialized(t); }
|
|
22121
|
+
function uint128_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
22122
|
+
function uint128_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (uint128_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22123
|
+
function uint128_getPrototypeOf(t) { return uint128_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, uint128_getPrototypeOf(t); }
|
|
22124
|
+
function uint128_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && uint128_setPrototypeOf(t, e); }
|
|
22125
|
+
function uint128_setPrototypeOf(t, e) { return uint128_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, uint128_setPrototypeOf(t, e); }
|
|
22370
22126
|
|
|
22371
|
-
|
|
22372
|
-
|
|
22373
|
-
|
|
22374
|
-
|
|
22375
|
-
|
|
22376
|
-
|
|
22377
|
-
|
|
22378
|
-
|
|
22379
|
-
|
|
22380
|
-
|
|
22381
|
-
|
|
22382
|
-
|
|
22383
|
-
|
|
22384
|
-
|
|
22385
|
-
|
|
22386
|
-
|
|
22387
|
-
key: "
|
|
22388
|
-
|
|
22389
|
-
|
|
22390
|
-
throw new Error('LedgerBounds has been already set - setting ledgerbounds would overwrite it.');
|
|
22391
|
-
}
|
|
22392
|
-
if (minLedger < 0) {
|
|
22393
|
-
throw new Error('min_ledger cannot be negative');
|
|
22394
|
-
}
|
|
22395
|
-
if (maxLedger < 0) {
|
|
22396
|
-
throw new Error('max_ledger cannot be negative');
|
|
22397
|
-
}
|
|
22398
|
-
if (maxLedger > 0 && minLedger > maxLedger) {
|
|
22399
|
-
throw new Error('min_ledger cannot be greater than max_ledger');
|
|
22400
|
-
}
|
|
22401
|
-
this.ledgerbounds = {
|
|
22402
|
-
minLedger: minLedger,
|
|
22403
|
-
maxLedger: maxLedger
|
|
22404
|
-
};
|
|
22405
|
-
return this;
|
|
22127
|
+
var Uint128 = /*#__PURE__*/function (_LargeInt) {
|
|
22128
|
+
/**
|
|
22129
|
+
* Construct an unsigned 128-bit integer that can be XDR-encoded.
|
|
22130
|
+
*
|
|
22131
|
+
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
22132
|
+
* in big-endian format (i.e. earlier elements are higher bits)
|
|
22133
|
+
*/
|
|
22134
|
+
function Uint128() {
|
|
22135
|
+
uint128_classCallCheck(this, Uint128);
|
|
22136
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22137
|
+
args[_key] = arguments[_key];
|
|
22138
|
+
}
|
|
22139
|
+
return uint128_callSuper(this, Uint128, [args]);
|
|
22140
|
+
}
|
|
22141
|
+
uint128_inherits(Uint128, _LargeInt);
|
|
22142
|
+
return uint128_createClass(Uint128, [{
|
|
22143
|
+
key: "unsigned",
|
|
22144
|
+
get: function get() {
|
|
22145
|
+
return true;
|
|
22406
22146
|
}
|
|
22407
|
-
|
|
22408
|
-
/**
|
|
22409
|
-
* If you want to prepare a transaction which will be valid only while the
|
|
22410
|
-
* account sequence number is
|
|
22411
|
-
*
|
|
22412
|
-
* minAccountSequence <= sourceAccountSequence < tx.seqNum
|
|
22413
|
-
*
|
|
22414
|
-
* Note that after execution the account's sequence number is always raised to
|
|
22415
|
-
* `tx.seqNum`. Internally this will set the `minAccountSequence`
|
|
22416
|
-
* precondition.
|
|
22417
|
-
*
|
|
22418
|
-
* @param {string} minAccountSequence The minimum source account sequence
|
|
22419
|
-
* number this transaction is valid for. If the value is `0` (the
|
|
22420
|
-
* default), the transaction is valid when `sourceAccount's sequence
|
|
22421
|
-
* number == tx.seqNum- 1`.
|
|
22422
|
-
*
|
|
22423
|
-
* @returns {TransactionBuilder}
|
|
22424
|
-
*/
|
|
22425
22147
|
}, {
|
|
22426
|
-
key: "
|
|
22427
|
-
|
|
22428
|
-
|
|
22429
|
-
throw new Error('min_account_sequence has been already set - setting min_account_sequence would overwrite it.');
|
|
22430
|
-
}
|
|
22431
|
-
this.minAccountSequence = minAccountSequence;
|
|
22432
|
-
return this;
|
|
22148
|
+
key: "size",
|
|
22149
|
+
get: function get() {
|
|
22150
|
+
return 128;
|
|
22433
22151
|
}
|
|
22152
|
+
}]);
|
|
22153
|
+
}(xdr.LargeInt);
|
|
22154
|
+
Uint128.defineIntBoundaries();
|
|
22155
|
+
;// ./src/numbers/uint256.js
|
|
22156
|
+
function uint256_typeof(o) { "@babel/helpers - typeof"; return uint256_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, uint256_typeof(o); }
|
|
22157
|
+
function uint256_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22158
|
+
function uint256_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, uint256_toPropertyKey(o.key), o); } }
|
|
22159
|
+
function uint256_createClass(e, r, t) { return r && uint256_defineProperties(e.prototype, r), t && uint256_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
22160
|
+
function uint256_toPropertyKey(t) { var i = uint256_toPrimitive(t, "string"); return "symbol" == uint256_typeof(i) ? i : i + ""; }
|
|
22161
|
+
function uint256_toPrimitive(t, r) { if ("object" != uint256_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != uint256_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22162
|
+
function uint256_callSuper(t, o, e) { return o = uint256_getPrototypeOf(o), uint256_possibleConstructorReturn(t, uint256_isNativeReflectConstruct() ? Reflect.construct(o, e || [], uint256_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
22163
|
+
function uint256_possibleConstructorReturn(t, e) { if (e && ("object" == uint256_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return uint256_assertThisInitialized(t); }
|
|
22164
|
+
function uint256_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
22165
|
+
function uint256_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (uint256_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22166
|
+
function uint256_getPrototypeOf(t) { return uint256_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, uint256_getPrototypeOf(t); }
|
|
22167
|
+
function uint256_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && uint256_setPrototypeOf(t, e); }
|
|
22168
|
+
function uint256_setPrototypeOf(t, e) { return uint256_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, uint256_setPrototypeOf(t, e); }
|
|
22434
22169
|
|
|
22435
|
-
|
|
22436
|
-
|
|
22437
|
-
|
|
22438
|
-
|
|
22439
|
-
|
|
22440
|
-
|
|
22441
|
-
|
|
22442
|
-
|
|
22443
|
-
|
|
22444
|
-
|
|
22445
|
-
|
|
22446
|
-
|
|
22447
|
-
|
|
22448
|
-
|
|
22449
|
-
|
|
22450
|
-
|
|
22451
|
-
|
|
22452
|
-
|
|
22453
|
-
|
|
22454
|
-
throw new Error('min_account_sequence_age has been already set - setting min_account_sequence_age would overwrite it.');
|
|
22455
|
-
}
|
|
22456
|
-
if (durationInSeconds < 0) {
|
|
22457
|
-
throw new Error('min_account_sequence_age cannot be negative');
|
|
22458
|
-
}
|
|
22459
|
-
this.minAccountSequenceAge = durationInSeconds;
|
|
22460
|
-
return this;
|
|
22170
|
+
var Uint256 = /*#__PURE__*/function (_LargeInt) {
|
|
22171
|
+
/**
|
|
22172
|
+
* Construct an unsigned 256-bit integer that can be XDR-encoded.
|
|
22173
|
+
*
|
|
22174
|
+
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
22175
|
+
* in big-endian format (i.e. earlier elements are higher bits)
|
|
22176
|
+
*/
|
|
22177
|
+
function Uint256() {
|
|
22178
|
+
uint256_classCallCheck(this, Uint256);
|
|
22179
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22180
|
+
args[_key] = arguments[_key];
|
|
22181
|
+
}
|
|
22182
|
+
return uint256_callSuper(this, Uint256, [args]);
|
|
22183
|
+
}
|
|
22184
|
+
uint256_inherits(Uint256, _LargeInt);
|
|
22185
|
+
return uint256_createClass(Uint256, [{
|
|
22186
|
+
key: "unsigned",
|
|
22187
|
+
get: function get() {
|
|
22188
|
+
return true;
|
|
22461
22189
|
}
|
|
22462
|
-
|
|
22463
|
-
/**
|
|
22464
|
-
* For the transaction to be valid, the current ledger number must be at least
|
|
22465
|
-
* `minAccountSequenceLedgerGap` greater than sourceAccount's ledger sequence.
|
|
22466
|
-
* Internally this will set the `minAccountSequenceLedgerGap` precondition.
|
|
22467
|
-
*
|
|
22468
|
-
* @param {number} gap The minimum number of ledgers between source account
|
|
22469
|
-
* sequence and the ledger number when this transaction will become valid.
|
|
22470
|
-
* If the value is `0`, the transaction is unrestricted by the account
|
|
22471
|
-
* sequence ledger. Cannot be negative.
|
|
22472
|
-
*
|
|
22473
|
-
* @returns {TransactionBuilder}
|
|
22474
|
-
*/
|
|
22475
22190
|
}, {
|
|
22476
|
-
key: "
|
|
22477
|
-
|
|
22478
|
-
|
|
22479
|
-
throw new Error('min_account_sequence_ledger_gap has been already set - setting min_account_sequence_ledger_gap would overwrite it.');
|
|
22480
|
-
}
|
|
22481
|
-
if (gap < 0) {
|
|
22482
|
-
throw new Error('min_account_sequence_ledger_gap cannot be negative');
|
|
22483
|
-
}
|
|
22484
|
-
this.minAccountSequenceLedgerGap = gap;
|
|
22485
|
-
return this;
|
|
22191
|
+
key: "size",
|
|
22192
|
+
get: function get() {
|
|
22193
|
+
return 256;
|
|
22486
22194
|
}
|
|
22195
|
+
}]);
|
|
22196
|
+
}(xdr.LargeInt);
|
|
22197
|
+
Uint256.defineIntBoundaries();
|
|
22198
|
+
;// ./src/numbers/int128.js
|
|
22199
|
+
function int128_typeof(o) { "@babel/helpers - typeof"; return int128_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, int128_typeof(o); }
|
|
22200
|
+
function int128_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22201
|
+
function int128_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, int128_toPropertyKey(o.key), o); } }
|
|
22202
|
+
function int128_createClass(e, r, t) { return r && int128_defineProperties(e.prototype, r), t && int128_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
22203
|
+
function int128_toPropertyKey(t) { var i = int128_toPrimitive(t, "string"); return "symbol" == int128_typeof(i) ? i : i + ""; }
|
|
22204
|
+
function int128_toPrimitive(t, r) { if ("object" != int128_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != int128_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22205
|
+
function int128_callSuper(t, o, e) { return o = int128_getPrototypeOf(o), int128_possibleConstructorReturn(t, int128_isNativeReflectConstruct() ? Reflect.construct(o, e || [], int128_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
22206
|
+
function int128_possibleConstructorReturn(t, e) { if (e && ("object" == int128_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return int128_assertThisInitialized(t); }
|
|
22207
|
+
function int128_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
22208
|
+
function int128_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (int128_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22209
|
+
function int128_getPrototypeOf(t) { return int128_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, int128_getPrototypeOf(t); }
|
|
22210
|
+
function int128_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && int128_setPrototypeOf(t, e); }
|
|
22211
|
+
function int128_setPrototypeOf(t, e) { return int128_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, int128_setPrototypeOf(t, e); }
|
|
22487
22212
|
|
|
22488
|
-
|
|
22489
|
-
|
|
22490
|
-
|
|
22491
|
-
|
|
22492
|
-
|
|
22493
|
-
|
|
22494
|
-
|
|
22495
|
-
|
|
22496
|
-
|
|
22497
|
-
|
|
22213
|
+
var Int128 = /*#__PURE__*/function (_LargeInt) {
|
|
22214
|
+
/**
|
|
22215
|
+
* Construct a signed 128-bit integer that can be XDR-encoded.
|
|
22216
|
+
*
|
|
22217
|
+
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
22218
|
+
* in big-endian format (i.e. earlier elements are higher bits)
|
|
22219
|
+
*/
|
|
22220
|
+
function Int128() {
|
|
22221
|
+
int128_classCallCheck(this, Int128);
|
|
22222
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22223
|
+
args[_key] = arguments[_key];
|
|
22224
|
+
}
|
|
22225
|
+
return int128_callSuper(this, Int128, [args]);
|
|
22226
|
+
}
|
|
22227
|
+
int128_inherits(Int128, _LargeInt);
|
|
22228
|
+
return int128_createClass(Int128, [{
|
|
22229
|
+
key: "unsigned",
|
|
22230
|
+
get: function get() {
|
|
22231
|
+
return false;
|
|
22232
|
+
}
|
|
22498
22233
|
}, {
|
|
22499
|
-
key: "
|
|
22500
|
-
|
|
22501
|
-
|
|
22502
|
-
throw new Error('extra_signers must be an array of strings.');
|
|
22503
|
-
}
|
|
22504
|
-
if (this.extraSigners !== null) {
|
|
22505
|
-
throw new Error('extra_signers has been already set - setting extra_signers would overwrite it.');
|
|
22506
|
-
}
|
|
22507
|
-
if (extraSigners.length > 2) {
|
|
22508
|
-
throw new Error('extra_signers cannot be longer than 2 elements.');
|
|
22509
|
-
}
|
|
22510
|
-
this.extraSigners = _toConsumableArray(extraSigners);
|
|
22511
|
-
return this;
|
|
22234
|
+
key: "size",
|
|
22235
|
+
get: function get() {
|
|
22236
|
+
return 128;
|
|
22512
22237
|
}
|
|
22238
|
+
}]);
|
|
22239
|
+
}(xdr.LargeInt);
|
|
22240
|
+
Int128.defineIntBoundaries();
|
|
22241
|
+
;// ./src/numbers/int256.js
|
|
22242
|
+
function int256_typeof(o) { "@babel/helpers - typeof"; return int256_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, int256_typeof(o); }
|
|
22243
|
+
function int256_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22244
|
+
function int256_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, int256_toPropertyKey(o.key), o); } }
|
|
22245
|
+
function int256_createClass(e, r, t) { return r && int256_defineProperties(e.prototype, r), t && int256_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
22246
|
+
function int256_toPropertyKey(t) { var i = int256_toPrimitive(t, "string"); return "symbol" == int256_typeof(i) ? i : i + ""; }
|
|
22247
|
+
function int256_toPrimitive(t, r) { if ("object" != int256_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != int256_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22248
|
+
function int256_callSuper(t, o, e) { return o = int256_getPrototypeOf(o), int256_possibleConstructorReturn(t, int256_isNativeReflectConstruct() ? Reflect.construct(o, e || [], int256_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
22249
|
+
function int256_possibleConstructorReturn(t, e) { if (e && ("object" == int256_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return int256_assertThisInitialized(t); }
|
|
22250
|
+
function int256_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
22251
|
+
function int256_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (int256_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22252
|
+
function int256_getPrototypeOf(t) { return int256_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, int256_getPrototypeOf(t); }
|
|
22253
|
+
function int256_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && int256_setPrototypeOf(t, e); }
|
|
22254
|
+
function int256_setPrototypeOf(t, e) { return int256_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, int256_setPrototypeOf(t, e); }
|
|
22513
22255
|
|
|
22514
|
-
|
|
22515
|
-
|
|
22516
|
-
|
|
22517
|
-
|
|
22518
|
-
|
|
22519
|
-
|
|
22520
|
-
|
|
22521
|
-
|
|
22256
|
+
var Int256 = /*#__PURE__*/function (_LargeInt) {
|
|
22257
|
+
/**
|
|
22258
|
+
* Construct a signed 256-bit integer that can be XDR-encoded.
|
|
22259
|
+
*
|
|
22260
|
+
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
22261
|
+
* in big-endian format (i.e. earlier elements are higher bits)
|
|
22262
|
+
*/
|
|
22263
|
+
function Int256() {
|
|
22264
|
+
int256_classCallCheck(this, Int256);
|
|
22265
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22266
|
+
args[_key] = arguments[_key];
|
|
22267
|
+
}
|
|
22268
|
+
return int256_callSuper(this, Int256, [args]);
|
|
22269
|
+
}
|
|
22270
|
+
int256_inherits(Int256, _LargeInt);
|
|
22271
|
+
return int256_createClass(Int256, [{
|
|
22272
|
+
key: "unsigned",
|
|
22273
|
+
get: function get() {
|
|
22274
|
+
return false;
|
|
22275
|
+
}
|
|
22522
22276
|
}, {
|
|
22523
|
-
key: "
|
|
22524
|
-
|
|
22525
|
-
|
|
22526
|
-
return this;
|
|
22277
|
+
key: "size",
|
|
22278
|
+
get: function get() {
|
|
22279
|
+
return 256;
|
|
22527
22280
|
}
|
|
22281
|
+
}]);
|
|
22282
|
+
}(xdr.LargeInt);
|
|
22283
|
+
Int256.defineIntBoundaries();
|
|
22284
|
+
;// ./src/numbers/xdr_large_int.js
|
|
22285
|
+
function xdr_large_int_typeof(o) { "@babel/helpers - typeof"; return xdr_large_int_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, xdr_large_int_typeof(o); }
|
|
22286
|
+
function xdr_large_int_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22287
|
+
function xdr_large_int_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, xdr_large_int_toPropertyKey(o.key), o); } }
|
|
22288
|
+
function xdr_large_int_createClass(e, r, t) { return r && xdr_large_int_defineProperties(e.prototype, r), t && xdr_large_int_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
22289
|
+
function xdr_large_int_defineProperty(e, r, t) { return (r = xdr_large_int_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
22290
|
+
function xdr_large_int_toPropertyKey(t) { var i = xdr_large_int_toPrimitive(t, "string"); return "symbol" == xdr_large_int_typeof(i) ? i : i + ""; }
|
|
22291
|
+
function xdr_large_int_toPrimitive(t, r) { if ("object" != xdr_large_int_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != xdr_large_int_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22292
|
+
/* eslint no-bitwise: ["error", {"allow": [">>"]}] */
|
|
22528
22293
|
|
|
22529
|
-
|
|
22530
|
-
|
|
22531
|
-
|
|
22532
|
-
|
|
22533
|
-
|
|
22534
|
-
|
|
22535
|
-
|
|
22536
|
-
|
|
22537
|
-
|
|
22538
|
-
|
|
22539
|
-
|
|
22540
|
-
|
|
22541
|
-
|
|
22542
|
-
|
|
22543
|
-
|
|
22544
|
-
|
|
22545
|
-
|
|
22546
|
-
|
|
22547
|
-
|
|
22548
|
-
|
|
22549
|
-
|
|
22550
|
-
|
|
22551
|
-
|
|
22552
|
-
|
|
22294
|
+
|
|
22295
|
+
|
|
22296
|
+
|
|
22297
|
+
|
|
22298
|
+
|
|
22299
|
+
|
|
22300
|
+
/**
|
|
22301
|
+
* A wrapper class to represent large XDR-encodable integers.
|
|
22302
|
+
*
|
|
22303
|
+
* This operates at a lower level than {@link ScInt} by forcing you to specify
|
|
22304
|
+
* the type / width / size in bits of the integer you're targeting, regardless
|
|
22305
|
+
* of the input value(s) you provide.
|
|
22306
|
+
*
|
|
22307
|
+
* @param {string} type - specifies a data type to use to represent the, one
|
|
22308
|
+
* of: 'i64', 'u64', 'i128', 'u128', 'i256', and 'u256' (see
|
|
22309
|
+
* {@link XdrLargeInt.isType})
|
|
22310
|
+
* @param {number|bigint|string|Array<number|bigint|string>} values a list of
|
|
22311
|
+
* integer-like values interpreted in big-endian order
|
|
22312
|
+
*/
|
|
22313
|
+
var XdrLargeInt = /*#__PURE__*/function () {
|
|
22314
|
+
function XdrLargeInt(type, values) {
|
|
22315
|
+
xdr_large_int_classCallCheck(this, XdrLargeInt);
|
|
22316
|
+
/** @type {xdr.LargeInt} */
|
|
22317
|
+
xdr_large_int_defineProperty(this, "int", void 0);
|
|
22318
|
+
// child class of a jsXdr.LargeInt
|
|
22319
|
+
/** @type {string} */
|
|
22320
|
+
xdr_large_int_defineProperty(this, "type", void 0);
|
|
22321
|
+
if (!(values instanceof Array)) {
|
|
22322
|
+
values = [values];
|
|
22553
22323
|
}
|
|
22554
22324
|
|
|
22555
|
-
|
|
22556
|
-
|
|
22557
|
-
|
|
22558
|
-
|
|
22559
|
-
|
|
22560
|
-
}, {
|
|
22561
|
-
key: "build",
|
|
22562
|
-
value: function build() {
|
|
22563
|
-
var sequenceNumber = new util_bignumber(this.source.sequenceNumber()).plus(1);
|
|
22564
|
-
var fee = new util_bignumber(this.baseFee).times(this.operations.length).toNumber();
|
|
22565
|
-
var attrs = {
|
|
22566
|
-
fee: fee,
|
|
22567
|
-
seqNum: src_xdr.SequenceNumber.fromString(sequenceNumber.toString()),
|
|
22568
|
-
memo: this.memo ? this.memo.toXDRObject() : null
|
|
22569
|
-
};
|
|
22570
|
-
if (this.timebounds === null || typeof this.timebounds.minTime === 'undefined' || typeof this.timebounds.maxTime === 'undefined') {
|
|
22571
|
-
throw new Error('TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).');
|
|
22572
|
-
}
|
|
22573
|
-
if (isValidDate(this.timebounds.minTime)) {
|
|
22574
|
-
this.timebounds.minTime = this.timebounds.minTime.getTime() / 1000;
|
|
22575
|
-
}
|
|
22576
|
-
if (isValidDate(this.timebounds.maxTime)) {
|
|
22577
|
-
this.timebounds.maxTime = this.timebounds.maxTime.getTime() / 1000;
|
|
22325
|
+
// normalize values to one type
|
|
22326
|
+
values = values.map(function (i) {
|
|
22327
|
+
// micro-optimization to no-op on the likeliest input value:
|
|
22328
|
+
if (typeof i === 'bigint') {
|
|
22329
|
+
return i;
|
|
22578
22330
|
}
|
|
22579
|
-
|
|
22580
|
-
|
|
22581
|
-
var timeBounds = new src_xdr.TimeBounds(this.timebounds);
|
|
22582
|
-
if (this.hasV2Preconditions()) {
|
|
22583
|
-
var ledgerBounds = null;
|
|
22584
|
-
if (this.ledgerbounds !== null) {
|
|
22585
|
-
ledgerBounds = new src_xdr.LedgerBounds(this.ledgerbounds);
|
|
22586
|
-
}
|
|
22587
|
-
var minSeqNum = this.minAccountSequence || '0';
|
|
22588
|
-
minSeqNum = src_xdr.SequenceNumber.fromString(minSeqNum);
|
|
22589
|
-
var minSeqAge = xdr.UnsignedHyper.fromString(this.minAccountSequenceAge !== null ? this.minAccountSequenceAge.toString() : '0');
|
|
22590
|
-
var minSeqLedgerGap = this.minAccountSequenceLedgerGap || 0;
|
|
22591
|
-
var extraSigners = this.extraSigners !== null ? this.extraSigners.map(SignerKey.decodeAddress) : [];
|
|
22592
|
-
attrs.cond = src_xdr.Preconditions.precondV2(new src_xdr.PreconditionsV2({
|
|
22593
|
-
timeBounds: timeBounds,
|
|
22594
|
-
ledgerBounds: ledgerBounds,
|
|
22595
|
-
minSeqNum: minSeqNum,
|
|
22596
|
-
minSeqAge: minSeqAge,
|
|
22597
|
-
minSeqLedgerGap: minSeqLedgerGap,
|
|
22598
|
-
extraSigners: extraSigners
|
|
22599
|
-
}));
|
|
22600
|
-
} else {
|
|
22601
|
-
attrs.cond = src_xdr.Preconditions.precondTime(timeBounds);
|
|
22331
|
+
if (typeof i.toBigInt === 'function') {
|
|
22332
|
+
return i.toBigInt();
|
|
22602
22333
|
}
|
|
22603
|
-
|
|
22334
|
+
return BigInt(i);
|
|
22335
|
+
});
|
|
22336
|
+
switch (type) {
|
|
22337
|
+
case 'i64':
|
|
22338
|
+
this["int"] = new xdr.Hyper(values);
|
|
22339
|
+
break;
|
|
22340
|
+
case 'i128':
|
|
22341
|
+
this["int"] = new Int128(values);
|
|
22342
|
+
break;
|
|
22343
|
+
case 'i256':
|
|
22344
|
+
this["int"] = new Int256(values);
|
|
22345
|
+
break;
|
|
22346
|
+
case 'u64':
|
|
22347
|
+
case 'timepoint':
|
|
22348
|
+
case 'duration':
|
|
22349
|
+
this["int"] = new xdr.UnsignedHyper(values);
|
|
22350
|
+
break;
|
|
22351
|
+
case 'u128':
|
|
22352
|
+
this["int"] = new Uint128(values);
|
|
22353
|
+
break;
|
|
22354
|
+
case 'u256':
|
|
22355
|
+
this["int"] = new Uint256(values);
|
|
22356
|
+
break;
|
|
22357
|
+
default:
|
|
22358
|
+
throw TypeError("invalid type: ".concat(type));
|
|
22359
|
+
}
|
|
22360
|
+
this.type = type;
|
|
22361
|
+
}
|
|
22604
22362
|
|
|
22605
|
-
|
|
22606
|
-
|
|
22607
|
-
|
|
22608
|
-
|
|
22609
|
-
|
|
22610
|
-
|
|
22611
|
-
|
|
22612
|
-
|
|
22613
|
-
|
|
22363
|
+
/**
|
|
22364
|
+
* @returns {number}
|
|
22365
|
+
* @throws {RangeError} if the value can't fit into a Number
|
|
22366
|
+
*/
|
|
22367
|
+
return xdr_large_int_createClass(XdrLargeInt, [{
|
|
22368
|
+
key: "toNumber",
|
|
22369
|
+
value: function toNumber() {
|
|
22370
|
+
var bi = this["int"].toBigInt();
|
|
22371
|
+
if (bi > Number.MAX_SAFE_INTEGER || bi < Number.MIN_SAFE_INTEGER) {
|
|
22372
|
+
throw RangeError("value ".concat(bi, " not in range for Number ") + "[".concat(Number.MAX_SAFE_INTEGER, ", ").concat(Number.MIN_SAFE_INTEGER, "]"));
|
|
22614
22373
|
}
|
|
22615
|
-
|
|
22616
|
-
xtx.operations(this.operations);
|
|
22617
|
-
var txEnvelope = new src_xdr.TransactionEnvelope.envelopeTypeTx(new src_xdr.TransactionV1Envelope({
|
|
22618
|
-
tx: xtx
|
|
22619
|
-
}));
|
|
22620
|
-
var tx = new Transaction(txEnvelope, this.networkPassphrase);
|
|
22621
|
-
this.source.incrementSequenceNumber();
|
|
22622
|
-
return tx;
|
|
22374
|
+
return Number(bi);
|
|
22623
22375
|
}
|
|
22376
|
+
|
|
22377
|
+
/** @returns {bigint} */
|
|
22624
22378
|
}, {
|
|
22625
|
-
key: "
|
|
22626
|
-
value: function
|
|
22627
|
-
return this.
|
|
22379
|
+
key: "toBigInt",
|
|
22380
|
+
value: function toBigInt() {
|
|
22381
|
+
return this["int"].toBigInt();
|
|
22628
22382
|
}
|
|
22629
22383
|
|
|
22630
|
-
/**
|
|
22631
|
-
|
|
22632
|
-
|
|
22633
|
-
|
|
22634
|
-
|
|
22635
|
-
|
|
22636
|
-
|
|
22637
|
-
|
|
22638
|
-
* in inner transaction (**in stroops**)
|
|
22639
|
-
* @param {Transaction} innerTx - {@link Transaction} to be bumped by
|
|
22640
|
-
* the fee bump transaction
|
|
22641
|
-
* @param {string} networkPassphrase - passphrase of the target
|
|
22642
|
-
* Stellar network (e.g. "Public Global Stellar Network ; September 2015",
|
|
22643
|
-
* see {@link Networks})
|
|
22644
|
-
*
|
|
22645
|
-
* @todo Alongside the next major version bump, this type signature can be
|
|
22646
|
-
* changed to be less awkward: accept a MuxedAccount as the `feeSource`
|
|
22647
|
-
* rather than a keypair or string.
|
|
22648
|
-
*
|
|
22649
|
-
* @note Your fee-bump amount should be >= 10x the original fee.
|
|
22650
|
-
* @see https://developers.stellar.org/docs/glossary/fee-bumps/#replace-by-fee
|
|
22651
|
-
*
|
|
22652
|
-
* @returns {FeeBumpTransaction}
|
|
22653
|
-
*/
|
|
22654
|
-
}], [{
|
|
22655
|
-
key: "cloneFrom",
|
|
22656
|
-
value: function cloneFrom(tx) {
|
|
22657
|
-
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22658
|
-
if (!(tx instanceof Transaction)) {
|
|
22659
|
-
throw new TypeError("expected a 'Transaction', got: ".concat(tx));
|
|
22660
|
-
}
|
|
22661
|
-
var sequenceNum = (BigInt(tx.sequence) - 1n).toString();
|
|
22662
|
-
var source;
|
|
22663
|
-
// rebuild the source account based on the strkey
|
|
22664
|
-
if (StrKey.isValidMed25519PublicKey(tx.source)) {
|
|
22665
|
-
source = MuxedAccount.fromAddress(tx.source, sequenceNum);
|
|
22666
|
-
} else if (StrKey.isValidEd25519PublicKey(tx.source)) {
|
|
22667
|
-
source = new Account(tx.source, sequenceNum);
|
|
22668
|
-
} else {
|
|
22669
|
-
throw new TypeError("unsupported tx source account: ".concat(tx.source));
|
|
22384
|
+
/** @returns {xdr.ScVal} the integer encoded with `ScValType = I64` */
|
|
22385
|
+
}, {
|
|
22386
|
+
key: "toI64",
|
|
22387
|
+
value: function toI64() {
|
|
22388
|
+
this._sizeCheck(64);
|
|
22389
|
+
var v = this.toBigInt();
|
|
22390
|
+
if (BigInt.asIntN(64, v) !== v) {
|
|
22391
|
+
throw RangeError("value too large for i64: ".concat(v));
|
|
22670
22392
|
}
|
|
22393
|
+
return src_xdr.ScVal.scvI64(new src_xdr.Int64(v));
|
|
22394
|
+
}
|
|
22671
22395
|
|
|
22672
|
-
|
|
22673
|
-
|
|
22674
|
-
|
|
22675
|
-
|
|
22676
|
-
|
|
22677
|
-
|
|
22678
|
-
|
|
22679
|
-
timebounds: tx.timeBounds,
|
|
22680
|
-
ledgerbounds: tx.ledgerBounds,
|
|
22681
|
-
minAccountSequence: tx.minAccountSequence,
|
|
22682
|
-
minAccountSequenceAge: tx.minAccountSequenceAge,
|
|
22683
|
-
minAccountSequenceLedgerGap: tx.minAccountSequenceLedgerGap,
|
|
22684
|
-
extraSigners: tx.extraSigners
|
|
22685
|
-
}, opts));
|
|
22686
|
-
tx._tx.operations().forEach(function (op) {
|
|
22687
|
-
return builder.addOperation(op);
|
|
22688
|
-
});
|
|
22689
|
-
return builder;
|
|
22396
|
+
/** @returns {xdr.ScVal} the integer encoded with `ScValType = U64` */
|
|
22397
|
+
}, {
|
|
22398
|
+
key: "toU64",
|
|
22399
|
+
value: function toU64() {
|
|
22400
|
+
this._sizeCheck(64);
|
|
22401
|
+
return src_xdr.ScVal.scvU64(new src_xdr.Uint64(BigInt.asUintN(64, this.toBigInt())) // reiterpret as unsigned
|
|
22402
|
+
);
|
|
22690
22403
|
}
|
|
22404
|
+
|
|
22405
|
+
/** @returns {xdr.ScVal} the integer encoded with `ScValType = Timepoint` */
|
|
22691
22406
|
}, {
|
|
22692
|
-
key: "
|
|
22693
|
-
value: function
|
|
22694
|
-
|
|
22695
|
-
|
|
22696
|
-
|
|
22697
|
-
|
|
22407
|
+
key: "toTimepoint",
|
|
22408
|
+
value: function toTimepoint() {
|
|
22409
|
+
this._sizeCheck(64);
|
|
22410
|
+
return src_xdr.ScVal.scvTimepoint(new src_xdr.Uint64(BigInt.asUintN(64, this.toBigInt())) // reiterpret as unsigned
|
|
22411
|
+
);
|
|
22412
|
+
}
|
|
22698
22413
|
|
|
22699
|
-
|
|
22700
|
-
|
|
22701
|
-
|
|
22702
|
-
|
|
22703
|
-
|
|
22704
|
-
|
|
22705
|
-
|
|
22706
|
-
|
|
22707
|
-
resourceFee = new util_bignumber((_sorobanData$resource = sorobanData === null || sorobanData === void 0 ? void 0 : sorobanData.resourceFee()) !== null && _sorobanData$resource !== void 0 ? _sorobanData$resource : 0);
|
|
22708
|
-
innerInclusionFee = util_bignumber.max(minBaseFee, innerInclusionFee.minus(resourceFee));
|
|
22709
|
-
break;
|
|
22710
|
-
}
|
|
22711
|
-
default:
|
|
22712
|
-
break;
|
|
22713
|
-
}
|
|
22714
|
-
var base = new util_bignumber(baseFee);
|
|
22414
|
+
/** @returns {xdr.ScVal} the integer encoded with `ScValType = Duration` */
|
|
22415
|
+
}, {
|
|
22416
|
+
key: "toDuration",
|
|
22417
|
+
value: function toDuration() {
|
|
22418
|
+
this._sizeCheck(64);
|
|
22419
|
+
return src_xdr.ScVal.scvDuration(new src_xdr.Uint64(BigInt.asUintN(64, this.toBigInt())) // reiterpret as unsigned
|
|
22420
|
+
);
|
|
22421
|
+
}
|
|
22715
22422
|
|
|
22716
|
-
|
|
22717
|
-
|
|
22718
|
-
|
|
22719
|
-
|
|
22423
|
+
/**
|
|
22424
|
+
* @returns {xdr.ScVal} the integer encoded with `ScValType = I128`
|
|
22425
|
+
* @throws {RangeError} if the value cannot fit in 128 bits
|
|
22426
|
+
*/
|
|
22427
|
+
}, {
|
|
22428
|
+
key: "toI128",
|
|
22429
|
+
value: function toI128() {
|
|
22430
|
+
this._sizeCheck(128);
|
|
22431
|
+
var v = this["int"].toBigInt();
|
|
22432
|
+
var hi64 = BigInt.asIntN(64, v >> 64n); // encode top 64 w/ sign bit
|
|
22433
|
+
var lo64 = BigInt.asUintN(64, v); // grab btm 64, encode sign
|
|
22720
22434
|
|
|
22721
|
-
|
|
22722
|
-
|
|
22723
|
-
|
|
22724
|
-
}
|
|
22725
|
-
var innerTxEnvelope = innerTx.toEnvelope();
|
|
22726
|
-
if (innerTxEnvelope["switch"]() === src_xdr.EnvelopeType.envelopeTypeTxV0()) {
|
|
22727
|
-
var v0Tx = innerTxEnvelope.v0().tx();
|
|
22728
|
-
var v1Tx = new src_xdr.Transaction({
|
|
22729
|
-
sourceAccount: new src_xdr.MuxedAccount.keyTypeEd25519(v0Tx.sourceAccountEd25519()),
|
|
22730
|
-
fee: v0Tx.fee(),
|
|
22731
|
-
seqNum: v0Tx.seqNum(),
|
|
22732
|
-
cond: src_xdr.Preconditions.precondTime(v0Tx.timeBounds()),
|
|
22733
|
-
memo: v0Tx.memo(),
|
|
22734
|
-
operations: v0Tx.operations(),
|
|
22735
|
-
ext: new src_xdr.TransactionExt(0)
|
|
22736
|
-
});
|
|
22737
|
-
innerTxEnvelope = new src_xdr.TransactionEnvelope.envelopeTypeTx(new src_xdr.TransactionV1Envelope({
|
|
22738
|
-
tx: v1Tx,
|
|
22739
|
-
signatures: innerTxEnvelope.v0().signatures()
|
|
22740
|
-
}));
|
|
22741
|
-
}
|
|
22742
|
-
var feeSourceAccount;
|
|
22743
|
-
if (typeof feeSource === 'string') {
|
|
22744
|
-
feeSourceAccount = decodeAddressToMuxedAccount(feeSource);
|
|
22745
|
-
} else {
|
|
22746
|
-
feeSourceAccount = feeSource.xdrMuxedAccount();
|
|
22747
|
-
}
|
|
22748
|
-
var tx = new src_xdr.FeeBumpTransaction({
|
|
22749
|
-
feeSource: feeSourceAccount,
|
|
22750
|
-
fee: src_xdr.Int64.fromString(base.times(innerOps + 1).plus(resourceFee).toString()),
|
|
22751
|
-
innerTx: src_xdr.FeeBumpTransactionInnerTx.envelopeTypeTx(innerTxEnvelope.v1()),
|
|
22752
|
-
ext: new src_xdr.FeeBumpTransactionExt(0)
|
|
22753
|
-
});
|
|
22754
|
-
var feeBumpTxEnvelope = new src_xdr.FeeBumpTransactionEnvelope({
|
|
22755
|
-
tx: tx,
|
|
22756
|
-
signatures: []
|
|
22757
|
-
});
|
|
22758
|
-
var envelope = new src_xdr.TransactionEnvelope.envelopeTypeTxFeeBump(feeBumpTxEnvelope);
|
|
22759
|
-
return new FeeBumpTransaction(envelope, networkPassphrase);
|
|
22435
|
+
return src_xdr.ScVal.scvI128(new src_xdr.Int128Parts({
|
|
22436
|
+
hi: new src_xdr.Int64(hi64),
|
|
22437
|
+
lo: new src_xdr.Uint64(lo64)
|
|
22438
|
+
}));
|
|
22760
22439
|
}
|
|
22761
22440
|
|
|
22762
22441
|
/**
|
|
22763
|
-
*
|
|
22764
|
-
*
|
|
22765
|
-
*
|
|
22766
|
-
* @param {string|xdr.TransactionEnvelope} envelope - The transaction envelope
|
|
22767
|
-
* object or base64 encoded string.
|
|
22768
|
-
* @param {string} networkPassphrase - The network passphrase of the target
|
|
22769
|
-
* Stellar network (e.g. "Public Global Stellar Network ; September
|
|
22770
|
-
* 2015"), see {@link Networks}.
|
|
22771
|
-
*
|
|
22772
|
-
* @returns {Transaction|FeeBumpTransaction}
|
|
22442
|
+
* @returns {xdr.ScVal} the integer encoded with `ScValType = U128`
|
|
22443
|
+
* @throws {RangeError} if the value cannot fit in 128 bits
|
|
22773
22444
|
*/
|
|
22774
22445
|
}, {
|
|
22775
|
-
key: "
|
|
22776
|
-
value: function
|
|
22777
|
-
|
|
22778
|
-
|
|
22779
|
-
|
|
22780
|
-
|
|
22781
|
-
|
|
22782
|
-
}
|
|
22783
|
-
return new Transaction(envelope, networkPassphrase);
|
|
22446
|
+
key: "toU128",
|
|
22447
|
+
value: function toU128() {
|
|
22448
|
+
this._sizeCheck(128);
|
|
22449
|
+
var v = this["int"].toBigInt();
|
|
22450
|
+
return src_xdr.ScVal.scvU128(new src_xdr.UInt128Parts({
|
|
22451
|
+
hi: new src_xdr.Uint64(BigInt.asUintN(64, v >> 64n)),
|
|
22452
|
+
lo: new src_xdr.Uint64(BigInt.asUintN(64, v))
|
|
22453
|
+
}));
|
|
22784
22454
|
}
|
|
22785
|
-
}]);
|
|
22786
|
-
}();
|
|
22787
22455
|
|
|
22788
|
-
/**
|
|
22789
|
-
|
|
22790
|
-
|
|
22791
|
-
|
|
22792
|
-
|
|
22793
|
-
|
|
22794
|
-
|
|
22795
|
-
|
|
22796
|
-
|
|
22797
|
-
|
|
22798
|
-
|
|
22799
|
-
|
|
22800
|
-
|
|
22801
|
-
|
|
22802
|
-
|
|
22803
|
-
|
|
22804
|
-
|
|
22805
|
-
|
|
22806
|
-
|
|
22807
|
-
|
|
22808
|
-
|
|
22809
|
-
|
|
22810
|
-
|
|
22811
|
-
|
|
22812
|
-
|
|
22813
|
-
|
|
22814
|
-
|
|
22815
|
-
|
|
22816
|
-
|
|
22817
|
-
|
|
22818
|
-
|
|
22819
|
-
|
|
22820
|
-
|
|
22821
|
-
|
|
22822
|
-
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
function
|
|
22826
|
-
|
|
22827
|
-
|
|
22828
|
-
|
|
22829
|
-
|
|
22830
|
-
|
|
22831
|
-
|
|
22832
|
-
|
|
22833
|
-
|
|
22834
|
-
|
|
22835
|
-
|
|
22836
|
-
|
|
22837
|
-
|
|
22838
|
-
|
|
22839
|
-
|
|
22840
|
-
|
|
22841
|
-
|
|
22842
|
-
|
|
22843
|
-
|
|
22844
|
-
|
|
22845
|
-
*
|
|
22846
|
-
* @returns {string} the display value
|
|
22847
|
-
* @throws {TypeError} if the given amount has a decimal point already
|
|
22848
|
-
* @example
|
|
22849
|
-
* formatTokenAmount("123000", 4) === "12.3";
|
|
22850
|
-
* formatTokenAmount("123000", 3) === "123.0";
|
|
22851
|
-
* formatTokenAmount("123", 3) === "0.123";
|
|
22852
|
-
*/
|
|
22853
|
-
function formatTokenAmount(amount, decimals) {
|
|
22854
|
-
if (amount.includes('.')) {
|
|
22855
|
-
throw new TypeError('No decimals are allowed');
|
|
22456
|
+
/** @returns {xdr.ScVal} the integer encoded with `ScValType = I256` */
|
|
22457
|
+
}, {
|
|
22458
|
+
key: "toI256",
|
|
22459
|
+
value: function toI256() {
|
|
22460
|
+
var v = this["int"].toBigInt();
|
|
22461
|
+
var hiHi64 = BigInt.asIntN(64, v >> 192n); // keep sign bit
|
|
22462
|
+
var hiLo64 = BigInt.asUintN(64, v >> 128n);
|
|
22463
|
+
var loHi64 = BigInt.asUintN(64, v >> 64n);
|
|
22464
|
+
var loLo64 = BigInt.asUintN(64, v);
|
|
22465
|
+
return src_xdr.ScVal.scvI256(new src_xdr.Int256Parts({
|
|
22466
|
+
hiHi: new src_xdr.Int64(hiHi64),
|
|
22467
|
+
hiLo: new src_xdr.Uint64(hiLo64),
|
|
22468
|
+
loHi: new src_xdr.Uint64(loHi64),
|
|
22469
|
+
loLo: new src_xdr.Uint64(loLo64)
|
|
22470
|
+
}));
|
|
22471
|
+
}
|
|
22472
|
+
|
|
22473
|
+
/** @returns {xdr.ScVal} the integer encoded with `ScValType = U256` */
|
|
22474
|
+
}, {
|
|
22475
|
+
key: "toU256",
|
|
22476
|
+
value: function toU256() {
|
|
22477
|
+
var v = this["int"].toBigInt();
|
|
22478
|
+
var hiHi64 = BigInt.asUintN(64, v >> 192n); // encode sign bit
|
|
22479
|
+
var hiLo64 = BigInt.asUintN(64, v >> 128n);
|
|
22480
|
+
var loHi64 = BigInt.asUintN(64, v >> 64n);
|
|
22481
|
+
var loLo64 = BigInt.asUintN(64, v);
|
|
22482
|
+
return src_xdr.ScVal.scvU256(new src_xdr.UInt256Parts({
|
|
22483
|
+
hiHi: new src_xdr.Uint64(hiHi64),
|
|
22484
|
+
hiLo: new src_xdr.Uint64(hiLo64),
|
|
22485
|
+
loHi: new src_xdr.Uint64(loHi64),
|
|
22486
|
+
loLo: new src_xdr.Uint64(loLo64)
|
|
22487
|
+
}));
|
|
22488
|
+
}
|
|
22489
|
+
|
|
22490
|
+
/** @returns {xdr.ScVal} the smallest interpretation of the stored value */
|
|
22491
|
+
}, {
|
|
22492
|
+
key: "toScVal",
|
|
22493
|
+
value: function toScVal() {
|
|
22494
|
+
switch (this.type) {
|
|
22495
|
+
case 'i64':
|
|
22496
|
+
return this.toI64();
|
|
22497
|
+
case 'i128':
|
|
22498
|
+
return this.toI128();
|
|
22499
|
+
case 'i256':
|
|
22500
|
+
return this.toI256();
|
|
22501
|
+
case 'u64':
|
|
22502
|
+
return this.toU64();
|
|
22503
|
+
case 'u128':
|
|
22504
|
+
return this.toU128();
|
|
22505
|
+
case 'u256':
|
|
22506
|
+
return this.toU256();
|
|
22507
|
+
case 'timepoint':
|
|
22508
|
+
return this.toTimepoint();
|
|
22509
|
+
case 'duration':
|
|
22510
|
+
return this.toDuration();
|
|
22511
|
+
default:
|
|
22512
|
+
throw TypeError("invalid type: ".concat(this.type));
|
|
22856
22513
|
}
|
|
22857
|
-
|
|
22858
|
-
|
|
22859
|
-
|
|
22860
|
-
|
|
22861
|
-
|
|
22862
|
-
|
|
22863
|
-
|
|
22514
|
+
}
|
|
22515
|
+
}, {
|
|
22516
|
+
key: "valueOf",
|
|
22517
|
+
value: function valueOf() {
|
|
22518
|
+
return this["int"].valueOf();
|
|
22519
|
+
}
|
|
22520
|
+
}, {
|
|
22521
|
+
key: "toString",
|
|
22522
|
+
value: function toString() {
|
|
22523
|
+
return this["int"].toString();
|
|
22524
|
+
}
|
|
22525
|
+
}, {
|
|
22526
|
+
key: "toJSON",
|
|
22527
|
+
value: function toJSON() {
|
|
22528
|
+
return {
|
|
22529
|
+
value: this.toBigInt().toString(),
|
|
22530
|
+
type: this.type
|
|
22531
|
+
};
|
|
22532
|
+
}
|
|
22533
|
+
}, {
|
|
22534
|
+
key: "_sizeCheck",
|
|
22535
|
+
value: function _sizeCheck(bits) {
|
|
22536
|
+
if (this["int"].size > bits) {
|
|
22537
|
+
throw RangeError("value too large for ".concat(bits, " bits (").concat(this.type, ")"));
|
|
22538
|
+
}
|
|
22539
|
+
}
|
|
22540
|
+
}], [{
|
|
22541
|
+
key: "isType",
|
|
22542
|
+
value: function isType(type) {
|
|
22543
|
+
switch (type) {
|
|
22544
|
+
case 'i64':
|
|
22545
|
+
case 'i128':
|
|
22546
|
+
case 'i256':
|
|
22547
|
+
case 'u64':
|
|
22548
|
+
case 'u128':
|
|
22549
|
+
case 'u256':
|
|
22550
|
+
case 'timepoint':
|
|
22551
|
+
case 'duration':
|
|
22552
|
+
return true;
|
|
22553
|
+
default:
|
|
22554
|
+
return false;
|
|
22864
22555
|
}
|
|
22865
|
-
return formatted.replace(/(\.\d*?)0+$/, '$1') // strip trailing zeroes
|
|
22866
|
-
.replace(/\.$/, '.0') // but keep at least one
|
|
22867
|
-
.replace(/^\./, '0.'); // and a leading one
|
|
22868
22556
|
}
|
|
22869
22557
|
|
|
22870
22558
|
/**
|
|
22871
|
-
*
|
|
22872
|
-
*
|
|
22873
|
-
* This function takes the display value and its decimals (if the token has
|
|
22874
|
-
* any) and returns a string that'll be used within the smart contract.
|
|
22875
|
-
*
|
|
22876
|
-
* @param {string} value the token amount you want to use it on smart
|
|
22877
|
-
* contract which you've been displaying in a UI
|
|
22878
|
-
* @param {number} decimals the number of decimal places expected in the
|
|
22879
|
-
* display value (different than the "actual" number, because suffix zeroes
|
|
22880
|
-
* might not be present)
|
|
22881
|
-
*
|
|
22882
|
-
* @returns {string} the whole number token amount represented by the display
|
|
22883
|
-
* value with the decimal places shifted over
|
|
22559
|
+
* Convert the raw `ScValType` string (e.g. 'scvI128', generated by the XDR)
|
|
22560
|
+
* to a type description for {@link XdrLargeInt} construction (e.g. 'i128')
|
|
22884
22561
|
*
|
|
22885
|
-
* @
|
|
22886
|
-
*
|
|
22887
|
-
* const parsedAmtForSmartContract = parseTokenAmount(displayValueAmount, 5);
|
|
22888
|
-
* parsedAmtForSmartContract === "12345600"
|
|
22562
|
+
* @param {string} scvType the `xdr.ScValType` as a string
|
|
22563
|
+
* @returns {string} a suitable equivalent type to construct this object
|
|
22889
22564
|
*/
|
|
22890
22565
|
}, {
|
|
22891
|
-
key: "
|
|
22892
|
-
value: function
|
|
22893
|
-
|
|
22894
|
-
var _value$split$slice = value.split('.').slice(),
|
|
22895
|
-
_value$split$slice2 = _toArray(_value$split$slice),
|
|
22896
|
-
whole = _value$split$slice2[0],
|
|
22897
|
-
fraction = _value$split$slice2[1],
|
|
22898
|
-
rest = soroban_arrayLikeToArray(_value$split$slice2).slice(2);
|
|
22899
|
-
if (rest.length) {
|
|
22900
|
-
throw new Error("Invalid decimal value: ".concat(value));
|
|
22901
|
-
}
|
|
22902
|
-
var shifted = BigInt(whole + ((_fraction$padEnd = fraction === null || fraction === void 0 ? void 0 : fraction.padEnd(decimals, '0')) !== null && _fraction$padEnd !== void 0 ? _fraction$padEnd : '0'.repeat(decimals)));
|
|
22903
|
-
return shifted.toString();
|
|
22566
|
+
key: "getType",
|
|
22567
|
+
value: function getType(scvType) {
|
|
22568
|
+
return scvType.slice(3).toLowerCase();
|
|
22904
22569
|
}
|
|
22905
22570
|
}]);
|
|
22906
22571
|
}();
|
|
22907
|
-
;// ./src/
|
|
22908
|
-
function
|
|
22909
|
-
function
|
|
22910
|
-
function
|
|
22911
|
-
function
|
|
22912
|
-
function
|
|
22913
|
-
function
|
|
22914
|
-
|
|
22915
|
-
|
|
22916
|
-
|
|
22572
|
+
;// ./src/numbers/sc_int.js
|
|
22573
|
+
function sc_int_typeof(o) { "@babel/helpers - typeof"; return sc_int_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, sc_int_typeof(o); }
|
|
22574
|
+
function sc_int_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, sc_int_toPropertyKey(o.key), o); } }
|
|
22575
|
+
function sc_int_createClass(e, r, t) { return r && sc_int_defineProperties(e.prototype, r), t && sc_int_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
22576
|
+
function sc_int_toPropertyKey(t) { var i = sc_int_toPrimitive(t, "string"); return "symbol" == sc_int_typeof(i) ? i : i + ""; }
|
|
22577
|
+
function sc_int_toPrimitive(t, r) { if ("object" != sc_int_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != sc_int_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22578
|
+
function sc_int_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
22579
|
+
function sc_int_callSuper(t, o, e) { return o = sc_int_getPrototypeOf(o), sc_int_possibleConstructorReturn(t, sc_int_isNativeReflectConstruct() ? Reflect.construct(o, e || [], sc_int_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
22580
|
+
function sc_int_possibleConstructorReturn(t, e) { if (e && ("object" == sc_int_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return sc_int_assertThisInitialized(t); }
|
|
22581
|
+
function sc_int_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
22582
|
+
function sc_int_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (sc_int_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22583
|
+
function sc_int_getPrototypeOf(t) { return sc_int_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, sc_int_getPrototypeOf(t); }
|
|
22584
|
+
function sc_int_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && sc_int_setPrototypeOf(t, e); }
|
|
22585
|
+
function sc_int_setPrototypeOf(t, e) { return sc_int_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, sc_int_setPrototypeOf(t, e); }
|
|
22917
22586
|
|
|
22918
22587
|
|
|
22919
22588
|
/**
|
|
22920
|
-
*
|
|
22589
|
+
* Provides an easier way to manipulate large numbers for Stellar operations.
|
|
22921
22590
|
*
|
|
22922
|
-
*
|
|
22923
|
-
*
|
|
22924
|
-
* [Contracts](https://soroban.stellar.org/docs/learn/interacting-with-contracts)
|
|
22925
|
-
* for more information about how contracts work in Stellar.
|
|
22591
|
+
* You can instantiate this "**s**mart **c**ontract integer" value either from
|
|
22592
|
+
* bigints, strings, or numbers (whole numbers, or this will throw).
|
|
22926
22593
|
*
|
|
22927
|
-
*
|
|
22594
|
+
* If you need to create a native BigInt from a list of integer "parts" (for
|
|
22595
|
+
* example, you have a series of encoded 32-bit integers that represent a larger
|
|
22596
|
+
* value), you can use the lower level abstraction {@link XdrLargeInt}. For
|
|
22597
|
+
* example, you could do `new XdrLargeInt('u128', bytes...).toBigInt()`.
|
|
22928
22598
|
*
|
|
22929
|
-
* @
|
|
22930
|
-
*
|
|
22599
|
+
* @example
|
|
22600
|
+
* import { xdr, ScInt, scValToBigInt } from "@stellar/stellar-base";
|
|
22601
|
+
*
|
|
22602
|
+
* // You have an ScVal from a contract and want to parse it into JS native.
|
|
22603
|
+
* const value = xdr.ScVal.fromXDR(someXdr, "base64");
|
|
22604
|
+
* const bigi = scValToBigInt(value); // grab it as a BigInt
|
|
22605
|
+
* let sci = new ScInt(bigi);
|
|
22606
|
+
*
|
|
22607
|
+
* sci.toNumber(); // gives native JS type (w/ size check)
|
|
22608
|
+
* sci.toBigInt(); // gives the native BigInt value
|
|
22609
|
+
* sci.toU64(); // gives ScValType-specific XDR constructs (with size checks)
|
|
22610
|
+
*
|
|
22611
|
+
* // You have a number and want to shove it into a contract.
|
|
22612
|
+
* sci = ScInt(0xdeadcafebabe);
|
|
22613
|
+
* sci.toBigInt() // returns 244838016400062n
|
|
22614
|
+
* sci.toNumber() // throws: too large
|
|
22615
|
+
*
|
|
22616
|
+
* // Pass any to e.g. a Contract.call(), conversion happens automatically
|
|
22617
|
+
* // regardless of the initial type.
|
|
22618
|
+
* const scValU128 = sci.toU128();
|
|
22619
|
+
* const scValI256 = sci.toI256();
|
|
22620
|
+
* const scValU64 = sci.toU64();
|
|
22621
|
+
*
|
|
22622
|
+
* // Lots of ways to initialize:
|
|
22623
|
+
* ScInt("123456789123456789")
|
|
22624
|
+
* ScInt(123456789123456789n);
|
|
22625
|
+
* ScInt(1n << 140n);
|
|
22626
|
+
* ScInt(-42);
|
|
22627
|
+
* ScInt(scValToBigInt(scValU128)); // from above
|
|
22628
|
+
*
|
|
22629
|
+
* // If you know the type ahead of time (accessing `.raw` is faster than
|
|
22630
|
+
* // conversions), you can specify the type directly (otherwise, it's
|
|
22631
|
+
* // interpreted from the numbers you pass in):
|
|
22632
|
+
* const i = ScInt(123456789n, { type: "u256" });
|
|
22633
|
+
*
|
|
22634
|
+
* // For example, you can use the underlying `sdk.U256` and convert it to an
|
|
22635
|
+
* // `xdr.ScVal` directly like so:
|
|
22636
|
+
* const scv = new xdr.ScVal.scvU256(i.raw);
|
|
22637
|
+
*
|
|
22638
|
+
* // Or reinterpret it as a different type (size permitting):
|
|
22639
|
+
* const scv = i.toI64();
|
|
22640
|
+
*
|
|
22641
|
+
* @param {number|bigint|string} value - a single, integer-like value which will
|
|
22642
|
+
* be interpreted in the smallest appropriate XDR type supported by Stellar
|
|
22643
|
+
* (64, 128, or 256 bit integer values). signed values are supported, though
|
|
22644
|
+
* they are sanity-checked against `opts.type`. if you need 32-bit values,
|
|
22645
|
+
* you can construct them directly without needing this wrapper, e.g.
|
|
22646
|
+
* `xdr.ScVal.scvU32(1234)`.
|
|
22647
|
+
*
|
|
22648
|
+
* @param {object} [opts] - an optional object controlling optional parameters
|
|
22649
|
+
* @param {string} [opts.type] - force a specific data type. the type choices
|
|
22650
|
+
* are: 'i64', 'u64', 'i128', 'u128', 'i256', and 'u256' (default: the
|
|
22651
|
+
* smallest one that fits the `value`)
|
|
22652
|
+
*
|
|
22653
|
+
* @throws {RangeError} if the `value` is invalid (e.g. floating point), too
|
|
22654
|
+
* large (i.e. exceeds a 256-bit value), or doesn't fit in the `opts.type`
|
|
22655
|
+
* @throws {TypeError} on missing parameters, or if the "signedness" of `opts`
|
|
22656
|
+
* doesn't match input `value`, e.g. passing `{type: 'u64'}` yet passing -1n
|
|
22657
|
+
* @throws {SyntaxError} if a string `value` can't be parsed as a big integer
|
|
22931
22658
|
*/
|
|
22932
|
-
var
|
|
22933
|
-
function
|
|
22934
|
-
|
|
22935
|
-
|
|
22936
|
-
|
|
22937
|
-
|
|
22938
|
-
|
|
22939
|
-
throw
|
|
22659
|
+
var ScInt = /*#__PURE__*/function (_XdrLargeInt) {
|
|
22660
|
+
function ScInt(value, opts) {
|
|
22661
|
+
var _opts$type;
|
|
22662
|
+
sc_int_classCallCheck(this, ScInt);
|
|
22663
|
+
var signed = value < 0;
|
|
22664
|
+
var type = (_opts$type = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type !== void 0 ? _opts$type : '';
|
|
22665
|
+
if (type.startsWith('u') && signed) {
|
|
22666
|
+
throw TypeError("specified type ".concat(opts.type, " yet negative (").concat(value, ")"));
|
|
22940
22667
|
}
|
|
22941
|
-
}
|
|
22942
22668
|
|
|
22943
|
-
|
|
22944
|
-
|
|
22945
|
-
|
|
22946
|
-
|
|
22947
|
-
|
|
22948
|
-
|
|
22949
|
-
|
|
22950
|
-
|
|
22951
|
-
|
|
22669
|
+
// If unspecified, we make a best guess at the type based on the bit length
|
|
22670
|
+
// of the value, treating 64 as a minimum and 256 as a maximum.
|
|
22671
|
+
if (type === '') {
|
|
22672
|
+
type = signed ? 'i' : 'u';
|
|
22673
|
+
var bitlen = nearestBigIntSize(value);
|
|
22674
|
+
switch (bitlen) {
|
|
22675
|
+
case 64:
|
|
22676
|
+
case 128:
|
|
22677
|
+
case 256:
|
|
22678
|
+
type += bitlen.toString();
|
|
22679
|
+
break;
|
|
22680
|
+
default:
|
|
22681
|
+
throw RangeError("expected 64/128/256 bits for input (".concat(value, "), got ").concat(bitlen));
|
|
22682
|
+
}
|
|
22952
22683
|
}
|
|
22684
|
+
return sc_int_callSuper(this, ScInt, [type, value]);
|
|
22685
|
+
}
|
|
22686
|
+
sc_int_inherits(ScInt, _XdrLargeInt);
|
|
22687
|
+
return sc_int_createClass(ScInt);
|
|
22688
|
+
}(XdrLargeInt);
|
|
22689
|
+
function nearestBigIntSize(bigI) {
|
|
22690
|
+
var _find;
|
|
22691
|
+
// Note: Even though BigInt.toString(2) includes the negative sign for
|
|
22692
|
+
// negative values (???), the following is still accurate, because the
|
|
22693
|
+
// negative sign would be represented by a sign bit.
|
|
22694
|
+
var bitlen = bigI.toString(2).length;
|
|
22695
|
+
return (_find = [64, 128, 256].find(function (len) {
|
|
22696
|
+
return bitlen <= len;
|
|
22697
|
+
})) !== null && _find !== void 0 ? _find : bitlen;
|
|
22698
|
+
}
|
|
22699
|
+
;// ./src/numbers/index.js
|
|
22953
22700
|
|
|
22954
|
-
/** @returns {string} the ID as a strkey (C...) */
|
|
22955
|
-
}, {
|
|
22956
|
-
key: "toString",
|
|
22957
|
-
value: function toString() {
|
|
22958
|
-
return this.contractId();
|
|
22959
|
-
}
|
|
22960
22701
|
|
|
22961
|
-
/** @returns {Address} the wrapped address of this contract */
|
|
22962
|
-
}, {
|
|
22963
|
-
key: "address",
|
|
22964
|
-
value: function address() {
|
|
22965
|
-
return Address.contract(this._id);
|
|
22966
|
-
}
|
|
22967
22702
|
|
|
22968
|
-
/**
|
|
22969
|
-
* Returns an operation that will invoke this contract call.
|
|
22970
|
-
*
|
|
22971
|
-
* @param {string} method name of the method to call
|
|
22972
|
-
* @param {...xdr.ScVal} params arguments to pass to the function call
|
|
22973
|
-
*
|
|
22974
|
-
* @returns {xdr.Operation} an InvokeHostFunctionOp operation to call the
|
|
22975
|
-
* contract with the given method and parameters
|
|
22976
|
-
*
|
|
22977
|
-
* @see Operation.invokeHostFunction
|
|
22978
|
-
* @see Operation.invokeContractFunction
|
|
22979
|
-
* @see Operation.createCustomContract
|
|
22980
|
-
* @see Operation.createStellarAssetContract
|
|
22981
|
-
* @see Operation.uploadContractWasm
|
|
22982
|
-
*/
|
|
22983
|
-
}, {
|
|
22984
|
-
key: "call",
|
|
22985
|
-
value: function call(method) {
|
|
22986
|
-
for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
22987
|
-
params[_key - 1] = arguments[_key];
|
|
22988
|
-
}
|
|
22989
|
-
return Operation.invokeContractFunction({
|
|
22990
|
-
contract: this.address().toString(),
|
|
22991
|
-
"function": method,
|
|
22992
|
-
args: params
|
|
22993
|
-
});
|
|
22994
|
-
}
|
|
22995
22703
|
|
|
22996
|
-
/**
|
|
22997
|
-
* Returns the read-only footprint entries necessary for any invocations to
|
|
22998
|
-
* this contract, for convenience when manually adding it to your
|
|
22999
|
-
* transaction's overall footprint or doing bump/restore operations.
|
|
23000
|
-
*
|
|
23001
|
-
* @returns {xdr.LedgerKey} the ledger key for the deployed contract instance
|
|
23002
|
-
*/
|
|
23003
|
-
}, {
|
|
23004
|
-
key: "getFootprint",
|
|
23005
|
-
value: function getFootprint() {
|
|
23006
|
-
return src_xdr.LedgerKey.contractData(new src_xdr.LedgerKeyContractData({
|
|
23007
|
-
contract: this.address().toScAddress(),
|
|
23008
|
-
key: src_xdr.ScVal.scvLedgerKeyContractInstance(),
|
|
23009
|
-
durability: src_xdr.ContractDataDurability.persistent()
|
|
23010
|
-
}));
|
|
23011
|
-
}
|
|
23012
|
-
}]);
|
|
23013
|
-
}();
|
|
23014
|
-
;// ./src/numbers/uint128.js
|
|
23015
|
-
function uint128_typeof(o) { "@babel/helpers - typeof"; return uint128_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, uint128_typeof(o); }
|
|
23016
|
-
function uint128_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
23017
|
-
function uint128_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, uint128_toPropertyKey(o.key), o); } }
|
|
23018
|
-
function uint128_createClass(e, r, t) { return r && uint128_defineProperties(e.prototype, r), t && uint128_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23019
|
-
function uint128_toPropertyKey(t) { var i = uint128_toPrimitive(t, "string"); return "symbol" == uint128_typeof(i) ? i : i + ""; }
|
|
23020
|
-
function uint128_toPrimitive(t, r) { if ("object" != uint128_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != uint128_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23021
|
-
function uint128_callSuper(t, o, e) { return o = uint128_getPrototypeOf(o), uint128_possibleConstructorReturn(t, uint128_isNativeReflectConstruct() ? Reflect.construct(o, e || [], uint128_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
23022
|
-
function uint128_possibleConstructorReturn(t, e) { if (e && ("object" == uint128_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return uint128_assertThisInitialized(t); }
|
|
23023
|
-
function uint128_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
23024
|
-
function uint128_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (uint128_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
23025
|
-
function uint128_getPrototypeOf(t) { return uint128_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, uint128_getPrototypeOf(t); }
|
|
23026
|
-
function uint128_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && uint128_setPrototypeOf(t, e); }
|
|
23027
|
-
function uint128_setPrototypeOf(t, e) { return uint128_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, uint128_setPrototypeOf(t, e); }
|
|
23028
22704
|
|
|
23029
|
-
var Uint128 = /*#__PURE__*/function (_LargeInt) {
|
|
23030
|
-
/**
|
|
23031
|
-
* Construct an unsigned 128-bit integer that can be XDR-encoded.
|
|
23032
|
-
*
|
|
23033
|
-
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
23034
|
-
* in big-endian format (i.e. earlier elements are higher bits)
|
|
23035
|
-
*/
|
|
23036
|
-
function Uint128() {
|
|
23037
|
-
uint128_classCallCheck(this, Uint128);
|
|
23038
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
23039
|
-
args[_key] = arguments[_key];
|
|
23040
|
-
}
|
|
23041
|
-
return uint128_callSuper(this, Uint128, [args]);
|
|
23042
|
-
}
|
|
23043
|
-
uint128_inherits(Uint128, _LargeInt);
|
|
23044
|
-
return uint128_createClass(Uint128, [{
|
|
23045
|
-
key: "unsigned",
|
|
23046
|
-
get: function get() {
|
|
23047
|
-
return true;
|
|
23048
|
-
}
|
|
23049
|
-
}, {
|
|
23050
|
-
key: "size",
|
|
23051
|
-
get: function get() {
|
|
23052
|
-
return 128;
|
|
23053
|
-
}
|
|
23054
|
-
}]);
|
|
23055
|
-
}(xdr.LargeInt);
|
|
23056
|
-
Uint128.defineIntBoundaries();
|
|
23057
|
-
;// ./src/numbers/uint256.js
|
|
23058
|
-
function uint256_typeof(o) { "@babel/helpers - typeof"; return uint256_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, uint256_typeof(o); }
|
|
23059
|
-
function uint256_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
23060
|
-
function uint256_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, uint256_toPropertyKey(o.key), o); } }
|
|
23061
|
-
function uint256_createClass(e, r, t) { return r && uint256_defineProperties(e.prototype, r), t && uint256_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23062
|
-
function uint256_toPropertyKey(t) { var i = uint256_toPrimitive(t, "string"); return "symbol" == uint256_typeof(i) ? i : i + ""; }
|
|
23063
|
-
function uint256_toPrimitive(t, r) { if ("object" != uint256_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != uint256_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23064
|
-
function uint256_callSuper(t, o, e) { return o = uint256_getPrototypeOf(o), uint256_possibleConstructorReturn(t, uint256_isNativeReflectConstruct() ? Reflect.construct(o, e || [], uint256_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
23065
|
-
function uint256_possibleConstructorReturn(t, e) { if (e && ("object" == uint256_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return uint256_assertThisInitialized(t); }
|
|
23066
|
-
function uint256_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
23067
|
-
function uint256_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (uint256_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
23068
|
-
function uint256_getPrototypeOf(t) { return uint256_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, uint256_getPrototypeOf(t); }
|
|
23069
|
-
function uint256_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && uint256_setPrototypeOf(t, e); }
|
|
23070
|
-
function uint256_setPrototypeOf(t, e) { return uint256_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, uint256_setPrototypeOf(t, e); }
|
|
23071
22705
|
|
|
23072
|
-
var Uint256 = /*#__PURE__*/function (_LargeInt) {
|
|
23073
|
-
/**
|
|
23074
|
-
* Construct an unsigned 256-bit integer that can be XDR-encoded.
|
|
23075
|
-
*
|
|
23076
|
-
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
23077
|
-
* in big-endian format (i.e. earlier elements are higher bits)
|
|
23078
|
-
*/
|
|
23079
|
-
function Uint256() {
|
|
23080
|
-
uint256_classCallCheck(this, Uint256);
|
|
23081
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
23082
|
-
args[_key] = arguments[_key];
|
|
23083
|
-
}
|
|
23084
|
-
return uint256_callSuper(this, Uint256, [args]);
|
|
23085
|
-
}
|
|
23086
|
-
uint256_inherits(Uint256, _LargeInt);
|
|
23087
|
-
return uint256_createClass(Uint256, [{
|
|
23088
|
-
key: "unsigned",
|
|
23089
|
-
get: function get() {
|
|
23090
|
-
return true;
|
|
23091
|
-
}
|
|
23092
|
-
}, {
|
|
23093
|
-
key: "size",
|
|
23094
|
-
get: function get() {
|
|
23095
|
-
return 256;
|
|
23096
|
-
}
|
|
23097
|
-
}]);
|
|
23098
|
-
}(xdr.LargeInt);
|
|
23099
|
-
Uint256.defineIntBoundaries();
|
|
23100
|
-
;// ./src/numbers/int128.js
|
|
23101
|
-
function int128_typeof(o) { "@babel/helpers - typeof"; return int128_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, int128_typeof(o); }
|
|
23102
|
-
function int128_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
23103
|
-
function int128_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, int128_toPropertyKey(o.key), o); } }
|
|
23104
|
-
function int128_createClass(e, r, t) { return r && int128_defineProperties(e.prototype, r), t && int128_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23105
|
-
function int128_toPropertyKey(t) { var i = int128_toPrimitive(t, "string"); return "symbol" == int128_typeof(i) ? i : i + ""; }
|
|
23106
|
-
function int128_toPrimitive(t, r) { if ("object" != int128_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != int128_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23107
|
-
function int128_callSuper(t, o, e) { return o = int128_getPrototypeOf(o), int128_possibleConstructorReturn(t, int128_isNativeReflectConstruct() ? Reflect.construct(o, e || [], int128_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
23108
|
-
function int128_possibleConstructorReturn(t, e) { if (e && ("object" == int128_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return int128_assertThisInitialized(t); }
|
|
23109
|
-
function int128_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
23110
|
-
function int128_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (int128_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
23111
|
-
function int128_getPrototypeOf(t) { return int128_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, int128_getPrototypeOf(t); }
|
|
23112
|
-
function int128_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && int128_setPrototypeOf(t, e); }
|
|
23113
|
-
function int128_setPrototypeOf(t, e) { return int128_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, int128_setPrototypeOf(t, e); }
|
|
23114
22706
|
|
|
23115
|
-
var Int128 = /*#__PURE__*/function (_LargeInt) {
|
|
23116
|
-
/**
|
|
23117
|
-
* Construct a signed 128-bit integer that can be XDR-encoded.
|
|
23118
|
-
*
|
|
23119
|
-
* @param {Array<number|bigint|string>} args - one or more slices to encode
|
|
23120
|
-
* in big-endian format (i.e. earlier elements are higher bits)
|
|
23121
|
-
*/
|
|
23122
|
-
function Int128() {
|
|
23123
|
-
int128_classCallCheck(this, Int128);
|
|
23124
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
23125
|
-
args[_key] = arguments[_key];
|
|
23126
|
-
}
|
|
23127
|
-
return int128_callSuper(this, Int128, [args]);
|
|
23128
|
-
}
|
|
23129
|
-
int128_inherits(Int128, _LargeInt);
|
|
23130
|
-
return int128_createClass(Int128, [{
|
|
23131
|
-
key: "unsigned",
|
|
23132
|
-
get: function get() {
|
|
23133
|
-
return false;
|
|
23134
|
-
}
|
|
23135
|
-
}, {
|
|
23136
|
-
key: "size",
|
|
23137
|
-
get: function get() {
|
|
23138
|
-
return 128;
|
|
23139
|
-
}
|
|
23140
|
-
}]);
|
|
23141
|
-
}(xdr.LargeInt);
|
|
23142
|
-
Int128.defineIntBoundaries();
|
|
23143
|
-
;// ./src/numbers/int256.js
|
|
23144
|
-
function int256_typeof(o) { "@babel/helpers - typeof"; return int256_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, int256_typeof(o); }
|
|
23145
|
-
function int256_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
23146
|
-
function int256_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, int256_toPropertyKey(o.key), o); } }
|
|
23147
|
-
function int256_createClass(e, r, t) { return r && int256_defineProperties(e.prototype, r), t && int256_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23148
|
-
function int256_toPropertyKey(t) { var i = int256_toPrimitive(t, "string"); return "symbol" == int256_typeof(i) ? i : i + ""; }
|
|
23149
|
-
function int256_toPrimitive(t, r) { if ("object" != int256_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != int256_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23150
|
-
function int256_callSuper(t, o, e) { return o = int256_getPrototypeOf(o), int256_possibleConstructorReturn(t, int256_isNativeReflectConstruct() ? Reflect.construct(o, e || [], int256_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
23151
|
-
function int256_possibleConstructorReturn(t, e) { if (e && ("object" == int256_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return int256_assertThisInitialized(t); }
|
|
23152
|
-
function int256_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
23153
|
-
function int256_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (int256_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
23154
|
-
function int256_getPrototypeOf(t) { return int256_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, int256_getPrototypeOf(t); }
|
|
23155
|
-
function int256_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && int256_setPrototypeOf(t, e); }
|
|
23156
|
-
function int256_setPrototypeOf(t, e) { return int256_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, int256_setPrototypeOf(t, e); }
|
|
23157
22707
|
|
|
23158
|
-
|
|
23159
|
-
|
|
23160
|
-
|
|
23161
|
-
|
|
23162
|
-
|
|
23163
|
-
|
|
23164
|
-
|
|
23165
|
-
|
|
23166
|
-
|
|
23167
|
-
|
|
23168
|
-
|
|
23169
|
-
|
|
23170
|
-
|
|
22708
|
+
/**
|
|
22709
|
+
* Transforms an opaque {@link xdr.ScVal} into a native bigint, if possible.
|
|
22710
|
+
*
|
|
22711
|
+
* If you then want to use this in the abstractions provided by this module,
|
|
22712
|
+
* you can pass it to the constructor of {@link XdrLargeInt}.
|
|
22713
|
+
*
|
|
22714
|
+
* @example
|
|
22715
|
+
* let scv = contract.call("add", x, y); // assume it returns an xdr.ScVal
|
|
22716
|
+
* let bigi = scValToBigInt(scv);
|
|
22717
|
+
*
|
|
22718
|
+
* new ScInt(bigi); // if you don't care about types, and
|
|
22719
|
+
* new XdrLargeInt('i128', bigi); // if you do
|
|
22720
|
+
*
|
|
22721
|
+
* @param {xdr.ScVal} scv - the raw XDR value to parse into an integer
|
|
22722
|
+
* @returns {bigint} the native value of this input value
|
|
22723
|
+
*
|
|
22724
|
+
* @throws {TypeError} if the `scv` input value doesn't represent an integer
|
|
22725
|
+
*/
|
|
22726
|
+
function scValToBigInt(scv) {
|
|
22727
|
+
var scIntType = XdrLargeInt.getType(scv["switch"]().name);
|
|
22728
|
+
switch (scv["switch"]().name) {
|
|
22729
|
+
case 'scvU32':
|
|
22730
|
+
case 'scvI32':
|
|
22731
|
+
return BigInt(scv.value());
|
|
22732
|
+
case 'scvU64':
|
|
22733
|
+
case 'scvI64':
|
|
22734
|
+
case 'scvTimepoint':
|
|
22735
|
+
case 'scvDuration':
|
|
22736
|
+
return new XdrLargeInt(scIntType, scv.value()).toBigInt();
|
|
22737
|
+
case 'scvU128':
|
|
22738
|
+
case 'scvI128':
|
|
22739
|
+
return new XdrLargeInt(scIntType, [scv.value().lo(), scv.value().hi()]).toBigInt();
|
|
22740
|
+
case 'scvU256':
|
|
22741
|
+
case 'scvI256':
|
|
22742
|
+
return new XdrLargeInt(scIntType, [scv.value().loLo(), scv.value().loHi(), scv.value().hiLo(), scv.value().hiHi()]).toBigInt();
|
|
22743
|
+
default:
|
|
22744
|
+
throw TypeError("expected integer type, got ".concat(scv["switch"]()));
|
|
23171
22745
|
}
|
|
23172
|
-
|
|
23173
|
-
|
|
23174
|
-
|
|
23175
|
-
|
|
23176
|
-
|
|
23177
|
-
|
|
23178
|
-
|
|
23179
|
-
|
|
23180
|
-
|
|
23181
|
-
|
|
23182
|
-
|
|
23183
|
-
|
|
23184
|
-
|
|
23185
|
-
|
|
23186
|
-
|
|
23187
|
-
function xdr_large_int_typeof(o) { "@babel/helpers - typeof"; return xdr_large_int_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, xdr_large_int_typeof(o); }
|
|
23188
|
-
function xdr_large_int_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
23189
|
-
function xdr_large_int_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, xdr_large_int_toPropertyKey(o.key), o); } }
|
|
23190
|
-
function xdr_large_int_createClass(e, r, t) { return r && xdr_large_int_defineProperties(e.prototype, r), t && xdr_large_int_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23191
|
-
function xdr_large_int_defineProperty(e, r, t) { return (r = xdr_large_int_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
23192
|
-
function xdr_large_int_toPropertyKey(t) { var i = xdr_large_int_toPrimitive(t, "string"); return "symbol" == xdr_large_int_typeof(i) ? i : i + ""; }
|
|
23193
|
-
function xdr_large_int_toPrimitive(t, r) { if ("object" != xdr_large_int_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != xdr_large_int_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23194
|
-
/* eslint no-bitwise: ["error", {"allow": [">>"]}] */
|
|
23195
|
-
|
|
22746
|
+
}
|
|
22747
|
+
;// ./src/scval.js
|
|
22748
|
+
/* provided dependency */ var scval_Buffer = __webpack_require__(8287)["Buffer"];
|
|
22749
|
+
function scval_slicedToArray(r, e) { return scval_arrayWithHoles(r) || scval_iterableToArrayLimit(r, e) || scval_unsupportedIterableToArray(r, e) || scval_nonIterableRest(); }
|
|
22750
|
+
function scval_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
22751
|
+
function scval_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return scval_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? scval_arrayLikeToArray(r, a) : void 0; } }
|
|
22752
|
+
function scval_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
22753
|
+
function scval_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
22754
|
+
function scval_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
22755
|
+
function scval_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22756
|
+
function scval_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? scval_ownKeys(Object(t), !0).forEach(function (r) { scval_defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : scval_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22757
|
+
function scval_defineProperty(e, r, t) { return (r = scval_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
22758
|
+
function scval_toPropertyKey(t) { var i = scval_toPrimitive(t, "string"); return "symbol" == scval_typeof(i) ? i : i + ""; }
|
|
22759
|
+
function scval_toPrimitive(t, r) { if ("object" != scval_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != scval_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
22760
|
+
function scval_typeof(o) { "@babel/helpers - typeof"; return scval_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, scval_typeof(o); }
|
|
23196
22761
|
|
|
23197
22762
|
|
|
23198
22763
|
|
|
@@ -23200,879 +22765,1473 @@ function xdr_large_int_toPrimitive(t, r) { if ("object" != xdr_large_int_typeof(
|
|
|
23200
22765
|
|
|
23201
22766
|
|
|
23202
22767
|
/**
|
|
23203
|
-
*
|
|
22768
|
+
* Attempts to convert native types into smart contract values
|
|
22769
|
+
* ({@link xdr.ScVal}).
|
|
23204
22770
|
*
|
|
23205
|
-
*
|
|
23206
|
-
*
|
|
23207
|
-
* of the input value(s) you provide.
|
|
22771
|
+
* Provides conversions from smart contract XDR values ({@link xdr.ScVal}) to
|
|
22772
|
+
* native JavaScript types.
|
|
23208
22773
|
*
|
|
23209
|
-
*
|
|
23210
|
-
*
|
|
23211
|
-
*
|
|
23212
|
-
*
|
|
23213
|
-
*
|
|
23214
|
-
|
|
23215
|
-
|
|
23216
|
-
|
|
23217
|
-
|
|
23218
|
-
|
|
23219
|
-
|
|
23220
|
-
|
|
23221
|
-
|
|
23222
|
-
|
|
23223
|
-
|
|
23224
|
-
|
|
23225
|
-
|
|
23226
|
-
|
|
23227
|
-
|
|
23228
|
-
|
|
23229
|
-
|
|
23230
|
-
|
|
23231
|
-
|
|
23232
|
-
|
|
23233
|
-
|
|
23234
|
-
|
|
23235
|
-
|
|
23236
|
-
|
|
23237
|
-
|
|
23238
|
-
|
|
23239
|
-
|
|
23240
|
-
|
|
23241
|
-
|
|
23242
|
-
|
|
23243
|
-
|
|
23244
|
-
|
|
23245
|
-
|
|
23246
|
-
|
|
23247
|
-
|
|
23248
|
-
|
|
23249
|
-
|
|
23250
|
-
|
|
23251
|
-
|
|
23252
|
-
|
|
23253
|
-
|
|
23254
|
-
|
|
23255
|
-
|
|
23256
|
-
|
|
23257
|
-
|
|
23258
|
-
|
|
23259
|
-
|
|
23260
|
-
|
|
22774
|
+
* The conversions are as follows:
|
|
22775
|
+
*
|
|
22776
|
+
* - xdr.ScVal -> passthrough
|
|
22777
|
+
* - null/undefined -> scvVoid
|
|
22778
|
+
* - string -> scvString (a copy is made)
|
|
22779
|
+
* - UintArray8 -> scvBytes (a copy is made)
|
|
22780
|
+
* - boolean -> scvBool
|
|
22781
|
+
*
|
|
22782
|
+
* - number/bigint -> the smallest possible XDR integer type that will fit the
|
|
22783
|
+
* input value (if you want a specific type, use {@link ScInt})
|
|
22784
|
+
*
|
|
22785
|
+
* - {@link Address} or {@link Contract} -> scvAddress (for contracts and
|
|
22786
|
+
* public keys)
|
|
22787
|
+
*
|
|
22788
|
+
* - Array<T> -> scvVec after attempting to convert each item of type `T` to an
|
|
22789
|
+
* xdr.ScVal (recursively). note that all values must be the same type!
|
|
22790
|
+
*
|
|
22791
|
+
* - object -> scvMap after attempting to convert each key and value to an
|
|
22792
|
+
* xdr.ScVal (recursively). note that there is no restriction on types
|
|
22793
|
+
* matching anywhere (unlike arrays)
|
|
22794
|
+
*
|
|
22795
|
+
* When passing an integer-like native value, you can also optionally specify a
|
|
22796
|
+
* type which will force a particular interpretation of that value.
|
|
22797
|
+
*
|
|
22798
|
+
* Note that not all type specifications are compatible with all `ScVal`s, e.g.
|
|
22799
|
+
* `toScVal("a string", {type: "i256"})` will throw.
|
|
22800
|
+
*
|
|
22801
|
+
* @param {any} val - a native (or convertible) input value to wrap
|
|
22802
|
+
* @param {object} [opts] - an optional set of hints around the type of
|
|
22803
|
+
* conversion you'd like to see
|
|
22804
|
+
* @param {string} [opts.type] - there is different behavior for different input
|
|
22805
|
+
* types for `val`:
|
|
22806
|
+
*
|
|
22807
|
+
* - when `val` is an integer-like type (i.e. number|bigint), this will be
|
|
22808
|
+
* forwarded to {@link ScInt} or forced to be u32/i32.
|
|
22809
|
+
*
|
|
22810
|
+
* - when `val` is an array type, this is forwarded to the recursion
|
|
22811
|
+
*
|
|
22812
|
+
* - when `val` is an object type (key-value entries), this should be an
|
|
22813
|
+
* object in which each key has a pair of types (to represent forced types
|
|
22814
|
+
* for the key and the value), where `null` (or a missing entry) indicates
|
|
22815
|
+
* the default interpretation(s) (refer to the examples, below)
|
|
22816
|
+
*
|
|
22817
|
+
* - when `val` is a string type, this can be 'string' or 'symbol' to force
|
|
22818
|
+
* a particular interpretation of `val`.
|
|
22819
|
+
*
|
|
22820
|
+
* - when `val` is a bytes-like type, this can be 'string', 'symbol', or
|
|
22821
|
+
* 'bytes' to force a particular interpretation
|
|
22822
|
+
*
|
|
22823
|
+
* As a simple example, `nativeToScVal("hello", {type: 'symbol'})` will
|
|
22824
|
+
* return an `scvSymbol`, whereas without the type it would have been an
|
|
22825
|
+
* `scvString`.
|
|
22826
|
+
*
|
|
22827
|
+
* @returns {xdr.ScVal} a wrapped, smart, XDR version of the input value
|
|
22828
|
+
* @throws {TypeError} if...
|
|
22829
|
+
* - there are arrays with more than one type in them
|
|
22830
|
+
* - there are values that do not have a sensible conversion (e.g. random XDR
|
|
22831
|
+
* types, custom classes)
|
|
22832
|
+
* - the type of the input object (or some inner value of said object) cannot
|
|
22833
|
+
* be determined (via `typeof`)
|
|
22834
|
+
* - the type you specified (via `opts.type`) is incompatible with the value
|
|
22835
|
+
* you passed in (`val`), e.g. `nativeToScVal("a string", { type: 'i128' })`,
|
|
22836
|
+
* though this does not apply for types that ignore `opts` (e.g. addresses).
|
|
22837
|
+
* @see scValToNative
|
|
22838
|
+
*
|
|
22839
|
+
* @example
|
|
22840
|
+
* nativeToScVal(1000); // gives ScValType === scvU64
|
|
22841
|
+
* nativeToScVal(1000n); // gives ScValType === scvU64
|
|
22842
|
+
* nativeToScVal(1n << 100n); // gives ScValType === scvU128
|
|
22843
|
+
* nativeToScVal(1000, { type: 'u32' }); // gives ScValType === scvU32
|
|
22844
|
+
* nativeToScVal(1000, { type: 'i125' }); // gives ScValType === scvI256
|
|
22845
|
+
* nativeToScVal("a string"); // gives ScValType === scvString
|
|
22846
|
+
* nativeToScVal("a string", { type: 'symbol' }); // gives scvSymbol
|
|
22847
|
+
* nativeToScVal(new Uint8Array(5)); // scvBytes
|
|
22848
|
+
* nativeToScVal(new Uint8Array(5), { type: 'symbol' }); // scvSymbol
|
|
22849
|
+
* nativeToScVal(null); // scvVoid
|
|
22850
|
+
* nativeToScVal(true); // scvBool
|
|
22851
|
+
* nativeToScVal([1, 2, 3]); // gives scvVec with each element as scvU64
|
|
22852
|
+
* nativeToScVal([1, 2, 3], { type: 'i128' }); // scvVec<scvI128>
|
|
22853
|
+
* nativeToScVal([1, '2'], { type: ['i128', 'symbol'] }); // scvVec with diff types
|
|
22854
|
+
* nativeToScVal([1, '2', 3], { type: ['i128', 'symbol'] });
|
|
22855
|
+
* // scvVec with diff types, using the default when omitted
|
|
22856
|
+
* nativeToScVal({ 'hello': 1, 'world': [ true, false ] }, {
|
|
22857
|
+
* type: {
|
|
22858
|
+
* 'hello': [ 'symbol', 'i128' ],
|
|
22859
|
+
* }
|
|
22860
|
+
* })
|
|
22861
|
+
* // gives scvMap with entries: [
|
|
22862
|
+
* // [ scvSymbol, scvI128 ],
|
|
22863
|
+
* // [ scvString, scvArray<scvBool> ]
|
|
22864
|
+
* // ]
|
|
22865
|
+
*
|
|
22866
|
+
* @example
|
|
22867
|
+
* import {
|
|
22868
|
+
* nativeToScVal,
|
|
22869
|
+
* scValToNative,
|
|
22870
|
+
* ScInt,
|
|
22871
|
+
* xdr
|
|
22872
|
+
* } from '@stellar/stellar-base';
|
|
22873
|
+
*
|
|
22874
|
+
* let gigaMap = {
|
|
22875
|
+
* bool: true,
|
|
22876
|
+
* void: null,
|
|
22877
|
+
* u32: xdr.ScVal.scvU32(1),
|
|
22878
|
+
* i32: xdr.ScVal.scvI32(1),
|
|
22879
|
+
* u64: 1n,
|
|
22880
|
+
* i64: -1n,
|
|
22881
|
+
* u128: new ScInt(1).toU128(),
|
|
22882
|
+
* i128: new ScInt(1).toI128(),
|
|
22883
|
+
* u256: new ScInt(1).toU256(),
|
|
22884
|
+
* i256: new ScInt(1).toI256(),
|
|
22885
|
+
* map: {
|
|
22886
|
+
* arbitrary: 1n,
|
|
22887
|
+
* nested: 'values',
|
|
22888
|
+
* etc: false
|
|
22889
|
+
* },
|
|
22890
|
+
* vec: ['same', 'type', 'list'],
|
|
22891
|
+
* vec: ['diff', 1, 'type', 2, 'list'],
|
|
22892
|
+
* };
|
|
22893
|
+
*
|
|
22894
|
+
* // then, simply:
|
|
22895
|
+
* let scv = nativeToScVal(gigaMap); // scv.switch() == xdr.ScValType.scvMap()
|
|
22896
|
+
*
|
|
22897
|
+
* // then...
|
|
22898
|
+
* someContract.call("method", scv);
|
|
22899
|
+
*
|
|
22900
|
+
* // Similarly, the inverse should work:
|
|
22901
|
+
* scValToNative(scv) == gigaMap; // true
|
|
22902
|
+
*/
|
|
22903
|
+
function nativeToScVal(val) {
|
|
22904
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22905
|
+
switch (scval_typeof(val)) {
|
|
22906
|
+
case 'object':
|
|
22907
|
+
{
|
|
22908
|
+
var _val$constructor$name, _val$constructor;
|
|
22909
|
+
if (val === null) {
|
|
22910
|
+
return src_xdr.ScVal.scvVoid();
|
|
22911
|
+
}
|
|
22912
|
+
if (val instanceof src_xdr.ScVal) {
|
|
22913
|
+
return val; // should we copy?
|
|
22914
|
+
}
|
|
22915
|
+
if (val instanceof Address) {
|
|
22916
|
+
return val.toScVal();
|
|
22917
|
+
}
|
|
22918
|
+
if (val instanceof Keypair) {
|
|
22919
|
+
return nativeToScVal(val.publicKey(), {
|
|
22920
|
+
type: 'address'
|
|
22921
|
+
});
|
|
22922
|
+
}
|
|
22923
|
+
if (val instanceof Contract) {
|
|
22924
|
+
return val.address().toScVal();
|
|
22925
|
+
}
|
|
22926
|
+
if (val instanceof Uint8Array || scval_Buffer.isBuffer(val)) {
|
|
22927
|
+
var _opts$type;
|
|
22928
|
+
var copy = Uint8Array.from(val);
|
|
22929
|
+
switch ((_opts$type = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type !== void 0 ? _opts$type : 'bytes') {
|
|
22930
|
+
case 'bytes':
|
|
22931
|
+
return src_xdr.ScVal.scvBytes(copy);
|
|
22932
|
+
case 'symbol':
|
|
22933
|
+
return src_xdr.ScVal.scvSymbol(copy);
|
|
22934
|
+
case 'string':
|
|
22935
|
+
return src_xdr.ScVal.scvString(copy);
|
|
22936
|
+
default:
|
|
22937
|
+
throw new TypeError("invalid type (".concat(opts.type, ") specified for bytes-like value"));
|
|
22938
|
+
}
|
|
22939
|
+
}
|
|
22940
|
+
if (Array.isArray(val)) {
|
|
22941
|
+
return src_xdr.ScVal.scvVec(val.map(function (v, idx) {
|
|
22942
|
+
// There may be different type specifications for each element in
|
|
22943
|
+
// the array, so we need to apply those accordingly.
|
|
22944
|
+
if (Array.isArray(opts.type)) {
|
|
22945
|
+
return nativeToScVal(v, // only include a `{ type: ... }` if it's present (safer than
|
|
22946
|
+
// `{type: undefined}`)
|
|
22947
|
+
scval_objectSpread({}, opts.type.length > idx && {
|
|
22948
|
+
type: opts.type[idx]
|
|
22949
|
+
}));
|
|
22950
|
+
}
|
|
22951
|
+
|
|
22952
|
+
// Otherwise apply a generic (or missing) type specifier on it.
|
|
22953
|
+
return nativeToScVal(v, opts);
|
|
22954
|
+
}));
|
|
22955
|
+
}
|
|
22956
|
+
if (((_val$constructor$name = (_val$constructor = val.constructor) === null || _val$constructor === void 0 ? void 0 : _val$constructor.name) !== null && _val$constructor$name !== void 0 ? _val$constructor$name : '') !== 'Object') {
|
|
22957
|
+
var _val$constructor2;
|
|
22958
|
+
throw new TypeError("cannot interpret ".concat((_val$constructor2 = val.constructor) === null || _val$constructor2 === void 0 ? void 0 : _val$constructor2.name, " value as ScVal (").concat(JSON.stringify(val), ")"));
|
|
22959
|
+
}
|
|
22960
|
+
return src_xdr.ScVal.scvMap(Object.entries(val)
|
|
22961
|
+
// The Soroban runtime expects maps to have their keys in sorted
|
|
22962
|
+
// order, so let's do that here as part of the conversion to prevent
|
|
22963
|
+
// confusing error messages on execution.
|
|
22964
|
+
.sort(function (_ref, _ref2) {
|
|
22965
|
+
var _ref3 = scval_slicedToArray(_ref, 1),
|
|
22966
|
+
key1 = _ref3[0];
|
|
22967
|
+
var _ref4 = scval_slicedToArray(_ref2, 1),
|
|
22968
|
+
key2 = _ref4[0];
|
|
22969
|
+
return key1.localeCompare(key2);
|
|
22970
|
+
}).map(function (_ref5) {
|
|
22971
|
+
var _k, _opts$type2;
|
|
22972
|
+
var _ref6 = scval_slicedToArray(_ref5, 2),
|
|
22973
|
+
k = _ref6[0],
|
|
22974
|
+
v = _ref6[1];
|
|
22975
|
+
// the type can be specified with an entry for the key and the value,
|
|
22976
|
+
// e.g. val = { 'hello': 1 } and opts.type = { hello: [ 'symbol',
|
|
22977
|
+
// 'u128' ]} or you can use `null` for the default interpretation
|
|
22978
|
+
var _ref7 = (_k = ((_opts$type2 = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type2 !== void 0 ? _opts$type2 : {})[k]) !== null && _k !== void 0 ? _k : [null, null],
|
|
22979
|
+
_ref8 = scval_slicedToArray(_ref7, 2),
|
|
22980
|
+
keyType = _ref8[0],
|
|
22981
|
+
valType = _ref8[1];
|
|
22982
|
+
var keyOpts = keyType ? {
|
|
22983
|
+
type: keyType
|
|
22984
|
+
} : {};
|
|
22985
|
+
var valOpts = valType ? {
|
|
22986
|
+
type: valType
|
|
22987
|
+
} : {};
|
|
22988
|
+
return new src_xdr.ScMapEntry({
|
|
22989
|
+
key: nativeToScVal(k, keyOpts),
|
|
22990
|
+
val: nativeToScVal(v, valOpts)
|
|
22991
|
+
});
|
|
22992
|
+
}));
|
|
22993
|
+
}
|
|
22994
|
+
case 'number':
|
|
22995
|
+
case 'bigint':
|
|
22996
|
+
switch (opts === null || opts === void 0 ? void 0 : opts.type) {
|
|
22997
|
+
case 'u32':
|
|
22998
|
+
return src_xdr.ScVal.scvU32(val);
|
|
22999
|
+
case 'i32':
|
|
23000
|
+
return src_xdr.ScVal.scvI32(val);
|
|
23001
|
+
default:
|
|
23002
|
+
break;
|
|
23003
|
+
}
|
|
23004
|
+
return new ScInt(val, {
|
|
23005
|
+
type: opts === null || opts === void 0 ? void 0 : opts.type
|
|
23006
|
+
}).toScVal();
|
|
23007
|
+
case 'string':
|
|
23008
|
+
{
|
|
23009
|
+
var _opts$type3;
|
|
23010
|
+
var optType = (_opts$type3 = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type3 !== void 0 ? _opts$type3 : 'string';
|
|
23011
|
+
switch (optType) {
|
|
23012
|
+
case 'string':
|
|
23013
|
+
return src_xdr.ScVal.scvString(val);
|
|
23014
|
+
case 'symbol':
|
|
23015
|
+
return src_xdr.ScVal.scvSymbol(val);
|
|
23016
|
+
case 'address':
|
|
23017
|
+
return new Address(val).toScVal();
|
|
23018
|
+
case 'u32':
|
|
23019
|
+
return src_xdr.ScVal.scvU32(parseInt(val, 10));
|
|
23020
|
+
case 'i32':
|
|
23021
|
+
return src_xdr.ScVal.scvI32(parseInt(val, 10));
|
|
23022
|
+
default:
|
|
23023
|
+
if (XdrLargeInt.isType(optType)) {
|
|
23024
|
+
return new XdrLargeInt(optType, val).toScVal();
|
|
23025
|
+
}
|
|
23026
|
+
throw new TypeError("invalid type (".concat(opts.type, ") specified for string value"));
|
|
23027
|
+
}
|
|
23028
|
+
}
|
|
23029
|
+
case 'boolean':
|
|
23030
|
+
return src_xdr.ScVal.scvBool(val);
|
|
23031
|
+
case 'undefined':
|
|
23032
|
+
return src_xdr.ScVal.scvVoid();
|
|
23033
|
+
case 'function':
|
|
23034
|
+
// FIXME: Is this too helpful?
|
|
23035
|
+
return nativeToScVal(val());
|
|
23036
|
+
default:
|
|
23037
|
+
throw new TypeError("failed to convert typeof ".concat(scval_typeof(val), " (").concat(val, ")"));
|
|
23038
|
+
}
|
|
23039
|
+
}
|
|
23040
|
+
|
|
23041
|
+
/**
|
|
23042
|
+
* Given a smart contract value, attempt to convert it to a native type.
|
|
23043
|
+
* Possible conversions include:
|
|
23044
|
+
*
|
|
23045
|
+
* - void -> `null`
|
|
23046
|
+
* - u32, i32 -> `number`
|
|
23047
|
+
* - u64, i64, u128, i128, u256, i256, timepoint, duration -> `bigint`
|
|
23048
|
+
* - vec -> `Array` of any of the above (via recursion)
|
|
23049
|
+
* - map -> key-value object of any of the above (via recursion)
|
|
23050
|
+
* - bool -> `boolean`
|
|
23051
|
+
* - bytes -> `Uint8Array`
|
|
23052
|
+
* - symbol -> `string`
|
|
23053
|
+
* - string -> `string` IF the underlying buffer can be decoded as ascii/utf8,
|
|
23054
|
+
* `Uint8Array` of the raw contents in any error case
|
|
23055
|
+
*
|
|
23056
|
+
* If no viable conversion can be determined, this just "unwraps" the smart
|
|
23057
|
+
* value to return its underlying XDR value.
|
|
23058
|
+
*
|
|
23059
|
+
* @param {xdr.ScVal} scv - the input smart contract value
|
|
23060
|
+
*
|
|
23061
|
+
* @returns {any}
|
|
23062
|
+
* @see nativeToScVal
|
|
23063
|
+
*/
|
|
23064
|
+
function scValToNative(scv) {
|
|
23065
|
+
var _scv$vec, _scv$map;
|
|
23066
|
+
// we use the verbose xdr.ScValType.<type>.value form here because it's faster
|
|
23067
|
+
// than string comparisons and the underlying constants never need to be
|
|
23068
|
+
// updated
|
|
23069
|
+
switch (scv["switch"]().value) {
|
|
23070
|
+
case src_xdr.ScValType.scvVoid().value:
|
|
23071
|
+
return null;
|
|
23072
|
+
|
|
23073
|
+
// these can be converted to bigints directly
|
|
23074
|
+
case src_xdr.ScValType.scvU64().value:
|
|
23075
|
+
case src_xdr.ScValType.scvI64().value:
|
|
23076
|
+
return scv.value().toBigInt();
|
|
23077
|
+
|
|
23078
|
+
// these can be parsed by internal abstractions note that this can also
|
|
23079
|
+
// handle the above two cases, but it's not as efficient (another
|
|
23080
|
+
// type-check, parsing, etc.)
|
|
23081
|
+
case src_xdr.ScValType.scvU128().value:
|
|
23082
|
+
case src_xdr.ScValType.scvI128().value:
|
|
23083
|
+
case src_xdr.ScValType.scvU256().value:
|
|
23084
|
+
case src_xdr.ScValType.scvI256().value:
|
|
23085
|
+
return scValToBigInt(scv);
|
|
23086
|
+
case src_xdr.ScValType.scvVec().value:
|
|
23087
|
+
return ((_scv$vec = scv.vec()) !== null && _scv$vec !== void 0 ? _scv$vec : []).map(scValToNative);
|
|
23088
|
+
case src_xdr.ScValType.scvAddress().value:
|
|
23089
|
+
return Address.fromScVal(scv).toString();
|
|
23090
|
+
case src_xdr.ScValType.scvMap().value:
|
|
23091
|
+
return Object.fromEntries(((_scv$map = scv.map()) !== null && _scv$map !== void 0 ? _scv$map : []).map(function (entry) {
|
|
23092
|
+
return [scValToNative(entry.key()), scValToNative(entry.val())];
|
|
23093
|
+
}));
|
|
23094
|
+
|
|
23095
|
+
// these return the primitive type directly
|
|
23096
|
+
case src_xdr.ScValType.scvBool().value:
|
|
23097
|
+
case src_xdr.ScValType.scvU32().value:
|
|
23098
|
+
case src_xdr.ScValType.scvI32().value:
|
|
23099
|
+
case src_xdr.ScValType.scvBytes().value:
|
|
23100
|
+
return scv.value();
|
|
23101
|
+
|
|
23102
|
+
// Symbols are limited to [a-zA-Z0-9_]+, so we can safely make ascii strings
|
|
23103
|
+
//
|
|
23104
|
+
// Strings, however, are "presented" as strings and we treat them as such
|
|
23105
|
+
// (in other words, string = bytes with a hint that it's text). If the user
|
|
23106
|
+
// encoded non-printable bytes in their string value, that's on them.
|
|
23107
|
+
//
|
|
23108
|
+
// Note that we assume a utf8 encoding (ascii-compatible). For other
|
|
23109
|
+
// encodings, you should probably use bytes anyway. If it cannot be decoded,
|
|
23110
|
+
// the raw bytes are returned.
|
|
23111
|
+
case src_xdr.ScValType.scvSymbol().value:
|
|
23112
|
+
case src_xdr.ScValType.scvString().value:
|
|
23113
|
+
{
|
|
23114
|
+
var v = scv.value(); // string|Buffer
|
|
23115
|
+
if (scval_Buffer.isBuffer(v) || ArrayBuffer.isView(v)) {
|
|
23116
|
+
try {
|
|
23117
|
+
return new TextDecoder().decode(v);
|
|
23118
|
+
} catch (e) {
|
|
23119
|
+
return new Uint8Array(v.buffer); // copy of bytes
|
|
23120
|
+
}
|
|
23121
|
+
}
|
|
23122
|
+
return v; // string already
|
|
23123
|
+
}
|
|
23124
|
+
|
|
23125
|
+
// these can be converted to bigint
|
|
23126
|
+
case src_xdr.ScValType.scvTimepoint().value:
|
|
23127
|
+
case src_xdr.ScValType.scvDuration().value:
|
|
23128
|
+
return new src_xdr.Uint64(scv.value()).toBigInt();
|
|
23129
|
+
case src_xdr.ScValType.scvError().value:
|
|
23130
|
+
switch (scv.error()["switch"]().value) {
|
|
23131
|
+
// Distinguish errors from the user contract.
|
|
23132
|
+
case src_xdr.ScErrorType.sceContract().value:
|
|
23133
|
+
return {
|
|
23134
|
+
type: 'contract',
|
|
23135
|
+
code: scv.error().contractCode()
|
|
23136
|
+
};
|
|
23137
|
+
default:
|
|
23138
|
+
{
|
|
23139
|
+
var err = scv.error();
|
|
23140
|
+
return {
|
|
23141
|
+
type: 'system',
|
|
23142
|
+
code: err.code().value,
|
|
23143
|
+
value: err.code().name
|
|
23144
|
+
};
|
|
23145
|
+
}
|
|
23146
|
+
}
|
|
23147
|
+
|
|
23148
|
+
// in the fallthrough case, just return the underlying value directly
|
|
23149
|
+
default:
|
|
23150
|
+
return scv.value();
|
|
23151
|
+
}
|
|
23152
|
+
}
|
|
23153
|
+
|
|
23154
|
+
/// Inject a sortable map builder into the xdr module.
|
|
23155
|
+
src_xdr.scvSortedMap = function (items) {
|
|
23156
|
+
var sorted = Array.from(items).sort(function (a, b) {
|
|
23157
|
+
// Both a and b are `ScMapEntry`s, so we need to sort by underlying key.
|
|
23158
|
+
//
|
|
23159
|
+
// We couldn't possibly handle every combination of keys since Soroban
|
|
23160
|
+
// maps don't enforce consistent types, so we do a best-effort and try
|
|
23161
|
+
// sorting by "number-like" or "string-like."
|
|
23162
|
+
var nativeA = scValToNative(a.key());
|
|
23163
|
+
var nativeB = scValToNative(b.key());
|
|
23164
|
+
switch (scval_typeof(nativeA)) {
|
|
23165
|
+
case 'number':
|
|
23166
|
+
case 'bigint':
|
|
23167
|
+
return nativeA < nativeB ? -1 : 1;
|
|
23168
|
+
default:
|
|
23169
|
+
return nativeA.toString().localeCompare(nativeB.toString());
|
|
23170
|
+
}
|
|
23171
|
+
});
|
|
23172
|
+
return src_xdr.ScVal.scvMap(sorted);
|
|
23173
|
+
};
|
|
23174
|
+
;// ./src/transaction_builder.js
|
|
23175
|
+
function transaction_builder_typeof(o) { "@babel/helpers - typeof"; return transaction_builder_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, transaction_builder_typeof(o); }
|
|
23176
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || transaction_builder_unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
23177
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23178
|
+
function transaction_builder_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return transaction_builder_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? transaction_builder_arrayLikeToArray(r, a) : void 0; } }
|
|
23179
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
23180
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return transaction_builder_arrayLikeToArray(r); }
|
|
23181
|
+
function transaction_builder_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
23182
|
+
function transaction_builder_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23183
|
+
function transaction_builder_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? transaction_builder_ownKeys(Object(t), !0).forEach(function (r) { transaction_builder_defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : transaction_builder_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23184
|
+
function transaction_builder_defineProperty(e, r, t) { return (r = transaction_builder_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
23185
|
+
function transaction_builder_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
23186
|
+
function transaction_builder_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, transaction_builder_toPropertyKey(o.key), o); } }
|
|
23187
|
+
function transaction_builder_createClass(e, r, t) { return r && transaction_builder_defineProperties(e.prototype, r), t && transaction_builder_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23188
|
+
function transaction_builder_toPropertyKey(t) { var i = transaction_builder_toPrimitive(t, "string"); return "symbol" == transaction_builder_typeof(i) ? i : i + ""; }
|
|
23189
|
+
function transaction_builder_toPrimitive(t, r) { if ("object" != transaction_builder_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != transaction_builder_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23190
|
+
|
|
23191
|
+
|
|
23192
|
+
|
|
23193
|
+
|
|
23194
|
+
|
|
23195
|
+
|
|
23196
|
+
|
|
23197
|
+
|
|
23198
|
+
|
|
23199
|
+
|
|
23200
|
+
|
|
23201
|
+
|
|
23202
|
+
// eslint-disable-next-line no-unused-vars
|
|
23203
|
+
|
|
23204
|
+
|
|
23205
|
+
|
|
23206
|
+
|
|
23207
|
+
|
|
23208
|
+
|
|
23209
|
+
/**
|
|
23210
|
+
* Minimum base fee for transactions. If this fee is below the network
|
|
23211
|
+
* minimum, the transaction will fail. The more operations in the
|
|
23212
|
+
* transaction, the greater the required fee. Use {@link
|
|
23213
|
+
* Server#fetchBaseFee} to get an accurate value of minimum transaction
|
|
23214
|
+
* fee on the network.
|
|
23215
|
+
*
|
|
23216
|
+
* @constant
|
|
23217
|
+
* @see [Fees](https://developers.stellar.org/docs/glossary/fees/)
|
|
23218
|
+
*/
|
|
23219
|
+
var BASE_FEE = '100'; // Stroops
|
|
23220
|
+
|
|
23221
|
+
/**
|
|
23222
|
+
* @constant
|
|
23223
|
+
* @see {@link TransactionBuilder#setTimeout}
|
|
23224
|
+
* @see [Timeout](https://developers.stellar.org/api/resources/transactions/post/)
|
|
23225
|
+
*/
|
|
23226
|
+
var TimeoutInfinite = 0;
|
|
23227
|
+
|
|
23228
|
+
/**
|
|
23229
|
+
* @typedef {object} SorobanFees
|
|
23230
|
+
* @property {number} instructions - the number of instructions executed by the transaction
|
|
23231
|
+
* @property {number} readBytes - the number of bytes read from the ledger by the transaction
|
|
23232
|
+
* @property {number} writeBytes - the number of bytes written to the ledger by the transaction
|
|
23233
|
+
* @property {bigint} resourceFee - the fee to be paid for the transaction, in stroops
|
|
23234
|
+
*/
|
|
23235
|
+
|
|
23236
|
+
/**
|
|
23237
|
+
* <p>Transaction builder helps constructs a new `{@link Transaction}` using the
|
|
23238
|
+
* given {@link Account} as the transaction's "source account". The transaction
|
|
23239
|
+
* will use the current sequence number of the given account as its sequence
|
|
23240
|
+
* number and increment the given account's sequence number by one. The given
|
|
23241
|
+
* source account must include a private key for signing the transaction or an
|
|
23242
|
+
* error will be thrown.</p>
|
|
23243
|
+
*
|
|
23244
|
+
* <p>Operations can be added to the transaction via their corresponding builder
|
|
23245
|
+
* methods, and each returns the TransactionBuilder object so they can be
|
|
23246
|
+
* chained together. After adding the desired operations, call the `build()`
|
|
23247
|
+
* method on the `TransactionBuilder` to return a fully constructed `{@link
|
|
23248
|
+
* Transaction}` that can be signed. The returned transaction will contain the
|
|
23249
|
+
* sequence number of the source account and include the signature from the
|
|
23250
|
+
* source account.</p>
|
|
23251
|
+
*
|
|
23252
|
+
* <p><strong>Be careful about unsubmitted transactions!</strong> When you build
|
|
23253
|
+
* a transaction, `stellar-sdk` automatically increments the source account's
|
|
23254
|
+
* sequence number. If you end up not submitting this transaction and submitting
|
|
23255
|
+
* another one instead, it'll fail due to the sequence number being wrong. So if
|
|
23256
|
+
* you decide not to use a built transaction, make sure to update the source
|
|
23257
|
+
* account's sequence number with
|
|
23258
|
+
* [Server.loadAccount](https://stellar.github.io/js-stellar-sdk/Server.html#loadAccount)
|
|
23259
|
+
* before creating another transaction.</p>
|
|
23260
|
+
*
|
|
23261
|
+
* <p>The following code example creates a new transaction with {@link
|
|
23262
|
+
* Operation.createAccount} and {@link Operation.payment} operations. The
|
|
23263
|
+
* Transaction's source account first funds `destinationA`, then sends a payment
|
|
23264
|
+
* to `destinationB`. The built transaction is then signed by
|
|
23265
|
+
* `sourceKeypair`.</p>
|
|
23266
|
+
*
|
|
23267
|
+
* ```
|
|
23268
|
+
* var transaction = new TransactionBuilder(source, { fee, networkPassphrase: Networks.TESTNET })
|
|
23269
|
+
* .addOperation(Operation.createAccount({
|
|
23270
|
+
* destination: destinationA,
|
|
23271
|
+
* startingBalance: "20"
|
|
23272
|
+
* })) // <- funds and creates destinationA
|
|
23273
|
+
* .addOperation(Operation.payment({
|
|
23274
|
+
* destination: destinationB,
|
|
23275
|
+
* amount: "100",
|
|
23276
|
+
* asset: Asset.native()
|
|
23277
|
+
* })) // <- sends 100 XLM to destinationB
|
|
23278
|
+
* .setTimeout(30)
|
|
23279
|
+
* .build();
|
|
23280
|
+
*
|
|
23281
|
+
* transaction.sign(sourceKeypair);
|
|
23282
|
+
* ```
|
|
23283
|
+
*
|
|
23284
|
+
* @constructor
|
|
23285
|
+
*
|
|
23286
|
+
* @param {Account} sourceAccount - source account for this transaction
|
|
23287
|
+
* @param {object} opts - Options object
|
|
23288
|
+
* @param {string} opts.fee - max fee you're willing to pay per
|
|
23289
|
+
* operation in this transaction (**in stroops**)
|
|
23290
|
+
*
|
|
23291
|
+
* @param {object} [opts.timebounds] - timebounds for the
|
|
23292
|
+
* validity of this transaction
|
|
23293
|
+
* @param {number|string|Date} [opts.timebounds.minTime] - 64-bit UNIX
|
|
23294
|
+
* timestamp or Date object
|
|
23295
|
+
* @param {number|string|Date} [opts.timebounds.maxTime] - 64-bit UNIX
|
|
23296
|
+
* timestamp or Date object
|
|
23297
|
+
* @param {object} [opts.ledgerbounds] - ledger bounds for the
|
|
23298
|
+
* validity of this transaction
|
|
23299
|
+
* @param {number} [opts.ledgerbounds.minLedger] - number of the minimum
|
|
23300
|
+
* ledger sequence
|
|
23301
|
+
* @param {number} [opts.ledgerbounds.maxLedger] - number of the maximum
|
|
23302
|
+
* ledger sequence
|
|
23303
|
+
* @param {string} [opts.minAccountSequence] - number for
|
|
23304
|
+
* the minimum account sequence
|
|
23305
|
+
* @param {number} [opts.minAccountSequenceAge] - number of
|
|
23306
|
+
* seconds for the minimum account sequence age
|
|
23307
|
+
* @param {number} [opts.minAccountSequenceLedgerGap] - number of
|
|
23308
|
+
* ledgers for the minimum account sequence ledger gap
|
|
23309
|
+
* @param {string[]} [opts.extraSigners] - list of the extra signers
|
|
23310
|
+
* required for this transaction
|
|
23311
|
+
* @param {Memo} [opts.memo] - memo for the transaction
|
|
23312
|
+
* @param {string} [opts.networkPassphrase] passphrase of the
|
|
23313
|
+
* target Stellar network (e.g. "Public Global Stellar Network ; September
|
|
23314
|
+
* 2015" for the pubnet)
|
|
23315
|
+
* @param {xdr.SorobanTransactionData | string} [opts.sorobanData] - an
|
|
23316
|
+
* optional instance of {@link xdr.SorobanTransactionData} to be set as the
|
|
23317
|
+
* internal `Transaction.Ext.SorobanData` field (either the xdr object or a
|
|
23318
|
+
* base64 string). In the case of Soroban transactions, this can be obtained
|
|
23319
|
+
* from a prior simulation of the transaction with a contract invocation and
|
|
23320
|
+
* provides necessary resource estimations. You can also use
|
|
23321
|
+
* {@link SorobanDataBuilder} to construct complicated combinations of
|
|
23322
|
+
* parameters without mucking with XDR directly. **Note:** For
|
|
23323
|
+
* non-contract(non-Soroban) transactions, this has no effect.
|
|
23324
|
+
*/
|
|
23325
|
+
var TransactionBuilder = /*#__PURE__*/function () {
|
|
23326
|
+
function TransactionBuilder(sourceAccount) {
|
|
23327
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23328
|
+
transaction_builder_classCallCheck(this, TransactionBuilder);
|
|
23329
|
+
if (!sourceAccount) {
|
|
23330
|
+
throw new Error('must specify source account for the transaction');
|
|
23261
23331
|
}
|
|
23262
|
-
|
|
23332
|
+
if (opts.fee === undefined) {
|
|
23333
|
+
throw new Error('must specify fee for the transaction (in stroops)');
|
|
23334
|
+
}
|
|
23335
|
+
this.source = sourceAccount;
|
|
23336
|
+
this.operations = [];
|
|
23337
|
+
this.baseFee = opts.fee;
|
|
23338
|
+
this.timebounds = opts.timebounds ? transaction_builder_objectSpread({}, opts.timebounds) : null;
|
|
23339
|
+
this.ledgerbounds = opts.ledgerbounds ? transaction_builder_objectSpread({}, opts.ledgerbounds) : null;
|
|
23340
|
+
this.minAccountSequence = opts.minAccountSequence || null;
|
|
23341
|
+
this.minAccountSequenceAge = opts.minAccountSequenceAge || null;
|
|
23342
|
+
this.minAccountSequenceLedgerGap = opts.minAccountSequenceLedgerGap || null;
|
|
23343
|
+
this.extraSigners = opts.extraSigners ? _toConsumableArray(opts.extraSigners) : null;
|
|
23344
|
+
this.memo = opts.memo || Memo.none();
|
|
23345
|
+
this.networkPassphrase = opts.networkPassphrase || null;
|
|
23346
|
+
this.sorobanData = opts.sorobanData ? new SorobanDataBuilder(opts.sorobanData).build() : null;
|
|
23263
23347
|
}
|
|
23264
23348
|
|
|
23265
23349
|
/**
|
|
23266
|
-
* @
|
|
23267
|
-
*
|
|
23350
|
+
* Creates a builder instance using an existing {@link Transaction} as a
|
|
23351
|
+
* template, ignoring any existing envelope signatures.
|
|
23352
|
+
*
|
|
23353
|
+
* Note that the sequence number WILL be cloned, so EITHER this transaction or
|
|
23354
|
+
* the one it was cloned from will be valid. This is useful in situations
|
|
23355
|
+
* where you are constructing a transaction in pieces and need to make
|
|
23356
|
+
* adjustments as you go (for example, when filling out Soroban resource
|
|
23357
|
+
* information).
|
|
23358
|
+
*
|
|
23359
|
+
* @param {Transaction} tx a "template" transaction to clone exactly
|
|
23360
|
+
* @param {object} [opts] additional options to override the clone, e.g.
|
|
23361
|
+
* {fee: '1000'} will override the existing base fee derived from `tx` (see
|
|
23362
|
+
* the {@link TransactionBuilder} constructor for detailed options)
|
|
23363
|
+
*
|
|
23364
|
+
* @returns {TransactionBuilder} a "prepared" builder instance with the same
|
|
23365
|
+
* configuration and operations as the given transaction
|
|
23366
|
+
*
|
|
23367
|
+
* @warning This does not clone the transaction's
|
|
23368
|
+
* {@link xdr.SorobanTransactionData} (if applicable), use
|
|
23369
|
+
* {@link SorobanDataBuilder} and {@link TransactionBuilder.setSorobanData}
|
|
23370
|
+
* as needed, instead..
|
|
23371
|
+
*
|
|
23372
|
+
* @todo This cannot clone {@link FeeBumpTransaction}s, yet.
|
|
23268
23373
|
*/
|
|
23269
|
-
return
|
|
23270
|
-
key: "
|
|
23271
|
-
value:
|
|
23272
|
-
|
|
23273
|
-
|
|
23274
|
-
|
|
23275
|
-
|
|
23276
|
-
|
|
23374
|
+
return transaction_builder_createClass(TransactionBuilder, [{
|
|
23375
|
+
key: "addOperation",
|
|
23376
|
+
value:
|
|
23377
|
+
/**
|
|
23378
|
+
* Adds an operation to the transaction.
|
|
23379
|
+
*
|
|
23380
|
+
* @param {xdr.Operation} operation The xdr operation object, use {@link
|
|
23381
|
+
* Operation} static methods.
|
|
23382
|
+
*
|
|
23383
|
+
* @returns {TransactionBuilder}
|
|
23384
|
+
*/
|
|
23385
|
+
function addOperation(operation) {
|
|
23386
|
+
this.operations.push(operation);
|
|
23387
|
+
return this;
|
|
23277
23388
|
}
|
|
23278
23389
|
|
|
23279
|
-
/**
|
|
23390
|
+
/**
|
|
23391
|
+
* Adds an operation to the transaction at a specific index.
|
|
23392
|
+
*
|
|
23393
|
+
* @param {xdr.Operation} operation - The xdr operation object to add, use {@link Operation} static methods.
|
|
23394
|
+
* @param {number} index - The index at which to insert the operation.
|
|
23395
|
+
*
|
|
23396
|
+
* @returns {TransactionBuilder} - The TransactionBuilder instance for method chaining.
|
|
23397
|
+
*/
|
|
23280
23398
|
}, {
|
|
23281
|
-
key: "
|
|
23282
|
-
value: function
|
|
23283
|
-
|
|
23399
|
+
key: "addOperationAt",
|
|
23400
|
+
value: function addOperationAt(operation, index) {
|
|
23401
|
+
this.operations.splice(index, 0, operation);
|
|
23402
|
+
return this;
|
|
23284
23403
|
}
|
|
23285
23404
|
|
|
23286
|
-
/**
|
|
23405
|
+
/**
|
|
23406
|
+
* Removes the operations from the builder (useful when cloning).
|
|
23407
|
+
* @returns {TransactionBuilder} this builder instance
|
|
23408
|
+
*/
|
|
23287
23409
|
}, {
|
|
23288
|
-
key: "
|
|
23289
|
-
value: function
|
|
23290
|
-
this.
|
|
23291
|
-
|
|
23292
|
-
if (BigInt.asIntN(64, v) !== v) {
|
|
23293
|
-
throw RangeError("value too large for i64: ".concat(v));
|
|
23294
|
-
}
|
|
23295
|
-
return src_xdr.ScVal.scvI64(new src_xdr.Int64(v));
|
|
23410
|
+
key: "clearOperations",
|
|
23411
|
+
value: function clearOperations() {
|
|
23412
|
+
this.operations = [];
|
|
23413
|
+
return this;
|
|
23296
23414
|
}
|
|
23297
23415
|
|
|
23298
|
-
/**
|
|
23416
|
+
/**
|
|
23417
|
+
* Removes the operation at the specified index from the transaction.
|
|
23418
|
+
*
|
|
23419
|
+
* @param {number} index - The index of the operation to remove.
|
|
23420
|
+
*
|
|
23421
|
+
* @returns {TransactionBuilder} The TransactionBuilder instance for method chaining.
|
|
23422
|
+
*/
|
|
23299
23423
|
}, {
|
|
23300
|
-
key: "
|
|
23301
|
-
value: function
|
|
23302
|
-
this.
|
|
23303
|
-
return
|
|
23304
|
-
);
|
|
23424
|
+
key: "clearOperationAt",
|
|
23425
|
+
value: function clearOperationAt(index) {
|
|
23426
|
+
this.operations.splice(index, 1);
|
|
23427
|
+
return this;
|
|
23305
23428
|
}
|
|
23306
23429
|
|
|
23307
|
-
/**
|
|
23430
|
+
/**
|
|
23431
|
+
* Adds a memo to the transaction.
|
|
23432
|
+
* @param {Memo} memo {@link Memo} object
|
|
23433
|
+
* @returns {TransactionBuilder}
|
|
23434
|
+
*/
|
|
23308
23435
|
}, {
|
|
23309
|
-
key: "
|
|
23310
|
-
value: function
|
|
23311
|
-
this.
|
|
23312
|
-
return
|
|
23313
|
-
);
|
|
23436
|
+
key: "addMemo",
|
|
23437
|
+
value: function addMemo(memo) {
|
|
23438
|
+
this.memo = memo;
|
|
23439
|
+
return this;
|
|
23314
23440
|
}
|
|
23315
23441
|
|
|
23316
|
-
/**
|
|
23442
|
+
/**
|
|
23443
|
+
* Sets a timeout precondition on the transaction.
|
|
23444
|
+
*
|
|
23445
|
+
* Because of the distributed nature of the Stellar network it is possible
|
|
23446
|
+
* that the status of your transaction will be determined after a long time
|
|
23447
|
+
* if the network is highly congested. If you want to be sure to receive the
|
|
23448
|
+
* status of the transaction within a given period you should set the {@link
|
|
23449
|
+
* TimeBounds} with `maxTime` on the transaction (this is what `setTimeout`
|
|
23450
|
+
* does internally; if there's `minTime` set but no `maxTime` it will be
|
|
23451
|
+
* added).
|
|
23452
|
+
*
|
|
23453
|
+
* A call to `TransactionBuilder.setTimeout` is **required** if Transaction
|
|
23454
|
+
* does not have `max_time` set. If you don't want to set timeout, use
|
|
23455
|
+
* `{@link TimeoutInfinite}`. In general you should set `{@link
|
|
23456
|
+
* TimeoutInfinite}` only in smart contracts.
|
|
23457
|
+
*
|
|
23458
|
+
* Please note that Horizon may still return <code>504 Gateway Timeout</code>
|
|
23459
|
+
* error, even for short timeouts. In such case you need to resubmit the same
|
|
23460
|
+
* transaction again without making any changes to receive a status. This
|
|
23461
|
+
* method is using the machine system time (UTC), make sure it is set
|
|
23462
|
+
* correctly.
|
|
23463
|
+
*
|
|
23464
|
+
* @param {number} timeoutSeconds Number of seconds the transaction is good.
|
|
23465
|
+
* Can't be negative. If the value is {@link TimeoutInfinite}, the
|
|
23466
|
+
* transaction is good indefinitely.
|
|
23467
|
+
*
|
|
23468
|
+
* @returns {TransactionBuilder}
|
|
23469
|
+
*
|
|
23470
|
+
* @see {@link TimeoutInfinite}
|
|
23471
|
+
* @see https://developers.stellar.org/docs/tutorials/handling-errors/
|
|
23472
|
+
*/
|
|
23317
23473
|
}, {
|
|
23318
|
-
key: "
|
|
23319
|
-
value: function
|
|
23320
|
-
this.
|
|
23321
|
-
|
|
23322
|
-
|
|
23474
|
+
key: "setTimeout",
|
|
23475
|
+
value: function setTimeout(timeoutSeconds) {
|
|
23476
|
+
if (this.timebounds !== null && this.timebounds.maxTime > 0) {
|
|
23477
|
+
throw new Error('TimeBounds.max_time has been already set - setting timeout would overwrite it.');
|
|
23478
|
+
}
|
|
23479
|
+
if (timeoutSeconds < 0) {
|
|
23480
|
+
throw new Error('timeout cannot be negative');
|
|
23481
|
+
}
|
|
23482
|
+
if (timeoutSeconds > 0) {
|
|
23483
|
+
var timeoutTimestamp = Math.floor(Date.now() / 1000) + timeoutSeconds;
|
|
23484
|
+
if (this.timebounds === null) {
|
|
23485
|
+
this.timebounds = {
|
|
23486
|
+
minTime: 0,
|
|
23487
|
+
maxTime: timeoutTimestamp
|
|
23488
|
+
};
|
|
23489
|
+
} else {
|
|
23490
|
+
this.timebounds = {
|
|
23491
|
+
minTime: this.timebounds.minTime,
|
|
23492
|
+
maxTime: timeoutTimestamp
|
|
23493
|
+
};
|
|
23494
|
+
}
|
|
23495
|
+
} else {
|
|
23496
|
+
this.timebounds = {
|
|
23497
|
+
minTime: 0,
|
|
23498
|
+
maxTime: 0
|
|
23499
|
+
};
|
|
23500
|
+
}
|
|
23501
|
+
return this;
|
|
23323
23502
|
}
|
|
23324
23503
|
|
|
23325
23504
|
/**
|
|
23326
|
-
*
|
|
23327
|
-
*
|
|
23505
|
+
* If you want to prepare a transaction which will become valid at some point
|
|
23506
|
+
* in the future, or be invalid after some time, you can set a timebounds
|
|
23507
|
+
* precondition. Internally this will set the `minTime`, and `maxTime`
|
|
23508
|
+
* preconditions. Conflicts with `setTimeout`, so use one or the other.
|
|
23509
|
+
*
|
|
23510
|
+
* @param {Date|number} minEpochOrDate Either a JS Date object, or a number
|
|
23511
|
+
* of UNIX epoch seconds. The transaction is valid after this timestamp.
|
|
23512
|
+
* Can't be negative. If the value is `0`, the transaction is valid
|
|
23513
|
+
* immediately.
|
|
23514
|
+
* @param {Date|number} maxEpochOrDate Either a JS Date object, or a number
|
|
23515
|
+
* of UNIX epoch seconds. The transaction is valid until this timestamp.
|
|
23516
|
+
* Can't be negative. If the value is `0`, the transaction is valid
|
|
23517
|
+
* indefinitely.
|
|
23518
|
+
*
|
|
23519
|
+
* @returns {TransactionBuilder}
|
|
23328
23520
|
*/
|
|
23329
23521
|
}, {
|
|
23330
|
-
key: "
|
|
23331
|
-
value: function
|
|
23332
|
-
|
|
23333
|
-
|
|
23334
|
-
|
|
23335
|
-
|
|
23522
|
+
key: "setTimebounds",
|
|
23523
|
+
value: function setTimebounds(minEpochOrDate, maxEpochOrDate) {
|
|
23524
|
+
// Force it to a date type
|
|
23525
|
+
if (typeof minEpochOrDate === 'number') {
|
|
23526
|
+
minEpochOrDate = new Date(minEpochOrDate * 1000);
|
|
23527
|
+
}
|
|
23528
|
+
if (typeof maxEpochOrDate === 'number') {
|
|
23529
|
+
maxEpochOrDate = new Date(maxEpochOrDate * 1000);
|
|
23530
|
+
}
|
|
23531
|
+
if (this.timebounds !== null) {
|
|
23532
|
+
throw new Error('TimeBounds has been already set - setting timebounds would overwrite it.');
|
|
23533
|
+
}
|
|
23336
23534
|
|
|
23337
|
-
|
|
23338
|
-
|
|
23339
|
-
|
|
23340
|
-
|
|
23535
|
+
// Convert that date to the epoch seconds
|
|
23536
|
+
var minTime = Math.floor(minEpochOrDate.valueOf() / 1000);
|
|
23537
|
+
var maxTime = Math.floor(maxEpochOrDate.valueOf() / 1000);
|
|
23538
|
+
if (minTime < 0) {
|
|
23539
|
+
throw new Error('min_time cannot be negative');
|
|
23540
|
+
}
|
|
23541
|
+
if (maxTime < 0) {
|
|
23542
|
+
throw new Error('max_time cannot be negative');
|
|
23543
|
+
}
|
|
23544
|
+
if (maxTime > 0 && minTime > maxTime) {
|
|
23545
|
+
throw new Error('min_time cannot be greater than max_time');
|
|
23546
|
+
}
|
|
23547
|
+
this.timebounds = {
|
|
23548
|
+
minTime: minTime,
|
|
23549
|
+
maxTime: maxTime
|
|
23550
|
+
};
|
|
23551
|
+
return this;
|
|
23341
23552
|
}
|
|
23342
23553
|
|
|
23343
23554
|
/**
|
|
23344
|
-
*
|
|
23345
|
-
*
|
|
23555
|
+
* If you want to prepare a transaction which will only be valid within some
|
|
23556
|
+
* range of ledgers, you can set a ledgerbounds precondition.
|
|
23557
|
+
* Internally this will set the `minLedger` and `maxLedger` preconditions.
|
|
23558
|
+
*
|
|
23559
|
+
* @param {number} minLedger The minimum ledger this transaction is valid at
|
|
23560
|
+
* or after. Cannot be negative. If the value is `0` (the default), the
|
|
23561
|
+
* transaction is valid immediately.
|
|
23562
|
+
*
|
|
23563
|
+
* @param {number} maxLedger The maximum ledger this transaction is valid
|
|
23564
|
+
* before. Cannot be negative. If the value is `0`, the transaction is
|
|
23565
|
+
* valid indefinitely.
|
|
23566
|
+
*
|
|
23567
|
+
* @returns {TransactionBuilder}
|
|
23346
23568
|
*/
|
|
23347
23569
|
}, {
|
|
23348
|
-
key: "
|
|
23349
|
-
value: function
|
|
23350
|
-
this.
|
|
23351
|
-
|
|
23352
|
-
|
|
23353
|
-
|
|
23354
|
-
|
|
23355
|
-
}
|
|
23356
|
-
|
|
23357
|
-
|
|
23358
|
-
|
|
23359
|
-
|
|
23360
|
-
|
|
23361
|
-
|
|
23362
|
-
|
|
23363
|
-
|
|
23364
|
-
|
|
23365
|
-
|
|
23366
|
-
|
|
23367
|
-
return src_xdr.ScVal.scvI256(new src_xdr.Int256Parts({
|
|
23368
|
-
hiHi: new src_xdr.Int64(hiHi64),
|
|
23369
|
-
hiLo: new src_xdr.Uint64(hiLo64),
|
|
23370
|
-
loHi: new src_xdr.Uint64(loHi64),
|
|
23371
|
-
loLo: new src_xdr.Uint64(loLo64)
|
|
23372
|
-
}));
|
|
23570
|
+
key: "setLedgerbounds",
|
|
23571
|
+
value: function setLedgerbounds(minLedger, maxLedger) {
|
|
23572
|
+
if (this.ledgerbounds !== null) {
|
|
23573
|
+
throw new Error('LedgerBounds has been already set - setting ledgerbounds would overwrite it.');
|
|
23574
|
+
}
|
|
23575
|
+
if (minLedger < 0) {
|
|
23576
|
+
throw new Error('min_ledger cannot be negative');
|
|
23577
|
+
}
|
|
23578
|
+
if (maxLedger < 0) {
|
|
23579
|
+
throw new Error('max_ledger cannot be negative');
|
|
23580
|
+
}
|
|
23581
|
+
if (maxLedger > 0 && minLedger > maxLedger) {
|
|
23582
|
+
throw new Error('min_ledger cannot be greater than max_ledger');
|
|
23583
|
+
}
|
|
23584
|
+
this.ledgerbounds = {
|
|
23585
|
+
minLedger: minLedger,
|
|
23586
|
+
maxLedger: maxLedger
|
|
23587
|
+
};
|
|
23588
|
+
return this;
|
|
23373
23589
|
}
|
|
23374
23590
|
|
|
23375
|
-
/**
|
|
23591
|
+
/**
|
|
23592
|
+
* If you want to prepare a transaction which will be valid only while the
|
|
23593
|
+
* account sequence number is
|
|
23594
|
+
*
|
|
23595
|
+
* minAccountSequence <= sourceAccountSequence < tx.seqNum
|
|
23596
|
+
*
|
|
23597
|
+
* Note that after execution the account's sequence number is always raised to
|
|
23598
|
+
* `tx.seqNum`. Internally this will set the `minAccountSequence`
|
|
23599
|
+
* precondition.
|
|
23600
|
+
*
|
|
23601
|
+
* @param {string} minAccountSequence The minimum source account sequence
|
|
23602
|
+
* number this transaction is valid for. If the value is `0` (the
|
|
23603
|
+
* default), the transaction is valid when `sourceAccount's sequence
|
|
23604
|
+
* number == tx.seqNum- 1`.
|
|
23605
|
+
*
|
|
23606
|
+
* @returns {TransactionBuilder}
|
|
23607
|
+
*/
|
|
23376
23608
|
}, {
|
|
23377
|
-
key: "
|
|
23378
|
-
value: function
|
|
23379
|
-
|
|
23380
|
-
|
|
23381
|
-
|
|
23382
|
-
|
|
23383
|
-
|
|
23384
|
-
return src_xdr.ScVal.scvU256(new src_xdr.UInt256Parts({
|
|
23385
|
-
hiHi: new src_xdr.Uint64(hiHi64),
|
|
23386
|
-
hiLo: new src_xdr.Uint64(hiLo64),
|
|
23387
|
-
loHi: new src_xdr.Uint64(loHi64),
|
|
23388
|
-
loLo: new src_xdr.Uint64(loLo64)
|
|
23389
|
-
}));
|
|
23609
|
+
key: "setMinAccountSequence",
|
|
23610
|
+
value: function setMinAccountSequence(minAccountSequence) {
|
|
23611
|
+
if (this.minAccountSequence !== null) {
|
|
23612
|
+
throw new Error('min_account_sequence has been already set - setting min_account_sequence would overwrite it.');
|
|
23613
|
+
}
|
|
23614
|
+
this.minAccountSequence = minAccountSequence;
|
|
23615
|
+
return this;
|
|
23390
23616
|
}
|
|
23391
23617
|
|
|
23392
|
-
/**
|
|
23618
|
+
/**
|
|
23619
|
+
* For the transaction to be valid, the current ledger time must be at least
|
|
23620
|
+
* `minAccountSequenceAge` greater than sourceAccount's `sequenceTime`.
|
|
23621
|
+
* Internally this will set the `minAccountSequenceAge` precondition.
|
|
23622
|
+
*
|
|
23623
|
+
* @param {number} durationInSeconds The minimum amount of time between
|
|
23624
|
+
* source account sequence time and the ledger time when this transaction
|
|
23625
|
+
* will become valid. If the value is `0`, the transaction is unrestricted
|
|
23626
|
+
* by the account sequence age. Cannot be negative.
|
|
23627
|
+
*
|
|
23628
|
+
* @returns {TransactionBuilder}
|
|
23629
|
+
*/
|
|
23393
23630
|
}, {
|
|
23394
|
-
key: "
|
|
23395
|
-
value: function
|
|
23396
|
-
|
|
23397
|
-
|
|
23398
|
-
return this.toI64();
|
|
23399
|
-
case 'i128':
|
|
23400
|
-
return this.toI128();
|
|
23401
|
-
case 'i256':
|
|
23402
|
-
return this.toI256();
|
|
23403
|
-
case 'u64':
|
|
23404
|
-
return this.toU64();
|
|
23405
|
-
case 'u128':
|
|
23406
|
-
return this.toU128();
|
|
23407
|
-
case 'u256':
|
|
23408
|
-
return this.toU256();
|
|
23409
|
-
case 'timepoint':
|
|
23410
|
-
return this.toTimepoint();
|
|
23411
|
-
case 'duration':
|
|
23412
|
-
return this.toDuration();
|
|
23413
|
-
default:
|
|
23414
|
-
throw TypeError("invalid type: ".concat(this.type));
|
|
23631
|
+
key: "setMinAccountSequenceAge",
|
|
23632
|
+
value: function setMinAccountSequenceAge(durationInSeconds) {
|
|
23633
|
+
if (typeof durationInSeconds !== 'number') {
|
|
23634
|
+
throw new Error('min_account_sequence_age must be a number');
|
|
23415
23635
|
}
|
|
23416
|
-
|
|
23417
|
-
|
|
23418
|
-
key: "valueOf",
|
|
23419
|
-
value: function valueOf() {
|
|
23420
|
-
return this["int"].valueOf();
|
|
23421
|
-
}
|
|
23422
|
-
}, {
|
|
23423
|
-
key: "toString",
|
|
23424
|
-
value: function toString() {
|
|
23425
|
-
return this["int"].toString();
|
|
23426
|
-
}
|
|
23427
|
-
}, {
|
|
23428
|
-
key: "toJSON",
|
|
23429
|
-
value: function toJSON() {
|
|
23430
|
-
return {
|
|
23431
|
-
value: this.toBigInt().toString(),
|
|
23432
|
-
type: this.type
|
|
23433
|
-
};
|
|
23434
|
-
}
|
|
23435
|
-
}, {
|
|
23436
|
-
key: "_sizeCheck",
|
|
23437
|
-
value: function _sizeCheck(bits) {
|
|
23438
|
-
if (this["int"].size > bits) {
|
|
23439
|
-
throw RangeError("value too large for ".concat(bits, " bits (").concat(this.type, ")"));
|
|
23636
|
+
if (this.minAccountSequenceAge !== null) {
|
|
23637
|
+
throw new Error('min_account_sequence_age has been already set - setting min_account_sequence_age would overwrite it.');
|
|
23440
23638
|
}
|
|
23441
|
-
|
|
23442
|
-
|
|
23443
|
-
key: "isType",
|
|
23444
|
-
value: function isType(type) {
|
|
23445
|
-
switch (type) {
|
|
23446
|
-
case 'i64':
|
|
23447
|
-
case 'i128':
|
|
23448
|
-
case 'i256':
|
|
23449
|
-
case 'u64':
|
|
23450
|
-
case 'u128':
|
|
23451
|
-
case 'u256':
|
|
23452
|
-
case 'timepoint':
|
|
23453
|
-
case 'duration':
|
|
23454
|
-
return true;
|
|
23455
|
-
default:
|
|
23456
|
-
return false;
|
|
23639
|
+
if (durationInSeconds < 0) {
|
|
23640
|
+
throw new Error('min_account_sequence_age cannot be negative');
|
|
23457
23641
|
}
|
|
23642
|
+
this.minAccountSequenceAge = durationInSeconds;
|
|
23643
|
+
return this;
|
|
23458
23644
|
}
|
|
23459
23645
|
|
|
23460
23646
|
/**
|
|
23461
|
-
*
|
|
23462
|
-
*
|
|
23647
|
+
* For the transaction to be valid, the current ledger number must be at least
|
|
23648
|
+
* `minAccountSequenceLedgerGap` greater than sourceAccount's ledger sequence.
|
|
23649
|
+
* Internally this will set the `minAccountSequenceLedgerGap` precondition.
|
|
23463
23650
|
*
|
|
23464
|
-
* @param {
|
|
23465
|
-
*
|
|
23651
|
+
* @param {number} gap The minimum number of ledgers between source account
|
|
23652
|
+
* sequence and the ledger number when this transaction will become valid.
|
|
23653
|
+
* If the value is `0`, the transaction is unrestricted by the account
|
|
23654
|
+
* sequence ledger. Cannot be negative.
|
|
23655
|
+
*
|
|
23656
|
+
* @returns {TransactionBuilder}
|
|
23466
23657
|
*/
|
|
23467
23658
|
}, {
|
|
23468
|
-
key: "
|
|
23469
|
-
value: function
|
|
23470
|
-
|
|
23471
|
-
|
|
23472
|
-
|
|
23473
|
-
|
|
23474
|
-
|
|
23475
|
-
|
|
23476
|
-
|
|
23477
|
-
|
|
23478
|
-
function sc_int_toPropertyKey(t) { var i = sc_int_toPrimitive(t, "string"); return "symbol" == sc_int_typeof(i) ? i : i + ""; }
|
|
23479
|
-
function sc_int_toPrimitive(t, r) { if ("object" != sc_int_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != sc_int_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23480
|
-
function sc_int_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
23481
|
-
function sc_int_callSuper(t, o, e) { return o = sc_int_getPrototypeOf(o), sc_int_possibleConstructorReturn(t, sc_int_isNativeReflectConstruct() ? Reflect.construct(o, e || [], sc_int_getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
23482
|
-
function sc_int_possibleConstructorReturn(t, e) { if (e && ("object" == sc_int_typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return sc_int_assertThisInitialized(t); }
|
|
23483
|
-
function sc_int_assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
23484
|
-
function sc_int_isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (sc_int_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
23485
|
-
function sc_int_getPrototypeOf(t) { return sc_int_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, sc_int_getPrototypeOf(t); }
|
|
23486
|
-
function sc_int_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && sc_int_setPrototypeOf(t, e); }
|
|
23487
|
-
function sc_int_setPrototypeOf(t, e) { return sc_int_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, sc_int_setPrototypeOf(t, e); }
|
|
23488
|
-
|
|
23489
|
-
|
|
23490
|
-
/**
|
|
23491
|
-
* Provides an easier way to manipulate large numbers for Stellar operations.
|
|
23492
|
-
*
|
|
23493
|
-
* You can instantiate this "**s**mart **c**ontract integer" value either from
|
|
23494
|
-
* bigints, strings, or numbers (whole numbers, or this will throw).
|
|
23495
|
-
*
|
|
23496
|
-
* If you need to create a native BigInt from a list of integer "parts" (for
|
|
23497
|
-
* example, you have a series of encoded 32-bit integers that represent a larger
|
|
23498
|
-
* value), you can use the lower level abstraction {@link XdrLargeInt}. For
|
|
23499
|
-
* example, you could do `new XdrLargeInt('u128', bytes...).toBigInt()`.
|
|
23500
|
-
*
|
|
23501
|
-
* @example
|
|
23502
|
-
* import { xdr, ScInt, scValToBigInt } from "@stellar/stellar-base";
|
|
23503
|
-
*
|
|
23504
|
-
* // You have an ScVal from a contract and want to parse it into JS native.
|
|
23505
|
-
* const value = xdr.ScVal.fromXDR(someXdr, "base64");
|
|
23506
|
-
* const bigi = scValToBigInt(value); // grab it as a BigInt
|
|
23507
|
-
* let sci = new ScInt(bigi);
|
|
23508
|
-
*
|
|
23509
|
-
* sci.toNumber(); // gives native JS type (w/ size check)
|
|
23510
|
-
* sci.toBigInt(); // gives the native BigInt value
|
|
23511
|
-
* sci.toU64(); // gives ScValType-specific XDR constructs (with size checks)
|
|
23512
|
-
*
|
|
23513
|
-
* // You have a number and want to shove it into a contract.
|
|
23514
|
-
* sci = ScInt(0xdeadcafebabe);
|
|
23515
|
-
* sci.toBigInt() // returns 244838016400062n
|
|
23516
|
-
* sci.toNumber() // throws: too large
|
|
23517
|
-
*
|
|
23518
|
-
* // Pass any to e.g. a Contract.call(), conversion happens automatically
|
|
23519
|
-
* // regardless of the initial type.
|
|
23520
|
-
* const scValU128 = sci.toU128();
|
|
23521
|
-
* const scValI256 = sci.toI256();
|
|
23522
|
-
* const scValU64 = sci.toU64();
|
|
23523
|
-
*
|
|
23524
|
-
* // Lots of ways to initialize:
|
|
23525
|
-
* ScInt("123456789123456789")
|
|
23526
|
-
* ScInt(123456789123456789n);
|
|
23527
|
-
* ScInt(1n << 140n);
|
|
23528
|
-
* ScInt(-42);
|
|
23529
|
-
* ScInt(scValToBigInt(scValU128)); // from above
|
|
23530
|
-
*
|
|
23531
|
-
* // If you know the type ahead of time (accessing `.raw` is faster than
|
|
23532
|
-
* // conversions), you can specify the type directly (otherwise, it's
|
|
23533
|
-
* // interpreted from the numbers you pass in):
|
|
23534
|
-
* const i = ScInt(123456789n, { type: "u256" });
|
|
23535
|
-
*
|
|
23536
|
-
* // For example, you can use the underlying `sdk.U256` and convert it to an
|
|
23537
|
-
* // `xdr.ScVal` directly like so:
|
|
23538
|
-
* const scv = new xdr.ScVal.scvU256(i.raw);
|
|
23539
|
-
*
|
|
23540
|
-
* // Or reinterpret it as a different type (size permitting):
|
|
23541
|
-
* const scv = i.toI64();
|
|
23542
|
-
*
|
|
23543
|
-
* @param {number|bigint|string} value - a single, integer-like value which will
|
|
23544
|
-
* be interpreted in the smallest appropriate XDR type supported by Stellar
|
|
23545
|
-
* (64, 128, or 256 bit integer values). signed values are supported, though
|
|
23546
|
-
* they are sanity-checked against `opts.type`. if you need 32-bit values,
|
|
23547
|
-
* you can construct them directly without needing this wrapper, e.g.
|
|
23548
|
-
* `xdr.ScVal.scvU32(1234)`.
|
|
23549
|
-
*
|
|
23550
|
-
* @param {object} [opts] - an optional object controlling optional parameters
|
|
23551
|
-
* @param {string} [opts.type] - force a specific data type. the type choices
|
|
23552
|
-
* are: 'i64', 'u64', 'i128', 'u128', 'i256', and 'u256' (default: the
|
|
23553
|
-
* smallest one that fits the `value`)
|
|
23554
|
-
*
|
|
23555
|
-
* @throws {RangeError} if the `value` is invalid (e.g. floating point), too
|
|
23556
|
-
* large (i.e. exceeds a 256-bit value), or doesn't fit in the `opts.type`
|
|
23557
|
-
* @throws {TypeError} on missing parameters, or if the "signedness" of `opts`
|
|
23558
|
-
* doesn't match input `value`, e.g. passing `{type: 'u64'}` yet passing -1n
|
|
23559
|
-
* @throws {SyntaxError} if a string `value` can't be parsed as a big integer
|
|
23560
|
-
*/
|
|
23561
|
-
var ScInt = /*#__PURE__*/function (_XdrLargeInt) {
|
|
23562
|
-
function ScInt(value, opts) {
|
|
23563
|
-
var _opts$type;
|
|
23564
|
-
sc_int_classCallCheck(this, ScInt);
|
|
23565
|
-
var signed = value < 0;
|
|
23566
|
-
var type = (_opts$type = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type !== void 0 ? _opts$type : '';
|
|
23567
|
-
if (type.startsWith('u') && signed) {
|
|
23568
|
-
throw TypeError("specified type ".concat(opts.type, " yet negative (").concat(value, ")"));
|
|
23659
|
+
key: "setMinAccountSequenceLedgerGap",
|
|
23660
|
+
value: function setMinAccountSequenceLedgerGap(gap) {
|
|
23661
|
+
if (this.minAccountSequenceLedgerGap !== null) {
|
|
23662
|
+
throw new Error('min_account_sequence_ledger_gap has been already set - setting min_account_sequence_ledger_gap would overwrite it.');
|
|
23663
|
+
}
|
|
23664
|
+
if (gap < 0) {
|
|
23665
|
+
throw new Error('min_account_sequence_ledger_gap cannot be negative');
|
|
23666
|
+
}
|
|
23667
|
+
this.minAccountSequenceLedgerGap = gap;
|
|
23668
|
+
return this;
|
|
23569
23669
|
}
|
|
23570
23670
|
|
|
23571
|
-
|
|
23572
|
-
|
|
23573
|
-
|
|
23574
|
-
|
|
23575
|
-
|
|
23576
|
-
|
|
23577
|
-
|
|
23578
|
-
|
|
23579
|
-
|
|
23580
|
-
|
|
23581
|
-
|
|
23582
|
-
|
|
23583
|
-
|
|
23671
|
+
/**
|
|
23672
|
+
* For the transaction to be valid, there must be a signature corresponding to
|
|
23673
|
+
* every Signer in this array, even if the signature is not otherwise required
|
|
23674
|
+
* by the sourceAccount or operations. Internally this will set the
|
|
23675
|
+
* `extraSigners` precondition.
|
|
23676
|
+
*
|
|
23677
|
+
* @param {string[]} extraSigners required extra signers (as {@link StrKey}s)
|
|
23678
|
+
*
|
|
23679
|
+
* @returns {TransactionBuilder}
|
|
23680
|
+
*/
|
|
23681
|
+
}, {
|
|
23682
|
+
key: "setExtraSigners",
|
|
23683
|
+
value: function setExtraSigners(extraSigners) {
|
|
23684
|
+
if (!Array.isArray(extraSigners)) {
|
|
23685
|
+
throw new Error('extra_signers must be an array of strings.');
|
|
23686
|
+
}
|
|
23687
|
+
if (this.extraSigners !== null) {
|
|
23688
|
+
throw new Error('extra_signers has been already set - setting extra_signers would overwrite it.');
|
|
23689
|
+
}
|
|
23690
|
+
if (extraSigners.length > 2) {
|
|
23691
|
+
throw new Error('extra_signers cannot be longer than 2 elements.');
|
|
23584
23692
|
}
|
|
23693
|
+
this.extraSigners = _toConsumableArray(extraSigners);
|
|
23694
|
+
return this;
|
|
23585
23695
|
}
|
|
23586
|
-
return sc_int_callSuper(this, ScInt, [type, value]);
|
|
23587
|
-
}
|
|
23588
|
-
sc_int_inherits(ScInt, _XdrLargeInt);
|
|
23589
|
-
return sc_int_createClass(ScInt);
|
|
23590
|
-
}(XdrLargeInt);
|
|
23591
|
-
function nearestBigIntSize(bigI) {
|
|
23592
|
-
var _find;
|
|
23593
|
-
// Note: Even though BigInt.toString(2) includes the negative sign for
|
|
23594
|
-
// negative values (???), the following is still accurate, because the
|
|
23595
|
-
// negative sign would be represented by a sign bit.
|
|
23596
|
-
var bitlen = bigI.toString(2).length;
|
|
23597
|
-
return (_find = [64, 128, 256].find(function (len) {
|
|
23598
|
-
return bitlen <= len;
|
|
23599
|
-
})) !== null && _find !== void 0 ? _find : bitlen;
|
|
23600
|
-
}
|
|
23601
|
-
;// ./src/numbers/index.js
|
|
23602
|
-
|
|
23603
|
-
|
|
23604
|
-
|
|
23605
|
-
|
|
23606
|
-
|
|
23607
|
-
|
|
23608
|
-
|
|
23609
|
-
|
|
23610
|
-
/**
|
|
23611
|
-
* Transforms an opaque {@link xdr.ScVal} into a native bigint, if possible.
|
|
23612
|
-
*
|
|
23613
|
-
* If you then want to use this in the abstractions provided by this module,
|
|
23614
|
-
* you can pass it to the constructor of {@link XdrLargeInt}.
|
|
23615
|
-
*
|
|
23616
|
-
* @example
|
|
23617
|
-
* let scv = contract.call("add", x, y); // assume it returns an xdr.ScVal
|
|
23618
|
-
* let bigi = scValToBigInt(scv);
|
|
23619
|
-
*
|
|
23620
|
-
* new ScInt(bigi); // if you don't care about types, and
|
|
23621
|
-
* new XdrLargeInt('i128', bigi); // if you do
|
|
23622
|
-
*
|
|
23623
|
-
* @param {xdr.ScVal} scv - the raw XDR value to parse into an integer
|
|
23624
|
-
* @returns {bigint} the native value of this input value
|
|
23625
|
-
*
|
|
23626
|
-
* @throws {TypeError} if the `scv` input value doesn't represent an integer
|
|
23627
|
-
*/
|
|
23628
|
-
function scValToBigInt(scv) {
|
|
23629
|
-
var scIntType = XdrLargeInt.getType(scv["switch"]().name);
|
|
23630
|
-
switch (scv["switch"]().name) {
|
|
23631
|
-
case 'scvU32':
|
|
23632
|
-
case 'scvI32':
|
|
23633
|
-
return BigInt(scv.value());
|
|
23634
|
-
case 'scvU64':
|
|
23635
|
-
case 'scvI64':
|
|
23636
|
-
case 'scvTimepoint':
|
|
23637
|
-
case 'scvDuration':
|
|
23638
|
-
return new XdrLargeInt(scIntType, scv.value()).toBigInt();
|
|
23639
|
-
case 'scvU128':
|
|
23640
|
-
case 'scvI128':
|
|
23641
|
-
return new XdrLargeInt(scIntType, [scv.value().lo(), scv.value().hi()]).toBigInt();
|
|
23642
|
-
case 'scvU256':
|
|
23643
|
-
case 'scvI256':
|
|
23644
|
-
return new XdrLargeInt(scIntType, [scv.value().loLo(), scv.value().loHi(), scv.value().hiLo(), scv.value().hiHi()]).toBigInt();
|
|
23645
|
-
default:
|
|
23646
|
-
throw TypeError("expected integer type, got ".concat(scv["switch"]()));
|
|
23647
|
-
}
|
|
23648
|
-
}
|
|
23649
|
-
;// ./src/scval.js
|
|
23650
|
-
/* provided dependency */ var scval_Buffer = __webpack_require__(8287)["Buffer"];
|
|
23651
|
-
function scval_slicedToArray(r, e) { return scval_arrayWithHoles(r) || scval_iterableToArrayLimit(r, e) || scval_unsupportedIterableToArray(r, e) || scval_nonIterableRest(); }
|
|
23652
|
-
function scval_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23653
|
-
function scval_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return scval_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? scval_arrayLikeToArray(r, a) : void 0; } }
|
|
23654
|
-
function scval_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
23655
|
-
function scval_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
23656
|
-
function scval_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
23657
|
-
function scval_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
23658
|
-
function scval_objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? scval_ownKeys(Object(t), !0).forEach(function (r) { scval_defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : scval_ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23659
|
-
function scval_defineProperty(e, r, t) { return (r = scval_toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
23660
|
-
function scval_toPropertyKey(t) { var i = scval_toPrimitive(t, "string"); return "symbol" == scval_typeof(i) ? i : i + ""; }
|
|
23661
|
-
function scval_toPrimitive(t, r) { if ("object" != scval_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != scval_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23662
|
-
function scval_typeof(o) { "@babel/helpers - typeof"; return scval_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, scval_typeof(o); }
|
|
23663
|
-
|
|
23664
|
-
|
|
23665
|
-
|
|
23666
23696
|
|
|
23697
|
+
/**
|
|
23698
|
+
* Set network nassphrase for the Transaction that will be built.
|
|
23699
|
+
*
|
|
23700
|
+
* @param {string} networkPassphrase passphrase of the target Stellar
|
|
23701
|
+
* network (e.g. "Public Global Stellar Network ; September 2015").
|
|
23702
|
+
*
|
|
23703
|
+
* @returns {TransactionBuilder}
|
|
23704
|
+
*/
|
|
23705
|
+
}, {
|
|
23706
|
+
key: "setNetworkPassphrase",
|
|
23707
|
+
value: function setNetworkPassphrase(networkPassphrase) {
|
|
23708
|
+
this.networkPassphrase = networkPassphrase;
|
|
23709
|
+
return this;
|
|
23710
|
+
}
|
|
23667
23711
|
|
|
23712
|
+
/**
|
|
23713
|
+
* Sets the transaction's internal Soroban transaction data (resources,
|
|
23714
|
+
* footprint, etc.).
|
|
23715
|
+
*
|
|
23716
|
+
* For non-contract(non-Soroban) transactions, this setting has no effect. In
|
|
23717
|
+
* the case of Soroban transactions, this is either an instance of
|
|
23718
|
+
* {@link xdr.SorobanTransactionData} or a base64-encoded string of said
|
|
23719
|
+
* structure. This is usually obtained from the simulation response based on a
|
|
23720
|
+
* transaction with a Soroban operation (e.g.
|
|
23721
|
+
* {@link Operation.invokeHostFunction}, providing necessary resource
|
|
23722
|
+
* and storage footprint estimations for contract invocation.
|
|
23723
|
+
*
|
|
23724
|
+
* @param {xdr.SorobanTransactionData | string} sorobanData the
|
|
23725
|
+
* {@link xdr.SorobanTransactionData} as a raw xdr object or a base64
|
|
23726
|
+
* string to be decoded
|
|
23727
|
+
*
|
|
23728
|
+
* @returns {TransactionBuilder}
|
|
23729
|
+
* @see {SorobanDataBuilder}
|
|
23730
|
+
*/
|
|
23731
|
+
}, {
|
|
23732
|
+
key: "setSorobanData",
|
|
23733
|
+
value: function setSorobanData(sorobanData) {
|
|
23734
|
+
this.sorobanData = new SorobanDataBuilder(sorobanData).build();
|
|
23735
|
+
return this;
|
|
23736
|
+
}
|
|
23668
23737
|
|
|
23669
|
-
/**
|
|
23670
|
-
|
|
23671
|
-
|
|
23672
|
-
|
|
23673
|
-
|
|
23674
|
-
|
|
23675
|
-
|
|
23676
|
-
|
|
23677
|
-
|
|
23678
|
-
|
|
23679
|
-
|
|
23680
|
-
|
|
23681
|
-
|
|
23682
|
-
|
|
23683
|
-
|
|
23684
|
-
|
|
23685
|
-
|
|
23686
|
-
|
|
23687
|
-
|
|
23688
|
-
|
|
23689
|
-
|
|
23690
|
-
|
|
23691
|
-
|
|
23692
|
-
|
|
23693
|
-
|
|
23694
|
-
|
|
23695
|
-
|
|
23696
|
-
|
|
23697
|
-
|
|
23698
|
-
* type which will force a particular interpretation of that value.
|
|
23699
|
-
*
|
|
23700
|
-
* Note that not all type specifications are compatible with all `ScVal`s, e.g.
|
|
23701
|
-
* `toScVal("a string", {type: "i256"})` will throw.
|
|
23702
|
-
*
|
|
23703
|
-
* @param {any} val - a native (or convertible) input value to wrap
|
|
23704
|
-
* @param {object} [opts] - an optional set of hints around the type of
|
|
23705
|
-
* conversion you'd like to see
|
|
23706
|
-
* @param {string} [opts.type] - there is different behavior for different input
|
|
23707
|
-
* types for `val`:
|
|
23708
|
-
*
|
|
23709
|
-
* - when `val` is an integer-like type (i.e. number|bigint), this will be
|
|
23710
|
-
* forwarded to {@link ScInt} or forced to be u32/i32.
|
|
23711
|
-
*
|
|
23712
|
-
* - when `val` is an array type, this is forwarded to the recursion
|
|
23713
|
-
*
|
|
23714
|
-
* - when `val` is an object type (key-value entries), this should be an
|
|
23715
|
-
* object in which each key has a pair of types (to represent forced types
|
|
23716
|
-
* for the key and the value), where `null` (or a missing entry) indicates
|
|
23717
|
-
* the default interpretation(s) (refer to the examples, below)
|
|
23718
|
-
*
|
|
23719
|
-
* - when `val` is a string type, this can be 'string' or 'symbol' to force
|
|
23720
|
-
* a particular interpretation of `val`.
|
|
23721
|
-
*
|
|
23722
|
-
* - when `val` is a bytes-like type, this can be 'string', 'symbol', or
|
|
23723
|
-
* 'bytes' to force a particular interpretation
|
|
23724
|
-
*
|
|
23725
|
-
* As a simple example, `nativeToScVal("hello", {type: 'symbol'})` will
|
|
23726
|
-
* return an `scvSymbol`, whereas without the type it would have been an
|
|
23727
|
-
* `scvString`.
|
|
23728
|
-
*
|
|
23729
|
-
* @returns {xdr.ScVal} a wrapped, smart, XDR version of the input value
|
|
23730
|
-
* @throws {TypeError} if...
|
|
23731
|
-
* - there are arrays with more than one type in them
|
|
23732
|
-
* - there are values that do not have a sensible conversion (e.g. random XDR
|
|
23733
|
-
* types, custom classes)
|
|
23734
|
-
* - the type of the input object (or some inner value of said object) cannot
|
|
23735
|
-
* be determined (via `typeof`)
|
|
23736
|
-
* - the type you specified (via `opts.type`) is incompatible with the value
|
|
23737
|
-
* you passed in (`val`), e.g. `nativeToScVal("a string", { type: 'i128' })`,
|
|
23738
|
-
* though this does not apply for types that ignore `opts` (e.g. addresses).
|
|
23739
|
-
* @see scValToNative
|
|
23740
|
-
*
|
|
23741
|
-
* @example
|
|
23742
|
-
* nativeToScVal(1000); // gives ScValType === scvU64
|
|
23743
|
-
* nativeToScVal(1000n); // gives ScValType === scvU64
|
|
23744
|
-
* nativeToScVal(1n << 100n); // gives ScValType === scvU128
|
|
23745
|
-
* nativeToScVal(1000, { type: 'u32' }); // gives ScValType === scvU32
|
|
23746
|
-
* nativeToScVal(1000, { type: 'i125' }); // gives ScValType === scvI256
|
|
23747
|
-
* nativeToScVal("a string"); // gives ScValType === scvString
|
|
23748
|
-
* nativeToScVal("a string", { type: 'symbol' }); // gives scvSymbol
|
|
23749
|
-
* nativeToScVal(new Uint8Array(5)); // scvBytes
|
|
23750
|
-
* nativeToScVal(new Uint8Array(5), { type: 'symbol' }); // scvSymbol
|
|
23751
|
-
* nativeToScVal(null); // scvVoid
|
|
23752
|
-
* nativeToScVal(true); // scvBool
|
|
23753
|
-
* nativeToScVal([1, 2, 3]); // gives scvVec with each element as scvU64
|
|
23754
|
-
* nativeToScVal([1, 2, 3], { type: 'i128' }); // scvVec<scvI128>
|
|
23755
|
-
* nativeToScVal([1, '2'], { type: ['i128', 'symbol'] }); // scvVec with diff types
|
|
23756
|
-
* nativeToScVal([1, '2', 3], { type: ['i128', 'symbol'] });
|
|
23757
|
-
* // scvVec with diff types, using the default when omitted
|
|
23758
|
-
* nativeToScVal({ 'hello': 1, 'world': [ true, false ] }, {
|
|
23759
|
-
* type: {
|
|
23760
|
-
* 'hello': [ 'symbol', 'i128' ],
|
|
23761
|
-
* }
|
|
23762
|
-
* })
|
|
23763
|
-
* // gives scvMap with entries: [
|
|
23764
|
-
* // [ scvSymbol, scvI128 ],
|
|
23765
|
-
* // [ scvString, scvArray<scvBool> ]
|
|
23766
|
-
* // ]
|
|
23767
|
-
*
|
|
23768
|
-
* @example
|
|
23769
|
-
* import {
|
|
23770
|
-
* nativeToScVal,
|
|
23771
|
-
* scValToNative,
|
|
23772
|
-
* ScInt,
|
|
23773
|
-
* xdr
|
|
23774
|
-
* } from '@stellar/stellar-base';
|
|
23775
|
-
*
|
|
23776
|
-
* let gigaMap = {
|
|
23777
|
-
* bool: true,
|
|
23778
|
-
* void: null,
|
|
23779
|
-
* u32: xdr.ScVal.scvU32(1),
|
|
23780
|
-
* i32: xdr.ScVal.scvI32(1),
|
|
23781
|
-
* u64: 1n,
|
|
23782
|
-
* i64: -1n,
|
|
23783
|
-
* u128: new ScInt(1).toU128(),
|
|
23784
|
-
* i128: new ScInt(1).toI128(),
|
|
23785
|
-
* u256: new ScInt(1).toU256(),
|
|
23786
|
-
* i256: new ScInt(1).toI256(),
|
|
23787
|
-
* map: {
|
|
23788
|
-
* arbitrary: 1n,
|
|
23789
|
-
* nested: 'values',
|
|
23790
|
-
* etc: false
|
|
23791
|
-
* },
|
|
23792
|
-
* vec: ['same', 'type', 'list'],
|
|
23793
|
-
* vec: ['diff', 1, 'type', 2, 'list'],
|
|
23794
|
-
* };
|
|
23795
|
-
*
|
|
23796
|
-
* // then, simply:
|
|
23797
|
-
* let scv = nativeToScVal(gigaMap); // scv.switch() == xdr.ScValType.scvMap()
|
|
23798
|
-
*
|
|
23799
|
-
* // then...
|
|
23800
|
-
* someContract.call("method", scv);
|
|
23801
|
-
*
|
|
23802
|
-
* // Similarly, the inverse should work:
|
|
23803
|
-
* scValToNative(scv) == gigaMap; // true
|
|
23804
|
-
*/
|
|
23805
|
-
function nativeToScVal(val) {
|
|
23806
|
-
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23807
|
-
switch (scval_typeof(val)) {
|
|
23808
|
-
case 'object':
|
|
23809
|
-
{
|
|
23810
|
-
var _val$constructor$name, _val$constructor;
|
|
23811
|
-
if (val === null) {
|
|
23812
|
-
return src_xdr.ScVal.scvVoid();
|
|
23813
|
-
}
|
|
23814
|
-
if (val instanceof src_xdr.ScVal) {
|
|
23815
|
-
return val; // should we copy?
|
|
23738
|
+
/**
|
|
23739
|
+
* Creates and adds an invoke host function operation for transferring SAC tokens.
|
|
23740
|
+
* This method removes the need for simulation by handling the creation of the
|
|
23741
|
+
* appropriate authorization entries and ledger footprint for the transfer operation.
|
|
23742
|
+
*
|
|
23743
|
+
* @param {string} destination - the address of the recipient of the SAC transfer (should be a valid Stellar address or contract ID)
|
|
23744
|
+
* @param {Asset} asset - the SAC asset to be transferred
|
|
23745
|
+
* @param {BigInt} amount - the amount of tokens to be transferred in 7 decimals. IE 1 token with 7 decimals of precision would be represented as "1_0000000"
|
|
23746
|
+
* @param {SorobanFees} [sorobanFees] - optional Soroban fees for the transaction to override the default fees used
|
|
23747
|
+
*
|
|
23748
|
+
* @returns {TransactionBuilder}
|
|
23749
|
+
*/
|
|
23750
|
+
}, {
|
|
23751
|
+
key: "addSacTransferOperation",
|
|
23752
|
+
value: function addSacTransferOperation(destination, asset, amount, sorobanFees) {
|
|
23753
|
+
if (BigInt(amount) <= 0n) {
|
|
23754
|
+
throw new Error('Amount must be a positive integer');
|
|
23755
|
+
} else if (BigInt(amount) > xdr.Hyper.MAX_VALUE) {
|
|
23756
|
+
// The largest supported value for SAC is i64 however the contract interface uses i128 which is why we convert it to i128
|
|
23757
|
+
throw new Error('Amount exceeds maximum value for i64');
|
|
23758
|
+
}
|
|
23759
|
+
if (sorobanFees) {
|
|
23760
|
+
var instructions = sorobanFees.instructions,
|
|
23761
|
+
readBytes = sorobanFees.readBytes,
|
|
23762
|
+
writeBytes = sorobanFees.writeBytes,
|
|
23763
|
+
resourceFee = sorobanFees.resourceFee;
|
|
23764
|
+
var U32_MAX = 4294967295;
|
|
23765
|
+
if (instructions <= 0 || instructions > U32_MAX) {
|
|
23766
|
+
throw new Error("instructions must be greater than 0 and at most ".concat(U32_MAX));
|
|
23816
23767
|
}
|
|
23817
|
-
if (
|
|
23818
|
-
|
|
23768
|
+
if (readBytes <= 0 || readBytes > U32_MAX) {
|
|
23769
|
+
throw new Error("readBytes must be greater than 0 and at most ".concat(U32_MAX));
|
|
23819
23770
|
}
|
|
23820
|
-
if (
|
|
23821
|
-
|
|
23822
|
-
type: 'address'
|
|
23823
|
-
});
|
|
23771
|
+
if (writeBytes <= 0 || writeBytes > U32_MAX) {
|
|
23772
|
+
throw new Error("writeBytes must be greater than 0 and at most ".concat(U32_MAX));
|
|
23824
23773
|
}
|
|
23825
|
-
if (
|
|
23826
|
-
|
|
23774
|
+
if (resourceFee <= 0n || resourceFee > xdr.Hyper.MAX_VALUE) {
|
|
23775
|
+
throw new Error('resourceFee must be greater than 0 and at most i64 max');
|
|
23827
23776
|
}
|
|
23828
|
-
|
|
23829
|
-
|
|
23830
|
-
|
|
23831
|
-
|
|
23832
|
-
|
|
23833
|
-
return src_xdr.ScVal.scvBytes(copy);
|
|
23834
|
-
case 'symbol':
|
|
23835
|
-
return src_xdr.ScVal.scvSymbol(copy);
|
|
23836
|
-
case 'string':
|
|
23837
|
-
return src_xdr.ScVal.scvString(copy);
|
|
23838
|
-
default:
|
|
23839
|
-
throw new TypeError("invalid type (".concat(opts.type, ") specified for bytes-like value"));
|
|
23840
|
-
}
|
|
23777
|
+
}
|
|
23778
|
+
var isDestinationContract = StrKey.isValidContract(destination);
|
|
23779
|
+
if (!isDestinationContract) {
|
|
23780
|
+
if (!StrKey.isValidEd25519PublicKey(destination) && !StrKey.isValidMed25519PublicKey(destination)) {
|
|
23781
|
+
throw new Error('Invalid destination address. Must be a valid Stellar address or contract ID.');
|
|
23841
23782
|
}
|
|
23842
|
-
|
|
23843
|
-
|
|
23844
|
-
|
|
23845
|
-
|
|
23846
|
-
|
|
23847
|
-
|
|
23848
|
-
|
|
23849
|
-
|
|
23850
|
-
|
|
23851
|
-
|
|
23852
|
-
|
|
23783
|
+
}
|
|
23784
|
+
if (destination === this.source.accountId()) {
|
|
23785
|
+
throw new Error('Destination cannot be the same as the source account.');
|
|
23786
|
+
}
|
|
23787
|
+
var contractId = asset.contractId(this.networkPassphrase);
|
|
23788
|
+
var functionName = 'transfer';
|
|
23789
|
+
var source = this.source.accountId();
|
|
23790
|
+
var args = [nativeToScVal(source, {
|
|
23791
|
+
type: 'address'
|
|
23792
|
+
}), nativeToScVal(destination, {
|
|
23793
|
+
type: 'address'
|
|
23794
|
+
}), nativeToScVal(amount, {
|
|
23795
|
+
type: 'i128'
|
|
23796
|
+
})];
|
|
23797
|
+
var isAssetNative = asset.isNative();
|
|
23798
|
+
var auths = new src_xdr.SorobanAuthorizationEntry({
|
|
23799
|
+
credentials: src_xdr.SorobanCredentials.sorobanCredentialsSourceAccount(),
|
|
23800
|
+
rootInvocation: new src_xdr.SorobanAuthorizedInvocation({
|
|
23801
|
+
"function": src_xdr.SorobanAuthorizedFunction.sorobanAuthorizedFunctionTypeContractFn(new src_xdr.InvokeContractArgs({
|
|
23802
|
+
contractAddress: Address.fromString(contractId).toScAddress(),
|
|
23803
|
+
functionName: functionName,
|
|
23804
|
+
args: args
|
|
23805
|
+
})),
|
|
23806
|
+
subInvocations: []
|
|
23807
|
+
})
|
|
23808
|
+
});
|
|
23809
|
+
var footprint = new src_xdr.LedgerFootprint({
|
|
23810
|
+
readOnly: [src_xdr.LedgerKey.contractData(new src_xdr.LedgerKeyContractData({
|
|
23811
|
+
contract: Address.fromString(contractId).toScAddress(),
|
|
23812
|
+
key: src_xdr.ScVal.scvLedgerKeyContractInstance(),
|
|
23813
|
+
durability: src_xdr.ContractDataDurability.persistent()
|
|
23814
|
+
}))],
|
|
23815
|
+
readWrite: []
|
|
23816
|
+
});
|
|
23853
23817
|
|
|
23854
|
-
|
|
23855
|
-
|
|
23856
|
-
|
|
23818
|
+
// Ledger entries for the destination account
|
|
23819
|
+
if (isDestinationContract) {
|
|
23820
|
+
footprint.readWrite().push(src_xdr.LedgerKey.contractData(new src_xdr.LedgerKeyContractData({
|
|
23821
|
+
contract: Address.fromString(contractId).toScAddress(),
|
|
23822
|
+
key: src_xdr.ScVal.scvVec([nativeToScVal('Balance', {
|
|
23823
|
+
type: 'symbol'
|
|
23824
|
+
}), nativeToScVal(destination, {
|
|
23825
|
+
type: 'address'
|
|
23826
|
+
})]),
|
|
23827
|
+
durability: src_xdr.ContractDataDurability.persistent()
|
|
23828
|
+
})));
|
|
23829
|
+
if (!isAssetNative) {
|
|
23830
|
+
footprint.readOnly().push(src_xdr.LedgerKey.account(new src_xdr.LedgerKeyAccount({
|
|
23831
|
+
accountId: Keypair.fromPublicKey(asset.getIssuer()).xdrPublicKey()
|
|
23832
|
+
})));
|
|
23857
23833
|
}
|
|
23858
|
-
|
|
23859
|
-
|
|
23860
|
-
|
|
23834
|
+
} else if (isAssetNative) {
|
|
23835
|
+
footprint.readWrite().push(src_xdr.LedgerKey.account(new src_xdr.LedgerKeyAccount({
|
|
23836
|
+
accountId: Keypair.fromPublicKey(destination).xdrPublicKey()
|
|
23837
|
+
})));
|
|
23838
|
+
} else if (asset.getIssuer() !== destination) {
|
|
23839
|
+
footprint.readWrite().push(src_xdr.LedgerKey.trustline(new src_xdr.LedgerKeyTrustLine({
|
|
23840
|
+
accountId: Keypair.fromPublicKey(destination).xdrPublicKey(),
|
|
23841
|
+
asset: asset.toTrustLineXDRObject()
|
|
23842
|
+
})));
|
|
23843
|
+
}
|
|
23844
|
+
|
|
23845
|
+
// Ledger entries for the source account
|
|
23846
|
+
if (asset.isNative()) {
|
|
23847
|
+
footprint.readWrite().push(src_xdr.LedgerKey.account(new src_xdr.LedgerKeyAccount({
|
|
23848
|
+
accountId: Keypair.fromPublicKey(source).xdrPublicKey()
|
|
23849
|
+
})));
|
|
23850
|
+
} else if (asset.getIssuer() !== source) {
|
|
23851
|
+
footprint.readWrite().push(src_xdr.LedgerKey.trustline(new src_xdr.LedgerKeyTrustLine({
|
|
23852
|
+
accountId: Keypair.fromPublicKey(source).xdrPublicKey(),
|
|
23853
|
+
asset: asset.toTrustLineXDRObject()
|
|
23854
|
+
})));
|
|
23855
|
+
}
|
|
23856
|
+
var defaultPaymentFees = {
|
|
23857
|
+
instructions: 400000,
|
|
23858
|
+
readBytes: 1000,
|
|
23859
|
+
writeBytes: 1000,
|
|
23860
|
+
resourceFee: BigInt(5000000)
|
|
23861
|
+
};
|
|
23862
|
+
var sorobanData = new src_xdr.SorobanTransactionData({
|
|
23863
|
+
resources: new src_xdr.SorobanResources({
|
|
23864
|
+
footprint: footprint,
|
|
23865
|
+
instructions: sorobanFees ? sorobanFees.instructions : defaultPaymentFees.instructions,
|
|
23866
|
+
diskReadBytes: sorobanFees ? sorobanFees.readBytes : defaultPaymentFees.readBytes,
|
|
23867
|
+
writeBytes: sorobanFees ? sorobanFees.writeBytes : defaultPaymentFees.writeBytes
|
|
23868
|
+
}),
|
|
23869
|
+
ext: new src_xdr.SorobanTransactionDataExt(0),
|
|
23870
|
+
resourceFee: new src_xdr.Int64(sorobanFees ? sorobanFees.resourceFee : defaultPaymentFees.resourceFee)
|
|
23871
|
+
});
|
|
23872
|
+
var operation = Operation.invokeContractFunction({
|
|
23873
|
+
contract: contractId,
|
|
23874
|
+
"function": functionName,
|
|
23875
|
+
args: args,
|
|
23876
|
+
auth: [auths]
|
|
23877
|
+
});
|
|
23878
|
+
this.setSorobanData(sorobanData);
|
|
23879
|
+
return this.addOperation(operation);
|
|
23880
|
+
}
|
|
23881
|
+
|
|
23882
|
+
/**
|
|
23883
|
+
* This will build the transaction.
|
|
23884
|
+
* It will also increment the source account's sequence number by 1.
|
|
23885
|
+
* @returns {Transaction} This method will return the built {@link Transaction}.
|
|
23886
|
+
*/
|
|
23887
|
+
}, {
|
|
23888
|
+
key: "build",
|
|
23889
|
+
value: function build() {
|
|
23890
|
+
var sequenceNumber = new util_bignumber(this.source.sequenceNumber()).plus(1);
|
|
23891
|
+
var fee = new util_bignumber(this.baseFee).times(this.operations.length).toNumber();
|
|
23892
|
+
var attrs = {
|
|
23893
|
+
fee: fee,
|
|
23894
|
+
seqNum: src_xdr.SequenceNumber.fromString(sequenceNumber.toString()),
|
|
23895
|
+
memo: this.memo ? this.memo.toXDRObject() : null
|
|
23896
|
+
};
|
|
23897
|
+
if (this.timebounds === null || typeof this.timebounds.minTime === 'undefined' || typeof this.timebounds.maxTime === 'undefined') {
|
|
23898
|
+
throw new Error('TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).');
|
|
23899
|
+
}
|
|
23900
|
+
if (isValidDate(this.timebounds.minTime)) {
|
|
23901
|
+
this.timebounds.minTime = this.timebounds.minTime.getTime() / 1000;
|
|
23902
|
+
}
|
|
23903
|
+
if (isValidDate(this.timebounds.maxTime)) {
|
|
23904
|
+
this.timebounds.maxTime = this.timebounds.maxTime.getTime() / 1000;
|
|
23905
|
+
}
|
|
23906
|
+
this.timebounds.minTime = xdr.UnsignedHyper.fromString(this.timebounds.minTime.toString());
|
|
23907
|
+
this.timebounds.maxTime = xdr.UnsignedHyper.fromString(this.timebounds.maxTime.toString());
|
|
23908
|
+
var timeBounds = new src_xdr.TimeBounds(this.timebounds);
|
|
23909
|
+
if (this.hasV2Preconditions()) {
|
|
23910
|
+
var ledgerBounds = null;
|
|
23911
|
+
if (this.ledgerbounds !== null) {
|
|
23912
|
+
ledgerBounds = new src_xdr.LedgerBounds(this.ledgerbounds);
|
|
23861
23913
|
}
|
|
23862
|
-
|
|
23863
|
-
|
|
23864
|
-
|
|
23865
|
-
|
|
23866
|
-
.
|
|
23867
|
-
|
|
23868
|
-
|
|
23869
|
-
|
|
23870
|
-
|
|
23871
|
-
|
|
23872
|
-
|
|
23873
|
-
|
|
23874
|
-
var _ref6 = scval_slicedToArray(_ref5, 2),
|
|
23875
|
-
k = _ref6[0],
|
|
23876
|
-
v = _ref6[1];
|
|
23877
|
-
// the type can be specified with an entry for the key and the value,
|
|
23878
|
-
// e.g. val = { 'hello': 1 } and opts.type = { hello: [ 'symbol',
|
|
23879
|
-
// 'u128' ]} or you can use `null` for the default interpretation
|
|
23880
|
-
var _ref7 = (_k = ((_opts$type2 = opts === null || opts === void 0 ? void 0 : opts.type) !== null && _opts$type2 !== void 0 ? _opts$type2 : {})[k]) !== null && _k !== void 0 ? _k : [null, null],
|
|
23881
|
-
_ref8 = scval_slicedToArray(_ref7, 2),
|
|
23882
|
-
keyType = _ref8[0],
|
|
23883
|
-
valType = _ref8[1];
|
|
23884
|
-
var keyOpts = keyType ? {
|
|
23885
|
-
type: keyType
|
|
23886
|
-
} : {};
|
|
23887
|
-
var valOpts = valType ? {
|
|
23888
|
-
type: valType
|
|
23889
|
-
} : {};
|
|
23890
|
-
return new src_xdr.ScMapEntry({
|
|
23891
|
-
key: nativeToScVal(k, keyOpts),
|
|
23892
|
-
val: nativeToScVal(v, valOpts)
|
|
23893
|
-
});
|
|
23914
|
+
var minSeqNum = this.minAccountSequence || '0';
|
|
23915
|
+
minSeqNum = src_xdr.SequenceNumber.fromString(minSeqNum);
|
|
23916
|
+
var minSeqAge = xdr.UnsignedHyper.fromString(this.minAccountSequenceAge !== null ? this.minAccountSequenceAge.toString() : '0');
|
|
23917
|
+
var minSeqLedgerGap = this.minAccountSequenceLedgerGap || 0;
|
|
23918
|
+
var extraSigners = this.extraSigners !== null ? this.extraSigners.map(SignerKey.decodeAddress) : [];
|
|
23919
|
+
attrs.cond = src_xdr.Preconditions.precondV2(new src_xdr.PreconditionsV2({
|
|
23920
|
+
timeBounds: timeBounds,
|
|
23921
|
+
ledgerBounds: ledgerBounds,
|
|
23922
|
+
minSeqNum: minSeqNum,
|
|
23923
|
+
minSeqAge: minSeqAge,
|
|
23924
|
+
minSeqLedgerGap: minSeqLedgerGap,
|
|
23925
|
+
extraSigners: extraSigners
|
|
23894
23926
|
}));
|
|
23927
|
+
} else {
|
|
23928
|
+
attrs.cond = src_xdr.Preconditions.precondTime(timeBounds);
|
|
23895
23929
|
}
|
|
23896
|
-
|
|
23897
|
-
|
|
23898
|
-
|
|
23899
|
-
|
|
23900
|
-
|
|
23901
|
-
|
|
23902
|
-
|
|
23930
|
+
attrs.sourceAccount = decodeAddressToMuxedAccount(this.source.accountId());
|
|
23931
|
+
|
|
23932
|
+
// TODO - remove this workaround for TransactionExt ts constructor
|
|
23933
|
+
// and use the typescript generated static factory method once fixed
|
|
23934
|
+
// https://github.com/stellar/dts-xdr/issues/5
|
|
23935
|
+
if (this.sorobanData) {
|
|
23936
|
+
// @ts-ignore
|
|
23937
|
+
attrs.ext = new src_xdr.TransactionExt(1, this.sorobanData);
|
|
23938
|
+
// Soroban transactions pay the resource fee in addition to the regular fee, so we need to add it here.
|
|
23939
|
+
attrs.fee = new util_bignumber(attrs.fee).plus(this.sorobanData.resourceFee()).toNumber();
|
|
23940
|
+
} else {
|
|
23941
|
+
// @ts-ignore
|
|
23942
|
+
attrs.ext = new src_xdr.TransactionExt(0, src_xdr.Void);
|
|
23943
|
+
}
|
|
23944
|
+
var xtx = new src_xdr.Transaction(attrs);
|
|
23945
|
+
xtx.operations(this.operations);
|
|
23946
|
+
var txEnvelope = new src_xdr.TransactionEnvelope.envelopeTypeTx(new src_xdr.TransactionV1Envelope({
|
|
23947
|
+
tx: xtx
|
|
23948
|
+
}));
|
|
23949
|
+
var tx = new Transaction(txEnvelope, this.networkPassphrase);
|
|
23950
|
+
this.source.incrementSequenceNumber();
|
|
23951
|
+
return tx;
|
|
23952
|
+
}
|
|
23953
|
+
}, {
|
|
23954
|
+
key: "hasV2Preconditions",
|
|
23955
|
+
value: function hasV2Preconditions() {
|
|
23956
|
+
return this.ledgerbounds !== null || this.minAccountSequence !== null || this.minAccountSequenceAge !== null || this.minAccountSequenceLedgerGap !== null || this.extraSigners !== null && this.extraSigners.length > 0;
|
|
23957
|
+
}
|
|
23958
|
+
|
|
23959
|
+
/**
|
|
23960
|
+
* Builds a {@link FeeBumpTransaction}, enabling you to resubmit an existing
|
|
23961
|
+
* transaction with a higher fee.
|
|
23962
|
+
*
|
|
23963
|
+
* @param {Keypair|string} feeSource - account paying for the transaction,
|
|
23964
|
+
* in the form of either a Keypair (only the public key is used) or
|
|
23965
|
+
* an account ID (in G... or M... form, but refer to `withMuxing`)
|
|
23966
|
+
* @param {string} baseFee - max fee willing to pay per operation
|
|
23967
|
+
* in inner transaction (**in stroops**)
|
|
23968
|
+
* @param {Transaction} innerTx - {@link Transaction} to be bumped by
|
|
23969
|
+
* the fee bump transaction
|
|
23970
|
+
* @param {string} networkPassphrase - passphrase of the target
|
|
23971
|
+
* Stellar network (e.g. "Public Global Stellar Network ; September 2015",
|
|
23972
|
+
* see {@link Networks})
|
|
23973
|
+
*
|
|
23974
|
+
* @todo Alongside the next major version bump, this type signature can be
|
|
23975
|
+
* changed to be less awkward: accept a MuxedAccount as the `feeSource`
|
|
23976
|
+
* rather than a keypair or string.
|
|
23977
|
+
*
|
|
23978
|
+
* @note Your fee-bump amount should be >= 10x the original fee.
|
|
23979
|
+
* @see https://developers.stellar.org/docs/glossary/fee-bumps/#replace-by-fee
|
|
23980
|
+
*
|
|
23981
|
+
* @returns {FeeBumpTransaction}
|
|
23982
|
+
*/
|
|
23983
|
+
}], [{
|
|
23984
|
+
key: "cloneFrom",
|
|
23985
|
+
value: function cloneFrom(tx) {
|
|
23986
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23987
|
+
if (!(tx instanceof Transaction)) {
|
|
23988
|
+
throw new TypeError("expected a 'Transaction', got: ".concat(tx));
|
|
23989
|
+
}
|
|
23990
|
+
var sequenceNum = (BigInt(tx.sequence) - 1n).toString();
|
|
23991
|
+
var source;
|
|
23992
|
+
// rebuild the source account based on the strkey
|
|
23993
|
+
if (StrKey.isValidMed25519PublicKey(tx.source)) {
|
|
23994
|
+
source = MuxedAccount.fromAddress(tx.source, sequenceNum);
|
|
23995
|
+
} else if (StrKey.isValidEd25519PublicKey(tx.source)) {
|
|
23996
|
+
source = new Account(tx.source, sequenceNum);
|
|
23997
|
+
} else {
|
|
23998
|
+
throw new TypeError("unsupported tx source account: ".concat(tx.source));
|
|
23999
|
+
}
|
|
24000
|
+
|
|
24001
|
+
// the initial fee passed to the builder gets scaled up based on the number
|
|
24002
|
+
// of operations at the end, so we have to down-scale first
|
|
24003
|
+
var unscaledFee = parseInt(tx.fee, 10) / tx.operations.length;
|
|
24004
|
+
var builder = new TransactionBuilder(source, transaction_builder_objectSpread({
|
|
24005
|
+
fee: (unscaledFee || BASE_FEE).toString(),
|
|
24006
|
+
memo: tx.memo,
|
|
24007
|
+
networkPassphrase: tx.networkPassphrase,
|
|
24008
|
+
timebounds: tx.timeBounds,
|
|
24009
|
+
ledgerbounds: tx.ledgerBounds,
|
|
24010
|
+
minAccountSequence: tx.minAccountSequence,
|
|
24011
|
+
minAccountSequenceAge: tx.minAccountSequenceAge,
|
|
24012
|
+
minAccountSequenceLedgerGap: tx.minAccountSequenceLedgerGap,
|
|
24013
|
+
extraSigners: tx.extraSigners
|
|
24014
|
+
}, opts));
|
|
24015
|
+
tx._tx.operations().forEach(function (op) {
|
|
24016
|
+
return builder.addOperation(op);
|
|
24017
|
+
});
|
|
24018
|
+
return builder;
|
|
24019
|
+
}
|
|
24020
|
+
}, {
|
|
24021
|
+
key: "buildFeeBumpTransaction",
|
|
24022
|
+
value: function buildFeeBumpTransaction(feeSource, baseFee, innerTx, networkPassphrase) {
|
|
24023
|
+
var innerOps = innerTx.operations.length;
|
|
24024
|
+
var minBaseFee = new util_bignumber(BASE_FEE);
|
|
24025
|
+
var resourceFee = new util_bignumber(0);
|
|
24026
|
+
|
|
24027
|
+
// Do we need to do special Soroban fee handling? We only want the fee-bump
|
|
24028
|
+
// requirement to match the inclusion fee, not the inclusion+resource fee.
|
|
24029
|
+
var env = innerTx.toEnvelope();
|
|
24030
|
+
switch (env["switch"]().value) {
|
|
24031
|
+
case src_xdr.EnvelopeType.envelopeTypeTx().value:
|
|
24032
|
+
{
|
|
24033
|
+
var _sorobanData$resource;
|
|
24034
|
+
var sorobanData = env.v1().tx().ext().value();
|
|
24035
|
+
resourceFee = new util_bignumber((_sorobanData$resource = sorobanData === null || sorobanData === void 0 ? void 0 : sorobanData.resourceFee()) !== null && _sorobanData$resource !== void 0 ? _sorobanData$resource : 0);
|
|
24036
|
+
break;
|
|
24037
|
+
}
|
|
23903
24038
|
default:
|
|
23904
24039
|
break;
|
|
23905
24040
|
}
|
|
23906
|
-
|
|
23907
|
-
|
|
23908
|
-
|
|
23909
|
-
|
|
23910
|
-
{
|
|
23911
|
-
|
|
23912
|
-
|
|
23913
|
-
|
|
23914
|
-
|
|
23915
|
-
|
|
23916
|
-
|
|
23917
|
-
|
|
23918
|
-
|
|
23919
|
-
|
|
23920
|
-
|
|
23921
|
-
|
|
23922
|
-
|
|
23923
|
-
|
|
23924
|
-
|
|
23925
|
-
|
|
23926
|
-
|
|
23927
|
-
|
|
23928
|
-
|
|
23929
|
-
}
|
|
24041
|
+
var innerInclusionFee = new util_bignumber(innerTx.fee).minus(resourceFee).div(innerOps);
|
|
24042
|
+
var base = new util_bignumber(baseFee);
|
|
24043
|
+
|
|
24044
|
+
// The fee rate for fee bump is at least the fee rate of the inner transaction
|
|
24045
|
+
if (base.lt(innerInclusionFee)) {
|
|
24046
|
+
throw new Error("Invalid baseFee, it should be at least ".concat(innerInclusionFee, " stroops."));
|
|
24047
|
+
}
|
|
24048
|
+
|
|
24049
|
+
// The fee rate is at least the minimum fee
|
|
24050
|
+
if (base.lt(minBaseFee)) {
|
|
24051
|
+
throw new Error("Invalid baseFee, it should be at least ".concat(minBaseFee, " stroops."));
|
|
24052
|
+
}
|
|
24053
|
+
var innerTxEnvelope = innerTx.toEnvelope();
|
|
24054
|
+
if (innerTxEnvelope["switch"]() === src_xdr.EnvelopeType.envelopeTypeTxV0()) {
|
|
24055
|
+
var v0Tx = innerTxEnvelope.v0().tx();
|
|
24056
|
+
var v1Tx = new src_xdr.Transaction({
|
|
24057
|
+
sourceAccount: new src_xdr.MuxedAccount.keyTypeEd25519(v0Tx.sourceAccountEd25519()),
|
|
24058
|
+
fee: v0Tx.fee(),
|
|
24059
|
+
seqNum: v0Tx.seqNum(),
|
|
24060
|
+
cond: src_xdr.Preconditions.precondTime(v0Tx.timeBounds()),
|
|
24061
|
+
memo: v0Tx.memo(),
|
|
24062
|
+
operations: v0Tx.operations(),
|
|
24063
|
+
ext: new src_xdr.TransactionExt(0)
|
|
24064
|
+
});
|
|
24065
|
+
innerTxEnvelope = new src_xdr.TransactionEnvelope.envelopeTypeTx(new src_xdr.TransactionV1Envelope({
|
|
24066
|
+
tx: v1Tx,
|
|
24067
|
+
signatures: innerTxEnvelope.v0().signatures()
|
|
24068
|
+
}));
|
|
24069
|
+
}
|
|
24070
|
+
var feeSourceAccount;
|
|
24071
|
+
if (typeof feeSource === 'string') {
|
|
24072
|
+
feeSourceAccount = decodeAddressToMuxedAccount(feeSource);
|
|
24073
|
+
} else {
|
|
24074
|
+
feeSourceAccount = feeSource.xdrMuxedAccount();
|
|
24075
|
+
}
|
|
24076
|
+
var tx = new src_xdr.FeeBumpTransaction({
|
|
24077
|
+
feeSource: feeSourceAccount,
|
|
24078
|
+
fee: src_xdr.Int64.fromString(base.times(innerOps + 1).plus(resourceFee).toString()),
|
|
24079
|
+
innerTx: src_xdr.FeeBumpTransactionInnerTx.envelopeTypeTx(innerTxEnvelope.v1()),
|
|
24080
|
+
ext: new src_xdr.FeeBumpTransactionExt(0)
|
|
24081
|
+
});
|
|
24082
|
+
var feeBumpTxEnvelope = new src_xdr.FeeBumpTransactionEnvelope({
|
|
24083
|
+
tx: tx,
|
|
24084
|
+
signatures: []
|
|
24085
|
+
});
|
|
24086
|
+
var envelope = new src_xdr.TransactionEnvelope.envelopeTypeTxFeeBump(feeBumpTxEnvelope);
|
|
24087
|
+
return new FeeBumpTransaction(envelope, networkPassphrase);
|
|
24088
|
+
}
|
|
24089
|
+
|
|
24090
|
+
/**
|
|
24091
|
+
* Build a {@link Transaction} or {@link FeeBumpTransaction} from an
|
|
24092
|
+
* xdr.TransactionEnvelope.
|
|
24093
|
+
*
|
|
24094
|
+
* @param {string|xdr.TransactionEnvelope} envelope - The transaction envelope
|
|
24095
|
+
* object or base64 encoded string.
|
|
24096
|
+
* @param {string} networkPassphrase - The network passphrase of the target
|
|
24097
|
+
* Stellar network (e.g. "Public Global Stellar Network ; September
|
|
24098
|
+
* 2015"), see {@link Networks}.
|
|
24099
|
+
*
|
|
24100
|
+
* @returns {Transaction|FeeBumpTransaction}
|
|
24101
|
+
*/
|
|
24102
|
+
}, {
|
|
24103
|
+
key: "fromXDR",
|
|
24104
|
+
value: function fromXDR(envelope, networkPassphrase) {
|
|
24105
|
+
if (typeof envelope === 'string') {
|
|
24106
|
+
envelope = src_xdr.TransactionEnvelope.fromXDR(envelope, 'base64');
|
|
23930
24107
|
}
|
|
23931
|
-
|
|
23932
|
-
|
|
23933
|
-
|
|
23934
|
-
return
|
|
23935
|
-
|
|
23936
|
-
|
|
23937
|
-
|
|
23938
|
-
default:
|
|
23939
|
-
throw new TypeError("failed to convert typeof ".concat(scval_typeof(val), " (").concat(val, ")"));
|
|
23940
|
-
}
|
|
23941
|
-
}
|
|
24108
|
+
if (envelope["switch"]() === src_xdr.EnvelopeType.envelopeTypeTxFeeBump()) {
|
|
24109
|
+
return new FeeBumpTransaction(envelope, networkPassphrase);
|
|
24110
|
+
}
|
|
24111
|
+
return new Transaction(envelope, networkPassphrase);
|
|
24112
|
+
}
|
|
24113
|
+
}]);
|
|
24114
|
+
}();
|
|
23942
24115
|
|
|
23943
24116
|
/**
|
|
23944
|
-
*
|
|
23945
|
-
*
|
|
23946
|
-
*
|
|
23947
|
-
|
|
23948
|
-
|
|
23949
|
-
|
|
23950
|
-
|
|
23951
|
-
|
|
23952
|
-
|
|
23953
|
-
|
|
23954
|
-
|
|
23955
|
-
*
|
|
23956
|
-
*
|
|
23957
|
-
*
|
|
23958
|
-
*
|
|
23959
|
-
*
|
|
23960
|
-
*
|
|
23961
|
-
* @param {xdr.ScVal} scv - the input smart contract value
|
|
24117
|
+
* Checks whether a provided object is a valid Date.
|
|
24118
|
+
* @argument {Date} d date object
|
|
24119
|
+
* @returns {boolean}
|
|
24120
|
+
*/
|
|
24121
|
+
function isValidDate(d) {
|
|
24122
|
+
// isnan is okay here because it correctly checks for invalid date objects
|
|
24123
|
+
// eslint-disable-next-line no-restricted-globals
|
|
24124
|
+
return d instanceof Date && !isNaN(d);
|
|
24125
|
+
}
|
|
24126
|
+
;// ./src/network.js
|
|
24127
|
+
/**
|
|
24128
|
+
* Contains passphrases for common networks:
|
|
24129
|
+
* * `Networks.PUBLIC`: `Public Global Stellar Network ; September 2015`
|
|
24130
|
+
* * `Networks.TESTNET`: `Test SDF Network ; September 2015`
|
|
24131
|
+
* * `Networks.FUTURENET`: `Test SDF Future Network ; October 2022`
|
|
24132
|
+
* * `Networks.STANDALONE`: `Standalone Network ; February 2017`
|
|
23962
24133
|
*
|
|
23963
|
-
* @
|
|
23964
|
-
* @see nativeToScVal
|
|
24134
|
+
* @type {{PUBLIC: string, TESTNET: string, FUTURENET: string, STANDALONE: string }}
|
|
23965
24135
|
*/
|
|
23966
|
-
|
|
23967
|
-
|
|
23968
|
-
|
|
23969
|
-
|
|
23970
|
-
|
|
23971
|
-
|
|
23972
|
-
|
|
23973
|
-
|
|
23974
|
-
|
|
23975
|
-
|
|
23976
|
-
|
|
23977
|
-
|
|
23978
|
-
|
|
23979
|
-
|
|
23980
|
-
|
|
23981
|
-
|
|
23982
|
-
|
|
23983
|
-
|
|
23984
|
-
|
|
23985
|
-
|
|
23986
|
-
|
|
23987
|
-
|
|
23988
|
-
|
|
23989
|
-
|
|
23990
|
-
|
|
23991
|
-
|
|
23992
|
-
|
|
23993
|
-
|
|
23994
|
-
|
|
23995
|
-
|
|
23996
|
-
|
|
23997
|
-
|
|
23998
|
-
|
|
23999
|
-
|
|
24000
|
-
|
|
24001
|
-
|
|
24002
|
-
|
|
24003
|
-
|
|
24004
|
-
|
|
24005
|
-
|
|
24006
|
-
|
|
24007
|
-
|
|
24008
|
-
|
|
24009
|
-
|
|
24010
|
-
|
|
24011
|
-
|
|
24012
|
-
|
|
24013
|
-
|
|
24014
|
-
|
|
24015
|
-
|
|
24016
|
-
|
|
24017
|
-
if (
|
|
24018
|
-
|
|
24019
|
-
|
|
24020
|
-
|
|
24021
|
-
return new Uint8Array(v.buffer); // copy of bytes
|
|
24022
|
-
}
|
|
24136
|
+
var Networks = {
|
|
24137
|
+
PUBLIC: 'Public Global Stellar Network ; September 2015',
|
|
24138
|
+
TESTNET: 'Test SDF Network ; September 2015',
|
|
24139
|
+
FUTURENET: 'Test SDF Future Network ; October 2022',
|
|
24140
|
+
SANDBOX: 'Local Sandbox Stellar Network ; September 2022',
|
|
24141
|
+
STANDALONE: 'Standalone Network ; February 2017'
|
|
24142
|
+
};
|
|
24143
|
+
;// ./src/soroban.js
|
|
24144
|
+
function soroban_typeof(o) { "@babel/helpers - typeof"; return soroban_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, soroban_typeof(o); }
|
|
24145
|
+
function _toArray(r) { return soroban_arrayWithHoles(r) || soroban_iterableToArray(r) || soroban_unsupportedIterableToArray(r) || soroban_nonIterableRest(); }
|
|
24146
|
+
function soroban_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24147
|
+
function soroban_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return soroban_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? soroban_arrayLikeToArray(r, a) : void 0; } }
|
|
24148
|
+
function soroban_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
24149
|
+
function soroban_iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
24150
|
+
function soroban_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
24151
|
+
function soroban_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
24152
|
+
function soroban_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, soroban_toPropertyKey(o.key), o); } }
|
|
24153
|
+
function soroban_createClass(e, r, t) { return r && soroban_defineProperties(e.prototype, r), t && soroban_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
24154
|
+
function soroban_toPropertyKey(t) { var i = soroban_toPrimitive(t, "string"); return "symbol" == soroban_typeof(i) ? i : i + ""; }
|
|
24155
|
+
function soroban_toPrimitive(t, r) { if ("object" != soroban_typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != soroban_typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24156
|
+
/* Helper class to assist with formatting and parsing token amounts. */
|
|
24157
|
+
var Soroban = /*#__PURE__*/function () {
|
|
24158
|
+
function Soroban() {
|
|
24159
|
+
soroban_classCallCheck(this, Soroban);
|
|
24160
|
+
}
|
|
24161
|
+
return soroban_createClass(Soroban, null, [{
|
|
24162
|
+
key: "formatTokenAmount",
|
|
24163
|
+
value:
|
|
24164
|
+
/**
|
|
24165
|
+
* Given a whole number smart contract amount of a token and an amount of
|
|
24166
|
+
* decimal places (if the token has any), it returns a "display" value.
|
|
24167
|
+
*
|
|
24168
|
+
* All arithmetic inside the contract is performed on integers to avoid
|
|
24169
|
+
* potential precision and consistency issues of floating-point.
|
|
24170
|
+
*
|
|
24171
|
+
* @param {string} amount the token amount you want to display
|
|
24172
|
+
* @param {number} decimals specify how many decimal places a token has
|
|
24173
|
+
*
|
|
24174
|
+
* @returns {string} the display value
|
|
24175
|
+
* @throws {TypeError} if the given amount has a decimal point already
|
|
24176
|
+
* @example
|
|
24177
|
+
* formatTokenAmount("123000", 4) === "12.3";
|
|
24178
|
+
* formatTokenAmount("123000", 3) === "123.0";
|
|
24179
|
+
* formatTokenAmount("123", 3) === "0.123";
|
|
24180
|
+
*/
|
|
24181
|
+
function formatTokenAmount(amount, decimals) {
|
|
24182
|
+
if (amount.includes('.')) {
|
|
24183
|
+
throw new TypeError('No decimals are allowed');
|
|
24184
|
+
}
|
|
24185
|
+
var formatted = amount;
|
|
24186
|
+
if (decimals > 0) {
|
|
24187
|
+
if (decimals > formatted.length) {
|
|
24188
|
+
formatted = ['0', formatted.toString().padStart(decimals, '0')].join('.');
|
|
24189
|
+
} else {
|
|
24190
|
+
formatted = [formatted.slice(0, -decimals), formatted.slice(-decimals)].join('.');
|
|
24023
24191
|
}
|
|
24024
|
-
return v; // string already
|
|
24025
24192
|
}
|
|
24193
|
+
return formatted.replace(/(\.\d*?)0+$/, '$1') // strip trailing zeroes
|
|
24194
|
+
.replace(/\.$/, '.0') // but keep at least one
|
|
24195
|
+
.replace(/^\./, '0.'); // and a leading one
|
|
24196
|
+
}
|
|
24026
24197
|
|
|
24027
|
-
|
|
24028
|
-
|
|
24029
|
-
|
|
24030
|
-
|
|
24031
|
-
|
|
24032
|
-
|
|
24033
|
-
|
|
24034
|
-
|
|
24035
|
-
|
|
24036
|
-
|
|
24037
|
-
|
|
24038
|
-
|
|
24039
|
-
|
|
24040
|
-
|
|
24041
|
-
|
|
24042
|
-
|
|
24043
|
-
|
|
24044
|
-
|
|
24045
|
-
|
|
24046
|
-
|
|
24047
|
-
|
|
24198
|
+
/**
|
|
24199
|
+
* Parse a token amount to use it on smart contract
|
|
24200
|
+
*
|
|
24201
|
+
* This function takes the display value and its decimals (if the token has
|
|
24202
|
+
* any) and returns a string that'll be used within the smart contract.
|
|
24203
|
+
*
|
|
24204
|
+
* @param {string} value the token amount you want to use it on smart
|
|
24205
|
+
* contract which you've been displaying in a UI
|
|
24206
|
+
* @param {number} decimals the number of decimal places expected in the
|
|
24207
|
+
* display value (different than the "actual" number, because suffix zeroes
|
|
24208
|
+
* might not be present)
|
|
24209
|
+
*
|
|
24210
|
+
* @returns {string} the whole number token amount represented by the display
|
|
24211
|
+
* value with the decimal places shifted over
|
|
24212
|
+
*
|
|
24213
|
+
* @example
|
|
24214
|
+
* const displayValueAmount = "123.4560"
|
|
24215
|
+
* const parsedAmtForSmartContract = parseTokenAmount(displayValueAmount, 5);
|
|
24216
|
+
* parsedAmtForSmartContract === "12345600"
|
|
24217
|
+
*/
|
|
24218
|
+
}, {
|
|
24219
|
+
key: "parseTokenAmount",
|
|
24220
|
+
value: function parseTokenAmount(value, decimals) {
|
|
24221
|
+
var _fraction$padEnd;
|
|
24222
|
+
var _value$split$slice = value.split('.').slice(),
|
|
24223
|
+
_value$split$slice2 = _toArray(_value$split$slice),
|
|
24224
|
+
whole = _value$split$slice2[0],
|
|
24225
|
+
fraction = _value$split$slice2[1],
|
|
24226
|
+
rest = soroban_arrayLikeToArray(_value$split$slice2).slice(2);
|
|
24227
|
+
if (rest.length) {
|
|
24228
|
+
throw new Error("Invalid decimal value: ".concat(value));
|
|
24048
24229
|
}
|
|
24049
|
-
|
|
24050
|
-
|
|
24051
|
-
default:
|
|
24052
|
-
return scv.value();
|
|
24053
|
-
}
|
|
24054
|
-
}
|
|
24055
|
-
|
|
24056
|
-
/// Inject a sortable map builder into the xdr module.
|
|
24057
|
-
src_xdr.scvSortedMap = function (items) {
|
|
24058
|
-
var sorted = Array.from(items).sort(function (a, b) {
|
|
24059
|
-
// Both a and b are `ScMapEntry`s, so we need to sort by underlying key.
|
|
24060
|
-
//
|
|
24061
|
-
// We couldn't possibly handle every combination of keys since Soroban
|
|
24062
|
-
// maps don't enforce consistent types, so we do a best-effort and try
|
|
24063
|
-
// sorting by "number-like" or "string-like."
|
|
24064
|
-
var nativeA = scValToNative(a.key());
|
|
24065
|
-
var nativeB = scValToNative(b.key());
|
|
24066
|
-
switch (scval_typeof(nativeA)) {
|
|
24067
|
-
case 'number':
|
|
24068
|
-
case 'bigint':
|
|
24069
|
-
return nativeA < nativeB ? -1 : 1;
|
|
24070
|
-
default:
|
|
24071
|
-
return nativeA.toString().localeCompare(nativeB.toString());
|
|
24230
|
+
var shifted = BigInt(whole + ((_fraction$padEnd = fraction === null || fraction === void 0 ? void 0 : fraction.padEnd(decimals, '0')) !== null && _fraction$padEnd !== void 0 ? _fraction$padEnd : '0'.repeat(decimals)));
|
|
24231
|
+
return shifted.toString();
|
|
24072
24232
|
}
|
|
24073
|
-
});
|
|
24074
|
-
|
|
24075
|
-
};
|
|
24233
|
+
}]);
|
|
24234
|
+
}();
|
|
24076
24235
|
;// ./src/events.js
|
|
24077
24236
|
function events_typeof(o) { "@babel/helpers - typeof"; return events_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, events_typeof(o); }
|
|
24078
24237
|
function events_ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -24141,10 +24300,8 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
|
|
|
24141
24300
|
* whose hash you should sign, so that you can inspect the entire structure
|
|
24142
24301
|
* if necessary (rather than blindly signing a hash)
|
|
24143
24302
|
*
|
|
24144
|
-
* @returns {
|
|
24145
|
-
*
|
|
24146
|
-
* Promise<{signature: Uint8Array, publicKey: string}
|
|
24147
|
-
* } the signature of the raw payload (which is the sha256 hash of the preimage
|
|
24303
|
+
* @returns {Promise<Uint8Array | {signature: Uint8Array, publicKey: string}>}
|
|
24304
|
+
* the signature of the raw payload (which is the sha256 hash of the preimage
|
|
24148
24305
|
* bytes, so `hash(preimage.toXDR())`) either naked, implying it is signed
|
|
24149
24306
|
* by the key corresponding to the public key in the entry you pass to
|
|
24150
24307
|
* {@link authorizeEntry} (decipherable from its
|