@stellar/stellar-sdk 14.1.1 → 14.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 (119) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +14 -20
  3. package/dist/stellar-sdk-minimal.js +449 -334
  4. package/dist/stellar-sdk-minimal.min.js +1 -1
  5. package/dist/stellar-sdk-no-axios.js +449 -334
  6. package/dist/stellar-sdk-no-axios.min.js +1 -1
  7. package/dist/stellar-sdk-no-eventsource.js +698 -510
  8. package/dist/stellar-sdk-no-eventsource.min.js +1 -1
  9. package/dist/stellar-sdk.js +698 -510
  10. package/dist/stellar-sdk.min.js +1 -1
  11. package/lib/contract/client.js +2 -2
  12. package/lib/contract/utils.js +7 -7
  13. package/lib/federation/index.d.ts +2 -2
  14. package/lib/horizon/call_builder.js +1 -1
  15. package/lib/horizon/horizon_api.js +0 -1
  16. package/lib/horizon/horizon_axios_client.js +4 -4
  17. package/lib/horizon/index.d.ts +1 -1
  18. package/lib/horizon/types/effects.d.ts +41 -41
  19. package/lib/horizon/types/trade.d.ts +1 -1
  20. package/lib/http-client/fetch-client.d.ts +2 -2
  21. package/lib/http-client/fetch-client.js +16 -16
  22. package/lib/http-client/index.js +2 -2
  23. package/lib/http-client/types.d.ts +2 -2
  24. package/lib/index.d.ts +11 -11
  25. package/lib/index.js +2 -2
  26. package/lib/minimal/contract/client.js +2 -2
  27. package/lib/minimal/contract/utils.js +7 -7
  28. package/lib/minimal/federation/index.d.ts +2 -2
  29. package/lib/minimal/horizon/call_builder.js +1 -1
  30. package/lib/minimal/horizon/horizon_api.js +0 -1
  31. package/lib/minimal/horizon/horizon_axios_client.js +4 -4
  32. package/lib/minimal/horizon/index.d.ts +1 -1
  33. package/lib/minimal/horizon/types/effects.d.ts +41 -41
  34. package/lib/minimal/horizon/types/trade.d.ts +1 -1
  35. package/lib/minimal/http-client/fetch-client.d.ts +2 -2
  36. package/lib/minimal/http-client/fetch-client.js +16 -16
  37. package/lib/minimal/http-client/index.js +2 -2
  38. package/lib/minimal/http-client/types.d.ts +2 -2
  39. package/lib/minimal/index.d.ts +11 -11
  40. package/lib/minimal/index.js +2 -2
  41. package/lib/minimal/rpc/api.d.ts +16 -8
  42. package/lib/minimal/rpc/api.js +3 -3
  43. package/lib/minimal/rpc/axios.js +3 -3
  44. package/lib/minimal/rpc/browser.d.ts +2 -2
  45. package/lib/minimal/rpc/index.d.ts +1 -1
  46. package/lib/minimal/rpc/parsers.d.ts +2 -2
  47. package/lib/minimal/rpc/parsers.js +19 -19
  48. package/lib/minimal/rpc/server.d.ts +72 -11
  49. package/lib/minimal/rpc/server.js +383 -267
  50. package/lib/minimal/rpc/transaction.d.ts +2 -2
  51. package/lib/minimal/rpc/transaction.js +6 -6
  52. package/lib/minimal/webauth/index.d.ts +2 -2
  53. package/lib/no-axios/contract/client.js +2 -2
  54. package/lib/no-axios/contract/utils.js +7 -7
  55. package/lib/no-axios/federation/index.d.ts +2 -2
  56. package/lib/no-axios/horizon/call_builder.js +1 -1
  57. package/lib/no-axios/horizon/horizon_api.js +0 -1
  58. package/lib/no-axios/horizon/horizon_axios_client.js +4 -4
  59. package/lib/no-axios/horizon/index.d.ts +1 -1
  60. package/lib/no-axios/horizon/types/effects.d.ts +41 -41
  61. package/lib/no-axios/horizon/types/trade.d.ts +1 -1
  62. package/lib/no-axios/http-client/fetch-client.d.ts +2 -2
  63. package/lib/no-axios/http-client/fetch-client.js +16 -16
  64. package/lib/no-axios/http-client/index.js +2 -2
  65. package/lib/no-axios/http-client/types.d.ts +2 -2
  66. package/lib/no-axios/index.d.ts +11 -11
  67. package/lib/no-axios/index.js +2 -2
  68. package/lib/no-axios/rpc/api.d.ts +16 -8
  69. package/lib/no-axios/rpc/api.js +3 -3
  70. package/lib/no-axios/rpc/axios.js +3 -3
  71. package/lib/no-axios/rpc/browser.d.ts +2 -2
  72. package/lib/no-axios/rpc/index.d.ts +1 -1
  73. package/lib/no-axios/rpc/parsers.d.ts +2 -2
  74. package/lib/no-axios/rpc/parsers.js +19 -19
  75. package/lib/no-axios/rpc/server.d.ts +72 -11
  76. package/lib/no-axios/rpc/server.js +383 -267
  77. package/lib/no-axios/rpc/transaction.d.ts +2 -2
  78. package/lib/no-axios/rpc/transaction.js +6 -6
  79. package/lib/no-axios/webauth/index.d.ts +2 -2
  80. package/lib/no-eventsource/contract/client.js +2 -2
  81. package/lib/no-eventsource/contract/utils.js +7 -7
  82. package/lib/no-eventsource/federation/index.d.ts +2 -2
  83. package/lib/no-eventsource/horizon/call_builder.js +1 -1
  84. package/lib/no-eventsource/horizon/horizon_api.js +0 -1
  85. package/lib/no-eventsource/horizon/horizon_axios_client.js +4 -4
  86. package/lib/no-eventsource/horizon/index.d.ts +1 -1
  87. package/lib/no-eventsource/horizon/types/effects.d.ts +41 -41
  88. package/lib/no-eventsource/horizon/types/trade.d.ts +1 -1
  89. package/lib/no-eventsource/http-client/fetch-client.d.ts +2 -2
  90. package/lib/no-eventsource/http-client/fetch-client.js +16 -16
  91. package/lib/no-eventsource/http-client/index.js +2 -2
  92. package/lib/no-eventsource/http-client/types.d.ts +2 -2
  93. package/lib/no-eventsource/index.d.ts +11 -11
  94. package/lib/no-eventsource/index.js +2 -2
  95. package/lib/no-eventsource/rpc/api.d.ts +16 -8
  96. package/lib/no-eventsource/rpc/api.js +3 -3
  97. package/lib/no-eventsource/rpc/axios.js +3 -3
  98. package/lib/no-eventsource/rpc/browser.d.ts +2 -2
  99. package/lib/no-eventsource/rpc/index.d.ts +1 -1
  100. package/lib/no-eventsource/rpc/parsers.d.ts +2 -2
  101. package/lib/no-eventsource/rpc/parsers.js +19 -19
  102. package/lib/no-eventsource/rpc/server.d.ts +72 -11
  103. package/lib/no-eventsource/rpc/server.js +383 -267
  104. package/lib/no-eventsource/rpc/transaction.d.ts +2 -2
  105. package/lib/no-eventsource/rpc/transaction.js +6 -6
  106. package/lib/no-eventsource/webauth/index.d.ts +2 -2
  107. package/lib/rpc/api.d.ts +16 -8
  108. package/lib/rpc/api.js +3 -3
  109. package/lib/rpc/axios.js +3 -3
  110. package/lib/rpc/browser.d.ts +2 -2
  111. package/lib/rpc/index.d.ts +1 -1
  112. package/lib/rpc/parsers.d.ts +2 -2
  113. package/lib/rpc/parsers.js +19 -19
  114. package/lib/rpc/server.d.ts +72 -11
  115. package/lib/rpc/server.js +383 -267
  116. package/lib/rpc/transaction.d.ts +2 -2
  117. package/lib/rpc/transaction.js +6 -6
  118. package/lib/webauth/index.d.ts +2 -2
  119. package/package.json +17 -9
