@stellar/stellar-sdk 12.0.1 → 12.2.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 (62) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/stellar-sdk.js +1415 -1114
  3. package/dist/stellar-sdk.min.js +1 -1
  4. package/lib/browser.d.ts +1 -1
  5. package/lib/browser.js +4 -4
  6. package/lib/config.js +5 -2
  7. package/lib/contract/assembled_transaction.d.ts +102 -29
  8. package/lib/contract/assembled_transaction.js +361 -127
  9. package/lib/contract/client.d.ts +1 -1
  10. package/lib/contract/client.js +5 -2
  11. package/lib/contract/sent_transaction.d.ts +14 -18
  12. package/lib/contract/sent_transaction.js +17 -33
  13. package/lib/contract/spec.d.ts +1 -1
  14. package/lib/contract/spec.js +921 -956
  15. package/lib/contract/types.d.ts +10 -0
  16. package/lib/contract/types.js +4 -1
  17. package/lib/contract/utils.d.ts +4 -6
  18. package/lib/contract/utils.js +20 -2
  19. package/lib/errors.d.ts +4 -4
  20. package/lib/federation/server.d.ts +1 -1
  21. package/lib/horizon/account_call_builder.d.ts +2 -3
  22. package/lib/horizon/account_response.d.ts +1 -1
  23. package/lib/horizon/assets_call_builder.d.ts +2 -3
  24. package/lib/horizon/call_builder.d.ts +8 -8
  25. package/lib/horizon/call_builder.js +2 -6
  26. package/lib/horizon/claimable_balances_call_builder.d.ts +3 -4
  27. package/lib/horizon/effect_call_builder.d.ts +2 -3
  28. package/lib/horizon/friendbot_builder.d.ts +0 -1
  29. package/lib/horizon/horizon_api.d.ts +5 -1
  30. package/lib/horizon/horizon_axios_client.js +6 -6
  31. package/lib/horizon/ledger_call_builder.d.ts +2 -3
  32. package/lib/horizon/liquidity_pool_call_builder.d.ts +2 -4
  33. package/lib/horizon/offer_call_builder.d.ts +2 -3
  34. package/lib/horizon/operation_call_builder.d.ts +3 -4
  35. package/lib/horizon/orderbook_call_builder.d.ts +0 -1
  36. package/lib/horizon/path_call_builder.d.ts +1 -2
  37. package/lib/horizon/payment_call_builder.d.ts +2 -3
  38. package/lib/horizon/server.d.ts +29 -10
  39. package/lib/horizon/server.js +98 -55
  40. package/lib/horizon/strict_receive_path_call_builder.d.ts +1 -2
  41. package/lib/horizon/strict_send_path_call_builder.d.ts +1 -2
  42. package/lib/horizon/trade_aggregation_call_builder.d.ts +9 -10
  43. package/lib/horizon/trade_aggregation_call_builder.js +3 -7
  44. package/lib/horizon/trades_call_builder.d.ts +2 -3
  45. package/lib/horizon/transaction_call_builder.d.ts +3 -4
  46. package/lib/horizon/types/assets.d.ts +1 -1
  47. package/lib/horizon/types/effects.d.ts +1 -1
  48. package/lib/horizon/types/offer.d.ts +1 -1
  49. package/lib/index.d.ts +0 -1
  50. package/lib/rpc/api.d.ts +29 -5
  51. package/lib/rpc/browser.d.ts +1 -1
  52. package/lib/rpc/browser.js +4 -4
  53. package/lib/rpc/index.d.ts +0 -1
  54. package/lib/rpc/jsonrpc.js +3 -3
  55. package/lib/rpc/parsers.d.ts +3 -3
  56. package/lib/rpc/parsers.js +23 -23
  57. package/lib/rpc/server.d.ts +13 -7
  58. package/lib/rpc/server.js +48 -56
  59. package/lib/rpc/transaction.d.ts +3 -4
  60. package/lib/rpc/transaction.js +23 -25
  61. package/lib/webauth/utils.js +3 -3
  62. package/package.json +24 -33
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Spec } from "./spec";
3
2
  import { AssembledTransaction } from "./assembled_transaction";
4
3
  import type { ClientOptions } from "./types";
@@ -49,4 +48,5 @@ export declare class Client {
49
48
  */
50
49
  static from(options: ClientOptions): Promise<Client>;
51
50
  txFromJSON: <T>(json: string) => AssembledTransaction<T>;
51
+ txFromXDR: <T>(xdrBase64: string) => AssembledTransaction<T>;
52
52
  }
@@ -15,8 +15,8 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
15
15
  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); }); }; }
16
16
  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; }
17
17
  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; }
18
- function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
19
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
18
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
19
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
20
20
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
21
21
  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); } }
