@stellar/stellar-base 10.0.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/CHANGELOG.md +1262 -0
- package/LICENSE +202 -0
- package/README.md +198 -0
- package/dist/stellar-base.js +30777 -0
- package/dist/stellar-base.min.js +2 -0
- package/lib/account.js +80 -0
- package/lib/address.js +169 -0
- package/lib/asset.js +323 -0
- package/lib/auth.js +253 -0
- package/lib/claimant.js +193 -0
- package/lib/contract.js +113 -0
- package/lib/events.js +42 -0
- package/lib/fee_bump_transaction.js +134 -0
- package/lib/generated/curr_generated.js +8315 -0
- package/lib/generated/next_generated.js +8315 -0
- package/lib/get_liquidity_pool_id.js +57 -0
- package/lib/hashing.js +12 -0
- package/lib/index.js +385 -0
- package/lib/invocation.js +195 -0
- package/lib/keypair.js +308 -0
- package/lib/liquidity_pool_asset.js +126 -0
- package/lib/liquidity_pool_id.js +101 -0
- package/lib/memo.js +270 -0
- package/lib/muxed_account.js +159 -0
- package/lib/network.js +22 -0
- package/lib/numbers/index.js +85 -0
- package/lib/numbers/int128.js +50 -0
- package/lib/numbers/int256.js +50 -0
- package/lib/numbers/sc_int.js +134 -0
- package/lib/numbers/uint128.js +50 -0
- package/lib/numbers/uint256.js +50 -0
- package/lib/numbers/xdr_large_int.js +267 -0
- package/lib/operation.js +715 -0
- package/lib/operations/account_merge.js +32 -0
- package/lib/operations/allow_trust.js +57 -0
- package/lib/operations/begin_sponsoring_future_reserves.js +38 -0
- package/lib/operations/bump_sequence.js +37 -0
- package/lib/operations/change_trust.js +52 -0
- package/lib/operations/claim_claimable_balance.js +40 -0
- package/lib/operations/clawback.js +46 -0
- package/lib/operations/clawback_claimable_balance.js +39 -0
- package/lib/operations/create_account.js +37 -0
- package/lib/operations/create_claimable_balance.js +65 -0
- package/lib/operations/create_passive_sell_offer.js +44 -0
- package/lib/operations/end_sponsoring_future_reserves.js +27 -0
- package/lib/operations/extend_footprint_ttl.js +45 -0
- package/lib/operations/index.js +254 -0
- package/lib/operations/inflation.js +23 -0
- package/lib/operations/invoke_host_function.js +219 -0
- package/lib/operations/liquidity_pool_deposit.js +64 -0
- package/lib/operations/liquidity_pool_withdraw.js +50 -0
- package/lib/operations/manage_buy_offer.js +50 -0
- package/lib/operations/manage_data.js +41 -0
- package/lib/operations/manage_sell_offer.js +50 -0
- package/lib/operations/path_payment_strict_receive.js +68 -0
- package/lib/operations/path_payment_strict_send.js +68 -0
- package/lib/operations/payment.js +47 -0
- package/lib/operations/restore_footprint.js +38 -0
- package/lib/operations/revoke_sponsorship.js +301 -0
- package/lib/operations/set_options.js +135 -0
- package/lib/operations/set_trustline_flags.js +84 -0
- package/lib/scval.js +369 -0
- package/lib/signerkey.js +103 -0
- package/lib/signing.js +96 -0
- package/lib/soroban.js +96 -0
- package/lib/sorobandata_builder.js +218 -0
- package/lib/strkey.js +400 -0
- package/lib/transaction.js +369 -0
- package/lib/transaction_base.js +248 -0
- package/lib/transaction_builder.js +753 -0
- package/lib/util/checksum.js +20 -0
- package/lib/util/continued_fraction.js +58 -0
- package/lib/util/decode_encode_muxed_account.js +116 -0
- package/lib/util/util.js +14 -0
- package/lib/xdr.js +9 -0
- package/package.json +133 -0
- package/types/curr.d.ts +14078 -0
- package/types/index.d.ts +1270 -0
- package/types/next.d.ts +14078 -0
- package/types/xdr.d.ts +1 -0
|
@@ -0,0 +1,753 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TransactionBuilder = exports.TimeoutInfinite = exports.BASE_FEE = void 0;
|
|
7
|
+
exports.isValidDate = isValidDate;
|
|
8
|
+
var _jsXdr = require("@stellar/js-xdr");
|
|
9
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
10
|
+
var _xdr = _interopRequireDefault(require("./xdr"));
|
|
11
|
+
var _account = require("./account");
|
|
12
|
+
var _muxed_account = require("./muxed_account");
|
|
13
|
+
var _decode_encode_muxed_account = require("./util/decode_encode_muxed_account");
|
|
14
|
+
var _transaction = require("./transaction");
|
|
15
|
+
var _fee_bump_transaction = require("./fee_bump_transaction");
|
|
16
|
+
var _sorobandata_builder = require("./sorobandata_builder");
|
|
17
|
+
var _strkey = require("./strkey");
|
|
18
|
+
var _signerkey = require("./signerkey");
|
|
19
|
+
var _memo = require("./memo");
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
21
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _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; }, _typeof(o); }
|
|
22
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
23
|
+
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."); }
|
|
24
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
26
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
27
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
28
|
+
function 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; }
|
|
29
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
30
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
31
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
32
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
33
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
34
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
35
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
36
|
+
/**
|
|
37
|
+
* Minimum base fee for transactions. If this fee is below the network
|
|
38
|
+
* minimum, the transaction will fail. The more operations in the
|
|
39
|
+
* transaction, the greater the required fee. Use {@link
|
|
40
|
+
* Server#fetchBaseFee} to get an accurate value of minimum transaction
|
|
41
|
+
* fee on the network.
|
|
42
|
+
*
|
|
43
|
+
* @constant
|
|
44
|
+
* @see [Fees](https://developers.stellar.org/docs/glossary/fees/)
|
|
45
|
+
*/
|
|
46
|
+
var BASE_FEE = exports.BASE_FEE = '100'; // Stroops
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @constant
|
|
50
|
+
* @see {@link TransactionBuilder#setTimeout}
|
|
51
|
+
* @see [Timeout](https://developers.stellar.org/api/resources/transactions/post/)
|
|
52
|
+
*/
|
|
53
|
+
var TimeoutInfinite = exports.TimeoutInfinite = 0;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* <p>Transaction builder helps constructs a new `{@link Transaction}` using the
|
|
57
|
+
* given {@link Account} as the transaction's "source account". The transaction
|
|
58
|
+
* will use the current sequence number of the given account as its sequence
|
|
59
|
+
* number and increment the given account's sequence number by one. The given
|
|
60
|
+
* source account must include a private key for signing the transaction or an
|
|
61
|
+
* error will be thrown.</p>
|
|
62
|
+
*
|
|
63
|
+
* <p>Operations can be added to the transaction via their corresponding builder
|
|
64
|
+
* methods, and each returns the TransactionBuilder object so they can be
|
|
65
|
+
* chained together. After adding the desired operations, call the `build()`
|
|
66
|
+
* method on the `TransactionBuilder` to return a fully constructed `{@link
|
|
67
|
+
* Transaction}` that can be signed. The returned transaction will contain the
|
|
68
|
+
* sequence number of the source account and include the signature from the
|
|
69
|
+
* source account.</p>
|
|
70
|
+
*
|
|
71
|
+
* <p><strong>Be careful about unsubmitted transactions!</strong> When you build
|
|
72
|
+
* a transaction, stellar-sdk automatically increments the source account's
|
|
73
|
+
* sequence number. If you end up not submitting this transaction and submitting
|
|
74
|
+
* another one instead, it'll fail due to the sequence number being wrong. So if
|
|
75
|
+
* you decide not to use a built transaction, make sure to update the source
|
|
76
|
+
* account's sequence number with
|
|
77
|
+
* [Server.loadAccount](https://stellar.github.io/js-stellar-sdk/Server.html#loadAccount)
|
|
78
|
+
* before creating another transaction.</p>
|
|
79
|
+
*
|
|
80
|
+
* <p>The following code example creates a new transaction with {@link
|
|
81
|
+
* Operation.createAccount} and {@link Operation.payment} operations. The
|
|
82
|
+
* Transaction's source account first funds `destinationA`, then sends a payment
|
|
83
|
+
* to `destinationB`. The built transaction is then signed by
|
|
84
|
+
* `sourceKeypair`.</p>
|
|
85
|
+
*
|
|
86
|
+
* ```
|
|
87
|
+
* var transaction = new TransactionBuilder(source, { fee, networkPassphrase: Networks.TESTNET })
|
|
88
|
+
* .addOperation(Operation.createAccount({
|
|
89
|
+
* destination: destinationA,
|
|
90
|
+
* startingBalance: "20"
|
|
91
|
+
* })) // <- funds and creates destinationA
|
|
92
|
+
* .addOperation(Operation.payment({
|
|
93
|
+
* destination: destinationB,
|
|
94
|
+
* amount: "100",
|
|
95
|
+
* asset: Asset.native()
|
|
96
|
+
* })) // <- sends 100 XLM to destinationB
|
|
97
|
+
* .setTimeout(30)
|
|
98
|
+
* .build();
|
|
99
|
+
*
|
|
100
|
+
* transaction.sign(sourceKeypair);
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @constructor
|
|
104
|
+
*
|
|
105
|
+
* @param {Account} sourceAccount - source account for this transaction
|
|
106
|
+
* @param {object} opts - Options object
|
|
107
|
+
* @param {string} opts.fee - max fee you're willing to pay per
|
|
108
|
+
* operation in this transaction (**in stroops**)
|
|
109
|
+
*
|
|
110
|
+
* @param {object} [opts.timebounds] - timebounds for the
|
|
111
|
+
* validity of this transaction
|
|
112
|
+
* @param {number|string|Date} [opts.timebounds.minTime] - 64-bit UNIX
|
|
113
|
+
* timestamp or Date object
|
|
114
|
+
* @param {number|string|Date} [opts.timebounds.maxTime] - 64-bit UNIX
|
|
115
|
+
* timestamp or Date object
|
|
116
|
+
* @param {object} [opts.ledgerbounds] - ledger bounds for the
|
|
117
|
+
* validity of this transaction
|
|
118
|
+
* @param {number} [opts.ledgerbounds.minLedger] - number of the minimum
|
|
119
|
+
* ledger sequence
|
|
120
|
+
* @param {number} [opts.ledgerbounds.maxLedger] - number of the maximum
|
|
121
|
+
* ledger sequence
|
|
122
|
+
* @param {string} [opts.minAccountSequence] - number for
|
|
123
|
+
* the minimum account sequence
|
|
124
|
+
* @param {number} [opts.minAccountSequenceAge] - number of
|
|
125
|
+
* seconds for the minimum account sequence age
|
|
126
|
+
* @param {number} [opts.minAccountSequenceLedgerGap] - number of
|
|
127
|
+
* ledgers for the minimum account sequence ledger gap
|
|
128
|
+
* @param {string[]} [opts.extraSigners] - list of the extra signers
|
|
129
|
+
* required for this transaction
|
|
130
|
+
* @param {Memo} [opts.memo] - memo for the transaction
|
|
131
|
+
* @param {string} [opts.networkPassphrase] passphrase of the
|
|
132
|
+
* target Stellar network (e.g. "Public Global Stellar Network ; September
|
|
133
|
+
* 2015" for the pubnet)
|
|
134
|
+
* @param {xdr.SorobanTransactionData | string} [opts.sorobanData] - an
|
|
135
|
+
* optional instance of {@link xdr.SorobanTransactionData} to be set as the
|
|
136
|
+
* internal `Transaction.Ext.SorobanData` field (either the xdr object or a
|
|
137
|
+
* base64 string). In the case of Soroban transactions, this can be obtained
|
|
138
|
+
* from a prior simulation of the transaction with a contract invocation and
|
|
139
|
+
* provides necessary resource estimations. You can also use
|
|
140
|
+
* {@link SorobanDataBuilder} to construct complicated combinations of
|
|
141
|
+
* parameters without mucking with XDR directly. **Note:** For
|
|
142
|
+
* non-contract(non-Soroban) transactions, this has no effect.
|
|
143
|
+
*/
|
|
144
|
+
var TransactionBuilder = exports.TransactionBuilder = /*#__PURE__*/function () {
|
|
145
|
+
function TransactionBuilder(sourceAccount) {
|
|
146
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
147
|
+
_classCallCheck(this, TransactionBuilder);
|
|
148
|
+
if (!sourceAccount) {
|
|
149
|
+
throw new Error('must specify source account for the transaction');
|
|
150
|
+
}
|
|
151
|
+
if (opts.fee === undefined) {
|
|
152
|
+
throw new Error('must specify fee for the transaction (in stroops)');
|
|
153
|
+
}
|
|
154
|
+
this.source = sourceAccount;
|
|
155
|
+
this.operations = [];
|
|
156
|
+
this.baseFee = opts.fee;
|
|
157
|
+
this.timebounds = opts.timebounds ? _objectSpread({}, opts.timebounds) : null;
|
|
158
|
+
this.ledgerbounds = opts.ledgerbounds ? _objectSpread({}, opts.ledgerbounds) : null;
|
|
159
|
+
this.minAccountSequence = opts.minAccountSequence || null;
|
|
160
|
+
this.minAccountSequenceAge = opts.minAccountSequenceAge || null;
|
|
161
|
+
this.minAccountSequenceLedgerGap = opts.minAccountSequenceLedgerGap || null;
|
|
162
|
+
this.extraSigners = opts.extraSigners ? _toConsumableArray(opts.extraSigners) : null;
|
|
163
|
+
this.memo = opts.memo || _memo.Memo.none();
|
|
164
|
+
this.networkPassphrase = opts.networkPassphrase || null;
|
|
165
|
+
this.sorobanData = opts.sorobanData ? new _sorobandata_builder.SorobanDataBuilder(opts.sorobanData).build() : null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Creates a builder instance using an existing {@link Transaction} as a
|
|
170
|
+
* template, ignoring any existing envelope signatures.
|
|
171
|
+
*
|
|
172
|
+
* Note that the sequence number WILL be cloned, so EITHER this transaction or
|
|
173
|
+
* the one it was cloned from will be valid. This is useful in situations
|
|
174
|
+
* where you are constructing a transaction in pieces and need to make
|
|
175
|
+
* adjustments as you go (for example, when filling out Soroban resource
|
|
176
|
+
* information).
|
|
177
|
+
*
|
|
178
|
+
* @param {Transaction} tx a "template" transaction to clone exactly
|
|
179
|
+
* @param {object} [opts] additional options to override the clone, e.g.
|
|
180
|
+
* {fee: '1000'} will override the existing base fee derived from `tx` (see
|
|
181
|
+
* the {@link TransactionBuilder} constructor for detailed options)
|
|
182
|
+
*
|
|
183
|
+
* @returns {TransactionBuilder} a "prepared" builder instance with the same
|
|
184
|
+
* configuration and operations as the given transaction
|
|
185
|
+
*
|
|
186
|
+
* @warning This does not clone the transaction's
|
|
187
|
+
* {@link xdr.SorobanTransactionData} (if applicable), use
|
|
188
|
+
* {@link SorobanDataBuilder} and {@link TransactionBuilder.setSorobanData}
|
|
189
|
+
* as needed, instead..
|
|
190
|
+
*
|
|
191
|
+
* @todo This cannot clone {@link FeeBumpTransaction}s, yet.
|
|
192
|
+
*/
|
|
193
|
+
_createClass(TransactionBuilder, [{
|
|
194
|
+
key: "addOperation",
|
|
195
|
+
value:
|
|
196
|
+
/**
|
|
197
|
+
* Adds an operation to the transaction.
|
|
198
|
+
*
|
|
199
|
+
* @param {xdr.Operation} operation The xdr operation object, use {@link
|
|
200
|
+
* Operation} static methods.
|
|
201
|
+
*
|
|
202
|
+
* @returns {TransactionBuilder}
|
|
203
|
+
*/
|
|
204
|
+
function addOperation(operation) {
|
|
205
|
+
this.operations.push(operation);
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Removes the operations from the builder (useful when cloning).
|
|
211
|
+
* @returns {TransactionBuilder} this builder instance
|
|
212
|
+
*/
|
|
213
|
+
}, {
|
|
214
|
+
key: "clearOperations",
|
|
215
|
+
value: function clearOperations() {
|
|
216
|
+
this.operations = [];
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Adds a memo to the transaction.
|
|
222
|
+
* @param {Memo} memo {@link Memo} object
|
|
223
|
+
* @returns {TransactionBuilder}
|
|
224
|
+
*/
|
|
225
|
+
}, {
|
|
226
|
+
key: "addMemo",
|
|
227
|
+
value: function addMemo(memo) {
|
|
228
|
+
this.memo = memo;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Sets a timeout precondition on the transaction.
|
|
234
|
+
*
|
|
235
|
+
* Because of the distributed nature of the Stellar network it is possible
|
|
236
|
+
* that the status of your transaction will be determined after a long time
|
|
237
|
+
* if the network is highly congested. If you want to be sure to receive the
|
|
238
|
+
* status of the transaction within a given period you should set the {@link
|
|
239
|
+
* TimeBounds} with `maxTime` on the transaction (this is what `setTimeout`
|
|
240
|
+
* does internally; if there's `minTime` set but no `maxTime` it will be
|
|
241
|
+
* added).
|
|
242
|
+
*
|
|
243
|
+
* A call to `TransactionBuilder.setTimeout` is **required** if Transaction
|
|
244
|
+
* does not have `max_time` set. If you don't want to set timeout, use
|
|
245
|
+
* `{@link TimeoutInfinite}`. In general you should set `{@link
|
|
246
|
+
* TimeoutInfinite}` only in smart contracts.
|
|
247
|
+
*
|
|
248
|
+
* Please note that Horizon may still return <code>504 Gateway Timeout</code>
|
|
249
|
+
* error, even for short timeouts. In such case you need to resubmit the same
|
|
250
|
+
* transaction again without making any changes to receive a status. This
|
|
251
|
+
* method is using the machine system time (UTC), make sure it is set
|
|
252
|
+
* correctly.
|
|
253
|
+
*
|
|
254
|
+
* @param {number} timeoutSeconds Number of seconds the transaction is good.
|
|
255
|
+
* Can't be negative. If the value is {@link TimeoutInfinite}, the
|
|
256
|
+
* transaction is good indefinitely.
|
|
257
|
+
*
|
|
258
|
+
* @returns {TransactionBuilder}
|
|
259
|
+
*
|
|
260
|
+
* @see {@link TimeoutInfinite}
|
|
261
|
+
* @see https://developers.stellar.org/docs/tutorials/handling-errors/
|
|
262
|
+
*/
|
|
263
|
+
}, {
|
|
264
|
+
key: "setTimeout",
|
|
265
|
+
value: function setTimeout(timeoutSeconds) {
|
|
266
|
+
if (this.timebounds !== null && this.timebounds.maxTime > 0) {
|
|
267
|
+
throw new Error('TimeBounds.max_time has been already set - setting timeout would overwrite it.');
|
|
268
|
+
}
|
|
269
|
+
if (timeoutSeconds < 0) {
|
|
270
|
+
throw new Error('timeout cannot be negative');
|
|
271
|
+
}
|
|
272
|
+
if (timeoutSeconds > 0) {
|
|
273
|
+
var timeoutTimestamp = Math.floor(Date.now() / 1000) + timeoutSeconds;
|
|
274
|
+
if (this.timebounds === null) {
|
|
275
|
+
this.timebounds = {
|
|
276
|
+
minTime: 0,
|
|
277
|
+
maxTime: timeoutTimestamp
|
|
278
|
+
};
|
|
279
|
+
} else {
|
|
280
|
+
this.timebounds = {
|
|
281
|
+
minTime: this.timebounds.minTime,
|
|
282
|
+
maxTime: timeoutTimestamp
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
} else {
|
|
286
|
+
this.timebounds = {
|
|
287
|
+
minTime: 0,
|
|
288
|
+
maxTime: 0
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return this;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* If you want to prepare a transaction which will become valid at some point
|
|
296
|
+
* in the future, or be invalid after some time, you can set a timebounds
|
|
297
|
+
* precondition. Internally this will set the `minTime`, and `maxTime`
|
|
298
|
+
* preconditions. Conflicts with `setTimeout`, so use one or the other.
|
|
299
|
+
*
|
|
300
|
+
* @param {Date|number} minEpochOrDate Either a JS Date object, or a number
|
|
301
|
+
* of UNIX epoch seconds. The transaction is valid after this timestamp.
|
|
302
|
+
* Can't be negative. If the value is `0`, the transaction is valid
|
|
303
|
+
* immediately.
|
|
304
|
+
* @param {Date|number} maxEpochOrDate Either a JS Date object, or a number
|
|
305
|
+
* of UNIX epoch seconds. The transaction is valid until this timestamp.
|
|
306
|
+
* Can't be negative. If the value is `0`, the transaction is valid
|
|
307
|
+
* indefinitely.
|
|
308
|
+
*
|
|
309
|
+
* @returns {TransactionBuilder}
|
|
310
|
+
*/
|
|
311
|
+
}, {
|
|
312
|
+
key: "setTimebounds",
|
|
313
|
+
value: function setTimebounds(minEpochOrDate, maxEpochOrDate) {
|
|
314
|
+
// Force it to a date type
|
|
315
|
+
if (typeof minEpochOrDate === 'number') {
|
|
316
|
+
minEpochOrDate = new Date(minEpochOrDate * 1000);
|
|
317
|
+
}
|
|
318
|
+
if (typeof maxEpochOrDate === 'number') {
|
|
319
|
+
maxEpochOrDate = new Date(maxEpochOrDate * 1000);
|
|
320
|
+
}
|
|
321
|
+
if (this.timebounds !== null) {
|
|
322
|
+
throw new Error('TimeBounds has been already set - setting timebounds would overwrite it.');
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Convert that date to the epoch seconds
|
|
326
|
+
var minTime = Math.floor(minEpochOrDate.valueOf() / 1000);
|
|
327
|
+
var maxTime = Math.floor(maxEpochOrDate.valueOf() / 1000);
|
|
328
|
+
if (minTime < 0) {
|
|
329
|
+
throw new Error('min_time cannot be negative');
|
|
330
|
+
}
|
|
331
|
+
if (maxTime < 0) {
|
|
332
|
+
throw new Error('max_time cannot be negative');
|
|
333
|
+
}
|
|
334
|
+
if (maxTime > 0 && minTime > maxTime) {
|
|
335
|
+
throw new Error('min_time cannot be greater than max_time');
|
|
336
|
+
}
|
|
337
|
+
this.timebounds = {
|
|
338
|
+
minTime: minTime,
|
|
339
|
+
maxTime: maxTime
|
|
340
|
+
};
|
|
341
|
+
return this;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* If you want to prepare a transaction which will only be valid within some
|
|
346
|
+
* range of ledgers, you can set a ledgerbounds precondition.
|
|
347
|
+
* Internally this will set the `minLedger` and `maxLedger` preconditions.
|
|
348
|
+
*
|
|
349
|
+
* @param {number} minLedger The minimum ledger this transaction is valid at
|
|
350
|
+
* or after. Cannot be negative. If the value is `0` (the default), the
|
|
351
|
+
* transaction is valid immediately.
|
|
352
|
+
*
|
|
353
|
+
* @param {number} maxLedger The maximum ledger this transaction is valid
|
|
354
|
+
* before. Cannot be negative. If the value is `0`, the transaction is
|
|
355
|
+
* valid indefinitely.
|
|
356
|
+
*
|
|
357
|
+
* @returns {TransactionBuilder}
|
|
358
|
+
*/
|
|
359
|
+
}, {
|
|
360
|
+
key: "setLedgerbounds",
|
|
361
|
+
value: function setLedgerbounds(minLedger, maxLedger) {
|
|
362
|
+
if (this.ledgerbounds !== null) {
|
|
363
|
+
throw new Error('LedgerBounds has been already set - setting ledgerbounds would overwrite it.');
|
|
364
|
+
}
|
|
365
|
+
if (minLedger < 0) {
|
|
366
|
+
throw new Error('min_ledger cannot be negative');
|
|
367
|
+
}
|
|
368
|
+
if (maxLedger < 0) {
|
|
369
|
+
throw new Error('max_ledger cannot be negative');
|
|
370
|
+
}
|
|
371
|
+
if (maxLedger > 0 && minLedger > maxLedger) {
|
|
372
|
+
throw new Error('min_ledger cannot be greater than max_ledger');
|
|
373
|
+
}
|
|
374
|
+
this.ledgerbounds = {
|
|
375
|
+
minLedger: minLedger,
|
|
376
|
+
maxLedger: maxLedger
|
|
377
|
+
};
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* If you want to prepare a transaction which will be valid only while the
|
|
383
|
+
* account sequence number is
|
|
384
|
+
*
|
|
385
|
+
* minAccountSequence <= sourceAccountSequence < tx.seqNum
|
|
386
|
+
*
|
|
387
|
+
* Note that after execution the account's sequence number is always raised to
|
|
388
|
+
* `tx.seqNum`. Internally this will set the `minAccountSequence`
|
|
389
|
+
* precondition.
|
|
390
|
+
*
|
|
391
|
+
* @param {string} minAccountSequence The minimum source account sequence
|
|
392
|
+
* number this transaction is valid for. If the value is `0` (the
|
|
393
|
+
* default), the transaction is valid when `sourceAccount's sequence
|
|
394
|
+
* number == tx.seqNum- 1`.
|
|
395
|
+
*
|
|
396
|
+
* @returns {TransactionBuilder}
|
|
397
|
+
*/
|
|
398
|
+
}, {
|
|
399
|
+
key: "setMinAccountSequence",
|
|
400
|
+
value: function setMinAccountSequence(minAccountSequence) {
|
|
401
|
+
if (this.minAccountSequence !== null) {
|
|
402
|
+
throw new Error('min_account_sequence has been already set - setting min_account_sequence would overwrite it.');
|
|
403
|
+
}
|
|
404
|
+
this.minAccountSequence = minAccountSequence;
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* For the transaction to be valid, the current ledger time must be at least
|
|
410
|
+
* `minAccountSequenceAge` greater than sourceAccount's `sequenceTime`.
|
|
411
|
+
* Internally this will set the `minAccountSequenceAge` precondition.
|
|
412
|
+
*
|
|
413
|
+
* @param {number} durationInSeconds The minimum amount of time between
|
|
414
|
+
* source account sequence time and the ledger time when this transaction
|
|
415
|
+
* will become valid. If the value is `0`, the transaction is unrestricted
|
|
416
|
+
* by the account sequence age. Cannot be negative.
|
|
417
|
+
*
|
|
418
|
+
* @returns {TransactionBuilder}
|
|
419
|
+
*/
|
|
420
|
+
}, {
|
|
421
|
+
key: "setMinAccountSequenceAge",
|
|
422
|
+
value: function setMinAccountSequenceAge(durationInSeconds) {
|
|
423
|
+
if (typeof durationInSeconds !== 'number') {
|
|
424
|
+
throw new Error('min_account_sequence_age must be a number');
|
|
425
|
+
}
|
|
426
|
+
if (this.minAccountSequenceAge !== null) {
|
|
427
|
+
throw new Error('min_account_sequence_age has been already set - setting min_account_sequence_age would overwrite it.');
|
|
428
|
+
}
|
|
429
|
+
if (durationInSeconds < 0) {
|
|
430
|
+
throw new Error('min_account_sequence_age cannot be negative');
|
|
431
|
+
}
|
|
432
|
+
this.minAccountSequenceAge = durationInSeconds;
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* For the transaction to be valid, the current ledger number must be at least
|
|
438
|
+
* `minAccountSequenceLedgerGap` greater than sourceAccount's ledger sequence.
|
|
439
|
+
* Internally this will set the `minAccountSequenceLedgerGap` precondition.
|
|
440
|
+
*
|
|
441
|
+
* @param {number} gap The minimum number of ledgers between source account
|
|
442
|
+
* sequence and the ledger number when this transaction will become valid.
|
|
443
|
+
* If the value is `0`, the transaction is unrestricted by the account
|
|
444
|
+
* sequence ledger. Cannot be negative.
|
|
445
|
+
*
|
|
446
|
+
* @returns {TransactionBuilder}
|
|
447
|
+
*/
|
|
448
|
+
}, {
|
|
449
|
+
key: "setMinAccountSequenceLedgerGap",
|
|
450
|
+
value: function setMinAccountSequenceLedgerGap(gap) {
|
|
451
|
+
if (this.minAccountSequenceLedgerGap !== null) {
|
|
452
|
+
throw new Error('min_account_sequence_ledger_gap has been already set - setting min_account_sequence_ledger_gap would overwrite it.');
|
|
453
|
+
}
|
|
454
|
+
if (gap < 0) {
|
|
455
|
+
throw new Error('min_account_sequence_ledger_gap cannot be negative');
|
|
456
|
+
}
|
|
457
|
+
this.minAccountSequenceLedgerGap = gap;
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* For the transaction to be valid, there must be a signature corresponding to
|
|
463
|
+
* every Signer in this array, even if the signature is not otherwise required
|
|
464
|
+
* by the sourceAccount or operations. Internally this will set the
|
|
465
|
+
* `extraSigners` precondition.
|
|
466
|
+
*
|
|
467
|
+
* @param {string[]} extraSigners required extra signers (as {@link StrKey}s)
|
|
468
|
+
*
|
|
469
|
+
* @returns {TransactionBuilder}
|
|
470
|
+
*/
|
|
471
|
+
}, {
|
|
472
|
+
key: "setExtraSigners",
|
|
473
|
+
value: function setExtraSigners(extraSigners) {
|
|
474
|
+
if (!Array.isArray(extraSigners)) {
|
|
475
|
+
throw new Error('extra_signers must be an array of strings.');
|
|
476
|
+
}
|
|
477
|
+
if (this.extraSigners !== null) {
|
|
478
|
+
throw new Error('extra_signers has been already set - setting extra_signers would overwrite it.');
|
|
479
|
+
}
|
|
480
|
+
if (extraSigners.length > 2) {
|
|
481
|
+
throw new Error('extra_signers cannot be longer than 2 elements.');
|
|
482
|
+
}
|
|
483
|
+
this.extraSigners = _toConsumableArray(extraSigners);
|
|
484
|
+
return this;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Set network nassphrase for the Transaction that will be built.
|
|
489
|
+
*
|
|
490
|
+
* @param {string} networkPassphrase passphrase of the target Stellar
|
|
491
|
+
* network (e.g. "Public Global Stellar Network ; September 2015").
|
|
492
|
+
*
|
|
493
|
+
* @returns {TransactionBuilder}
|
|
494
|
+
*/
|
|
495
|
+
}, {
|
|
496
|
+
key: "setNetworkPassphrase",
|
|
497
|
+
value: function setNetworkPassphrase(networkPassphrase) {
|
|
498
|
+
this.networkPassphrase = networkPassphrase;
|
|
499
|
+
return this;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Sets the transaction's internal Soroban transaction data (resources,
|
|
504
|
+
* footprint, etc.).
|
|
505
|
+
*
|
|
506
|
+
* For non-contract(non-Soroban) transactions, this setting has no effect. In
|
|
507
|
+
* the case of Soroban transactions, this is either an instance of
|
|
508
|
+
* {@link xdr.SorobanTransactionData} or a base64-encoded string of said
|
|
509
|
+
* structure. This is usually obtained from the simulation response based on a
|
|
510
|
+
* transaction with a Soroban operation (e.g.
|
|
511
|
+
* {@link Operation.invokeHostFunction}, providing necessary resource
|
|
512
|
+
* and storage footprint estimations for contract invocation.
|
|
513
|
+
*
|
|
514
|
+
* @param {xdr.SorobanTransactionData | string} sorobanData the
|
|
515
|
+
* {@link xdr.SorobanTransactionData} as a raw xdr object or a base64
|
|
516
|
+
* string to be decoded
|
|
517
|
+
*
|
|
518
|
+
* @returns {TransactionBuilder}
|
|
519
|
+
* @see {SorobanDataBuilder}
|
|
520
|
+
*/
|
|
521
|
+
}, {
|
|
522
|
+
key: "setSorobanData",
|
|
523
|
+
value: function setSorobanData(sorobanData) {
|
|
524
|
+
this.sorobanData = new _sorobandata_builder.SorobanDataBuilder(sorobanData).build();
|
|
525
|
+
return this;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* This will build the transaction.
|
|
530
|
+
* It will also increment the source account's sequence number by 1.
|
|
531
|
+
* @returns {Transaction} This method will return the built {@link Transaction}.
|
|
532
|
+
*/
|
|
533
|
+
}, {
|
|
534
|
+
key: "build",
|
|
535
|
+
value: function build() {
|
|
536
|
+
var sequenceNumber = new _bignumber["default"](this.source.sequenceNumber()).plus(1);
|
|
537
|
+
var fee = new _bignumber["default"](this.baseFee).times(this.operations.length).toNumber();
|
|
538
|
+
var attrs = {
|
|
539
|
+
fee: fee,
|
|
540
|
+
seqNum: _xdr["default"].SequenceNumber.fromString(sequenceNumber.toString()),
|
|
541
|
+
memo: this.memo ? this.memo.toXDRObject() : null
|
|
542
|
+
};
|
|
543
|
+
if (this.timebounds === null || typeof this.timebounds.minTime === 'undefined' || typeof this.timebounds.maxTime === 'undefined') {
|
|
544
|
+
throw new Error('TimeBounds has to be set or you must call setTimeout(TimeoutInfinite).');
|
|
545
|
+
}
|
|
546
|
+
if (isValidDate(this.timebounds.minTime)) {
|
|
547
|
+
this.timebounds.minTime = this.timebounds.minTime.getTime() / 1000;
|
|
548
|
+
}
|
|
549
|
+
if (isValidDate(this.timebounds.maxTime)) {
|
|
550
|
+
this.timebounds.maxTime = this.timebounds.maxTime.getTime() / 1000;
|
|
551
|
+
}
|
|
552
|
+
this.timebounds.minTime = _jsXdr.UnsignedHyper.fromString(this.timebounds.minTime.toString());
|
|
553
|
+
this.timebounds.maxTime = _jsXdr.UnsignedHyper.fromString(this.timebounds.maxTime.toString());
|
|
554
|
+
var timeBounds = new _xdr["default"].TimeBounds(this.timebounds);
|
|
555
|
+
if (this.hasV2Preconditions()) {
|
|
556
|
+
var ledgerBounds = null;
|
|
557
|
+
if (this.ledgerbounds !== null) {
|
|
558
|
+
ledgerBounds = new _xdr["default"].LedgerBounds(this.ledgerbounds);
|
|
559
|
+
}
|
|
560
|
+
var minSeqNum = this.minAccountSequence || '0';
|
|
561
|
+
minSeqNum = _xdr["default"].SequenceNumber.fromString(minSeqNum);
|
|
562
|
+
var minSeqAge = _jsXdr.UnsignedHyper.fromString(this.minAccountSequenceAge !== null ? this.minAccountSequenceAge.toString() : '0');
|
|
563
|
+
var minSeqLedgerGap = this.minAccountSequenceLedgerGap || 0;
|
|
564
|
+
var extraSigners = this.extraSigners !== null ? this.extraSigners.map(_signerkey.SignerKey.decodeAddress) : [];
|
|
565
|
+
attrs.cond = _xdr["default"].Preconditions.precondV2(new _xdr["default"].PreconditionsV2({
|
|
566
|
+
timeBounds: timeBounds,
|
|
567
|
+
ledgerBounds: ledgerBounds,
|
|
568
|
+
minSeqNum: minSeqNum,
|
|
569
|
+
minSeqAge: minSeqAge,
|
|
570
|
+
minSeqLedgerGap: minSeqLedgerGap,
|
|
571
|
+
extraSigners: extraSigners
|
|
572
|
+
}));
|
|
573
|
+
} else {
|
|
574
|
+
attrs.cond = _xdr["default"].Preconditions.precondTime(timeBounds);
|
|
575
|
+
}
|
|
576
|
+
attrs.sourceAccount = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(this.source.accountId());
|
|
577
|
+
|
|
578
|
+
// TODO - remove this workaround for TransactionExt ts constructor
|
|
579
|
+
// and use the typescript generated static factory method once fixed
|
|
580
|
+
// https://github.com/stellar/dts-xdr/issues/5
|
|
581
|
+
if (this.sorobanData) {
|
|
582
|
+
// @ts-ignore
|
|
583
|
+
attrs.ext = new _xdr["default"].TransactionExt(1, this.sorobanData);
|
|
584
|
+
} else {
|
|
585
|
+
// @ts-ignore
|
|
586
|
+
attrs.ext = new _xdr["default"].TransactionExt(0, _xdr["default"].Void);
|
|
587
|
+
}
|
|
588
|
+
var xtx = new _xdr["default"].Transaction(attrs);
|
|
589
|
+
xtx.operations(this.operations);
|
|
590
|
+
var txEnvelope = new _xdr["default"].TransactionEnvelope.envelopeTypeTx(new _xdr["default"].TransactionV1Envelope({
|
|
591
|
+
tx: xtx
|
|
592
|
+
}));
|
|
593
|
+
var tx = new _transaction.Transaction(txEnvelope, this.networkPassphrase);
|
|
594
|
+
this.source.incrementSequenceNumber();
|
|
595
|
+
return tx;
|
|
596
|
+
}
|
|
597
|
+
}, {
|
|
598
|
+
key: "hasV2Preconditions",
|
|
599
|
+
value: function hasV2Preconditions() {
|
|
600
|
+
return this.ledgerbounds !== null || this.minAccountSequence !== null || this.minAccountSequenceAge !== null || this.minAccountSequenceLedgerGap !== null || this.extraSigners !== null && this.extraSigners.length > 0;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Builds a {@link FeeBumpTransaction}, enabling you to resubmit an existing
|
|
605
|
+
* transaction with a higher fee.
|
|
606
|
+
*
|
|
607
|
+
* @param {Keypair|string} feeSource - account paying for the transaction,
|
|
608
|
+
* in the form of either a Keypair (only the public key is used) or
|
|
609
|
+
* an account ID (in G... or M... form, but refer to `withMuxing`)
|
|
610
|
+
* @param {string} baseFee - max fee willing to pay per operation
|
|
611
|
+
* in inner transaction (**in stroops**)
|
|
612
|
+
* @param {Transaction} innerTx - {@link Transaction} to be bumped by
|
|
613
|
+
* the fee bump transaction
|
|
614
|
+
* @param {string} networkPassphrase - passphrase of the target
|
|
615
|
+
* Stellar network (e.g. "Public Global Stellar Network ; September 2015",
|
|
616
|
+
* see {@link Networks})
|
|
617
|
+
*
|
|
618
|
+
* @todo Alongside the next major version bump, this type signature can be
|
|
619
|
+
* changed to be less awkward: accept a MuxedAccount as the `feeSource`
|
|
620
|
+
* rather than a keypair or string.
|
|
621
|
+
*
|
|
622
|
+
* @note Your fee-bump amount should be >= 10x the original fee.
|
|
623
|
+
* @see https://developers.stellar.org/docs/glossary/fee-bumps/#replace-by-fee
|
|
624
|
+
*
|
|
625
|
+
* @returns {FeeBumpTransaction}
|
|
626
|
+
*/
|
|
627
|
+
}], [{
|
|
628
|
+
key: "cloneFrom",
|
|
629
|
+
value: function cloneFrom(tx) {
|
|
630
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
631
|
+
if (!(tx instanceof _transaction.Transaction)) {
|
|
632
|
+
throw new TypeError("expected a 'Transaction', got: ".concat(tx));
|
|
633
|
+
}
|
|
634
|
+
var sequenceNum = (BigInt(tx.sequence) - 1n).toString();
|
|
635
|
+
var source;
|
|
636
|
+
// rebuild the source account based on the strkey
|
|
637
|
+
if (_strkey.StrKey.isValidMed25519PublicKey(tx.source)) {
|
|
638
|
+
source = _muxed_account.MuxedAccount.fromAddress(tx.source, sequenceNum);
|
|
639
|
+
} else if (_strkey.StrKey.isValidEd25519PublicKey(tx.source)) {
|
|
640
|
+
source = new _account.Account(tx.source, sequenceNum);
|
|
641
|
+
} else {
|
|
642
|
+
throw new TypeError("unsupported tx source account: ".concat(tx.source));
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// the initial fee passed to the builder gets scaled up based on the number
|
|
646
|
+
// of operations at the end, so we have to down-scale first
|
|
647
|
+
var unscaledFee = parseInt(tx.fee, 10) / tx.operations.length;
|
|
648
|
+
var builder = new TransactionBuilder(source, _objectSpread({
|
|
649
|
+
fee: (unscaledFee || BASE_FEE).toString(),
|
|
650
|
+
memo: tx.memo,
|
|
651
|
+
networkPassphrase: tx.networkPassphrase,
|
|
652
|
+
timebounds: tx.timeBounds,
|
|
653
|
+
ledgerbounds: tx.ledgerBounds,
|
|
654
|
+
minAccountSequence: tx.minAccountSequence,
|
|
655
|
+
minAccountSequenceAge: tx.minAccountSequenceAge,
|
|
656
|
+
minAccountSequenceLedgerGap: tx.minAccountSequenceLedgerGap,
|
|
657
|
+
extraSigners: tx.extraSigners
|
|
658
|
+
}, opts));
|
|
659
|
+
tx._tx.operations().forEach(function (op) {
|
|
660
|
+
return builder.addOperation(op);
|
|
661
|
+
});
|
|
662
|
+
return builder;
|
|
663
|
+
}
|
|
664
|
+
}, {
|
|
665
|
+
key: "buildFeeBumpTransaction",
|
|
666
|
+
value: function buildFeeBumpTransaction(feeSource, baseFee, innerTx, networkPassphrase) {
|
|
667
|
+
var innerOps = innerTx.operations.length;
|
|
668
|
+
var innerBaseFeeRate = new _bignumber["default"](innerTx.fee).div(innerOps);
|
|
669
|
+
var base = new _bignumber["default"](baseFee);
|
|
670
|
+
|
|
671
|
+
// The fee rate for fee bump is at least the fee rate of the inner transaction
|
|
672
|
+
if (base.lt(innerBaseFeeRate)) {
|
|
673
|
+
throw new Error("Invalid baseFee, it should be at least ".concat(innerBaseFeeRate, " stroops."));
|
|
674
|
+
}
|
|
675
|
+
var minBaseFee = new _bignumber["default"](BASE_FEE);
|
|
676
|
+
|
|
677
|
+
// The fee rate is at least the minimum fee
|
|
678
|
+
if (base.lt(minBaseFee)) {
|
|
679
|
+
throw new Error("Invalid baseFee, it should be at least ".concat(minBaseFee, " stroops."));
|
|
680
|
+
}
|
|
681
|
+
var innerTxEnvelope = innerTx.toEnvelope();
|
|
682
|
+
if (innerTxEnvelope["switch"]() === _xdr["default"].EnvelopeType.envelopeTypeTxV0()) {
|
|
683
|
+
var v0Tx = innerTxEnvelope.v0().tx();
|
|
684
|
+
var v1Tx = new _xdr["default"].Transaction({
|
|
685
|
+
sourceAccount: new _xdr["default"].MuxedAccount.keyTypeEd25519(v0Tx.sourceAccountEd25519()),
|
|
686
|
+
fee: v0Tx.fee(),
|
|
687
|
+
seqNum: v0Tx.seqNum(),
|
|
688
|
+
cond: _xdr["default"].Preconditions.precondTime(v0Tx.timeBounds()),
|
|
689
|
+
memo: v0Tx.memo(),
|
|
690
|
+
operations: v0Tx.operations(),
|
|
691
|
+
ext: new _xdr["default"].TransactionExt(0)
|
|
692
|
+
});
|
|
693
|
+
innerTxEnvelope = new _xdr["default"].TransactionEnvelope.envelopeTypeTx(new _xdr["default"].TransactionV1Envelope({
|
|
694
|
+
tx: v1Tx,
|
|
695
|
+
signatures: innerTxEnvelope.v0().signatures()
|
|
696
|
+
}));
|
|
697
|
+
}
|
|
698
|
+
var feeSourceAccount;
|
|
699
|
+
if (typeof feeSource === 'string') {
|
|
700
|
+
feeSourceAccount = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(feeSource);
|
|
701
|
+
} else {
|
|
702
|
+
feeSourceAccount = feeSource.xdrMuxedAccount();
|
|
703
|
+
}
|
|
704
|
+
var tx = new _xdr["default"].FeeBumpTransaction({
|
|
705
|
+
feeSource: feeSourceAccount,
|
|
706
|
+
fee: _xdr["default"].Int64.fromString(base.times(innerOps + 1).toString()),
|
|
707
|
+
innerTx: _xdr["default"].FeeBumpTransactionInnerTx.envelopeTypeTx(innerTxEnvelope.v1()),
|
|
708
|
+
ext: new _xdr["default"].FeeBumpTransactionExt(0)
|
|
709
|
+
});
|
|
710
|
+
var feeBumpTxEnvelope = new _xdr["default"].FeeBumpTransactionEnvelope({
|
|
711
|
+
tx: tx,
|
|
712
|
+
signatures: []
|
|
713
|
+
});
|
|
714
|
+
var envelope = new _xdr["default"].TransactionEnvelope.envelopeTypeTxFeeBump(feeBumpTxEnvelope);
|
|
715
|
+
return new _fee_bump_transaction.FeeBumpTransaction(envelope, networkPassphrase);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Build a {@link Transaction} or {@link FeeBumpTransaction} from an
|
|
720
|
+
* xdr.TransactionEnvelope.
|
|
721
|
+
*
|
|
722
|
+
* @param {string|xdr.TransactionEnvelope} envelope - The transaction envelope
|
|
723
|
+
* object or base64 encoded string.
|
|
724
|
+
* @param {string} networkPassphrase - The network passphrase of the target
|
|
725
|
+
* Stellar network (e.g. "Public Global Stellar Network ; September
|
|
726
|
+
* 2015"), see {@link Networks}.
|
|
727
|
+
*
|
|
728
|
+
* @returns {Transaction|FeeBumpTransaction}
|
|
729
|
+
*/
|
|
730
|
+
}, {
|
|
731
|
+
key: "fromXDR",
|
|
732
|
+
value: function fromXDR(envelope, networkPassphrase) {
|
|
733
|
+
if (typeof envelope === 'string') {
|
|
734
|
+
envelope = _xdr["default"].TransactionEnvelope.fromXDR(envelope, 'base64');
|
|
735
|
+
}
|
|
736
|
+
if (envelope["switch"]() === _xdr["default"].EnvelopeType.envelopeTypeTxFeeBump()) {
|
|
737
|
+
return new _fee_bump_transaction.FeeBumpTransaction(envelope, networkPassphrase);
|
|
738
|
+
}
|
|
739
|
+
return new _transaction.Transaction(envelope, networkPassphrase);
|
|
740
|
+
}
|
|
741
|
+
}]);
|
|
742
|
+
return TransactionBuilder;
|
|
743
|
+
}();
|
|
744
|
+
/**
|
|
745
|
+
* Checks whether a provided object is a valid Date.
|
|
746
|
+
* @argument {Date} d date object
|
|
747
|
+
* @returns {boolean}
|
|
748
|
+
*/
|
|
749
|
+
function isValidDate(d) {
|
|
750
|
+
// isnan is okay here because it correctly checks for invalid date objects
|
|
751
|
+
// eslint-disable-next-line no-restricted-globals
|
|
752
|
+
return d instanceof Date && !isNaN(d);
|
|
753
|
+
}
|