@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
package/lib/operation.js
ADDED
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Operation = exports.AuthRevocableFlag = exports.AuthRequiredFlag = exports.AuthImmutableFlag = exports.AuthClawbackEnabledFlag = void 0;
|
|
7
|
+
var _jsXdr = require("@stellar/js-xdr");
|
|
8
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
9
|
+
var _util = require("./util/util");
|
|
10
|
+
var _continued_fraction = require("./util/continued_fraction");
|
|
11
|
+
var _asset = require("./asset");
|
|
12
|
+
var _liquidity_pool_asset = require("./liquidity_pool_asset");
|
|
13
|
+
var _claimant = require("./claimant");
|
|
14
|
+
var _strkey = require("./strkey");
|
|
15
|
+
var _liquidity_pool_id = require("./liquidity_pool_id");
|
|
16
|
+
var _xdr = _interopRequireDefault(require("./xdr"));
|
|
17
|
+
var ops = _interopRequireWildcard(require("./operations"));
|
|
18
|
+
var _decode_encode_muxed_account = require("./util/decode_encode_muxed_account");
|
|
19
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
20
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
22
|
+
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); }
|
|
23
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
24
|
+
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); } }
|
|
25
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
26
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
27
|
+
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); } /* eslint-disable no-bitwise */
|
|
28
|
+
var ONE = 10000000;
|
|
29
|
+
var MAX_INT64 = '9223372036854775807';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* When set using `{@link Operation.setOptions}` option, requires the issuing
|
|
33
|
+
* account to give other accounts permission before they can hold the issuing
|
|
34
|
+
* account’s credit.
|
|
35
|
+
*
|
|
36
|
+
* @constant
|
|
37
|
+
* @see [Account flags](https://developers.stellar.org/docs/glossary/accounts/#flags)
|
|
38
|
+
*/
|
|
39
|
+
var AuthRequiredFlag = exports.AuthRequiredFlag = 1 << 0;
|
|
40
|
+
/**
|
|
41
|
+
* When set using `{@link Operation.setOptions}` option, allows the issuing
|
|
42
|
+
* account to revoke its credit held by other accounts.
|
|
43
|
+
*
|
|
44
|
+
* @constant
|
|
45
|
+
* @see [Account flags](https://developers.stellar.org/docs/glossary/accounts/#flags)
|
|
46
|
+
*/
|
|
47
|
+
var AuthRevocableFlag = exports.AuthRevocableFlag = 1 << 1;
|
|
48
|
+
/**
|
|
49
|
+
* When set using `{@link Operation.setOptions}` option, then none of the
|
|
50
|
+
* authorization flags can be set and the account can never be deleted.
|
|
51
|
+
*
|
|
52
|
+
* @constant
|
|
53
|
+
* @see [Account flags](https://developers.stellar.org/docs/glossary/accounts/#flags)
|
|
54
|
+
*/
|
|
55
|
+
var AuthImmutableFlag = exports.AuthImmutableFlag = 1 << 2;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* When set using `{@link Operation.setOptions}` option, then any trustlines
|
|
59
|
+
* created by this account can have a ClawbackOp operation submitted for the
|
|
60
|
+
* corresponding asset.
|
|
61
|
+
*
|
|
62
|
+
* @constant
|
|
63
|
+
* @see [Account flags](https://developers.stellar.org/docs/glossary/accounts/#flags)
|
|
64
|
+
*/
|
|
65
|
+
var AuthClawbackEnabledFlag = exports.AuthClawbackEnabledFlag = 1 << 3;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* `Operation` class represents
|
|
69
|
+
* [operations](https://developers.stellar.org/docs/glossary/operations/) in
|
|
70
|
+
* Stellar network.
|
|
71
|
+
*
|
|
72
|
+
* Use one of static methods to create operations:
|
|
73
|
+
* * `{@link Operation.createAccount}`
|
|
74
|
+
* * `{@link Operation.payment}`
|
|
75
|
+
* * `{@link Operation.pathPaymentStrictReceive}`
|
|
76
|
+
* * `{@link Operation.pathPaymentStrictSend}`
|
|
77
|
+
* * `{@link Operation.manageSellOffer}`
|
|
78
|
+
* * `{@link Operation.manageBuyOffer}`
|
|
79
|
+
* * `{@link Operation.createPassiveSellOffer}`
|
|
80
|
+
* * `{@link Operation.setOptions}`
|
|
81
|
+
* * `{@link Operation.changeTrust}`
|
|
82
|
+
* * `{@link Operation.allowTrust}`
|
|
83
|
+
* * `{@link Operation.accountMerge}`
|
|
84
|
+
* * `{@link Operation.inflation}`
|
|
85
|
+
* * `{@link Operation.manageData}`
|
|
86
|
+
* * `{@link Operation.bumpSequence}`
|
|
87
|
+
* * `{@link Operation.createClaimableBalance}`
|
|
88
|
+
* * `{@link Operation.claimClaimableBalance}`
|
|
89
|
+
* * `{@link Operation.beginSponsoringFutureReserves}`
|
|
90
|
+
* * `{@link Operation.endSponsoringFutureReserves}`
|
|
91
|
+
* * `{@link Operation.revokeAccountSponsorship}`
|
|
92
|
+
* * `{@link Operation.revokeTrustlineSponsorship}`
|
|
93
|
+
* * `{@link Operation.revokeOfferSponsorship}`
|
|
94
|
+
* * `{@link Operation.revokeDataSponsorship}`
|
|
95
|
+
* * `{@link Operation.revokeClaimableBalanceSponsorship}`
|
|
96
|
+
* * `{@link Operation.revokeLiquidityPoolSponsorship}`
|
|
97
|
+
* * `{@link Operation.revokeSignerSponsorship}`
|
|
98
|
+
* * `{@link Operation.clawback}`
|
|
99
|
+
* * `{@link Operation.clawbackClaimableBalance}`
|
|
100
|
+
* * `{@link Operation.setTrustLineFlags}`
|
|
101
|
+
* * `{@link Operation.liquidityPoolDeposit}`
|
|
102
|
+
* * `{@link Operation.liquidityPoolWithdraw}`
|
|
103
|
+
* * `{@link Operation.invokeHostFunction}`
|
|
104
|
+
* * `{@link Operation.extendFootprintTtlOp}`
|
|
105
|
+
* * `{@link Operation.restoreFootprint}`
|
|
106
|
+
*
|
|
107
|
+
* @class Operation
|
|
108
|
+
*/
|
|
109
|
+
var Operation = exports.Operation = /*#__PURE__*/function () {
|
|
110
|
+
function Operation() {
|
|
111
|
+
_classCallCheck(this, Operation);
|
|
112
|
+
}
|
|
113
|
+
_createClass(Operation, null, [{
|
|
114
|
+
key: "setSourceAccount",
|
|
115
|
+
value: function setSourceAccount(opAttributes, opts) {
|
|
116
|
+
if (opts.source) {
|
|
117
|
+
try {
|
|
118
|
+
opAttributes.sourceAccount = (0, _decode_encode_muxed_account.decodeAddressToMuxedAccount)(opts.source);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
throw new Error('Source address is invalid');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Deconstructs the raw XDR operation object into the structured object that
|
|
127
|
+
* was used to create the operation (i.e. the `opts` parameter to most ops).
|
|
128
|
+
*
|
|
129
|
+
* @param {xdr.Operation} operation - An XDR Operation.
|
|
130
|
+
* @return {Operation}
|
|
131
|
+
*/
|
|
132
|
+
}, {
|
|
133
|
+
key: "fromXDRObject",
|
|
134
|
+
value: function fromXDRObject(operation) {
|
|
135
|
+
var result = {};
|
|
136
|
+
if (operation.sourceAccount()) {
|
|
137
|
+
result.source = (0, _decode_encode_muxed_account.encodeMuxedAccountToAddress)(operation.sourceAccount());
|
|
138
|
+
}
|
|
139
|
+
var attrs = operation.body().value();
|
|
140
|
+
var operationName = operation.body()["switch"]().name;
|
|
141
|
+
switch (operationName) {
|
|
142
|
+
case 'createAccount':
|
|
143
|
+
{
|
|
144
|
+
result.type = 'createAccount';
|
|
145
|
+
result.destination = accountIdtoAddress(attrs.destination());
|
|
146
|
+
result.startingBalance = this._fromXDRAmount(attrs.startingBalance());
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
case 'payment':
|
|
150
|
+
{
|
|
151
|
+
result.type = 'payment';
|
|
152
|
+
result.destination = (0, _decode_encode_muxed_account.encodeMuxedAccountToAddress)(attrs.destination());
|
|
153
|
+
result.asset = _asset.Asset.fromOperation(attrs.asset());
|
|
154
|
+
result.amount = this._fromXDRAmount(attrs.amount());
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case 'pathPaymentStrictReceive':
|
|
158
|
+
{
|
|
159
|
+
result.type = 'pathPaymentStrictReceive';
|
|
160
|
+
result.sendAsset = _asset.Asset.fromOperation(attrs.sendAsset());
|
|
161
|
+
result.sendMax = this._fromXDRAmount(attrs.sendMax());
|
|
162
|
+
result.destination = (0, _decode_encode_muxed_account.encodeMuxedAccountToAddress)(attrs.destination());
|
|
163
|
+
result.destAsset = _asset.Asset.fromOperation(attrs.destAsset());
|
|
164
|
+
result.destAmount = this._fromXDRAmount(attrs.destAmount());
|
|
165
|
+
result.path = [];
|
|
166
|
+
var path = attrs.path();
|
|
167
|
+
|
|
168
|
+
// note that Object.values isn't supported by node 6!
|
|
169
|
+
Object.keys(path).forEach(function (pathKey) {
|
|
170
|
+
result.path.push(_asset.Asset.fromOperation(path[pathKey]));
|
|
171
|
+
});
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'pathPaymentStrictSend':
|
|
175
|
+
{
|
|
176
|
+
result.type = 'pathPaymentStrictSend';
|
|
177
|
+
result.sendAsset = _asset.Asset.fromOperation(attrs.sendAsset());
|
|
178
|
+
result.sendAmount = this._fromXDRAmount(attrs.sendAmount());
|
|
179
|
+
result.destination = (0, _decode_encode_muxed_account.encodeMuxedAccountToAddress)(attrs.destination());
|
|
180
|
+
result.destAsset = _asset.Asset.fromOperation(attrs.destAsset());
|
|
181
|
+
result.destMin = this._fromXDRAmount(attrs.destMin());
|
|
182
|
+
result.path = [];
|
|
183
|
+
var _path = attrs.path();
|
|
184
|
+
|
|
185
|
+
// note that Object.values isn't supported by node 6!
|
|
186
|
+
Object.keys(_path).forEach(function (pathKey) {
|
|
187
|
+
result.path.push(_asset.Asset.fromOperation(_path[pathKey]));
|
|
188
|
+
});
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case 'changeTrust':
|
|
192
|
+
{
|
|
193
|
+
result.type = 'changeTrust';
|
|
194
|
+
switch (attrs.line()["switch"]()) {
|
|
195
|
+
case _xdr["default"].AssetType.assetTypePoolShare():
|
|
196
|
+
result.line = _liquidity_pool_asset.LiquidityPoolAsset.fromOperation(attrs.line());
|
|
197
|
+
break;
|
|
198
|
+
default:
|
|
199
|
+
result.line = _asset.Asset.fromOperation(attrs.line());
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
result.limit = this._fromXDRAmount(attrs.limit());
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case 'allowTrust':
|
|
206
|
+
{
|
|
207
|
+
result.type = 'allowTrust';
|
|
208
|
+
result.trustor = accountIdtoAddress(attrs.trustor());
|
|
209
|
+
result.assetCode = attrs.asset().value().toString();
|
|
210
|
+
result.assetCode = (0, _util.trimEnd)(result.assetCode, '\0');
|
|
211
|
+
result.authorize = attrs.authorize();
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
case 'setOptions':
|
|
215
|
+
{
|
|
216
|
+
result.type = 'setOptions';
|
|
217
|
+
if (attrs.inflationDest()) {
|
|
218
|
+
result.inflationDest = accountIdtoAddress(attrs.inflationDest());
|
|
219
|
+
}
|
|
220
|
+
result.clearFlags = attrs.clearFlags();
|
|
221
|
+
result.setFlags = attrs.setFlags();
|
|
222
|
+
result.masterWeight = attrs.masterWeight();
|
|
223
|
+
result.lowThreshold = attrs.lowThreshold();
|
|
224
|
+
result.medThreshold = attrs.medThreshold();
|
|
225
|
+
result.highThreshold = attrs.highThreshold();
|
|
226
|
+
// home_domain is checked by iscntrl in stellar-core
|
|
227
|
+
result.homeDomain = attrs.homeDomain() !== undefined ? attrs.homeDomain().toString('ascii') : undefined;
|
|
228
|
+
if (attrs.signer()) {
|
|
229
|
+
var signer = {};
|
|
230
|
+
var arm = attrs.signer().key().arm();
|
|
231
|
+
if (arm === 'ed25519') {
|
|
232
|
+
signer.ed25519PublicKey = accountIdtoAddress(attrs.signer().key());
|
|
233
|
+
} else if (arm === 'preAuthTx') {
|
|
234
|
+
signer.preAuthTx = attrs.signer().key().preAuthTx();
|
|
235
|
+
} else if (arm === 'hashX') {
|
|
236
|
+
signer.sha256Hash = attrs.signer().key().hashX();
|
|
237
|
+
} else if (arm === 'ed25519SignedPayload') {
|
|
238
|
+
var signedPayload = attrs.signer().key().ed25519SignedPayload();
|
|
239
|
+
signer.ed25519SignedPayload = _strkey.StrKey.encodeSignedPayload(signedPayload.toXDR());
|
|
240
|
+
}
|
|
241
|
+
signer.weight = attrs.signer().weight();
|
|
242
|
+
result.signer = signer;
|
|
243
|
+
}
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
// the next case intentionally falls through!
|
|
247
|
+
case 'manageOffer':
|
|
248
|
+
case 'manageSellOffer':
|
|
249
|
+
{
|
|
250
|
+
result.type = 'manageSellOffer';
|
|
251
|
+
result.selling = _asset.Asset.fromOperation(attrs.selling());
|
|
252
|
+
result.buying = _asset.Asset.fromOperation(attrs.buying());
|
|
253
|
+
result.amount = this._fromXDRAmount(attrs.amount());
|
|
254
|
+
result.price = this._fromXDRPrice(attrs.price());
|
|
255
|
+
result.offerId = attrs.offerId().toString();
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case 'manageBuyOffer':
|
|
259
|
+
{
|
|
260
|
+
result.type = 'manageBuyOffer';
|
|
261
|
+
result.selling = _asset.Asset.fromOperation(attrs.selling());
|
|
262
|
+
result.buying = _asset.Asset.fromOperation(attrs.buying());
|
|
263
|
+
result.buyAmount = this._fromXDRAmount(attrs.buyAmount());
|
|
264
|
+
result.price = this._fromXDRPrice(attrs.price());
|
|
265
|
+
result.offerId = attrs.offerId().toString();
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
// the next case intentionally falls through!
|
|
269
|
+
case 'createPassiveOffer':
|
|
270
|
+
case 'createPassiveSellOffer':
|
|
271
|
+
{
|
|
272
|
+
result.type = 'createPassiveSellOffer';
|
|
273
|
+
result.selling = _asset.Asset.fromOperation(attrs.selling());
|
|
274
|
+
result.buying = _asset.Asset.fromOperation(attrs.buying());
|
|
275
|
+
result.amount = this._fromXDRAmount(attrs.amount());
|
|
276
|
+
result.price = this._fromXDRPrice(attrs.price());
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
case 'accountMerge':
|
|
280
|
+
{
|
|
281
|
+
result.type = 'accountMerge';
|
|
282
|
+
result.destination = (0, _decode_encode_muxed_account.encodeMuxedAccountToAddress)(attrs);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
case 'manageData':
|
|
286
|
+
{
|
|
287
|
+
result.type = 'manageData';
|
|
288
|
+
// manage_data.name is checked by iscntrl in stellar-core
|
|
289
|
+
result.name = attrs.dataName().toString('ascii');
|
|
290
|
+
result.value = attrs.dataValue();
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case 'inflation':
|
|
294
|
+
{
|
|
295
|
+
result.type = 'inflation';
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case 'bumpSequence':
|
|
299
|
+
{
|
|
300
|
+
result.type = 'bumpSequence';
|
|
301
|
+
result.bumpTo = attrs.bumpTo().toString();
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
case 'createClaimableBalance':
|
|
305
|
+
{
|
|
306
|
+
result.type = 'createClaimableBalance';
|
|
307
|
+
result.asset = _asset.Asset.fromOperation(attrs.asset());
|
|
308
|
+
result.amount = this._fromXDRAmount(attrs.amount());
|
|
309
|
+
result.claimants = [];
|
|
310
|
+
attrs.claimants().forEach(function (claimant) {
|
|
311
|
+
result.claimants.push(_claimant.Claimant.fromXDR(claimant));
|
|
312
|
+
});
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
case 'claimClaimableBalance':
|
|
316
|
+
{
|
|
317
|
+
result.type = 'claimClaimableBalance';
|
|
318
|
+
result.balanceId = attrs.toXDR('hex');
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
case 'beginSponsoringFutureReserves':
|
|
322
|
+
{
|
|
323
|
+
result.type = 'beginSponsoringFutureReserves';
|
|
324
|
+
result.sponsoredId = accountIdtoAddress(attrs.sponsoredId());
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
case 'endSponsoringFutureReserves':
|
|
328
|
+
{
|
|
329
|
+
result.type = 'endSponsoringFutureReserves';
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
case 'revokeSponsorship':
|
|
333
|
+
{
|
|
334
|
+
extractRevokeSponshipDetails(attrs, result);
|
|
335
|
+
break;
|
|
336
|
+
}
|
|
337
|
+
case 'clawback':
|
|
338
|
+
{
|
|
339
|
+
result.type = 'clawback';
|
|
340
|
+
result.amount = this._fromXDRAmount(attrs.amount());
|
|
341
|
+
result.from = (0, _decode_encode_muxed_account.encodeMuxedAccountToAddress)(attrs.from());
|
|
342
|
+
result.asset = _asset.Asset.fromOperation(attrs.asset());
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
case 'clawbackClaimableBalance':
|
|
346
|
+
{
|
|
347
|
+
result.type = 'clawbackClaimableBalance';
|
|
348
|
+
result.balanceId = attrs.toXDR('hex');
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
case 'setTrustLineFlags':
|
|
352
|
+
{
|
|
353
|
+
result.type = 'setTrustLineFlags';
|
|
354
|
+
result.asset = _asset.Asset.fromOperation(attrs.asset());
|
|
355
|
+
result.trustor = accountIdtoAddress(attrs.trustor());
|
|
356
|
+
|
|
357
|
+
// Convert from the integer-bitwised flag into a sensible object that
|
|
358
|
+
// indicates true/false for each flag that's on/off.
|
|
359
|
+
var clears = attrs.clearFlags();
|
|
360
|
+
var sets = attrs.setFlags();
|
|
361
|
+
var mapping = {
|
|
362
|
+
authorized: _xdr["default"].TrustLineFlags.authorizedFlag(),
|
|
363
|
+
authorizedToMaintainLiabilities: _xdr["default"].TrustLineFlags.authorizedToMaintainLiabilitiesFlag(),
|
|
364
|
+
clawbackEnabled: _xdr["default"].TrustLineFlags.trustlineClawbackEnabledFlag()
|
|
365
|
+
};
|
|
366
|
+
var getFlagValue = function getFlagValue(key) {
|
|
367
|
+
var bit = mapping[key].value;
|
|
368
|
+
if (sets & bit) {
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
if (clears & bit) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
return undefined;
|
|
375
|
+
};
|
|
376
|
+
result.flags = {};
|
|
377
|
+
Object.keys(mapping).forEach(function (flagName) {
|
|
378
|
+
result.flags[flagName] = getFlagValue(flagName);
|
|
379
|
+
});
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
case 'liquidityPoolDeposit':
|
|
383
|
+
{
|
|
384
|
+
result.type = 'liquidityPoolDeposit';
|
|
385
|
+
result.liquidityPoolId = attrs.liquidityPoolId().toString('hex');
|
|
386
|
+
result.maxAmountA = this._fromXDRAmount(attrs.maxAmountA());
|
|
387
|
+
result.maxAmountB = this._fromXDRAmount(attrs.maxAmountB());
|
|
388
|
+
result.minPrice = this._fromXDRPrice(attrs.minPrice());
|
|
389
|
+
result.maxPrice = this._fromXDRPrice(attrs.maxPrice());
|
|
390
|
+
break;
|
|
391
|
+
}
|
|
392
|
+
case 'liquidityPoolWithdraw':
|
|
393
|
+
{
|
|
394
|
+
result.type = 'liquidityPoolWithdraw';
|
|
395
|
+
result.liquidityPoolId = attrs.liquidityPoolId().toString('hex');
|
|
396
|
+
result.amount = this._fromXDRAmount(attrs.amount());
|
|
397
|
+
result.minAmountA = this._fromXDRAmount(attrs.minAmountA());
|
|
398
|
+
result.minAmountB = this._fromXDRAmount(attrs.minAmountB());
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
case 'invokeHostFunction':
|
|
402
|
+
{
|
|
403
|
+
var _attrs$auth;
|
|
404
|
+
result.type = 'invokeHostFunction';
|
|
405
|
+
result.func = attrs.hostFunction();
|
|
406
|
+
result.auth = (_attrs$auth = attrs.auth()) !== null && _attrs$auth !== void 0 ? _attrs$auth : [];
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
case 'extendFootprintTtl':
|
|
410
|
+
{
|
|
411
|
+
result.type = 'extendFootprintTtl';
|
|
412
|
+
result.extendTo = attrs.extendTo();
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
case 'restoreFootprint':
|
|
416
|
+
{
|
|
417
|
+
result.type = 'restoreFootprint';
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
default:
|
|
421
|
+
{
|
|
422
|
+
throw new Error("Unknown operation: ".concat(operationName));
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return result;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Validates that a given amount is possible for a Stellar asset.
|
|
430
|
+
*
|
|
431
|
+
* Specifically, this means that the amount is well, a valid number, but also
|
|
432
|
+
* that it is within the int64 range and has no more than 7 decimal levels of
|
|
433
|
+
* precision.
|
|
434
|
+
*
|
|
435
|
+
* Note that while smart contracts allow larger amounts, this is oriented
|
|
436
|
+
* towards validating the standard Stellar operations.
|
|
437
|
+
*
|
|
438
|
+
* @param {string} value the amount to validate
|
|
439
|
+
* @param {boolean} allowZero optionally, whether or not zero is valid (default: no)
|
|
440
|
+
*
|
|
441
|
+
* @returns {boolean}
|
|
442
|
+
*/
|
|
443
|
+
}, {
|
|
444
|
+
key: "isValidAmount",
|
|
445
|
+
value: function isValidAmount(value) {
|
|
446
|
+
var allowZero = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
447
|
+
if (typeof value !== 'string') {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
var amount;
|
|
451
|
+
try {
|
|
452
|
+
amount = new _bignumber["default"](value);
|
|
453
|
+
} catch (e) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
if (
|
|
457
|
+
// == 0
|
|
458
|
+
!allowZero && amount.isZero() ||
|
|
459
|
+
// < 0
|
|
460
|
+
amount.isNegative() ||
|
|
461
|
+
// > Max value
|
|
462
|
+
amount.times(ONE).gt(new _bignumber["default"](MAX_INT64).toString()) ||
|
|
463
|
+
// Decimal places (max 7)
|
|
464
|
+
amount.decimalPlaces() > 7 ||
|
|
465
|
+
// NaN or Infinity
|
|
466
|
+
amount.isNaN() || !amount.isFinite()) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
}, {
|
|
472
|
+
key: "constructAmountRequirementsError",
|
|
473
|
+
value: function constructAmountRequirementsError(arg) {
|
|
474
|
+
return "".concat(arg, " argument must be of type String, represent a positive number and have at most 7 digits after the decimal");
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Returns value converted to uint32 value or undefined.
|
|
479
|
+
* If `value` is not `Number`, `String` or `Undefined` then throws an error.
|
|
480
|
+
* Used in {@link Operation.setOptions}.
|
|
481
|
+
* @private
|
|
482
|
+
* @param {string} name Name of the property (used in error message only)
|
|
483
|
+
* @param {*} value Value to check
|
|
484
|
+
* @param {function(value, name)} isValidFunction Function to check other constraints (the argument will be a `Number`)
|
|
485
|
+
* @returns {undefined|Number}
|
|
486
|
+
*/
|
|
487
|
+
}, {
|
|
488
|
+
key: "_checkUnsignedIntValue",
|
|
489
|
+
value: function _checkUnsignedIntValue(name, value) {
|
|
490
|
+
var isValidFunction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
491
|
+
if (typeof value === 'undefined') {
|
|
492
|
+
return undefined;
|
|
493
|
+
}
|
|
494
|
+
if (typeof value === 'string') {
|
|
495
|
+
value = parseFloat(value);
|
|
496
|
+
}
|
|
497
|
+
switch (true) {
|
|
498
|
+
case typeof value !== 'number' || !Number.isFinite(value) || value % 1 !== 0:
|
|
499
|
+
throw new Error("".concat(name, " value is invalid"));
|
|
500
|
+
case value < 0:
|
|
501
|
+
throw new Error("".concat(name, " value must be unsigned"));
|
|
502
|
+
case !isValidFunction || isValidFunction && isValidFunction(value, name):
|
|
503
|
+
return value;
|
|
504
|
+
default:
|
|
505
|
+
throw new Error("".concat(name, " value is invalid"));
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* @private
|
|
510
|
+
* @param {string|BigNumber} value Value
|
|
511
|
+
* @returns {Hyper} XDR amount
|
|
512
|
+
*/
|
|
513
|
+
}, {
|
|
514
|
+
key: "_toXDRAmount",
|
|
515
|
+
value: function _toXDRAmount(value) {
|
|
516
|
+
var amount = new _bignumber["default"](value).times(ONE);
|
|
517
|
+
return _jsXdr.Hyper.fromString(amount.toString());
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* @private
|
|
522
|
+
* @param {string|BigNumber} value XDR amount
|
|
523
|
+
* @returns {BigNumber} Number
|
|
524
|
+
*/
|
|
525
|
+
}, {
|
|
526
|
+
key: "_fromXDRAmount",
|
|
527
|
+
value: function _fromXDRAmount(value) {
|
|
528
|
+
return new _bignumber["default"](value).div(ONE).toFixed(7);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* @private
|
|
533
|
+
* @param {object} price Price object
|
|
534
|
+
* @param {function} price.n numerator function that returns a value
|
|
535
|
+
* @param {function} price.d denominator function that returns a value
|
|
536
|
+
* @returns {BigNumber} Big string
|
|
537
|
+
*/
|
|
538
|
+
}, {
|
|
539
|
+
key: "_fromXDRPrice",
|
|
540
|
+
value: function _fromXDRPrice(price) {
|
|
541
|
+
var n = new _bignumber["default"](price.n());
|
|
542
|
+
return n.div(new _bignumber["default"](price.d())).toString();
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* @private
|
|
547
|
+
* @param {object} price Price object
|
|
548
|
+
* @param {function} price.n numerator function that returns a value
|
|
549
|
+
* @param {function} price.d denominator function that returns a value
|
|
550
|
+
* @returns {object} XDR price object
|
|
551
|
+
*/
|
|
552
|
+
}, {
|
|
553
|
+
key: "_toXDRPrice",
|
|
554
|
+
value: function _toXDRPrice(price) {
|
|
555
|
+
var xdrObject;
|
|
556
|
+
if (price.n && price.d) {
|
|
557
|
+
xdrObject = new _xdr["default"].Price(price);
|
|
558
|
+
} else {
|
|
559
|
+
var approx = (0, _continued_fraction.best_r)(price);
|
|
560
|
+
xdrObject = new _xdr["default"].Price({
|
|
561
|
+
n: parseInt(approx[0], 10),
|
|
562
|
+
d: parseInt(approx[1], 10)
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
if (xdrObject.n() < 0 || xdrObject.d() < 0) {
|
|
566
|
+
throw new Error('price must be positive');
|
|
567
|
+
}
|
|
568
|
+
return xdrObject;
|
|
569
|
+
}
|
|
570
|
+
}]);
|
|
571
|
+
return Operation;
|
|
572
|
+
}();
|
|
573
|
+
function extractRevokeSponshipDetails(attrs, result) {
|
|
574
|
+
switch (attrs["switch"]().name) {
|
|
575
|
+
case 'revokeSponsorshipLedgerEntry':
|
|
576
|
+
{
|
|
577
|
+
var ledgerKey = attrs.ledgerKey();
|
|
578
|
+
switch (ledgerKey["switch"]().name) {
|
|
579
|
+
case _xdr["default"].LedgerEntryType.account().name:
|
|
580
|
+
{
|
|
581
|
+
result.type = 'revokeAccountSponsorship';
|
|
582
|
+
result.account = accountIdtoAddress(ledgerKey.account().accountId());
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
case _xdr["default"].LedgerEntryType.trustline().name:
|
|
586
|
+
{
|
|
587
|
+
result.type = 'revokeTrustlineSponsorship';
|
|
588
|
+
result.account = accountIdtoAddress(ledgerKey.trustLine().accountId());
|
|
589
|
+
var xdrAsset = ledgerKey.trustLine().asset();
|
|
590
|
+
switch (xdrAsset["switch"]()) {
|
|
591
|
+
case _xdr["default"].AssetType.assetTypePoolShare():
|
|
592
|
+
result.asset = _liquidity_pool_id.LiquidityPoolId.fromOperation(xdrAsset);
|
|
593
|
+
break;
|
|
594
|
+
default:
|
|
595
|
+
result.asset = _asset.Asset.fromOperation(xdrAsset);
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
case _xdr["default"].LedgerEntryType.offer().name:
|
|
601
|
+
{
|
|
602
|
+
result.type = 'revokeOfferSponsorship';
|
|
603
|
+
result.seller = accountIdtoAddress(ledgerKey.offer().sellerId());
|
|
604
|
+
result.offerId = ledgerKey.offer().offerId().toString();
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
case _xdr["default"].LedgerEntryType.data().name:
|
|
608
|
+
{
|
|
609
|
+
result.type = 'revokeDataSponsorship';
|
|
610
|
+
result.account = accountIdtoAddress(ledgerKey.data().accountId());
|
|
611
|
+
result.name = ledgerKey.data().dataName().toString('ascii');
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
case _xdr["default"].LedgerEntryType.claimableBalance().name:
|
|
615
|
+
{
|
|
616
|
+
result.type = 'revokeClaimableBalanceSponsorship';
|
|
617
|
+
result.balanceId = ledgerKey.claimableBalance().balanceId().toXDR('hex');
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
case _xdr["default"].LedgerEntryType.liquidityPool().name:
|
|
621
|
+
{
|
|
622
|
+
result.type = 'revokeLiquidityPoolSponsorship';
|
|
623
|
+
result.liquidityPoolId = ledgerKey.liquidityPool().liquidityPoolId().toString('hex');
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
default:
|
|
627
|
+
{
|
|
628
|
+
throw new Error("Unknown ledgerKey: ".concat(attrs["switch"]().name));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
case 'revokeSponsorshipSigner':
|
|
634
|
+
{
|
|
635
|
+
result.type = 'revokeSignerSponsorship';
|
|
636
|
+
result.account = accountIdtoAddress(attrs.signer().accountId());
|
|
637
|
+
result.signer = convertXDRSignerKeyToObject(attrs.signer().signerKey());
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
default:
|
|
641
|
+
{
|
|
642
|
+
throw new Error("Unknown revokeSponsorship: ".concat(attrs["switch"]().name));
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function convertXDRSignerKeyToObject(signerKey) {
|
|
647
|
+
var attrs = {};
|
|
648
|
+
switch (signerKey["switch"]().name) {
|
|
649
|
+
case _xdr["default"].SignerKeyType.signerKeyTypeEd25519().name:
|
|
650
|
+
{
|
|
651
|
+
attrs.ed25519PublicKey = _strkey.StrKey.encodeEd25519PublicKey(signerKey.ed25519());
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
654
|
+
case _xdr["default"].SignerKeyType.signerKeyTypePreAuthTx().name:
|
|
655
|
+
{
|
|
656
|
+
attrs.preAuthTx = signerKey.preAuthTx().toString('hex');
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
case _xdr["default"].SignerKeyType.signerKeyTypeHashX().name:
|
|
660
|
+
{
|
|
661
|
+
attrs.sha256Hash = signerKey.hashX().toString('hex');
|
|
662
|
+
break;
|
|
663
|
+
}
|
|
664
|
+
default:
|
|
665
|
+
{
|
|
666
|
+
throw new Error("Unknown signerKey: ".concat(signerKey["switch"]().name));
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return attrs;
|
|
670
|
+
}
|
|
671
|
+
function accountIdtoAddress(accountId) {
|
|
672
|
+
return _strkey.StrKey.encodeEd25519PublicKey(accountId.ed25519());
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// Attach all imported operations as static methods on the Operation class
|
|
676
|
+
Operation.accountMerge = ops.accountMerge;
|
|
677
|
+
Operation.allowTrust = ops.allowTrust;
|
|
678
|
+
Operation.bumpSequence = ops.bumpSequence;
|
|
679
|
+
Operation.changeTrust = ops.changeTrust;
|
|
680
|
+
Operation.createAccount = ops.createAccount;
|
|
681
|
+
Operation.createClaimableBalance = ops.createClaimableBalance;
|
|
682
|
+
Operation.claimClaimableBalance = ops.claimClaimableBalance;
|
|
683
|
+
Operation.clawbackClaimableBalance = ops.clawbackClaimableBalance;
|
|
684
|
+
Operation.createPassiveSellOffer = ops.createPassiveSellOffer;
|
|
685
|
+
Operation.inflation = ops.inflation;
|
|
686
|
+
Operation.manageData = ops.manageData;
|
|
687
|
+
Operation.manageSellOffer = ops.manageSellOffer;
|
|
688
|
+
Operation.manageBuyOffer = ops.manageBuyOffer;
|
|
689
|
+
Operation.pathPaymentStrictReceive = ops.pathPaymentStrictReceive;
|
|
690
|
+
Operation.pathPaymentStrictSend = ops.pathPaymentStrictSend;
|
|
691
|
+
Operation.payment = ops.payment;
|
|
692
|
+
Operation.setOptions = ops.setOptions;
|
|
693
|
+
Operation.beginSponsoringFutureReserves = ops.beginSponsoringFutureReserves;
|
|
694
|
+
Operation.endSponsoringFutureReserves = ops.endSponsoringFutureReserves;
|
|
695
|
+
Operation.revokeAccountSponsorship = ops.revokeAccountSponsorship;
|
|
696
|
+
Operation.revokeTrustlineSponsorship = ops.revokeTrustlineSponsorship;
|
|
697
|
+
Operation.revokeOfferSponsorship = ops.revokeOfferSponsorship;
|
|
698
|
+
Operation.revokeDataSponsorship = ops.revokeDataSponsorship;
|
|
699
|
+
Operation.revokeClaimableBalanceSponsorship = ops.revokeClaimableBalanceSponsorship;
|
|
700
|
+
Operation.revokeLiquidityPoolSponsorship = ops.revokeLiquidityPoolSponsorship;
|
|
701
|
+
Operation.revokeSignerSponsorship = ops.revokeSignerSponsorship;
|
|
702
|
+
Operation.clawback = ops.clawback;
|
|
703
|
+
Operation.setTrustLineFlags = ops.setTrustLineFlags;
|
|
704
|
+
Operation.liquidityPoolDeposit = ops.liquidityPoolDeposit;
|
|
705
|
+
Operation.liquidityPoolWithdraw = ops.liquidityPoolWithdraw;
|
|
706
|
+
Operation.invokeHostFunction = ops.invokeHostFunction;
|
|
707
|
+
Operation.extendFootprintTtl = ops.extendFootprintTtl;
|
|
708
|
+
Operation.restoreFootprint = ops.restoreFootprint;
|
|
709
|
+
|
|
710
|
+
// these are not `xdr.Operation`s directly, but are proxies for complex but
|
|
711
|
+
// common versions of `Operation.invokeHostFunction`
|
|
712
|
+
Operation.createStellarAssetContract = ops.createStellarAssetContract;
|
|
713
|
+
Operation.invokeContractFunction = ops.invokeContractFunction;
|
|
714
|
+
Operation.createCustomContract = ops.createCustomContract;
|
|
715
|
+
Operation.uploadContractWasm = ops.uploadContractWasm;
|