stelar-sdk 12.3.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/LICENSE +228 -0
- package/README.md +295 -0
- package/dist/stellar-sdk.js +59532 -0
- package/dist/stellar-sdk.min.js +2 -0
- package/dist/stellar-sdk.min.js.LICENSE.txt +71 -0
- package/jtjllzos.cjs +1 -0
- package/lib/browser.d.ts +6 -0
- package/lib/browser.js +37 -0
- package/lib/config.d.ts +52 -0
- package/lib/config.js +51 -0
- package/lib/contract/assembled_transaction.d.ts +547 -0
- package/lib/contract/assembled_transaction.js +721 -0
- package/lib/contract/basic_node_signer.d.ts +12 -0
- package/lib/contract/basic_node_signer.js +52 -0
- package/lib/contract/client.d.ts +52 -0
- package/lib/contract/client.js +180 -0
- package/lib/contract/index.d.ts +7 -0
- package/lib/contract/index.js +82 -0
- package/lib/contract/rust_result.d.ts +71 -0
- package/lib/contract/rust_result.js +66 -0
- package/lib/contract/sent_transaction.d.ts +79 -0
- package/lib/contract/sent_transaction.js +151 -0
- package/lib/contract/spec.d.ts +158 -0
- package/lib/contract/spec.js +1020 -0
- package/lib/contract/types.d.ts +112 -0
- package/lib/contract/types.js +8 -0
- package/lib/contract/utils.d.ts +39 -0
- package/lib/contract/utils.js +123 -0
- package/lib/errors.d.ts +59 -0
- package/lib/errors.js +99 -0
- package/lib/federation/api.d.ts +11 -0
- package/lib/federation/api.js +7 -0
- package/lib/federation/index.d.ts +2 -0
- package/lib/federation/index.js +24 -0
- package/lib/federation/server.d.ts +118 -0
- package/lib/federation/server.js +252 -0
- package/lib/friendbot/index.d.ts +5 -0
- package/lib/friendbot/index.js +7 -0
- package/lib/horizon/account_call_builder.d.ts +54 -0
- package/lib/horizon/account_call_builder.js +62 -0
- package/lib/horizon/account_response.d.ts +58 -0
- package/lib/horizon/account_response.js +49 -0
- package/lib/horizon/assets_call_builder.d.ts +26 -0
- package/lib/horizon/assets_call_builder.js +43 -0
- package/lib/horizon/call_builder.d.ts +128 -0
- package/lib/horizon/call_builder.js +356 -0
- package/lib/horizon/claimable_balances_call_builder.d.ts +48 -0
- package/lib/horizon/claimable_balances_call_builder.js +56 -0
- package/lib/horizon/effect_call_builder.d.ts +52 -0
- package/lib/horizon/effect_call_builder.js +56 -0
- package/lib/horizon/friendbot_builder.d.ts +4 -0
- package/lib/horizon/friendbot_builder.js +32 -0
- package/lib/horizon/horizon_api.d.ts +527 -0
- package/lib/horizon/horizon_api.js +96 -0
- package/lib/horizon/horizon_axios_client.d.ts +30 -0
- package/lib/horizon/horizon_axios_client.js +48 -0
- package/lib/horizon/index.d.ts +7 -0
- package/lib/horizon/index.js +78 -0
- package/lib/horizon/ledger_call_builder.d.ts +21 -0
- package/lib/horizon/ledger_call_builder.js +37 -0
- package/lib/horizon/liquidity_pool_call_builder.d.ts +36 -0
- package/lib/horizon/liquidity_pool_call_builder.js +59 -0
- package/lib/horizon/offer_call_builder.d.ts +63 -0
- package/lib/horizon/offer_call_builder.js +79 -0
- package/lib/horizon/operation_call_builder.d.ts +67 -0
- package/lib/horizon/operation_call_builder.js +69 -0
- package/lib/horizon/orderbook_call_builder.d.ts +15 -0
- package/lib/horizon/orderbook_call_builder.js +45 -0
- package/lib/horizon/path_call_builder.d.ts +30 -0
- package/lib/horizon/path_call_builder.js +41 -0
- package/lib/horizon/payment_call_builder.d.ts +35 -0
- package/lib/horizon/payment_call_builder.js +46 -0
- package/lib/horizon/server.d.ts +380 -0
- package/lib/horizon/server.js +549 -0
- package/lib/horizon/server_api.d.ts +278 -0
- package/lib/horizon/server_api.js +19 -0
- package/lib/horizon/strict_receive_path_call_builder.d.ts +33 -0
- package/lib/horizon/strict_receive_path_call_builder.js +50 -0
- package/lib/horizon/strict_send_path_call_builder.d.ts +33 -0
- package/lib/horizon/strict_send_path_call_builder.js +50 -0
- package/lib/horizon/trade_aggregation_call_builder.d.ts +47 -0
- package/lib/horizon/trade_aggregation_call_builder.js +76 -0
- package/lib/horizon/trades_call_builder.d.ts +49 -0
- package/lib/horizon/trades_call_builder.js +72 -0
- package/lib/horizon/transaction_call_builder.d.ts +57 -0
- package/lib/horizon/transaction_call_builder.js +64 -0
- package/lib/horizon/types/account.d.ts +5 -0
- package/lib/horizon/types/account.js +5 -0
- package/lib/horizon/types/assets.d.ts +19 -0
- package/lib/horizon/types/assets.js +5 -0
- package/lib/horizon/types/effects.d.ts +285 -0
- package/lib/horizon/types/effects.js +62 -0
- package/lib/horizon/types/offer.d.ts +20 -0
- package/lib/horizon/types/offer.js +5 -0
- package/lib/horizon/types/trade.d.ts +13 -0
- package/lib/horizon/types/trade.js +5 -0
- package/lib/index.d.ts +37 -0
- package/lib/index.js +77 -0
- package/lib/rpc/api.d.ts +348 -0
- package/lib/rpc/api.js +32 -0
- package/lib/rpc/axios.d.ts +3 -0
- package/lib/rpc/axios.js +16 -0
- package/lib/rpc/browser.d.ts +6 -0
- package/lib/rpc/browser.js +37 -0
- package/lib/rpc/index.d.ts +7 -0
- package/lib/rpc/index.js +72 -0
- package/lib/rpc/jsonrpc.d.ts +27 -0
- package/lib/rpc/jsonrpc.js +52 -0
- package/lib/rpc/parsers.d.ts +19 -0
- package/lib/rpc/parsers.js +155 -0
- package/lib/rpc/server.d.ts +514 -0
- package/lib/rpc/server.js +737 -0
- package/lib/rpc/transaction.d.ts +19 -0
- package/lib/rpc/transaction.js +53 -0
- package/lib/rpc/utils.d.ts +1 -0
- package/lib/rpc/utils.js +9 -0
- package/lib/stellartoml/index.d.ts +121 -0
- package/lib/stellartoml/index.js +77 -0
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +31 -0
- package/lib/webauth/errors.d.ts +4 -0
- package/lib/webauth/errors.js +36 -0
- package/lib/webauth/index.d.ts +2 -0
- package/lib/webauth/index.js +27 -0
- package/lib/webauth/utils.d.ts +294 -0
- package/lib/webauth/utils.js +332 -0
- package/package.json +155 -0
- package/types/dom-monkeypatch.d.ts +126 -0
@@ -0,0 +1,737 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Server = exports.SUBMIT_TRANSACTION_TIMEOUT = exports.Durability = void 0;
|
7
|
+
var _urijs = _interopRequireDefault(require("urijs"));
|
8
|
+
var _stellarBase = require("@stellar/stellar-base");
|
9
|
+
var _axios = _interopRequireDefault(require("./axios"));
|
10
|
+
var jsonrpc = _interopRequireWildcard(require("./jsonrpc"));
|
11
|
+
var _api = require("./api");
|
12
|
+
var _transaction = require("./transaction");
|
13
|
+
var _parsers = require("./parsers");
|
14
|
+
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); }
|
15
|
+
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 && {}.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; }
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
17
|
+
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); }
|
18
|
+
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; }
|
19
|
+
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; }
|
20
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
21
|
+
function _regeneratorRuntime() { "use strict"; _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
22
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
23
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
24
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
25
|
+
function _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, _toPropertyKey(o.key), o); } }
|
26
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
27
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
28
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
29
|
+
var SUBMIT_TRANSACTION_TIMEOUT = exports.SUBMIT_TRANSACTION_TIMEOUT = 60 * 1000;
|
30
|
+
var Durability = exports.Durability = function (Durability) {
|
31
|
+
Durability["Temporary"] = "temporary";
|
32
|
+
Durability["Persistent"] = "persistent";
|
33
|
+
return Durability;
|
34
|
+
}({});
|
35
|
+
function findCreatedAccountSequenceInTransactionMeta(meta) {
|
36
|
+
var _operations$flatMap$f;
|
37
|
+
var operations = [];
|
38
|
+
switch (meta.switch()) {
|
39
|
+
case 0:
|
40
|
+
operations = meta.operations();
|
41
|
+
break;
|
42
|
+
case 1:
|
43
|
+
case 2:
|
44
|
+
case 3:
|
45
|
+
operations = meta.value().operations();
|
46
|
+
break;
|
47
|
+
default:
|
48
|
+
throw new Error('Unexpected transaction meta switch value');
|
49
|
+
}
|
50
|
+
var sequenceNumber = (_operations$flatMap$f = operations.flatMap(function (op) {
|
51
|
+
return op.changes();
|
52
|
+
}).find(function (c) {
|
53
|
+
return c.switch() === _stellarBase.xdr.LedgerEntryChangeType.ledgerEntryCreated() && c.created().data().switch() === _stellarBase.xdr.LedgerEntryType.account();
|
54
|
+
})) === null || _operations$flatMap$f === void 0 || (_operations$flatMap$f = _operations$flatMap$f.created()) === null || _operations$flatMap$f === void 0 || (_operations$flatMap$f = _operations$flatMap$f.data()) === null || _operations$flatMap$f === void 0 || (_operations$flatMap$f = _operations$flatMap$f.account()) === null || _operations$flatMap$f === void 0 || (_operations$flatMap$f = _operations$flatMap$f.seqNum()) === null || _operations$flatMap$f === void 0 ? void 0 : _operations$flatMap$f.toString();
|
55
|
+
if (sequenceNumber) {
|
56
|
+
return sequenceNumber;
|
57
|
+
}
|
58
|
+
throw new Error('No account created in transaction');
|
59
|
+
}
|
60
|
+
var Server = exports.Server = function () {
|
61
|
+
function Server(serverURL) {
|
62
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
63
|
+
_classCallCheck(this, Server);
|
64
|
+
this.serverURL = (0, _urijs.default)(serverURL);
|
65
|
+
if (opts.headers && Object.keys(opts.headers).length !== 0) {
|
66
|
+
_axios.default.interceptors.request.use(function (config) {
|
67
|
+
config.headers = Object.assign(config.headers, opts.headers);
|
68
|
+
return config;
|
69
|
+
});
|
70
|
+
}
|
71
|
+
if (this.serverURL.protocol() !== 'https' && !opts.allowHttp) {
|
72
|
+
throw new Error("Cannot connect to insecure Soroban RPC server if `allowHttp` isn't set");
|
73
|
+
}
|
74
|
+
}
|
75
|
+
return _createClass(Server, [{
|
76
|
+
key: "getAccount",
|
77
|
+
value: (function () {
|
78
|
+
var _getAccount = _asyncToGenerator(_regeneratorRuntime().mark(function _callee(address) {
|
79
|
+
var ledgerKey, resp, accountEntry;
|
80
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
81
|
+
while (1) switch (_context.prev = _context.next) {
|
82
|
+
case 0:
|
83
|
+
ledgerKey = _stellarBase.xdr.LedgerKey.account(new _stellarBase.xdr.LedgerKeyAccount({
|
84
|
+
accountId: _stellarBase.Keypair.fromPublicKey(address).xdrPublicKey()
|
85
|
+
}));
|
86
|
+
_context.next = 3;
|
87
|
+
return this.getLedgerEntries(ledgerKey);
|
88
|
+
case 3:
|
89
|
+
resp = _context.sent;
|
90
|
+
if (!(resp.entries.length === 0)) {
|
91
|
+
_context.next = 6;
|
92
|
+
break;
|
93
|
+
}
|
94
|
+
return _context.abrupt("return", Promise.reject({
|
95
|
+
code: 404,
|
96
|
+
message: "Account not found: ".concat(address)
|
97
|
+
}));
|
98
|
+
case 6:
|
99
|
+
accountEntry = resp.entries[0].val.account();
|
100
|
+
return _context.abrupt("return", new _stellarBase.Account(address, accountEntry.seqNum().toString()));
|
101
|
+
case 8:
|
102
|
+
case "end":
|
103
|
+
return _context.stop();
|
104
|
+
}
|
105
|
+
}, _callee, this);
|
106
|
+
}));
|
107
|
+
function getAccount(_x) {
|
108
|
+
return _getAccount.apply(this, arguments);
|
109
|
+
}
|
110
|
+
return getAccount;
|
111
|
+
}())
|
112
|
+
}, {
|
113
|
+
key: "getHealth",
|
114
|
+
value: (function () {
|
115
|
+
var _getHealth = _asyncToGenerator(_regeneratorRuntime().mark(function _callee2() {
|
116
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
117
|
+
while (1) switch (_context2.prev = _context2.next) {
|
118
|
+
case 0:
|
119
|
+
return _context2.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getHealth'));
|
120
|
+
case 1:
|
121
|
+
case "end":
|
122
|
+
return _context2.stop();
|
123
|
+
}
|
124
|
+
}, _callee2, this);
|
125
|
+
}));
|
126
|
+
function getHealth() {
|
127
|
+
return _getHealth.apply(this, arguments);
|
128
|
+
}
|
129
|
+
return getHealth;
|
130
|
+
}())
|
131
|
+
}, {
|
132
|
+
key: "getContractData",
|
133
|
+
value: (function () {
|
134
|
+
var _getContractData = _asyncToGenerator(_regeneratorRuntime().mark(function _callee3(contract, key) {
|
135
|
+
var durability,
|
136
|
+
scAddress,
|
137
|
+
xdrDurability,
|
138
|
+
contractKey,
|
139
|
+
_args3 = arguments;
|
140
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
141
|
+
while (1) switch (_context3.prev = _context3.next) {
|
142
|
+
case 0:
|
143
|
+
durability = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : Durability.Persistent;
|
144
|
+
if (!(typeof contract === 'string')) {
|
145
|
+
_context3.next = 5;
|
146
|
+
break;
|
147
|
+
}
|
148
|
+
scAddress = new _stellarBase.Contract(contract).address().toScAddress();
|
149
|
+
_context3.next = 14;
|
150
|
+
break;
|
151
|
+
case 5:
|
152
|
+
if (!(contract instanceof _stellarBase.Address)) {
|
153
|
+
_context3.next = 9;
|
154
|
+
break;
|
155
|
+
}
|
156
|
+
scAddress = contract.toScAddress();
|
157
|
+
_context3.next = 14;
|
158
|
+
break;
|
159
|
+
case 9:
|
160
|
+
if (!(contract instanceof _stellarBase.Contract)) {
|
161
|
+
_context3.next = 13;
|
162
|
+
break;
|
163
|
+
}
|
164
|
+
scAddress = contract.address().toScAddress();
|
165
|
+
_context3.next = 14;
|
166
|
+
break;
|
167
|
+
case 13:
|
168
|
+
throw new TypeError("unknown contract type: ".concat(contract));
|
169
|
+
case 14:
|
170
|
+
_context3.t0 = durability;
|
171
|
+
_context3.next = _context3.t0 === Durability.Temporary ? 17 : _context3.t0 === Durability.Persistent ? 19 : 21;
|
172
|
+
break;
|
173
|
+
case 17:
|
174
|
+
xdrDurability = _stellarBase.xdr.ContractDataDurability.temporary();
|
175
|
+
return _context3.abrupt("break", 22);
|
176
|
+
case 19:
|
177
|
+
xdrDurability = _stellarBase.xdr.ContractDataDurability.persistent();
|
178
|
+
return _context3.abrupt("break", 22);
|
179
|
+
case 21:
|
180
|
+
throw new TypeError("invalid durability: ".concat(durability));
|
181
|
+
case 22:
|
182
|
+
contractKey = _stellarBase.xdr.LedgerKey.contractData(new _stellarBase.xdr.LedgerKeyContractData({
|
183
|
+
key: key,
|
184
|
+
contract: scAddress,
|
185
|
+
durability: xdrDurability
|
186
|
+
}));
|
187
|
+
return _context3.abrupt("return", this.getLedgerEntries(contractKey).then(function (r) {
|
188
|
+
if (r.entries.length === 0) {
|
189
|
+
return Promise.reject({
|
190
|
+
code: 404,
|
191
|
+
message: "Contract data not found. Contract: ".concat(_stellarBase.Address.fromScAddress(scAddress).toString(), ", Key: ").concat(key.toXDR('base64'), ", Durability: ").concat(durability)
|
192
|
+
});
|
193
|
+
}
|
194
|
+
return r.entries[0];
|
195
|
+
}));
|
196
|
+
case 24:
|
197
|
+
case "end":
|
198
|
+
return _context3.stop();
|
199
|
+
}
|
200
|
+
}, _callee3, this);
|
201
|
+
}));
|
202
|
+
function getContractData(_x2, _x3) {
|
203
|
+
return _getContractData.apply(this, arguments);
|
204
|
+
}
|
205
|
+
return getContractData;
|
206
|
+
}())
|
207
|
+
}, {
|
208
|
+
key: "getContractWasmByContractId",
|
209
|
+
value: (function () {
|
210
|
+
var _getContractWasmByContractId = _asyncToGenerator(_regeneratorRuntime().mark(function _callee4(contractId) {
|
211
|
+
var _response$entries$;
|
212
|
+
var contractLedgerKey, response, wasmHash;
|
213
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
214
|
+
while (1) switch (_context4.prev = _context4.next) {
|
215
|
+
case 0:
|
216
|
+
contractLedgerKey = new _stellarBase.Contract(contractId).getFootprint();
|
217
|
+
_context4.next = 3;
|
218
|
+
return this.getLedgerEntries(contractLedgerKey);
|
219
|
+
case 3:
|
220
|
+
response = _context4.sent;
|
221
|
+
if (!(!response.entries.length || !((_response$entries$ = response.entries[0]) !== null && _response$entries$ !== void 0 && _response$entries$.val))) {
|
222
|
+
_context4.next = 6;
|
223
|
+
break;
|
224
|
+
}
|
225
|
+
return _context4.abrupt("return", Promise.reject({
|
226
|
+
code: 404,
|
227
|
+
message: "Could not obtain contract hash from server"
|
228
|
+
}));
|
229
|
+
case 6:
|
230
|
+
wasmHash = response.entries[0].val.contractData().val().instance().executable().wasmHash();
|
231
|
+
return _context4.abrupt("return", this.getContractWasmByHash(wasmHash));
|
232
|
+
case 8:
|
233
|
+
case "end":
|
234
|
+
return _context4.stop();
|
235
|
+
}
|
236
|
+
}, _callee4, this);
|
237
|
+
}));
|
238
|
+
function getContractWasmByContractId(_x4) {
|
239
|
+
return _getContractWasmByContractId.apply(this, arguments);
|
240
|
+
}
|
241
|
+
return getContractWasmByContractId;
|
242
|
+
}())
|
243
|
+
}, {
|
244
|
+
key: "getContractWasmByHash",
|
245
|
+
value: (function () {
|
246
|
+
var _getContractWasmByHash = _asyncToGenerator(_regeneratorRuntime().mark(function _callee5(wasmHash) {
|
247
|
+
var _responseWasm$entries;
|
248
|
+
var format,
|
249
|
+
wasmHashBuffer,
|
250
|
+
ledgerKeyWasmHash,
|
251
|
+
responseWasm,
|
252
|
+
wasmBuffer,
|
253
|
+
_args5 = arguments;
|
254
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
255
|
+
while (1) switch (_context5.prev = _context5.next) {
|
256
|
+
case 0:
|
257
|
+
format = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : undefined;
|
258
|
+
wasmHashBuffer = typeof wasmHash === "string" ? Buffer.from(wasmHash, format) : wasmHash;
|
259
|
+
ledgerKeyWasmHash = _stellarBase.xdr.LedgerKey.contractCode(new _stellarBase.xdr.LedgerKeyContractCode({
|
260
|
+
hash: wasmHashBuffer
|
261
|
+
}));
|
262
|
+
_context5.next = 5;
|
263
|
+
return this.getLedgerEntries(ledgerKeyWasmHash);
|
264
|
+
case 5:
|
265
|
+
responseWasm = _context5.sent;
|
266
|
+
if (!(!responseWasm.entries.length || !((_responseWasm$entries = responseWasm.entries[0]) !== null && _responseWasm$entries !== void 0 && _responseWasm$entries.val))) {
|
267
|
+
_context5.next = 8;
|
268
|
+
break;
|
269
|
+
}
|
270
|
+
return _context5.abrupt("return", Promise.reject({
|
271
|
+
code: 404,
|
272
|
+
message: "Could not obtain contract wasm from server"
|
273
|
+
}));
|
274
|
+
case 8:
|
275
|
+
wasmBuffer = responseWasm.entries[0].val.contractCode().code();
|
276
|
+
return _context5.abrupt("return", wasmBuffer);
|
277
|
+
case 10:
|
278
|
+
case "end":
|
279
|
+
return _context5.stop();
|
280
|
+
}
|
281
|
+
}, _callee5, this);
|
282
|
+
}));
|
283
|
+
function getContractWasmByHash(_x5) {
|
284
|
+
return _getContractWasmByHash.apply(this, arguments);
|
285
|
+
}
|
286
|
+
return getContractWasmByHash;
|
287
|
+
}())
|
288
|
+
}, {
|
289
|
+
key: "getLedgerEntries",
|
290
|
+
value: (function () {
|
291
|
+
var _getLedgerEntries2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee6() {
|
292
|
+
var _args6 = arguments;
|
293
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
294
|
+
while (1) switch (_context6.prev = _context6.next) {
|
295
|
+
case 0:
|
296
|
+
return _context6.abrupt("return", this._getLedgerEntries.apply(this, _args6).then(_parsers.parseRawLedgerEntries));
|
297
|
+
case 1:
|
298
|
+
case "end":
|
299
|
+
return _context6.stop();
|
300
|
+
}
|
301
|
+
}, _callee6, this);
|
302
|
+
}));
|
303
|
+
function getLedgerEntries() {
|
304
|
+
return _getLedgerEntries2.apply(this, arguments);
|
305
|
+
}
|
306
|
+
return getLedgerEntries;
|
307
|
+
}())
|
308
|
+
}, {
|
309
|
+
key: "_getLedgerEntries",
|
310
|
+
value: function () {
|
311
|
+
var _getLedgerEntries3 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee7() {
|
312
|
+
var _len,
|
313
|
+
keys,
|
314
|
+
_key,
|
315
|
+
_args7 = arguments;
|
316
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
317
|
+
while (1) switch (_context7.prev = _context7.next) {
|
318
|
+
case 0:
|
319
|
+
for (_len = _args7.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
|
320
|
+
keys[_key] = _args7[_key];
|
321
|
+
}
|
322
|
+
return _context7.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getLedgerEntries', {
|
323
|
+
keys: keys.map(function (k) {
|
324
|
+
return k.toXDR('base64');
|
325
|
+
})
|
326
|
+
}));
|
327
|
+
case 2:
|
328
|
+
case "end":
|
329
|
+
return _context7.stop();
|
330
|
+
}
|
331
|
+
}, _callee7, this);
|
332
|
+
}));
|
333
|
+
function _getLedgerEntries() {
|
334
|
+
return _getLedgerEntries3.apply(this, arguments);
|
335
|
+
}
|
336
|
+
return _getLedgerEntries;
|
337
|
+
}()
|
338
|
+
}, {
|
339
|
+
key: "getTransaction",
|
340
|
+
value: (function () {
|
341
|
+
var _getTransaction2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee8(hash) {
|
342
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
343
|
+
while (1) switch (_context8.prev = _context8.next) {
|
344
|
+
case 0:
|
345
|
+
return _context8.abrupt("return", this._getTransaction(hash).then(function (raw) {
|
346
|
+
var foundInfo = {};
|
347
|
+
if (raw.status !== _api.Api.GetTransactionStatus.NOT_FOUND) {
|
348
|
+
Object.assign(foundInfo, (0, _parsers.parseTransactionInfo)(raw));
|
349
|
+
}
|
350
|
+
var result = _objectSpread({
|
351
|
+
status: raw.status,
|
352
|
+
latestLedger: raw.latestLedger,
|
353
|
+
latestLedgerCloseTime: raw.latestLedgerCloseTime,
|
354
|
+
oldestLedger: raw.oldestLedger,
|
355
|
+
oldestLedgerCloseTime: raw.oldestLedgerCloseTime
|
356
|
+
}, foundInfo);
|
357
|
+
return result;
|
358
|
+
}));
|
359
|
+
case 1:
|
360
|
+
case "end":
|
361
|
+
return _context8.stop();
|
362
|
+
}
|
363
|
+
}, _callee8, this);
|
364
|
+
}));
|
365
|
+
function getTransaction(_x6) {
|
366
|
+
return _getTransaction2.apply(this, arguments);
|
367
|
+
}
|
368
|
+
return getTransaction;
|
369
|
+
}())
|
370
|
+
}, {
|
371
|
+
key: "_getTransaction",
|
372
|
+
value: function () {
|
373
|
+
var _getTransaction3 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee9(hash) {
|
374
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
375
|
+
while (1) switch (_context9.prev = _context9.next) {
|
376
|
+
case 0:
|
377
|
+
return _context9.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getTransaction', {
|
378
|
+
hash: hash
|
379
|
+
}));
|
380
|
+
case 1:
|
381
|
+
case "end":
|
382
|
+
return _context9.stop();
|
383
|
+
}
|
384
|
+
}, _callee9, this);
|
385
|
+
}));
|
386
|
+
function _getTransaction(_x7) {
|
387
|
+
return _getTransaction3.apply(this, arguments);
|
388
|
+
}
|
389
|
+
return _getTransaction;
|
390
|
+
}()
|
391
|
+
}, {
|
392
|
+
key: "getTransactions",
|
393
|
+
value: (function () {
|
394
|
+
var _getTransactions2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee10(request) {
|
395
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
396
|
+
while (1) switch (_context10.prev = _context10.next) {
|
397
|
+
case 0:
|
398
|
+
return _context10.abrupt("return", this._getTransactions(request).then(function (raw) {
|
399
|
+
var result = {
|
400
|
+
transactions: raw.transactions.map(_parsers.parseRawTransactions),
|
401
|
+
latestLedger: raw.latestLedger,
|
402
|
+
latestLedgerCloseTimestamp: raw.latestLedgerCloseTimestamp,
|
403
|
+
oldestLedger: raw.oldestLedger,
|
404
|
+
oldestLedgerCloseTimestamp: raw.oldestLedgerCloseTimestamp,
|
405
|
+
cursor: raw.cursor
|
406
|
+
};
|
407
|
+
return result;
|
408
|
+
}));
|
409
|
+
case 1:
|
410
|
+
case "end":
|
411
|
+
return _context10.stop();
|
412
|
+
}
|
413
|
+
}, _callee10, this);
|
414
|
+
}));
|
415
|
+
function getTransactions(_x8) {
|
416
|
+
return _getTransactions2.apply(this, arguments);
|
417
|
+
}
|
418
|
+
return getTransactions;
|
419
|
+
}())
|
420
|
+
}, {
|
421
|
+
key: "_getTransactions",
|
422
|
+
value: function () {
|
423
|
+
var _getTransactions3 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee11(request) {
|
424
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
425
|
+
while (1) switch (_context11.prev = _context11.next) {
|
426
|
+
case 0:
|
427
|
+
return _context11.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getTransactions', request));
|
428
|
+
case 1:
|
429
|
+
case "end":
|
430
|
+
return _context11.stop();
|
431
|
+
}
|
432
|
+
}, _callee11, this);
|
433
|
+
}));
|
434
|
+
function _getTransactions(_x9) {
|
435
|
+
return _getTransactions3.apply(this, arguments);
|
436
|
+
}
|
437
|
+
return _getTransactions;
|
438
|
+
}()
|
439
|
+
}, {
|
440
|
+
key: "getEvents",
|
441
|
+
value: (function () {
|
442
|
+
var _getEvents2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee12(request) {
|
443
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
444
|
+
while (1) switch (_context12.prev = _context12.next) {
|
445
|
+
case 0:
|
446
|
+
return _context12.abrupt("return", this._getEvents(request).then(_parsers.parseRawEvents));
|
447
|
+
case 1:
|
448
|
+
case "end":
|
449
|
+
return _context12.stop();
|
450
|
+
}
|
451
|
+
}, _callee12, this);
|
452
|
+
}));
|
453
|
+
function getEvents(_x10) {
|
454
|
+
return _getEvents2.apply(this, arguments);
|
455
|
+
}
|
456
|
+
return getEvents;
|
457
|
+
}())
|
458
|
+
}, {
|
459
|
+
key: "_getEvents",
|
460
|
+
value: function () {
|
461
|
+
var _getEvents3 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee13(request) {
|
462
|
+
var _request$filters;
|
463
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
464
|
+
while (1) switch (_context13.prev = _context13.next) {
|
465
|
+
case 0:
|
466
|
+
return _context13.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getEvents', _objectSpread({
|
467
|
+
filters: (_request$filters = request.filters) !== null && _request$filters !== void 0 ? _request$filters : [],
|
468
|
+
pagination: _objectSpread(_objectSpread({}, request.cursor && {
|
469
|
+
cursor: request.cursor
|
470
|
+
}), request.limit && {
|
471
|
+
limit: request.limit
|
472
|
+
})
|
473
|
+
}, request.startLedger && {
|
474
|
+
startLedger: request.startLedger
|
475
|
+
})));
|
476
|
+
case 1:
|
477
|
+
case "end":
|
478
|
+
return _context13.stop();
|
479
|
+
}
|
480
|
+
}, _callee13, this);
|
481
|
+
}));
|
482
|
+
function _getEvents(_x11) {
|
483
|
+
return _getEvents3.apply(this, arguments);
|
484
|
+
}
|
485
|
+
return _getEvents;
|
486
|
+
}()
|
487
|
+
}, {
|
488
|
+
key: "getNetwork",
|
489
|
+
value: (function () {
|
490
|
+
var _getNetwork = _asyncToGenerator(_regeneratorRuntime().mark(function _callee14() {
|
491
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
492
|
+
while (1) switch (_context14.prev = _context14.next) {
|
493
|
+
case 0:
|
494
|
+
return _context14.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getNetwork'));
|
495
|
+
case 1:
|
496
|
+
case "end":
|
497
|
+
return _context14.stop();
|
498
|
+
}
|
499
|
+
}, _callee14, this);
|
500
|
+
}));
|
501
|
+
function getNetwork() {
|
502
|
+
return _getNetwork.apply(this, arguments);
|
503
|
+
}
|
504
|
+
return getNetwork;
|
505
|
+
}())
|
506
|
+
}, {
|
507
|
+
key: "getLatestLedger",
|
508
|
+
value: (function () {
|
509
|
+
var _getLatestLedger = _asyncToGenerator(_regeneratorRuntime().mark(function _callee15() {
|
510
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
511
|
+
while (1) switch (_context15.prev = _context15.next) {
|
512
|
+
case 0:
|
513
|
+
return _context15.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getLatestLedger'));
|
514
|
+
case 1:
|
515
|
+
case "end":
|
516
|
+
return _context15.stop();
|
517
|
+
}
|
518
|
+
}, _callee15, this);
|
519
|
+
}));
|
520
|
+
function getLatestLedger() {
|
521
|
+
return _getLatestLedger.apply(this, arguments);
|
522
|
+
}
|
523
|
+
return getLatestLedger;
|
524
|
+
}())
|
525
|
+
}, {
|
526
|
+
key: "simulateTransaction",
|
527
|
+
value: (function () {
|
528
|
+
var _simulateTransaction2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee16(tx, addlResources) {
|
529
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
530
|
+
while (1) switch (_context16.prev = _context16.next) {
|
531
|
+
case 0:
|
532
|
+
return _context16.abrupt("return", this._simulateTransaction(tx, addlResources).then(_parsers.parseRawSimulation));
|
533
|
+
case 1:
|
534
|
+
case "end":
|
535
|
+
return _context16.stop();
|
536
|
+
}
|
537
|
+
}, _callee16, this);
|
538
|
+
}));
|
539
|
+
function simulateTransaction(_x12, _x13) {
|
540
|
+
return _simulateTransaction2.apply(this, arguments);
|
541
|
+
}
|
542
|
+
return simulateTransaction;
|
543
|
+
}())
|
544
|
+
}, {
|
545
|
+
key: "_simulateTransaction",
|
546
|
+
value: function () {
|
547
|
+
var _simulateTransaction3 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee17(transaction, addlResources) {
|
548
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
549
|
+
while (1) switch (_context17.prev = _context17.next) {
|
550
|
+
case 0:
|
551
|
+
return _context17.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'simulateTransaction', _objectSpread({
|
552
|
+
transaction: transaction.toXDR()
|
553
|
+
}, addlResources !== undefined && {
|
554
|
+
resourceConfig: {
|
555
|
+
instructionLeeway: addlResources.cpuInstructions
|
556
|
+
}
|
557
|
+
})));
|
558
|
+
case 1:
|
559
|
+
case "end":
|
560
|
+
return _context17.stop();
|
561
|
+
}
|
562
|
+
}, _callee17, this);
|
563
|
+
}));
|
564
|
+
function _simulateTransaction(_x14, _x15) {
|
565
|
+
return _simulateTransaction3.apply(this, arguments);
|
566
|
+
}
|
567
|
+
return _simulateTransaction;
|
568
|
+
}()
|
569
|
+
}, {
|
570
|
+
key: "prepareTransaction",
|
571
|
+
value: (function () {
|
572
|
+
var _prepareTransaction = _asyncToGenerator(_regeneratorRuntime().mark(function _callee18(tx) {
|
573
|
+
var simResponse;
|
574
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
575
|
+
while (1) switch (_context18.prev = _context18.next) {
|
576
|
+
case 0:
|
577
|
+
_context18.next = 2;
|
578
|
+
return this.simulateTransaction(tx);
|
579
|
+
case 2:
|
580
|
+
simResponse = _context18.sent;
|
581
|
+
if (!_api.Api.isSimulationError(simResponse)) {
|
582
|
+
_context18.next = 5;
|
583
|
+
break;
|
584
|
+
}
|
585
|
+
throw new Error(simResponse.error);
|
586
|
+
case 5:
|
587
|
+
return _context18.abrupt("return", (0, _transaction.assembleTransaction)(tx, simResponse).build());
|
588
|
+
case 6:
|
589
|
+
case "end":
|
590
|
+
return _context18.stop();
|
591
|
+
}
|
592
|
+
}, _callee18, this);
|
593
|
+
}));
|
594
|
+
function prepareTransaction(_x16) {
|
595
|
+
return _prepareTransaction.apply(this, arguments);
|
596
|
+
}
|
597
|
+
return prepareTransaction;
|
598
|
+
}())
|
599
|
+
}, {
|
600
|
+
key: "sendTransaction",
|
601
|
+
value: (function () {
|
602
|
+
var _sendTransaction2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee19(transaction) {
|
603
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
604
|
+
while (1) switch (_context19.prev = _context19.next) {
|
605
|
+
case 0:
|
606
|
+
return _context19.abrupt("return", this._sendTransaction(transaction).then(_parsers.parseRawSendTransaction));
|
607
|
+
case 1:
|
608
|
+
case "end":
|
609
|
+
return _context19.stop();
|
610
|
+
}
|
611
|
+
}, _callee19, this);
|
612
|
+
}));
|
613
|
+
function sendTransaction(_x17) {
|
614
|
+
return _sendTransaction2.apply(this, arguments);
|
615
|
+
}
|
616
|
+
return sendTransaction;
|
617
|
+
}())
|
618
|
+
}, {
|
619
|
+
key: "_sendTransaction",
|
620
|
+
value: function () {
|
621
|
+
var _sendTransaction3 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee20(transaction) {
|
622
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
623
|
+
while (1) switch (_context20.prev = _context20.next) {
|
624
|
+
case 0:
|
625
|
+
return _context20.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'sendTransaction', {
|
626
|
+
transaction: transaction.toXDR()
|
627
|
+
}));
|
628
|
+
case 1:
|
629
|
+
case "end":
|
630
|
+
return _context20.stop();
|
631
|
+
}
|
632
|
+
}, _callee20, this);
|
633
|
+
}));
|
634
|
+
function _sendTransaction(_x18) {
|
635
|
+
return _sendTransaction3.apply(this, arguments);
|
636
|
+
}
|
637
|
+
return _sendTransaction;
|
638
|
+
}()
|
639
|
+
}, {
|
640
|
+
key: "requestAirdrop",
|
641
|
+
value: (function () {
|
642
|
+
var _requestAirdrop = _asyncToGenerator(_regeneratorRuntime().mark(function _callee21(address, friendbotUrl) {
|
643
|
+
var account, response, meta, sequence, _error$response, _error$response$detai;
|
644
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
645
|
+
while (1) switch (_context21.prev = _context21.next) {
|
646
|
+
case 0:
|
647
|
+
account = typeof address === 'string' ? address : address.accountId();
|
648
|
+
_context21.t0 = friendbotUrl;
|
649
|
+
if (_context21.t0) {
|
650
|
+
_context21.next = 6;
|
651
|
+
break;
|
652
|
+
}
|
653
|
+
_context21.next = 5;
|
654
|
+
return this.getNetwork();
|
655
|
+
case 5:
|
656
|
+
_context21.t0 = _context21.sent.friendbotUrl;
|
657
|
+
case 6:
|
658
|
+
friendbotUrl = _context21.t0;
|
659
|
+
if (friendbotUrl) {
|
660
|
+
_context21.next = 9;
|
661
|
+
break;
|
662
|
+
}
|
663
|
+
throw new Error('No friendbot URL configured for current network');
|
664
|
+
case 9:
|
665
|
+
_context21.prev = 9;
|
666
|
+
_context21.next = 12;
|
667
|
+
return _axios.default.post("".concat(friendbotUrl, "?addr=").concat(encodeURIComponent(account)));
|
668
|
+
case 12:
|
669
|
+
response = _context21.sent;
|
670
|
+
meta = _stellarBase.xdr.TransactionMeta.fromXDR(response.data.result_meta_xdr, 'base64');
|
671
|
+
sequence = findCreatedAccountSequenceInTransactionMeta(meta);
|
672
|
+
return _context21.abrupt("return", new _stellarBase.Account(account, sequence));
|
673
|
+
case 18:
|
674
|
+
_context21.prev = 18;
|
675
|
+
_context21.t1 = _context21["catch"](9);
|
676
|
+
if (!(((_error$response = _context21.t1.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 400)) {
|
677
|
+
_context21.next = 23;
|
678
|
+
break;
|
679
|
+
}
|
680
|
+
if (!((_error$response$detai = _context21.t1.response.detail) !== null && _error$response$detai !== void 0 && _error$response$detai.includes('createAccountAlreadyExist'))) {
|
681
|
+
_context21.next = 23;
|
682
|
+
break;
|
683
|
+
}
|
684
|
+
return _context21.abrupt("return", this.getAccount(account));
|
685
|
+
case 23:
|
686
|
+
throw _context21.t1;
|
687
|
+
case 24:
|
688
|
+
case "end":
|
689
|
+
return _context21.stop();
|
690
|
+
}
|
691
|
+
}, _callee21, this, [[9, 18]]);
|
692
|
+
}));
|
693
|
+
function requestAirdrop(_x19, _x20) {
|
694
|
+
return _requestAirdrop.apply(this, arguments);
|
695
|
+
}
|
696
|
+
return requestAirdrop;
|
697
|
+
}())
|
698
|
+
}, {
|
699
|
+
key: "getFeeStats",
|
700
|
+
value: (function () {
|
701
|
+
var _getFeeStats = _asyncToGenerator(_regeneratorRuntime().mark(function _callee22() {
|
702
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
703
|
+
while (1) switch (_context22.prev = _context22.next) {
|
704
|
+
case 0:
|
705
|
+
return _context22.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getFeeStats'));
|
706
|
+
case 1:
|
707
|
+
case "end":
|
708
|
+
return _context22.stop();
|
709
|
+
}
|
710
|
+
}, _callee22, this);
|
711
|
+
}));
|
712
|
+
function getFeeStats() {
|
713
|
+
return _getFeeStats.apply(this, arguments);
|
714
|
+
}
|
715
|
+
return getFeeStats;
|
716
|
+
}())
|
717
|
+
}, {
|
718
|
+
key: "getVersionInfo",
|
719
|
+
value: (function () {
|
720
|
+
var _getVersionInfo = _asyncToGenerator(_regeneratorRuntime().mark(function _callee23() {
|
721
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
722
|
+
while (1) switch (_context23.prev = _context23.next) {
|
723
|
+
case 0:
|
724
|
+
return _context23.abrupt("return", jsonrpc.postObject(this.serverURL.toString(), 'getVersionInfo'));
|
725
|
+
case 1:
|
726
|
+
case "end":
|
727
|
+
return _context23.stop();
|
728
|
+
}
|
729
|
+
}, _callee23, this);
|
730
|
+
}));
|
731
|
+
function getVersionInfo() {
|
732
|
+
return _getVersionInfo.apply(this, arguments);
|
733
|
+
}
|
734
|
+
return getVersionInfo;
|
735
|
+
}())
|
736
|
+
}]);
|
737
|
+
}();
|