package/lib/rpc/server.js CHANGED
@@ -12,7 +12,7 @@ var _api = require("./api");
12
12
  var _transaction = require("./transaction");
13
13
  var _parsers = require("./parsers");
14
14
  var _utils = require("../utils");
15
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t5 in e) "default" !== _t5 && {}.hasOwnProperty.call(e, _t5) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t5)) && (i.get || i.set) ? o(f, _t5, i) : f[_t5] = e[_t5]); return f; })(e, t); }
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t9 in e) "default" !== _t9 && {}.hasOwnProperty.call(e, _t9) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t9)) && (i.get || i.set) ? o(f, _t9, i) : f[_t9] = e[_t9]); return f; })(e, t); }
16
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
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
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; }
@@ -54,7 +54,7 @@ function findCreatedAccountSequenceInTransactionMeta(meta) {
54
54
  operations = meta.value().operations();
55
55
  break;
56
56
  default:
57
- throw new Error('Unexpected transaction meta switch value');
57
+ throw new Error("Unexpected transaction meta switch value");
58
58
  }
59
59
  var sequenceNumber = (_operations$flatMap$f = operations.flatMap(function (op) {
60
60
  return op.changes();
@@ -64,7 +64,7 @@ function findCreatedAccountSequenceInTransactionMeta(meta) {
64
64
  if (sequenceNumber) {
65
65
  return sequenceNumber;
66
66
  }
67
- throw new Error('No account created in transaction');
67
+ throw new Error("No account created in transaction");
68
68
  }
69
69
  var RpcServer = exports.RpcServer = function () {
70
70
  function RpcServer(serverURL) {
@@ -77,7 +77,7 @@ var RpcServer = exports.RpcServer = function () {
77
77
  return config;
78
78
  });
79
79
  }
80
- if (this.serverURL.protocol() !== 'https' && !opts.allowHttp) {
80
+ if (this.serverURL.protocol() !== "https" && !opts.allowHttp) {
81
81
  throw new Error("Cannot connect to insecure Soroban RPC server if `allowHttp` isn't set");
82
82
  }
83
83
  }
@@ -85,46 +85,155 @@ var RpcServer = exports.RpcServer = function () {
85
85
  key: "getAccount",
86
86
  value: (function () {
87
87
  var _getAccount = _asyncToGenerator(_regenerator().m(function _callee(address) {
88
- var ledgerKey, resp, accountEntry;
88
+ var entry;
89
89
  return _regenerator().w(function (_context) {
90
90
  while (1) switch (_context.n) {
91
+ case 0:
92
+ _context.n = 1;
93
+ return this.getAccountEntry(address);
94
+ case 1:
95
+ entry = _context.v;
96
+ return _context.a(2, new _stellarBase.Account(address, entry.seqNum().toString()));
97
+ }
98
+ }, _callee, this);
99
+ }));
100
+ function getAccount(_x) {
101
+ return _getAccount.apply(this, arguments);
102
+ }
103
+ return getAccount;
104
+ }())
105
+ }, {
106
+ key: "getAccountEntry",
107
+ value: (function () {
108
+ var _getAccountEntry = _asyncToGenerator(_regenerator().m(function _callee2(address) {
109
+ var ledgerKey, resp, _t;
110
+ return _regenerator().w(function (_context2) {
111
+ while (1) switch (_context2.p = _context2.n) {
91
112
  case 0:
92
113
  ledgerKey = _stellarBase.xdr.LedgerKey.account(new _stellarBase.xdr.LedgerKeyAccount({
93
114
  accountId: _stellarBase.Keypair.fromPublicKey(address).xdrPublicKey()
94
115
  }));
95
- _context.n = 1;
96
- return this.getLedgerEntries(ledgerKey);
116
+ _context2.p = 1;
117
+ _context2.n = 2;
118
+ return this.getLedgerEntry(ledgerKey);
119
+ case 2:
120
+ resp = _context2.v;
121
+ return _context2.a(2, resp.val.account());
122
+ case 3:
123
+ _context2.p = 3;
124
+ _t = _context2.v;
125
+ throw new Error("Account not found: ".concat(address));
126
+ case 4:
127
+ return _context2.a(2);
128
+ }
129
+ }, _callee2, this, [[1, 3]]);
130
+ }));
131
+ function getAccountEntry(_x2) {
132
+ return _getAccountEntry.apply(this, arguments);
133
+ }
134
+ return getAccountEntry;
135
+ }())
136
+ }, {
137
+ key: "getTrustline",
138
+ value: (function () {
139
+ var _getTrustline = _asyncToGenerator(_regenerator().m(function _callee3(account, asset) {
140
+ var trustlineLedgerKey, entry, _t2;
141
+ return _regenerator().w(function (_context3) {
142
+ while (1) switch (_context3.p = _context3.n) {
143
+ case 0:
144
+ trustlineLedgerKey = _stellarBase.xdr.LedgerKey.trustline(new _stellarBase.xdr.LedgerKeyTrustLine({
145
+ accountId: _stellarBase.Keypair.fromPublicKey(account).xdrAccountId(),
146
+ asset: asset.toTrustLineXDRObject()
147
+ }));
148
+ _context3.p = 1;
149
+ _context3.n = 2;
150
+ return this.getLedgerEntry(trustlineLedgerKey);
151
+ case 2:
152
+ entry = _context3.v;
153
+ return _context3.a(2, entry.val.trustLine());
154
+ case 3:
155
+ _context3.p = 3;
156
+ _t2 = _context3.v;
157
+ throw new Error("Trustline for ".concat(asset.getCode(), ":").concat(asset.getIssuer(), " not found for ").concat(account));
158
+ case 4:
159
+ return _context3.a(2);
160
+ }
161
+ }, _callee3, this, [[1, 3]]);
162
+ }));
163
+ function getTrustline(_x3, _x4) {
164
+ return _getTrustline.apply(this, arguments);
165
+ }
166
+ return getTrustline;
167
+ }())
168
+ }, {
169
+ key: "getClaimableBalance",
170
+ value: (function () {
171
+ var _getClaimableBalance = _asyncToGenerator(_regenerator().m(function _callee4(id) {
172
+ var balanceId, buffer, v, trustlineLedgerKey, entry, _t3;
173
+ return _regenerator().w(function (_context4) {
174
+ while (1) switch (_context4.p = _context4.n) {
175
+ case 0:
176
+ if (!_stellarBase.StrKey.isValidClaimableBalance(id)) {
177
+ _context4.n = 1;
178
+ break;
179
+ }
180
+ buffer = _stellarBase.StrKey.decodeClaimableBalance(id);
181
+ v = Buffer.concat([Buffer.from("\x00\x00\x00"), buffer.subarray(0, 1)]);
182
+ balanceId = _stellarBase.xdr.ClaimableBalanceId.fromXDR(Buffer.concat([v, buffer.subarray(1)]));
183
+ _context4.n = 4;
184
+ break;
97
185
  case 1:
98
- resp = _context.v;
99
- if (!(resp.entries.length === 0)) {
100
- _context.n = 2;
186
+ if (!id.match(/[a-f0-9]{72}/i)) {
187
+ _context4.n = 2;
101
188
  break;
102
189
  }
103
- return _context.a(2, Promise.reject({
104
- code: 404,
105
- message: "Account not found: ".concat(address)
106
- }));
190
+ balanceId = _stellarBase.xdr.ClaimableBalanceId.fromXDR(id, "hex");
191
+ _context4.n = 4;
192
+ break;
107
193
  case 2:
108
- accountEntry = resp.entries[0].val.account();
109
- return _context.a(2, new _stellarBase.Account(address, accountEntry.seqNum().toString()));
194
+ if (!id.match(/[a-f0-9]{64}/i)) {
195
+ _context4.n = 3;
196
+ break;
197
+ }
198
+ balanceId = _stellarBase.xdr.ClaimableBalanceId.fromXDR(id.padStart(72, "0"), "hex");
199
+ _context4.n = 4;
200
+ break;
201
+ case 3:
202
+ throw new TypeError("expected 72-char hex ID or strkey, not ".concat(id));
203
+ case 4:
204
+ trustlineLedgerKey = _stellarBase.xdr.LedgerKey.claimableBalance(new _stellarBase.xdr.LedgerKeyClaimableBalance({
205
+ balanceId: balanceId
206
+ }));
207
+ _context4.p = 5;
208
+ _context4.n = 6;
209
+ return this.getLedgerEntry(trustlineLedgerKey);
210
+ case 6:
211
+ entry = _context4.v;
212
+ return _context4.a(2, entry.val.claimableBalance());
213
+ case 7:
214
+ _context4.p = 7;
215
+ _t3 = _context4.v;
216
+ throw new Error("Claimable balance ".concat(id, " not found"));
217
+ case 8:
218
+ return _context4.a(2);
110
219
  }
111
- }, _callee, this);
220
+ }, _callee4, this, [[5, 7]]);
112
221
  }));
113
- function getAccount(_x) {
114
- return _getAccount.apply(this, arguments);
222
+ function getClaimableBalance(_x5) {
223
+ return _getClaimableBalance.apply(this, arguments);
115
224
  }
116
- return getAccount;
225
+ return getClaimableBalance;
117
226
  }())
118
227
  }, {
119
228
  key: "getHealth",
120
229
  value: (function () {
121
- var _getHealth = _asyncToGenerator(_regenerator().m(function _callee2() {
122
- return _regenerator().w(function (_context2) {
123
- while (1) switch (_context2.n) {
230
+ var _getHealth = _asyncToGenerator(_regenerator().m(function _callee5() {
231
+ return _regenerator().w(function (_context5) {
232
+ while (1) switch (_context5.n) {
124
233
  case 0:
125
- return _context2.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getHealth'));
234
+ return _context5.a(2, jsonrpc.postObject(this.serverURL.toString(), "getHealth"));
126
235
  }
127
- }, _callee2, this);
236
+ }, _callee5, this);
128
237
  }));
129
238
  function getHealth() {
130
239
  return _getHealth.apply(this, arguments);
@@ -134,52 +243,53 @@ var RpcServer = exports.RpcServer = function () {
134
243
  }, {
135
244
  key: "getContractData",
136
245
  value: (function () {
137
- var _getContractData = _asyncToGenerator(_regenerator().m(function _callee3(contract, key) {
246
+ var _getContractData = _asyncToGenerator(_regenerator().m(function _callee6(contract, key) {
138
247
  var durability,
139
248
  scAddress,
140
249
  xdrDurability,
141
250
  contractKey,
142
- _args3 = arguments,
143
- _t;
144
- return _regenerator().w(function (_context3) {
145
- while (1) switch (_context3.n) {
251
+ _args6 = arguments,
252
+ _t4,
253
+ _t5;
254
+ return _regenerator().w(function (_context6) {
255
+ while (1) switch (_context6.p = _context6.n) {
146
256
  case 0:
147
- durability = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : Durability.Persistent;
148
- if (!(typeof contract === 'string')) {
149
- _context3.n = 1;
257
+ durability = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : Durability.Persistent;
258
+ if (!(typeof contract === "string")) {
259
+ _context6.n = 1;
150
260
  break;
151
261
  }
152
262
  scAddress = new _stellarBase.Contract(contract).address().toScAddress();
153
- _context3.n = 4;
263
+ _context6.n = 4;
154
264
  break;
155
265
  case 1:
156
266
  if (!(contract instanceof _stellarBase.Address)) {
157
- _context3.n = 2;
267
+ _context6.n = 2;
158
268
  break;
159
269
  }
160
270
  scAddress = contract.toScAddress();
161
- _context3.n = 4;
271
+ _context6.n = 4;
162
272
  break;
163
273
  case 2:
164
274
  if (!(contract instanceof _stellarBase.Contract)) {
165
- _context3.n = 3;
275
+ _context6.n = 3;
166
276
  break;
167
277
  }
168
278
  scAddress = contract.address().toScAddress();
169
- _context3.n = 4;
279
+ _context6.n = 4;
170
280
  break;
171
281
  case 3:
172
282
  throw new TypeError("unknown contract type: ".concat(contract));
173
283
  case 4:
174
- _t = durability;
175
- _context3.n = _t === Durability.Temporary ? 5 : _t === Durability.Persistent ? 6 : 7;
284
+ _t4 = durability;
285
+ _context6.n = _t4 === Durability.Temporary ? 5 : _t4 === Durability.Persistent ? 6 : 7;
176
286
  break;
177
287
  case 5:
178
288
  xdrDurability = _stellarBase.xdr.ContractDataDurability.temporary();
179
- return _context3.a(3, 8);
289
+ return _context6.a(3, 8);
180
290
  case 6:
181
291
  xdrDurability = _stellarBase.xdr.ContractDataDurability.persistent();
182
- return _context3.a(3, 8);
292
+ return _context6.a(3, 8);
183
293
  case 7:
184
294
  throw new TypeError("invalid durability: ".concat(durability));
185
295
  case 8:
@@ -188,19 +298,24 @@ var RpcServer = exports.RpcServer = function () {
188
298
  contract: scAddress,
189
299
  durability: xdrDurability
190
300
  }));
191
- return _context3.a(2, this.getLedgerEntries(contractKey).then(function (r) {
192
- if (r.entries.length === 0) {
193
- return Promise.reject({
194
- code: 404,
195
- message: "Contract data not found. Contract: ".concat(_stellarBase.Address.fromScAddress(scAddress).toString(), ", Key: ").concat(key.toXDR('base64'), ", Durability: ").concat(durability)
196
- });
197
- }
198
- return r.entries[0];
199
- }));
301
+ _context6.p = 9;
302
+ _context6.n = 10;
303
+ return this.getLedgerEntry(contractKey);
304
+ case 10:
305
+ return _context6.a(2, _context6.v);
306
+ case 11:
307
+ _context6.p = 11;
308
+ _t5 = _context6.v;
309
+ throw {
310
+ code: 404,
311
+ message: "Contract data not found for ".concat(_stellarBase.Address.fromScAddress(scAddress).toString(), " with key ").concat(key.toXDR("base64"), " and durability: ").concat(durability)
312
+ };
313
+ case 12:
314
+ return _context6.a(2);
200
315
  }
201
- }, _callee3, this);
316
+ }, _callee6, this, [[9, 11]]);
202
317
  }));
203
- function getContractData(_x2, _x3) {
318
+ function getContractData(_x6, _x7) {
204
319
  return _getContractData.apply(this, arguments);
205
320
  }
206
321
  return getContractData;
@@ -208,32 +323,32 @@ var RpcServer = exports.RpcServer = function () {
208
323
  }, {
209
324
  key: "getContractWasmByContractId",
210
325
  value: (function () {
211
- var _getContractWasmByContractId = _asyncToGenerator(_regenerator().m(function _callee4(contractId) {
326
+ var _getContractWasmByContractId = _asyncToGenerator(_regenerator().m(function _callee7(contractId) {
212
327
  var _response$entries$;
213
328
  var contractLedgerKey, response, wasmHash;
214
- return _regenerator().w(function (_context4) {
215
- while (1) switch (_context4.n) {
329
+ return _regenerator().w(function (_context7) {
330
+ while (1) switch (_context7.n) {
216
331
  case 0:
217
332
  contractLedgerKey = new _stellarBase.Contract(contractId).getFootprint();
218
- _context4.n = 1;
333
+ _context7.n = 1;
219
334
  return this.getLedgerEntries(contractLedgerKey);
220
335
  case 1:
221
- response = _context4.v;
336
+ response = _context7.v;
222
337
  if (!(!response.entries.length || !((_response$entries$ = response.entries[0]) !== null && _response$entries$ !== void 0 && _response$entries$.val))) {
223
- _context4.n = 2;
338
+ _context7.n = 2;
224
339
  break;
225
340
  }
226
- return _context4.a(2, Promise.reject({
341
+ return _context7.a(2, Promise.reject({
227
342
  code: 404,
228
343
  message: "Could not obtain contract hash from server"
229
344
  }));
230
345
  case 2:
231
346
  wasmHash = response.entries[0].val.contractData().val().instance().executable().wasmHash();
232
- return _context4.a(2, this.getContractWasmByHash(wasmHash));
347
+ return _context7.a(2, this.getContractWasmByHash(wasmHash));
233
348
  }
234
- }, _callee4, this);
349
+ }, _callee7, this);
235
350
  }));
236
- function getContractWasmByContractId(_x4) {
351
+ function getContractWasmByContractId(_x8) {
237
352
  return _getContractWasmByContractId.apply(this, arguments);
238
353
  }
239
354
  return getContractWasmByContractId;
@@ -241,127 +356,127 @@ var RpcServer = exports.RpcServer = function () {
241
356
  }, {
242
357
  key: "getContractWasmByHash",
243
358
  value: (function () {
244
- var _getContractWasmByHash = _asyncToGenerator(_regenerator().m(function _callee5(wasmHash) {
359
+ var _getContractWasmByHash = _asyncToGenerator(_regenerator().m(function _callee8(wasmHash) {
245
360
  var _responseWasm$entries;
246
361
  var format,
247
362
  wasmHashBuffer,
248
363
  ledgerKeyWasmHash,
249
364
  responseWasm,
250
365
  wasmBuffer,
251
- _args5 = arguments;
252
- return _regenerator().w(function (_context5) {
253
- while (1) switch (_context5.n) {
366
+ _args8 = arguments;
367
+ return _regenerator().w(function (_context8) {
368
+ while (1) switch (_context8.n) {
254
369
  case 0:
255
- format = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : undefined;
370
+ format = _args8.length > 1 && _args8[1] !== undefined ? _args8[1] : undefined;
256
371
  wasmHashBuffer = typeof wasmHash === "string" ? Buffer.from(wasmHash, format) : wasmHash;
257
372
  ledgerKeyWasmHash = _stellarBase.xdr.LedgerKey.contractCode(new _stellarBase.xdr.LedgerKeyContractCode({
258
373
  hash: wasmHashBuffer
259
374
  }));
260
- _context5.n = 1;
375
+ _context8.n = 1;
261
376
  return this.getLedgerEntries(ledgerKeyWasmHash);
262
377
  case 1:
263
- responseWasm = _context5.v;
378
+ responseWasm = _context8.v;
264
379
  if (!(!responseWasm.entries.length || !((_responseWasm$entries = responseWasm.entries[0]) !== null && _responseWasm$entries !== void 0 && _responseWasm$entries.val))) {
265
- _context5.n = 2;
380
+ _context8.n = 2;
266
381
  break;
267
382
  }
268
- return _context5.a(2, Promise.reject({
383
+ return _context8.a(2, Promise.reject({
269
384
  code: 404,
270
385
  message: "Could not obtain contract wasm from server"
271
386
  }));
272
387
  case 2:
273
388
  wasmBuffer = responseWasm.entries[0].val.contractCode().code();
274
- return _context5.a(2, wasmBuffer);
389
+ return _context8.a(2, wasmBuffer);
275
390
  }
276
- }, _callee5, this);
391
+ }, _callee8, this);
277
392
  }));
278
- function getContractWasmByHash(_x5) {
393
+ function getContractWasmByHash(_x9) {
279
394
  return _getContractWasmByHash.apply(this, arguments);
280
395
  }
281
396
  return getContractWasmByHash;
282
397
  }())
283
398
  }, {
284
399
  key: "getLedgerEntries",
285
- value: (function () {
286
- var _getLedgerEntries2 = _asyncToGenerator(_regenerator().m(function _callee6() {
287
- var _args6 = arguments;
288
- return _regenerator().w(function (_context6) {
289
- while (1) switch (_context6.n) {
290
- case 0:
291
- return _context6.a(2, this._getLedgerEntries.apply(this, _args6).then(_parsers.parseRawLedgerEntries));
292
- }
293
- }, _callee6, this);
294
- }));
295
- function getLedgerEntries() {
296
- return _getLedgerEntries2.apply(this, arguments);
297
- }
298
- return getLedgerEntries;
299
- }())
400
+ value: function getLedgerEntries() {
401
+ return this._getLedgerEntries.apply(this, arguments).then(_parsers.parseRawLedgerEntries);
402
+ }
300
403
  }, {
301
404
  key: "_getLedgerEntries",
405
+ value: function _getLedgerEntries() {
406
+ for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
407
+ keys[_key] = arguments[_key];
408
+ }
409
+ return jsonrpc.postObject(this.serverURL.toString(), "getLedgerEntries", {
410
+ keys: keys.map(function (k) {
411
+ return k.toXDR("base64");
412
+ })
413
+ });
414
+ }
415
+ }, {
416
+ key: "getLedgerEntry",
302
417
  value: function () {
303
- var _getLedgerEntries3 = _asyncToGenerator(_regenerator().m(function _callee7() {
304
- var _len,
305
- keys,
306
- _key,
307
- _args7 = arguments;
308
- return _regenerator().w(function (_context7) {
309
- while (1) switch (_context7.n) {
418
+ var _getLedgerEntry = _asyncToGenerator(_regenerator().m(function _callee9(key) {
419
+ var results;
420
+ return _regenerator().w(function (_context9) {
421
+ while (1) switch (_context9.n) {
310
422
  case 0:
311
- for (_len = _args7.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
312
- keys[_key] = _args7[_key];
423
+ _context9.n = 1;
424
+ return this._getLedgerEntries(key).then(_parsers.parseRawLedgerEntries);
425
+ case 1:
426
+ results = _context9.v;
427
+ if (!(results.entries.length !== 1)) {
428
+ _context9.n = 2;
429
+ break;
313
430
  }
314
- return _context7.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getLedgerEntries', {
315
- keys: keys.map(function (k) {
316
- return k.toXDR('base64');
317
- })
318
- }));
431
+ throw new Error("failed to find an entry for key ".concat(key.toXDR("base64")));
432
+ case 2:
433
+ return _context9.a(2, results.entries[0]);
319
434
  }
320
- }, _callee7, this);
435
+ }, _callee9, this);
321
436
  }));
322
- function _getLedgerEntries() {
323
- return _getLedgerEntries3.apply(this, arguments);
437
+ function getLedgerEntry(_x0) {
438
+ return _getLedgerEntry.apply(this, arguments);
324
439
  }
325
- return _getLedgerEntries;
440
+ return getLedgerEntry;
326
441
  }()
327
442
  }, {
328
443
  key: "pollTransaction",
329
444
  value: (function () {
330
- var _pollTransaction = _asyncToGenerator(_regenerator().m(function _callee8(hash, opts) {
445
+ var _pollTransaction = _asyncToGenerator(_regenerator().m(function _callee0(hash, opts) {
331
446
  var _opts$attempts, _opts$attempts2;
332
447
  var maxAttempts, foundInfo, attempt, _opts$sleepStrategy;
333
- return _regenerator().w(function (_context8) {
334
- while (1) switch (_context8.n) {
448
+ return _regenerator().w(function (_context0) {
449
+ while (1) switch (_context0.n) {
335
450
  case 0:
336
451
  maxAttempts = ((_opts$attempts = opts === null || opts === void 0 ? void 0 : opts.attempts) !== null && _opts$attempts !== void 0 ? _opts$attempts : 0) < 1 ? DEFAULT_GET_TRANSACTION_TIMEOUT : (_opts$attempts2 = opts === null || opts === void 0 ? void 0 : opts.attempts) !== null && _opts$attempts2 !== void 0 ? _opts$attempts2 : DEFAULT_GET_TRANSACTION_TIMEOUT;
337
452
  attempt = 1;
338
453
  case 1:
339
454
  if (!(attempt < maxAttempts)) {
340
- _context8.n = 5;
455
+ _context0.n = 5;
341
456
  break;
342
457
  }
343
- _context8.n = 2;
458
+ _context0.n = 2;
344
459
  return this.getTransaction(hash);
345
460
  case 2:
346
- foundInfo = _context8.v;
461
+ foundInfo = _context0.v;
347
462
  if (!(foundInfo.status !== _api.Api.GetTransactionStatus.NOT_FOUND)) {
348
- _context8.n = 3;
463
+ _context0.n = 3;
349
464
  break;
350
465
  }
351
- return _context8.a(2, foundInfo);
466
+ return _context0.a(2, foundInfo);
352
467
  case 3:
353
- _context8.n = 4;
468
+ _context0.n = 4;
354
469
  return _utils.Utils.sleep(((_opts$sleepStrategy = opts === null || opts === void 0 ? void 0 : opts.sleepStrategy) !== null && _opts$sleepStrategy !== void 0 ? _opts$sleepStrategy : BasicSleepStrategy)(attempt));
355
470
  case 4:
356
471
  attempt++;
357
- _context8.n = 1;
472
+ _context0.n = 1;
358
473
  break;
359
474
  case 5:
360
- return _context8.a(2, foundInfo);
475
+ return _context0.a(2, foundInfo);
361
476
  }
362
- }, _callee8, this);
477
+ }, _callee0, this);
363
478
  }));
364
- function pollTransaction(_x6, _x7) {
479
+ function pollTransaction(_x1, _x10) {
365
480
  return _pollTransaction.apply(this, arguments);
366
481
  }
367
482
  return pollTransaction;
@@ -369,11 +484,11 @@ var RpcServer = exports.RpcServer = function () {
369
484
  }, {
370
485
  key: "getTransaction",
371
486
  value: (function () {
372
- var _getTransaction2 = _asyncToGenerator(_regenerator().m(function _callee9(hash) {
373
- return _regenerator().w(function (_context9) {
374
- while (1) switch (_context9.n) {
487
+ var _getTransaction2 = _asyncToGenerator(_regenerator().m(function _callee1(hash) {
488
+ return _regenerator().w(function (_context1) {
489
+ while (1) switch (_context1.n) {
375
490
  case 0:
376
- return _context9.a(2, this._getTransaction(hash).then(function (raw) {
491
+ return _context1.a(2, this._getTransaction(hash).then(function (raw) {
377
492
  var foundInfo = {};
378
493
  if (raw.status !== _api.Api.GetTransactionStatus.NOT_FOUND) {
379
494
  Object.assign(foundInfo, (0, _parsers.parseTransactionInfo)(raw));
@@ -389,9 +504,9 @@ var RpcServer = exports.RpcServer = function () {
389
504
  return result;
390
505
  }));
391
506
  }
392
- }, _callee9, this);
507
+ }, _callee1, this);
393
508
  }));
394
- function getTransaction(_x8) {
509
+ function getTransaction(_x11) {
395
510
  return _getTransaction2.apply(this, arguments);
396
511
  }
397
512
  return getTransaction;
@@ -399,17 +514,17 @@ var RpcServer = exports.RpcServer = function () {
399
514
  }, {
400
515
  key: "_getTransaction",
401
516
  value: function () {
402
- var _getTransaction3 = _asyncToGenerator(_regenerator().m(function _callee0(hash) {
403
- return _regenerator().w(function (_context0) {
404
- while (1) switch (_context0.n) {
517
+ var _getTransaction3 = _asyncToGenerator(_regenerator().m(function _callee10(hash) {
518
+ return _regenerator().w(function (_context10) {
519
+ while (1) switch (_context10.n) {
405
520
  case 0:
406
- return _context0.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getTransaction', {
521
+ return _context10.a(2, jsonrpc.postObject(this.serverURL.toString(), "getTransaction", {
407
522
  hash: hash
408
523
  }));
409
524
  }
410
- }, _callee0, this);
525
+ }, _callee10, this);
411
526
  }));
412
- function _getTransaction(_x9) {
527
+ function _getTransaction(_x12) {
413
528
  return _getTransaction3.apply(this, arguments);
414
529
  }
415
530
  return _getTransaction;
@@ -417,11 +532,11 @@ var RpcServer = exports.RpcServer = function () {
417
532
  }, {
418
533
  key: "getTransactions",
419
534
  value: (function () {
420
- var _getTransactions2 = _asyncToGenerator(_regenerator().m(function _callee1(request) {
421
- return _regenerator().w(function (_context1) {
422
- while (1) switch (_context1.n) {
535
+ var _getTransactions2 = _asyncToGenerator(_regenerator().m(function _callee11(request) {
536
+ return _regenerator().w(function (_context11) {
537
+ while (1) switch (_context11.n) {
423
538
  case 0:
424
- return _context1.a(2, this._getTransactions(request).then(function (raw) {
539
+ return _context11.a(2, this._getTransactions(request).then(function (raw) {
425
540
  var result = {
426
541
  transactions: (raw.transactions || []).map(_parsers.parseRawTransactions),
427
542
  latestLedger: raw.latestLedger,
@@ -433,9 +548,9 @@ var RpcServer = exports.RpcServer = function () {
433
548
  return result;
434
549
  }));
435
550
  }
436
- }, _callee1, this);
551
+ }, _callee11, this);
437
552
  }));
438
- function getTransactions(_x0) {
553
+ function getTransactions(_x13) {
439
554
  return _getTransactions2.apply(this, arguments);
440
555
  }
441
556
  return getTransactions;
@@ -443,15 +558,15 @@ var RpcServer = exports.RpcServer = function () {
443
558
  }, {
444
559
  key: "_getTransactions",
445
560
  value: function () {
446
- var _getTransactions3 = _asyncToGenerator(_regenerator().m(function _callee10(request) {
447
- return _regenerator().w(function (_context10) {
448
- while (1) switch (_context10.n) {
561
+ var _getTransactions3 = _asyncToGenerator(_regenerator().m(function _callee12(request) {
562
+ return _regenerator().w(function (_context12) {
563
+ while (1) switch (_context12.n) {
449
564
  case 0:
450
- return _context10.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getTransactions', request));
565
+ return _context12.a(2, jsonrpc.postObject(this.serverURL.toString(), "getTransactions", request));
451
566
  }
452
- }, _callee10, this);
567
+ }, _callee12, this);
453
568
  }));
454
- function _getTransactions(_x1) {
569
+ function _getTransactions(_x14) {
455
570
  return _getTransactions3.apply(this, arguments);
456
571
  }
457
572
  return _getTransactions;
@@ -459,15 +574,15 @@ var RpcServer = exports.RpcServer = function () {
459
574
  }, {
460
575
  key: "getEvents",
461
576
  value: (function () {
462
- var _getEvents2 = _asyncToGenerator(_regenerator().m(function _callee11(request) {
463
- return _regenerator().w(function (_context11) {
464
- while (1) switch (_context11.n) {
577
+ var _getEvents2 = _asyncToGenerator(_regenerator().m(function _callee13(request) {
578
+ return _regenerator().w(function (_context13) {
579
+ while (1) switch (_context13.n) {
465
580
  case 0:
466
- return _context11.a(2, this._getEvents(request).then(_parsers.parseRawEvents));
581
+ return _context13.a(2, this._getEvents(request).then(_parsers.parseRawEvents));
467
582
  }
468
- }, _callee11, this);
583
+ }, _callee13, this);
469
584
  }));
470
- function getEvents(_x10) {
585
+ function getEvents(_x15) {
471
586
  return _getEvents2.apply(this, arguments);
472
587
  }
473
588
  return getEvents;
@@ -475,12 +590,12 @@ var RpcServer = exports.RpcServer = function () {
475
590
  }, {
476
591
  key: "_getEvents",
477
592
  value: function () {
478
- var _getEvents3 = _asyncToGenerator(_regenerator().m(function _callee12(request) {
593
+ var _getEvents3 = _asyncToGenerator(_regenerator().m(function _callee14(request) {
479
594
  var _request$filters;
480
- return _regenerator().w(function (_context12) {
481
- while (1) switch (_context12.n) {
595
+ return _regenerator().w(function (_context14) {
596
+ while (1) switch (_context14.n) {
482
597
  case 0:
483
- return _context12.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getEvents', _objectSpread(_objectSpread({
598
+ return _context14.a(2, jsonrpc.postObject(this.serverURL.toString(), "getEvents", _objectSpread(_objectSpread({
484
599
  filters: (_request$filters = request.filters) !== null && _request$filters !== void 0 ? _request$filters : [],
485
600
  pagination: _objectSpread(_objectSpread({}, request.cursor && {
486
601
  cursor: request.cursor
@@ -493,9 +608,9 @@ var RpcServer = exports.RpcServer = function () {
493
608
  endLedger: request.endLedger
494
609
  })));
495
610
  }
496
- }, _callee12, this);
611
+ }, _callee14, this);
497
612
  }));
498
- function _getEvents(_x11) {
613
+ function _getEvents(_x16) {
499
614
  return _getEvents3.apply(this, arguments);
500
615
  }
501
616
  return _getEvents;
@@ -503,13 +618,13 @@ var RpcServer = exports.RpcServer = function () {
503
618
  }, {
504
619
  key: "getNetwork",
505
620
  value: (function () {
506
- var _getNetwork = _asyncToGenerator(_regenerator().m(function _callee13() {
507
- return _regenerator().w(function (_context13) {
508
- while (1) switch (_context13.n) {
621
+ var _getNetwork = _asyncToGenerator(_regenerator().m(function _callee15() {
622
+ return _regenerator().w(function (_context15) {
623
+ while (1) switch (_context15.n) {
509
624
  case 0:
510
- return _context13.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getNetwork'));
625
+ return _context15.a(2, jsonrpc.postObject(this.serverURL.toString(), "getNetwork"));
511
626
  }
512
- }, _callee13, this);
627
+ }, _callee15, this);
513
628
  }));
514
629
  function getNetwork() {
515
630
  return _getNetwork.apply(this, arguments);
@@ -519,13 +634,13 @@ var RpcServer = exports.RpcServer = function () {
519
634
  }, {
520
635
  key: "getLatestLedger",
521
636
  value: (function () {
522
- var _getLatestLedger = _asyncToGenerator(_regenerator().m(function _callee14() {
523
- return _regenerator().w(function (_context14) {
524
- while (1) switch (_context14.n) {
637
+ var _getLatestLedger = _asyncToGenerator(_regenerator().m(function _callee16() {
638
+ return _regenerator().w(function (_context16) {
639
+ while (1) switch (_context16.n) {
525
640
  case 0:
526
- return _context14.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getLatestLedger'));
641
+ return _context16.a(2, jsonrpc.postObject(this.serverURL.toString(), "getLatestLedger"));
527
642
  }
528
- }, _callee14, this);
643
+ }, _callee16, this);
529
644
  }));
530
645
  function getLatestLedger() {
531
646
  return _getLatestLedger.apply(this, arguments);
@@ -535,15 +650,15 @@ var RpcServer = exports.RpcServer = function () {
535
650
  }, {
536
651
  key: "simulateTransaction",
537
652
  value: (function () {
538
- var _simulateTransaction2 = _asyncToGenerator(_regenerator().m(function _callee15(tx, addlResources, authMode) {
539
- return _regenerator().w(function (_context15) {
540
- while (1) switch (_context15.n) {
653
+ var _simulateTransaction2 = _asyncToGenerator(_regenerator().m(function _callee17(tx, addlResources, authMode) {
654
+ return _regenerator().w(function (_context17) {
655
+ while (1) switch (_context17.n) {
541
656
  case 0:
542
- return _context15.a(2, this._simulateTransaction(tx, addlResources, authMode).then(_parsers.parseRawSimulation));
657
+ return _context17.a(2, this._simulateTransaction(tx, addlResources, authMode).then(_parsers.parseRawSimulation));
543
658
  }
544
- }, _callee15, this);
659
+ }, _callee17, this);
545
660
  }));
546
- function simulateTransaction(_x12, _x13, _x14) {
661
+ function simulateTransaction(_x17, _x18, _x19) {
547
662
  return _simulateTransaction2.apply(this, arguments);
548
663
  }
549
664
  return simulateTransaction;
@@ -551,11 +666,11 @@ var RpcServer = exports.RpcServer = function () {
551
666
  }, {
552
667
  key: "_simulateTransaction",
553
668
  value: function () {
554
- var _simulateTransaction3 = _asyncToGenerator(_regenerator().m(function _callee16(transaction, addlResources, authMode) {
555
- return _regenerator().w(function (_context16) {
556
- while (1) switch (_context16.n) {
669
+ var _simulateTransaction3 = _asyncToGenerator(_regenerator().m(function _callee18(transaction, addlResources, authMode) {
670
+ return _regenerator().w(function (_context18) {
671
+ while (1) switch (_context18.n) {
557
672
  case 0:
558
- return _context16.a(2, jsonrpc.postObject(this.serverURL.toString(), 'simulateTransaction', _objectSpread({
673
+ return _context18.a(2, jsonrpc.postObject(this.serverURL.toString(), "simulateTransaction", _objectSpread({
559
674
  transaction: transaction.toXDR(),
560
675
  authMode: authMode
561
676
  }, addlResources !== undefined && {
@@ -564,9 +679,9 @@ var RpcServer = exports.RpcServer = function () {
564
679
  }
565
680
  })));
566
681
  }
567
- }, _callee16, this);
682
+ }, _callee18, this);
568
683
  }));
569
- function _simulateTransaction(_x15, _x16, _x17) {
684
+ function _simulateTransaction(_x20, _x21, _x22) {
570
685
  return _simulateTransaction3.apply(this, arguments);
571
686
  }
572
687
  return _simulateTransaction;
@@ -574,26 +689,26 @@ var RpcServer = exports.RpcServer = function () {
574
689
  }, {
575
690
  key: "prepareTransaction",
576
691
  value: (function () {
577
- var _prepareTransaction = _asyncToGenerator(_regenerator().m(function _callee17(tx) {
692
+ var _prepareTransaction = _asyncToGenerator(_regenerator().m(function _callee19(tx) {
578
693
  var simResponse;
579
- return _regenerator().w(function (_context17) {
580
- while (1) switch (_context17.n) {
694
+ return _regenerator().w(function (_context19) {
695
+ while (1) switch (_context19.n) {
581
696
  case 0:
582
- _context17.n = 1;
697
+ _context19.n = 1;
583
698
  return this.simulateTransaction(tx);
584
699
  case 1:
585
- simResponse = _context17.v;
700
+ simResponse = _context19.v;
586
701
  if (!_api.Api.isSimulationError(simResponse)) {
587
- _context17.n = 2;
702
+ _context19.n = 2;
588
703
  break;
589
704
  }
590
705
  throw new Error(simResponse.error);
591
706
  case 2:
592
- return _context17.a(2, (0, _transaction.assembleTransaction)(tx, simResponse).build());
707
+ return _context19.a(2, (0, _transaction.assembleTransaction)(tx, simResponse).build());
593
708
  }
594
- }, _callee17, this);
709
+ }, _callee19, this);
595
710
  }));
596
- function prepareTransaction(_x18) {
711
+ function prepareTransaction(_x23) {
597
712
  return _prepareTransaction.apply(this, arguments);
598
713
  }
599
714
  return prepareTransaction;
@@ -601,15 +716,15 @@ var RpcServer = exports.RpcServer = function () {
601
716
  }, {
602
717
  key: "sendTransaction",
603
718
  value: (function () {
604
- var _sendTransaction2 = _asyncToGenerator(_regenerator().m(function _callee18(transaction) {
605
- return _regenerator().w(function (_context18) {
606
- while (1) switch (_context18.n) {
719
+ var _sendTransaction2 = _asyncToGenerator(_regenerator().m(function _callee20(transaction) {
720
+ return _regenerator().w(function (_context20) {
721
+ while (1) switch (_context20.n) {
607
722
  case 0:
608
- return _context18.a(2, this._sendTransaction(transaction).then(_parsers.parseRawSendTransaction));
723
+ return _context20.a(2, this._sendTransaction(transaction).then(_parsers.parseRawSendTransaction));
609
724
  }
610
- }, _callee18, this);
725
+ }, _callee20, this);
611
726
  }));
612
- function sendTransaction(_x19) {
727
+ function sendTransaction(_x24) {
613
728
  return _sendTransaction2.apply(this, arguments);
614
729
  }
615
730
  return sendTransaction;
@@ -617,17 +732,17 @@ var RpcServer = exports.RpcServer = function () {
617
732
  }, {
618
733
  key: "_sendTransaction",
619
734
  value: function () {
620
- var _sendTransaction3 = _asyncToGenerator(_regenerator().m(function _callee19(transaction) {
621
- return _regenerator().w(function (_context19) {
622
- while (1) switch (_context19.n) {
735
+ var _sendTransaction3 = _asyncToGenerator(_regenerator().m(function _callee21(transaction) {
736
+ return _regenerator().w(function (_context21) {
737
+ while (1) switch (_context21.n) {
623
738
  case 0:
624
- return _context19.a(2, jsonrpc.postObject(this.serverURL.toString(), 'sendTransaction', {
739
+ return _context21.a(2, jsonrpc.postObject(this.serverURL.toString(), "sendTransaction", {
625
740
  transaction: transaction.toXDR()
626
741
  }));
627
742
  }
628
- }, _callee19, this);
743
+ }, _callee21, this);
629
744
  }));
630
- function _sendTransaction(_x20) {
745
+ function _sendTransaction(_x25) {
631
746
  return _sendTransaction3.apply(this, arguments);
632
747
  }
633
748
  return _sendTransaction;
@@ -635,76 +750,76 @@ var RpcServer = exports.RpcServer = function () {
635
750
  }, {
636
751
  key: "requestAirdrop",
637
752
  value: (function () {
638
- var _requestAirdrop = _asyncToGenerator(_regenerator().m(function _callee20(address, friendbotUrl) {
639
- var account, response, meta, txMeta, sequence, _error$response, _error$response$detai, _t2, _t3;
640
- return _regenerator().w(function (_context20) {
641
- while (1) switch (_context20.p = _context20.n) {
753
+ var _requestAirdrop = _asyncToGenerator(_regenerator().m(function _callee22(address, friendbotUrl) {
754
+ var account, response, meta, txMeta, sequence, _error$response, _error$response$detai, _t6, _t7;
755
+ return _regenerator().w(function (_context22) {
756
+ while (1) switch (_context22.p = _context22.n) {
642
757
  case 0:
643
- account = typeof address === 'string' ? address : address.accountId();
644
- _t2 = friendbotUrl;
645
- if (_t2) {
646
- _context20.n = 2;
758
+ account = typeof address === "string" ? address : address.accountId();
759
+ _t6 = friendbotUrl;
760
+ if (_t6) {
761
+ _context22.n = 2;
647
762
  break;
648
763
  }
649
- _context20.n = 1;
764
+ _context22.n = 1;
650
765
  return this.getNetwork();
651
766
  case 1:
652
- _t2 = _context20.v.friendbotUrl;
767
+ _t6 = _context22.v.friendbotUrl;
653
768
  case 2:
654
- friendbotUrl = _t2;
769
+ friendbotUrl = _t6;
655
770
  if (friendbotUrl) {
656
- _context20.n = 3;
771
+ _context22.n = 3;
657
772
  break;
658
773
  }
659
- throw new Error('No friendbot URL configured for current network');
774
+ throw new Error("No friendbot URL configured for current network");
660
775
  case 3:
661
- _context20.p = 3;
662
- _context20.n = 4;
776
+ _context22.p = 3;
777
+ _context22.n = 4;
663
778
  return _axios.default.post("".concat(friendbotUrl, "?addr=").concat(encodeURIComponent(account)));
664
779
  case 4:
665
- response = _context20.v;
780
+ response = _context22.v;
666
781
  if (response.data.result_meta_xdr) {
667
- _context20.n = 7;
782
+ _context22.n = 7;
668
783
  break;
669
784
  }
670
- _context20.n = 5;
785
+ _context22.n = 5;
671
786
  return this.getTransaction(response.data.hash);
672
787
  case 5:
673
- txMeta = _context20.v;
788
+ txMeta = _context22.v;
674
789
  if (!(txMeta.status !== _api.Api.GetTransactionStatus.SUCCESS)) {
675
- _context20.n = 6;
790
+ _context22.n = 6;
676
791
  break;
677
792
  }
678
793
  throw new Error("Funding account ".concat(address, " failed"));
679
794
  case 6:
680
795
  meta = txMeta.resultMetaXdr;
681
- _context20.n = 8;
796
+ _context22.n = 8;
682
797
  break;
683
798
  case 7:
684
- meta = _stellarBase.xdr.TransactionMeta.fromXDR(response.data.result_meta_xdr, 'base64');
799
+ meta = _stellarBase.xdr.TransactionMeta.fromXDR(response.data.result_meta_xdr, "base64");
685
800
  case 8:
686
801
  sequence = findCreatedAccountSequenceInTransactionMeta(meta);
687
- return _context20.a(2, new _stellarBase.Account(account, sequence));
802
+ return _context22.a(2, new _stellarBase.Account(account, sequence));
688
803
  case 9:
689
- _context20.p = 9;
690
- _t3 = _context20.v;
691
- if (!(((_error$response = _t3.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 400)) {
692
- _context20.n = 10;
804
+ _context22.p = 9;
805
+ _t7 = _context22.v;
806
+ if (!(((_error$response = _t7.response) === null || _error$response === void 0 ? void 0 : _error$response.status) === 400)) {
807
+ _context22.n = 10;
693
808
  break;
694
809
  }
695
- if (!((_error$response$detai = _t3.response.detail) !== null && _error$response$detai !== void 0 && _error$response$detai.includes('createAccountAlreadyExist'))) {
696
- _context20.n = 10;
810
+ if (!((_error$response$detai = _t7.response.detail) !== null && _error$response$detai !== void 0 && _error$response$detai.includes("createAccountAlreadyExist"))) {
811
+ _context22.n = 10;
697
812
  break;
698
813
  }
699
- return _context20.a(2, this.getAccount(account));
814
+ return _context22.a(2, this.getAccount(account));
700
815
  case 10:
701
- throw _t3;
816
+ throw _t7;
702
817
  case 11:
703
- return _context20.a(2);
818
+ return _context22.a(2);
704
819
  }
705
- }, _callee20, this, [[3, 9]]);
820
+ }, _callee22, this, [[3, 9]]);
706
821
  }));
707
- function requestAirdrop(_x21, _x22) {
822
+ function requestAirdrop(_x26, _x27) {
708
823
  return _requestAirdrop.apply(this, arguments);
709
824
  }
710
825
  return requestAirdrop;
@@ -712,13 +827,13 @@ var RpcServer = exports.RpcServer = function () {
712
827
  }, {
713
828
  key: "getFeeStats",
714
829
  value: (function () {
715
- var _getFeeStats = _asyncToGenerator(_regenerator().m(function _callee21() {
716
- return _regenerator().w(function (_context21) {
717
- while (1) switch (_context21.n) {
830
+ var _getFeeStats = _asyncToGenerator(_regenerator().m(function _callee23() {
831
+ return _regenerator().w(function (_context23) {
832
+ while (1) switch (_context23.n) {
718
833
  case 0:
719
- return _context21.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getFeeStats'));
834
+ return _context23.a(2, jsonrpc.postObject(this.serverURL.toString(), "getFeeStats"));
720
835
  }
721
- }, _callee21, this);
836
+ }, _callee23, this);
722
837
  }));
723
838
  function getFeeStats() {
724
839
  return _getFeeStats.apply(this, arguments);
@@ -728,13 +843,13 @@ var RpcServer = exports.RpcServer = function () {
728
843
  }, {
729
844
  key: "getVersionInfo",
730
845
  value: (function () {
731
- var _getVersionInfo = _asyncToGenerator(_regenerator().m(function _callee22() {
732
- return _regenerator().w(function (_context22) {
733
- while (1) switch (_context22.n) {
846
+ var _getVersionInfo = _asyncToGenerator(_regenerator().m(function _callee24() {
847
+ return _regenerator().w(function (_context24) {
848
+ while (1) switch (_context24.n) {
734
849
  case 0:
735
- return _context22.a(2, jsonrpc.postObject(this.serverURL.toString(), 'getVersionInfo'));
850
+ return _context24.a(2, jsonrpc.postObject(this.serverURL.toString(), "getVersionInfo"));
736
851
  }
737
- }, _callee22, this);
852
+ }, _callee24, this);
738
853
  }));
739
854
  function getVersionInfo() {
740
855
  return _getVersionInfo.apply(this, arguments);
@@ -744,35 +859,36 @@ var RpcServer = exports.RpcServer = function () {
744
859
  }, {
745
860
  key: "getSACBalance",
746
861
  value: (function () {
747
- var _getSACBalance = _asyncToGenerator(_regenerator().m(function _callee23(contractId, sac, networkPassphrase) {
748
- var passphrase, sacId, key, ledgerKey, response, _response$entries$2, lastModifiedLedgerSeq, liveUntilLedgerSeq, val, entry, _t4;
749
- return _regenerator().w(function (_context23) {
750
- while (1) switch (_context23.n) {
862
+ var _getSACBalance = _asyncToGenerator(_regenerator().m(function _callee25(address, sac, networkPassphrase) {
863
+ var addressString, passphrase, sacId, key, ledgerKey, response, _response$entries$2, lastModifiedLedgerSeq, liveUntilLedgerSeq, val, entry, _t8;
864
+ return _regenerator().w(function (_context25) {
865
+ while (1) switch (_context25.n) {
751
866
  case 0:
752
- if (_stellarBase.StrKey.isValidContract(contractId)) {
753
- _context23.n = 1;
867
+ addressString = address instanceof _stellarBase.Address ? address.toString() : address;
868
+ if (_stellarBase.StrKey.isValidContract(addressString)) {
869
+ _context25.n = 1;
754
870
  break;
755
871
  }
756
- throw new TypeError("expected contract ID, got ".concat(contractId));
872
+ throw new TypeError("expected contract ID, got ".concat(addressString));
757
873
  case 1:
758
874
  if (!(networkPassphrase !== null && networkPassphrase !== void 0)) {
759
- _context23.n = 2;
875
+ _context25.n = 2;
760
876
  break;
761
877
  }
762
- _t4 = networkPassphrase;
763
- _context23.n = 4;
878
+ _t8 = networkPassphrase;
879
+ _context25.n = 4;
764
880
  break;
765
881
  case 2:
766
- _context23.n = 3;
882
+ _context25.n = 3;
767
883
  return this.getNetwork().then(function (n) {
768
884
  return n.passphrase;
769
885
  });
770
886
  case 3:
771
- _t4 = _context23.v;
887
+ _t8 = _context25.v;
772
888
  case 4:
773
- passphrase = _t4;
889
+ passphrase = _t8;
774
890
  sacId = sac.contractId(passphrase);
775
- key = (0, _stellarBase.nativeToScVal)(["Balance", contractId], {
891
+ key = (0, _stellarBase.nativeToScVal)(["Balance", addressString], {
776
892
  type: ["symbol", "address"]
777
893
  });
778
894
  ledgerKey = _stellarBase.xdr.LedgerKey.contractData(new _stellarBase.xdr.LedgerKeyContractData({
@@ -780,29 +896,29 @@ var RpcServer = exports.RpcServer = function () {
780
896
  durability: _stellarBase.xdr.ContractDataDurability.persistent(),
781
897
  key: key
782
898
  }));
783
- _context23.n = 5;
899
+ _context25.n = 5;
784
900
  return this.getLedgerEntries(ledgerKey);
785
901
  case 5:
786
- response = _context23.v;
902
+ response = _context25.v;
787
903
  if (!(response.entries.length === 0)) {
788
- _context23.n = 6;
904
+ _context25.n = 6;
789
905
  break;
790
906
  }
791
- return _context23.a(2, {
907
+ return _context25.a(2, {
792
908
  latestLedger: response.latestLedger
793
909
  });
794
910
  case 6:
795
911
  _response$entries$2 = response.entries[0], lastModifiedLedgerSeq = _response$entries$2.lastModifiedLedgerSeq, liveUntilLedgerSeq = _response$entries$2.liveUntilLedgerSeq, val = _response$entries$2.val;
796
912
  if (!(val.switch().value !== _stellarBase.xdr.LedgerEntryType.contractData().value)) {
797
- _context23.n = 7;
913
+ _context25.n = 7;
798
914
  break;
799
915
  }
800
- return _context23.a(2, {
916
+ return _context25.a(2, {
801
917
  latestLedger: response.latestLedger
802
918
  });
803
919
  case 7:
804
920
  entry = (0, _stellarBase.scValToNative)(val.contractData().val());
805
- return _context23.a(2, {
921
+ return _context25.a(2, {
806
922
  latestLedger: response.latestLedger,
807
923
  balanceEntry: {
808
924
  liveUntilLedgerSeq: liveUntilLedgerSeq,
@@ -813,9 +929,9 @@ var RpcServer = exports.RpcServer = function () {
813
929
  }
814
930
  });
815
931
  }
816
- }, _callee23, this);
932
+ }, _callee25, this);
817
933
  }));
818
- function getSACBalance(_x23, _x24, _x25) {
934
+ function getSACBalance(_x28, _x29, _x30) {
819
935
  return _getSACBalance.apply(this, arguments);
820
936
  }
821
937
  return getSACBalance;