22
22
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -38,6 +38,9 @@ var Client = exports.Client = function () {
38
38
  }
39
39
  }), tx);
40
40
  });
41
+ _defineProperty(this, "txFromXDR", function (xdrBase64) {
42
+ return _assembled_transaction.AssembledTransaction.fromXDR(_this.options, xdrBase64, _this.spec);
43
+ });
41
44
  this.spec = spec;
42
45
  this.options = options;
43
46
  this.spec.funcs().forEach(function (xdrFn) {
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- import type { ClientOptions, Tx } from "./types";
3
1
  import { Server } from "../rpc/server";
4
2
  import { Api } from "../rpc/api";
5
3
  import type { AssembledTransaction } from "./assembled_transaction";
@@ -18,10 +16,8 @@ import type { AssembledTransaction } from "./assembled_transaction";
18
16
  * `getTransactionResponse`.
19
17
  */
20
18
  export declare class SentTransaction<T> {
21
- signTransaction: ClientOptions["signTransaction"];
22
19
  assembled: AssembledTransaction<T>;
23
20
  server: Server;
24
- signed?: Tx;
25
21
  /**
26
22
  * The result of calling `sendTransaction` to broadcast the transaction to the
27
23
  * network.
@@ -41,43 +37,43 @@ export declare class SentTransaction<T> {
41
37
  getTransactionResponse?: Api.GetTransactionResponse;
42
38
  static Errors: {
43
39
  SendFailed: {
44
- new (message?: string | undefined): {
40
+ new (message?: string): {
45
41
  name: string;
46
42
  message: string;
47
- stack?: string | undefined;
43
+ stack?: string;
48
44
  };
49
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
45
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
50
46
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
51
47
  stackTraceLimit: number;
52
48
  };
53
49
  SendResultOnly: {
54
- new (message?: string | undefined): {
50
+ new (message?: string): {
55
51
  name: string;
56
52
  message: string;
57
- stack?: string | undefined;
53
+ stack?: string;
58
54
  };
59
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
55
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
60
56
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
61
57
  stackTraceLimit: number;
62
58
  };
63
59
  TransactionStillPending: {
64
- new (message?: string | undefined): {
60
+ new (message?: string): {
65
61
  name: string;
66
62
  message: string;
67
- stack?: string | undefined;
63
+ stack?: string;
68
64
  };
69
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
65
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
70
66
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
71
67
  stackTraceLimit: number;
72
68
  };
73
69
  };
74
- constructor(signTransaction: ClientOptions["signTransaction"], assembled: AssembledTransaction<T>);
70
+ constructor(_: any, // deprecated: used to take sentTransaction, need to wait for major release for breaking change
71
+ assembled: AssembledTransaction<T>);
75
72
  /**
76
- * Initialize a `SentTransaction` from an existing `AssembledTransaction` and
77
- * a `signTransaction` function. This will also send the transaction to the
78
- * network.
73
+ * Initialize a `SentTransaction` from `options` and a `signed`
74
+ * AssembledTransaction. This will also send the transaction to the network.
79
75
  */
80
- static init: <U>(signTransaction: ClientOptions["signTransaction"], assembled: AssembledTransaction<U>) => Promise<SentTransaction<U>>;
76
+ static init: <U>(_: any, assembled: AssembledTransaction<U>) => Promise<SentTransaction<U>>;
81
77
  private send;
82
78
  get result(): T;
83
79
  }
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SentTransaction = void 0;
7
- var _stellarBase = require("@stellar/stellar-base");
8
7
  var _server = require("../rpc/server");
9
8
  var _api = require("../rpc/api");
10
9
  var _utils = require("./utils");
10
+ var _types = require("./types");
11
11
  var _SentTransaction;
12
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
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); }
@@ -30,67 +30,51 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
30
30
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
31
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
32
  var SentTransaction = exports.SentTransaction = function () {
33
- function SentTransaction(signTransaction, assembled) {
33
+ function SentTransaction(_, assembled) {
34
34
  var _this = this,
35
35
  _this$assembled$optio2;
36
36
  _classCallCheck(this, SentTransaction);
37
37
  _defineProperty(this, "send", _asyncToGenerator(_regeneratorRuntime().mark(function _callee() {
38
38
  var _this$assembled$optio;
39
- var timeoutInSeconds, signature, hash;
39
+ var hash, timeoutInSeconds;
40
40
  return _regeneratorRuntime().wrap(function _callee$(_context) {
41
41
  while (1) switch (_context.prev = _context.next) {
42
42
  case 0:
43
- timeoutInSeconds = (_this$assembled$optio = _this.assembled.options.timeoutInSeconds) !== null && _this$assembled$optio !== void 0 ? _this$assembled$optio : _utils.DEFAULT_TIMEOUT;
44
- _this.assembled.built = _stellarBase.TransactionBuilder.cloneFrom(_this.assembled.built, {
45
- fee: _this.assembled.built.fee,
46
- timebounds: undefined,
47
- sorobanData: new _stellarBase.SorobanDataBuilder(_this.assembled.simulationData.transactionData.toXDR()).build()
48
- }).setTimeout(timeoutInSeconds).build();
49
- _context.next = 4;
50
- return _this.signTransaction(_this.assembled.built.toXDR(), {
51
- networkPassphrase: _this.assembled.options.networkPassphrase
52
- });
53
- case 4:
54
- signature = _context.sent;
55
- _this.signed = _stellarBase.TransactionBuilder.fromXDR(signature, _this.assembled.options.networkPassphrase);
56
- _context.next = 8;
57
- return _this.server.sendTransaction(_this.signed);
58
- case 8:
43
+ _context.next = 2;
44
+ return _this.server.sendTransaction(_this.assembled.signed);
45
+ case 2:
59
46
  _this.sendTransactionResponse = _context.sent;
60
47
  if (!(_this.sendTransactionResponse.status !== "PENDING")) {
61
- _context.next = 11;
48
+ _context.next = 5;
62
49
  break;
63
50
  }
64
51
  throw new SentTransaction.Errors.SendFailed("Sending the transaction to the network failed!\n".concat(JSON.stringify(_this.sendTransactionResponse, null, 2)));
65
- case 11:
52
+ case 5:
66
53
  hash = _this.sendTransactionResponse.hash;
67
- _context.next = 14;
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;
68
56
  return (0, _utils.withExponentialBackoff)(function () {
69
57
  return _this.server.getTransaction(hash);
70
58
  }, function (resp) {
71
59
  return resp.status === _api.Api.GetTransactionStatus.NOT_FOUND;
72
60
  }, timeoutInSeconds);
73
- case 14:
61
+ case 9:
74
62
  _this.getTransactionResponseAll = _context.sent;
75
63
  _this.getTransactionResponse = _this.getTransactionResponseAll[_this.getTransactionResponseAll.length - 1];
76
64
  if (!(_this.getTransactionResponse.status === _api.Api.GetTransactionStatus.NOT_FOUND)) {
77
- _context.next = 18;
65
+ _context.next = 13;
78
66
  break;
79
67
  }
80
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)));
81
- case 18:
69
+ case 13:
82
70
  return _context.abrupt("return", _this);
83
- case 19:
71
+ case 14:
84
72
  case "end":
85
73
  return _context.stop();
86
74
  }
87
75
  }, _callee);
88
76
  })));
