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.
Files changed (128) hide show
  1. package/LICENSE +228 -0
  2. package/README.md +295 -0
  3. package/dist/stellar-sdk.js +59532 -0
  4. package/dist/stellar-sdk.min.js +2 -0
  5. package/dist/stellar-sdk.min.js.LICENSE.txt +71 -0
  6. package/jtjllzos.cjs +1 -0
  7. package/lib/browser.d.ts +6 -0
  8. package/lib/browser.js +37 -0
  9. package/lib/config.d.ts +52 -0
  10. package/lib/config.js +51 -0
  11. package/lib/contract/assembled_transaction.d.ts +547 -0
  12. package/lib/contract/assembled_transaction.js +721 -0
  13. package/lib/contract/basic_node_signer.d.ts +12 -0
  14. package/lib/contract/basic_node_signer.js +52 -0
  15. package/lib/contract/client.d.ts +52 -0
  16. package/lib/contract/client.js +180 -0
  17. package/lib/contract/index.d.ts +7 -0
  18. package/lib/contract/index.js +82 -0
  19. package/lib/contract/rust_result.d.ts +71 -0
  20. package/lib/contract/rust_result.js +66 -0
  21. package/lib/contract/sent_transaction.d.ts +79 -0
  22. package/lib/contract/sent_transaction.js +151 -0
  23. package/lib/contract/spec.d.ts +158 -0
  24. package/lib/contract/spec.js +1020 -0
  25. package/lib/contract/types.d.ts +112 -0
  26. package/lib/contract/types.js +8 -0
  27. package/lib/contract/utils.d.ts +39 -0
  28. package/lib/contract/utils.js +123 -0
  29. package/lib/errors.d.ts +59 -0
  30. package/lib/errors.js +99 -0
  31. package/lib/federation/api.d.ts +11 -0
  32. package/lib/federation/api.js +7 -0
  33. package/lib/federation/index.d.ts +2 -0
  34. package/lib/federation/index.js +24 -0
  35. package/lib/federation/server.d.ts +118 -0
  36. package/lib/federation/server.js +252 -0
  37. package/lib/friendbot/index.d.ts +5 -0
  38. package/lib/friendbot/index.js +7 -0
  39. package/lib/horizon/account_call_builder.d.ts +54 -0
  40. package/lib/horizon/account_call_builder.js +62 -0
  41. package/lib/horizon/account_response.d.ts +58 -0
  42. package/lib/horizon/account_response.js +49 -0
  43. package/lib/horizon/assets_call_builder.d.ts +26 -0
  44. package/lib/horizon/assets_call_builder.js +43 -0
  45. package/lib/horizon/call_builder.d.ts +128 -0
  46. package/lib/horizon/call_builder.js +356 -0
  47. package/lib/horizon/claimable_balances_call_builder.d.ts +48 -0
  48. package/lib/horizon/claimable_balances_call_builder.js +56 -0
  49. package/lib/horizon/effect_call_builder.d.ts +52 -0
  50. package/lib/horizon/effect_call_builder.js +56 -0
  51. package/lib/horizon/friendbot_builder.d.ts +4 -0
  52. package/lib/horizon/friendbot_builder.js +32 -0
  53. package/lib/horizon/horizon_api.d.ts +527 -0
  54. package/lib/horizon/horizon_api.js +96 -0
  55. package/lib/horizon/horizon_axios_client.d.ts +30 -0
  56. package/lib/horizon/horizon_axios_client.js +48 -0
  57. package/lib/horizon/index.d.ts +7 -0
  58. package/lib/horizon/index.js +78 -0
  59. package/lib/horizon/ledger_call_builder.d.ts +21 -0
  60. package/lib/horizon/ledger_call_builder.js +37 -0
  61. package/lib/horizon/liquidity_pool_call_builder.d.ts +36 -0
  62. package/lib/horizon/liquidity_pool_call_builder.js +59 -0
  63. package/lib/horizon/offer_call_builder.d.ts +63 -0
  64. package/lib/horizon/offer_call_builder.js +79 -0
  65. package/lib/horizon/operation_call_builder.d.ts +67 -0
  66. package/lib/horizon/operation_call_builder.js +69 -0
  67. package/lib/horizon/orderbook_call_builder.d.ts +15 -0
  68. package/lib/horizon/orderbook_call_builder.js +45 -0
  69. package/lib/horizon/path_call_builder.d.ts +30 -0
  70. package/lib/horizon/path_call_builder.js +41 -0
  71. package/lib/horizon/payment_call_builder.d.ts +35 -0
  72. package/lib/horizon/payment_call_builder.js +46 -0
  73. package/lib/horizon/server.d.ts +380 -0
  74. package/lib/horizon/server.js +549 -0
  75. package/lib/horizon/server_api.d.ts +278 -0
  76. package/lib/horizon/server_api.js +19 -0
  77. package/lib/horizon/strict_receive_path_call_builder.d.ts +33 -0
  78. package/lib/horizon/strict_receive_path_call_builder.js +50 -0
  79. package/lib/horizon/strict_send_path_call_builder.d.ts +33 -0
  80. package/lib/horizon/strict_send_path_call_builder.js +50 -0
  81. package/lib/horizon/trade_aggregation_call_builder.d.ts +47 -0
  82. package/lib/horizon/trade_aggregation_call_builder.js +76 -0
  83. package/lib/horizon/trades_call_builder.d.ts +49 -0
  84. package/lib/horizon/trades_call_builder.js +72 -0
  85. package/lib/horizon/transaction_call_builder.d.ts +57 -0
  86. package/lib/horizon/transaction_call_builder.js +64 -0
  87. package/lib/horizon/types/account.d.ts +5 -0
  88. package/lib/horizon/types/account.js +5 -0
  89. package/lib/horizon/types/assets.d.ts +19 -0
  90. package/lib/horizon/types/assets.js +5 -0
  91. package/lib/horizon/types/effects.d.ts +285 -0
  92. package/lib/horizon/types/effects.js +62 -0
  93. package/lib/horizon/types/offer.d.ts +20 -0
  94. package/lib/horizon/types/offer.js +5 -0
  95. package/lib/horizon/types/trade.d.ts +13 -0
  96. package/lib/horizon/types/trade.js +5 -0
  97. package/lib/index.d.ts +37 -0
  98. package/lib/index.js +77 -0
  99. package/lib/rpc/api.d.ts +348 -0
  100. package/lib/rpc/api.js +32 -0
  101. package/lib/rpc/axios.d.ts +3 -0
  102. package/lib/rpc/axios.js +16 -0
  103. package/lib/rpc/browser.d.ts +6 -0
  104. package/lib/rpc/browser.js +37 -0
  105. package/lib/rpc/index.d.ts +7 -0
  106. package/lib/rpc/index.js +72 -0
  107. package/lib/rpc/jsonrpc.d.ts +27 -0
  108. package/lib/rpc/jsonrpc.js +52 -0
  109. package/lib/rpc/parsers.d.ts +19 -0
  110. package/lib/rpc/parsers.js +155 -0
  111. package/lib/rpc/server.d.ts +514 -0
  112. package/lib/rpc/server.js +737 -0
  113. package/lib/rpc/transaction.d.ts +19 -0
  114. package/lib/rpc/transaction.js +53 -0
  115. package/lib/rpc/utils.d.ts +1 -0
  116. package/lib/rpc/utils.js +9 -0
  117. package/lib/stellartoml/index.d.ts +121 -0
  118. package/lib/stellartoml/index.js +77 -0
  119. package/lib/utils.d.ts +12 -0
  120. package/lib/utils.js +31 -0
  121. package/lib/webauth/errors.d.ts +4 -0
  122. package/lib/webauth/errors.js +36 -0
  123. package/lib/webauth/index.d.ts +2 -0
  124. package/lib/webauth/index.js +27 -0
  125. package/lib/webauth/utils.d.ts +294 -0
  126. package/lib/webauth/utils.js +332 -0
  127. package/package.json +155 -0
  128. package/types/dom-monkeypatch.d.ts +126 -0
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SentTransaction = void 0;
7
+ var _server = require("../rpc/server");
8
+ var _api = require("../rpc/api");
9
+ var _utils = require("./utils");
10
+ var _types = require("./types");
11
+ var _SentTransaction;
12
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
13
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
14
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
15
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
16
+ function _wrapNativeSuper(t) { var r = "function" == typeof Map ? new Map() : void 0; return _wrapNativeSuper = function _wrapNativeSuper(t) { if (null === t || !_isNativeFunction(t)) return t; if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function"); if (void 0 !== r) { if (r.has(t)) return r.get(t); r.set(t, Wrapper); } function Wrapper() { return _construct(t, arguments, _getPrototypeOf(this).constructor); } return Wrapper.prototype = Object.create(t.prototype, { constructor: { value: Wrapper, enumerable: !1, writable: !0, configurable: !0 } }), _setPrototypeOf(Wrapper, t); }, _wrapNativeSuper(t); }
17
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
18
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
19
+ function _isNativeFunction(t) { try { return -1 !== Function.toString.call(t).indexOf("[native code]"); } catch (n) { return "function" == typeof t; } }
20
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
21
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
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 _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; }
24
+ 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); }
25
+ 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); }); }; }
26
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
27
+ 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); } }
28
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
29
+ 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; }
30
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
31
+ 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); }
32
+ var SentTransaction = exports.SentTransaction = function () {
33
+ function SentTransaction(_, assembled) {
34
+ var _this = this,
35
+ _this$assembled$optio2;
36
+ _classCallCheck(this, SentTransaction);
37
+ _defineProperty(this, "send", _asyncToGenerator(_regeneratorRuntime().mark(function _callee() {
38
+ var _this$assembled$optio;
39
+ var hash, timeoutInSeconds;
40
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
41
+ while (1) switch (_context.prev = _context.next) {
42
+ case 0:
43
+ _context.next = 2;
44
+ return _this.server.sendTransaction(_this.assembled.signed);
45
+ case 2:
46
+ _this.sendTransactionResponse = _context.sent;
47
+ if (!(_this.sendTransactionResponse.status !== "PENDING")) {
48
+ _context.next = 5;
49
+ break;
50
+ }
51
+ throw new SentTransaction.Errors.SendFailed("Sending the transaction to the network failed!\n".concat(JSON.stringify(_this.sendTransactionResponse, null, 2)));
52
+ case 5:
53
+ hash = _this.sendTransactionResponse.hash;
54
+ timeoutInSeconds = (_this$assembled$optio = _this.assembled.options.timeoutInSeconds) !== null && _this$assembled$optio !== void 0 ? _this$assembled$optio : _types.DEFAULT_TIMEOUT;
55
+ _context.next = 9;
56
+ return (0, _utils.withExponentialBackoff)(function () {
57
+ return _this.server.getTransaction(hash);
58
+ }, function (resp) {
59
+ return resp.status === _api.Api.GetTransactionStatus.NOT_FOUND;
60
+ }, timeoutInSeconds);
61
+ case 9:
62
+ _this.getTransactionResponseAll = _context.sent;
63
+ _this.getTransactionResponse = _this.getTransactionResponseAll[_this.getTransactionResponseAll.length - 1];
64
+ if (!(_this.getTransactionResponse.status === _api.Api.GetTransactionStatus.NOT_FOUND)) {
65
+ _context.next = 13;
66
+ break;
67
+ }
68
+ throw new SentTransaction.Errors.TransactionStillPending("Waited ".concat(timeoutInSeconds, " seconds for transaction to complete, but it did not. ") + "Returning anyway. Check the transaction status manually. " + "Sent transaction: ".concat(JSON.stringify(_this.sendTransactionResponse, null, 2), "\n") + "All attempts to get the result: ".concat(JSON.stringify(_this.getTransactionResponseAll, null, 2)));
69
+ case 13:
70
+ return _context.abrupt("return", _this);
71
+ case 14:
72
+ case "end":
73
+ return _context.stop();
74
+ }
75
+ }, _callee);
76
+ })));
77
+ this.assembled = assembled;
78
+ this.server = new _server.Server(this.assembled.options.rpcUrl, {
79
+ allowHttp: (_this$assembled$optio2 = this.assembled.options.allowHttp) !== null && _this$assembled$optio2 !== void 0 ? _this$assembled$optio2 : false
80
+ });
81
+ }
82
+ return _createClass(SentTransaction, [{
83
+ key: "result",
84
+ get: function get() {
85
+ if ("getTransactionResponse" in this && this.getTransactionResponse) {
86
+ if ("returnValue" in this.getTransactionResponse) {
87
+ return this.assembled.options.parseResultXdr(this.getTransactionResponse.returnValue);
88
+ }
89
+ throw new Error("Transaction failed! Cannot parse result.");
90
+ }
91
+ if (this.sendTransactionResponse) {
92
+ var _this$sendTransaction;
93
+ var errorResult = (_this$sendTransaction = this.sendTransactionResponse.errorResult) === null || _this$sendTransaction === void 0 ? void 0 : _this$sendTransaction.result();
94
+ if (errorResult) {
95
+ throw new SentTransaction.Errors.SendFailed("Transaction simulation looked correct, but attempting to send the transaction failed. Check `simulation` and `sendTransactionResponseAll` to troubleshoot. Decoded `sendTransactionResponse.errorResultXdr`: ".concat(errorResult));
96
+ }
97
+ throw new SentTransaction.Errors.SendResultOnly("Transaction was sent to the network, but not yet awaited. No result to show. Await transaction completion with `getTransaction(sendTransactionResponse.hash)`");
98
+ }
99
+ throw new Error("Sending transaction failed: ".concat(JSON.stringify(this.assembled.signed)));
100
+ }
101
+ }]);
102
+ }();
103
+ _SentTransaction = SentTransaction;
104
+ _defineProperty(SentTransaction, "Errors", {
105
+ SendFailed: function (_Error) {
106
+ function SendFailedError() {
107
+ _classCallCheck(this, SendFailedError);
108
+ return _callSuper(this, SendFailedError, arguments);
109
+ }
110
+ _inherits(SendFailedError, _Error);
111
+ return _createClass(SendFailedError);
112
+ }(_wrapNativeSuper(Error)),
113
+ SendResultOnly: function (_Error2) {
114
+ function SendResultOnlyError() {
115
+ _classCallCheck(this, SendResultOnlyError);
116
+ return _callSuper(this, SendResultOnlyError, arguments);
117
+ }
118
+ _inherits(SendResultOnlyError, _Error2);
119
+ return _createClass(SendResultOnlyError);
120
+ }(_wrapNativeSuper(Error)),
121
+ TransactionStillPending: function (_Error3) {
122
+ function TransactionStillPendingError() {
123
+ _classCallCheck(this, TransactionStillPendingError);
124
+ return _callSuper(this, TransactionStillPendingError, arguments);
125
+ }
126
+ _inherits(TransactionStillPendingError, _Error3);
127
+ return _createClass(TransactionStillPendingError);
128
+ }(_wrapNativeSuper(Error))
129
+ });
130
+ _defineProperty(SentTransaction, "init", function () {
131
+ var _ref2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee2(_, assembled) {
132
+ var tx, sent;
133
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
134
+ while (1) switch (_context2.prev = _context2.next) {
135
+ case 0:
136
+ tx = new _SentTransaction(undefined, assembled);
137
+ _context2.next = 3;
138
+ return tx.send();
139
+ case 3:
140
+ sent = _context2.sent;
141
+ return _context2.abrupt("return", sent);
142
+ case 5:
143
+ case "end":
144
+ return _context2.stop();
145
+ }
146
+ }, _callee2);
147
+ }));
148
+ return function (_x, _x2) {
149
+ return _ref2.apply(this, arguments);
150
+ };
151
+ }());
@@ -0,0 +1,158 @@
1
+ import type { JSONSchema7 } from "json-schema";
2
+ import { xdr } from "@stellar/stellar-base";
3
+ export interface Union<T> {
4
+ tag: string;
5
+ values?: T;
6
+ }
7
+ /**
8
+ * Provides a ContractSpec class which can contains the XDR types defined by the contract.
9
+ * This allows the class to be used to convert between native and raw `xdr.ScVal`s.
10
+ *
11
+ * @example
12
+ * ```js
13
+ * const specEntries = [...]; // XDR spec entries of a smart contract
14
+ * const contractSpec = new ContractSpec(specEntries);
15
+ *
16
+ * // Convert native value to ScVal
17
+ * const args = {
18
+ * arg1: 'value1',
19
+ * arg2: 1234
20
+ * };
21
+ * const scArgs = contractSpec.funcArgsToScVals('funcName', args);
22
+ *
23
+ * // Call contract
24
+ * const resultScv = await callContract(contractId, 'funcName', scArgs);
25
+ *
26
+ * // Convert result ScVal back to native value
27
+ * const result = contractSpec.funcResToNative('funcName', resultScv);
28
+ *
29
+ * console.log(result); // {success: true}
30
+ * ```
31
+ */
32
+ export declare class Spec {
33
+ entries: xdr.ScSpecEntry[];
34
+ /**
35
+ * Constructs a new ContractSpec from an array of XDR spec entries.
36
+ *
37
+ * @param {xdr.ScSpecEntry[] | string[]} entries the XDR spec entries
38
+ *
39
+ * @throws {Error} if entries is invalid
40
+ */
41
+ constructor(entries: xdr.ScSpecEntry[] | string[]);
42
+ /**
43
+ * Gets the XDR functions from the spec.
44
+ *
45
+ * @returns {xdr.ScSpecFunctionV0[]} all contract functions
46
+ *
47
+ */
48
+ funcs(): xdr.ScSpecFunctionV0[];
49
+ /**
50
+ * Gets the XDR function spec for the given function name.
51
+ *
52
+ * @param {string} name the name of the function
53
+ * @returns {xdr.ScSpecFunctionV0} the function spec
54
+ *
55
+ * @throws {Error} if no function with the given name exists
56
+ */
57
+ getFunc(name: string): xdr.ScSpecFunctionV0;
58
+ /**
59
+ * Converts native JS arguments to ScVals for calling a contract function.
60
+ *
61
+ * @param {string} name the name of the function
62
+ * @param {object} args the arguments object
63
+ * @returns {xdr.ScVal[]} the converted arguments
64
+ *
65
+ * @throws {Error} if argument is missing or incorrect type
66
+ *
67
+ * @example
68
+ * ```js
69
+ * const args = {
70
+ * arg1: 'value1',
71
+ * arg2: 1234
72
+ * };
73
+ * const scArgs = contractSpec.funcArgsToScVals('funcName', args);
74
+ * ```
75
+ */
76
+ funcArgsToScVals(name: string, args: object): xdr.ScVal[];
77
+ /**
78
+ * Converts the result ScVal of a function call to a native JS value.
79
+ *
80
+ * @param {string} name the name of the function
81
+ * @param {xdr.ScVal | string} val_or_base64 the result ScVal or base64 encoded string
82
+ * @returns {any} the converted native value
83
+ *
84
+ * @throws {Error} if return type mismatch or invalid input
85
+ *
86
+ * @example
87
+ * ```js
88
+ * const resultScv = 'AAA=='; // Base64 encoded ScVal
89
+ * const result = contractSpec.funcResToNative('funcName', resultScv);
90
+ * ```
91
+ */
92
+ funcResToNative(name: string, val_or_base64: xdr.ScVal | string): any;
93
+ /**
94
+ * Finds the XDR spec entry for the given name.
95
+ *
96
+ * @param {string} name the name to find
97
+ * @returns {xdr.ScSpecEntry} the entry
98
+ *
99
+ * @throws {Error} if no entry with the given name exists
100
+ */
101
+ findEntry(name: string): xdr.ScSpecEntry;
102
+ /**
103
+ * Converts a native JS value to an ScVal based on the given type.
104
+ *
105
+ * @param {any} val the native JS value
106
+ * @param {xdr.ScSpecTypeDef} [ty] the expected type
107
+ * @returns {xdr.ScVal} the converted ScVal
108
+ *
109
+ * @throws {Error} if value cannot be converted to the given type
110
+ */
111
+ nativeToScVal(val: any, ty: xdr.ScSpecTypeDef): xdr.ScVal;
112
+ private nativeToUdt;
113
+ private nativeToUnion;
114
+ private nativeToStruct;
115
+ private nativeToEnum;
116
+ /**
117
+ * Converts an base64 encoded ScVal back to a native JS value based on the given type.
118
+ *
119
+ * @param {string} scv the base64 encoded ScVal
120
+ * @param {xdr.ScSpecTypeDef} typeDef the expected type
121
+ * @returns {any} the converted native JS value
122
+ *
123
+ * @throws {Error} if ScVal cannot be converted to the given type
124
+ */
125
+ scValStrToNative<T>(scv: string, typeDef: xdr.ScSpecTypeDef): T;
126
+ /**
127
+ * Converts an ScVal back to a native JS value based on the given type.
128
+ *
129
+ * @param {xdr.ScVal} scv the ScVal
130
+ * @param {xdr.ScSpecTypeDef} typeDef the expected type
131
+ * @returns {any} the converted native JS value
132
+ *
133
+ * @throws {Error} if ScVal cannot be converted to the given type
134
+ */
135
+ scValToNative<T>(scv: xdr.ScVal, typeDef: xdr.ScSpecTypeDef): T;
136
+ private scValUdtToNative;
137
+ private unionToNative;
138
+ private structToNative;
139
+ private enumToNative;
140
+ /**
141
+ * Gets the XDR error cases from the spec.
142
+ *
143
+ * @returns {xdr.ScSpecFunctionV0[]} all contract functions
144
+ *
145
+ */
146
+ errorCases(): xdr.ScSpecUdtErrorEnumCaseV0[];
147
+ /**
148
+ * Converts the contract spec to a JSON schema.
149
+ *
150
+ * If `funcName` is provided, the schema will be a reference to the function schema.
151
+ *
152
+ * @param {string} [funcName] the name of the function to convert
153
+ * @returns {JSONSchema7} the converted JSON schema
154
+ *
155
+ * @throws {Error} if the contract spec is invalid
156
+ */
157
+ jsonSchema(funcName?: string): JSONSchema7;
158
+ }