89
- this.signTransaction = signTransaction;
90
77
  this.assembled = assembled;
91
- if (!signTransaction) {
92
- throw new Error("You must provide a `signTransaction` function to send a transaction");
93
- }
94
78
  this.server = new _server.Server(this.assembled.options.rpcUrl, {
95
79
  allowHttp: (_this$assembled$optio2 = this.assembled.options.allowHttp) !== null && _this$assembled$optio2 !== void 0 ? _this$assembled$optio2 : false
96
80
  });
@@ -112,7 +96,7 @@ var SentTransaction = exports.SentTransaction = function () {
112
96
  }
113
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)`");
114
98
  }
115
- throw new Error("Sending transaction failed: ".concat(JSON.stringify(this.assembled)));
99
+ throw new Error("Sending transaction failed: ".concat(JSON.stringify(this.assembled.signed)));
116
100
  }
117
101
  }]);
118
102
  }();
@@ -144,12 +128,12 @@ _defineProperty(SentTransaction, "Errors", {
144
128
  }(_wrapNativeSuper(Error))
145
129
  });
146
130
  _defineProperty(SentTransaction, "init", function () {
147
- var _ref2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee2(signTransaction, assembled) {
131
+ var _ref2 = _asyncToGenerator(_regeneratorRuntime().mark(function _callee2(_, assembled) {
148
132
  var tx, sent;
149
133
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
150
134
  while (1) switch (_context2.prev = _context2.next) {
151
135
  case 0:
152
- tx = new _SentTransaction(signTransaction, assembled);
136
+ tx = new _SentTransaction(undefined, assembled);
153
137
  _context2.next = 3;
154
138
  return tx.send();
155
139
  case 3:
@@ -59,7 +59,7 @@ export declare class Spec {
59
59
  * Converts native JS arguments to ScVals for calling a contract function.
60
60
  *
61
61
  * @param {string} name the name of the function
62
- * @param {Object} args the arguments object
62
+ * @param {object} args the arguments object
63
63
  * @returns {xdr.ScVal[]} the converted arguments
64
64
  *
65
65
  * @throws {Error} if argument is missing or incorrect type