@stellar/stellar-sdk 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1275 -0
- package/LICENSE +228 -0
- package/README.md +274 -0
- package/dist/stellar-sdk.js +56470 -0
- package/dist/stellar-sdk.min.js +2 -0
- package/dist/stellar-sdk.min.js.LICENSE.txt +71 -0
- package/lib/browser.d.ts +6 -0
- package/lib/browser.js +37 -0
- package/lib/config.d.ts +52 -0
- package/lib/config.js +49 -0
- package/lib/contract_spec.d.ts +130 -0
- package/lib/contract_spec.js +549 -0
- package/lib/errors.d.ts +59 -0
- package/lib/errors.js +105 -0
- package/lib/federation/api.d.ts +11 -0
- package/lib/federation/api.js +7 -0
- package/lib/federation/index.d.ts +2 -0
- package/lib/federation/index.js +24 -0
- package/lib/federation/server.d.ts +118 -0
- package/lib/federation/server.js +253 -0
- package/lib/friendbot/index.d.ts +5 -0
- package/lib/friendbot/index.js +7 -0
- package/lib/horizon/account_call_builder.d.ts +55 -0
- package/lib/horizon/account_call_builder.js +64 -0
- package/lib/horizon/account_response.d.ts +58 -0
- package/lib/horizon/account_response.js +50 -0
- package/lib/horizon/assets_call_builder.d.ts +27 -0
- package/lib/horizon/assets_call_builder.js +45 -0
- package/lib/horizon/call_builder.d.ts +128 -0
- package/lib/horizon/call_builder.js +360 -0
- package/lib/horizon/claimable_balances_call_builder.d.ts +49 -0
- package/lib/horizon/claimable_balances_call_builder.js +58 -0
- package/lib/horizon/effect_call_builder.d.ts +53 -0
- package/lib/horizon/effect_call_builder.js +58 -0
- package/lib/horizon/friendbot_builder.d.ts +5 -0
- package/lib/horizon/friendbot_builder.js +33 -0
- package/lib/horizon/horizon_api.d.ts +523 -0
- package/lib/horizon/horizon_api.js +96 -0
- package/lib/horizon/horizon_axios_client.d.ts +30 -0
- package/lib/horizon/horizon_axios_client.js +48 -0
- package/lib/horizon/index.d.ts +7 -0
- package/lib/horizon/index.js +78 -0
- package/lib/horizon/ledger_call_builder.d.ts +22 -0
- package/lib/horizon/ledger_call_builder.js +39 -0
- package/lib/horizon/liquidity_pool_call_builder.d.ts +38 -0
- package/lib/horizon/liquidity_pool_call_builder.js +61 -0
- package/lib/horizon/offer_call_builder.d.ts +64 -0
- package/lib/horizon/offer_call_builder.js +81 -0
- package/lib/horizon/operation_call_builder.d.ts +68 -0
- package/lib/horizon/operation_call_builder.js +71 -0
- package/lib/horizon/orderbook_call_builder.d.ts +16 -0
- package/lib/horizon/orderbook_call_builder.js +46 -0
- package/lib/horizon/path_call_builder.d.ts +31 -0
- package/lib/horizon/path_call_builder.js +42 -0
- package/lib/horizon/payment_call_builder.d.ts +36 -0
- package/lib/horizon/payment_call_builder.js +48 -0
- package/lib/horizon/server.d.ts +361 -0
- package/lib/horizon/server.js +507 -0
- package/lib/horizon/server_api.d.ts +279 -0
- package/lib/horizon/server_api.js +19 -0
- package/lib/horizon/strict_receive_path_call_builder.d.ts +34 -0
- package/lib/horizon/strict_receive_path_call_builder.js +51 -0
- package/lib/horizon/strict_send_path_call_builder.d.ts +34 -0
- package/lib/horizon/strict_send_path_call_builder.js +51 -0
- package/lib/horizon/trade_aggregation_call_builder.d.ts +48 -0
- package/lib/horizon/trade_aggregation_call_builder.js +82 -0
- package/lib/horizon/trades_call_builder.d.ts +50 -0
- package/lib/horizon/trades_call_builder.js +74 -0
- package/lib/horizon/transaction_call_builder.d.ts +58 -0
- package/lib/horizon/transaction_call_builder.js +66 -0
- package/lib/horizon/types/account.d.ts +5 -0
- package/lib/horizon/types/account.js +5 -0
- package/lib/horizon/types/assets.d.ts +19 -0
- package/lib/horizon/types/assets.js +5 -0
- package/lib/horizon/types/effects.d.ts +285 -0
- package/lib/horizon/types/effects.js +62 -0
- package/lib/horizon/types/offer.d.ts +20 -0
- package/lib/horizon/types/offer.js +5 -0
- package/lib/horizon/types/trade.d.ts +13 -0
- package/lib/horizon/types/trade.js +5 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +79 -0
- package/lib/soroban/api.d.ts +247 -0
- package/lib/soroban/api.js +32 -0
- package/lib/soroban/axios.d.ts +3 -0
- package/lib/soroban/axios.js +16 -0
- package/lib/soroban/browser.d.ts +6 -0
- package/lib/soroban/browser.js +37 -0
- package/lib/soroban/index.d.ts +8 -0
- package/lib/soroban/index.js +72 -0
- package/lib/soroban/jsonrpc.d.ts +33 -0
- package/lib/soroban/jsonrpc.js +93 -0
- package/lib/soroban/parsers.d.ts +17 -0
- package/lib/soroban/parsers.js +111 -0
- package/lib/soroban/server.d.ts +427 -0
- package/lib/soroban/server.js +598 -0
- package/lib/soroban/transaction.d.ts +20 -0
- package/lib/soroban/transaction.js +55 -0
- package/lib/soroban/utils.d.ts +1 -0
- package/lib/soroban/utils.js +9 -0
- package/lib/stellartoml/index.d.ts +121 -0
- package/lib/stellartoml/index.js +78 -0
- package/lib/utils.d.ts +12 -0
- package/lib/utils.js +32 -0
- package/lib/webauth/errors.d.ts +4 -0
- package/lib/webauth/errors.js +37 -0
- package/lib/webauth/index.d.ts +2 -0
- package/lib/webauth/index.js +27 -0
- package/lib/webauth/utils.d.ts +294 -0
- package/lib/webauth/utils.js +332 -0
- package/package.json +153 -0
- package/types/dom-monkeypatch.d.ts +126 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.AccountCallBuilder = void 0;
|
|
8
|
+
var _call_builder = require("./call_builder");
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
15
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
16
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
19
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
|
+
var AccountCallBuilder = exports.AccountCallBuilder = function (_CallBuilder) {
|
|
22
|
+
_inherits(AccountCallBuilder, _CallBuilder);
|
|
23
|
+
var _super = _createSuper(AccountCallBuilder);
|
|
24
|
+
function AccountCallBuilder(serverUrl) {
|
|
25
|
+
var _this;
|
|
26
|
+
_classCallCheck(this, AccountCallBuilder);
|
|
27
|
+
_this = _super.call(this, serverUrl);
|
|
28
|
+
_this.url.segment("accounts");
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
_createClass(AccountCallBuilder, [{
|
|
32
|
+
key: "accountId",
|
|
33
|
+
value: function accountId(id) {
|
|
34
|
+
var builder = new _call_builder.CallBuilder(this.url.clone());
|
|
35
|
+
builder.filter.push([id]);
|
|
36
|
+
return builder;
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "forSigner",
|
|
40
|
+
value: function forSigner(id) {
|
|
41
|
+
this.url.setQuery("signer", id);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: "forAsset",
|
|
46
|
+
value: function forAsset(asset) {
|
|
47
|
+
this.url.setQuery("asset", "".concat(asset));
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "sponsor",
|
|
52
|
+
value: function sponsor(id) {
|
|
53
|
+
this.url.setQuery("sponsor", id);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
}, {
|
|
57
|
+
key: "forLiquidityPool",
|
|
58
|
+
value: function forLiquidityPool(id) {
|
|
59
|
+
this.url.setQuery("liquidity_pool", id);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
}]);
|
|
63
|
+
return AccountCallBuilder;
|
|
64
|
+
}(_call_builder.CallBuilder);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { HorizonApi } from "./horizon_api";
|
|
2
|
+
import { ServerApi } from "./server_api";
|
|
3
|
+
/**
|
|
4
|
+
* Do not create this object directly, use {@link Server#loadAccount}.
|
|
5
|
+
*
|
|
6
|
+
* Returns information and links relating to a single account.
|
|
7
|
+
* The balances section in the returned JSON will also list all the trust lines this account has set up.
|
|
8
|
+
* It also contains {@link Account} object and exposes it's methods so can be used in {@link TransactionBuilder}.
|
|
9
|
+
*
|
|
10
|
+
* @see [Account Details](https://developers.stellar.org/api/resources/accounts/object/)
|
|
11
|
+
* @param {string} response Response from horizon account endpoint.
|
|
12
|
+
* @returns {AccountResponse} AccountResponse instance
|
|
13
|
+
*/
|
|
14
|
+
export declare class AccountResponse {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly paging_token: string;
|
|
17
|
+
readonly account_id: string;
|
|
18
|
+
sequence: string;
|
|
19
|
+
readonly sequence_ledger?: number;
|
|
20
|
+
readonly sequence_time?: string;
|
|
21
|
+
readonly subentry_count: number;
|
|
22
|
+
readonly home_domain?: string;
|
|
23
|
+
readonly inflation_destination?: string;
|
|
24
|
+
readonly last_modified_ledger: number;
|
|
25
|
+
readonly last_modified_time: string;
|
|
26
|
+
readonly thresholds: HorizonApi.AccountThresholds;
|
|
27
|
+
readonly flags: HorizonApi.Flags;
|
|
28
|
+
readonly balances: HorizonApi.BalanceLine[];
|
|
29
|
+
readonly signers: ServerApi.AccountRecordSigners[];
|
|
30
|
+
readonly data: (options: {
|
|
31
|
+
value: string;
|
|
32
|
+
}) => Promise<{
|
|
33
|
+
value: string;
|
|
34
|
+
}>;
|
|
35
|
+
readonly data_attr: Record<string, string>;
|
|
36
|
+
readonly effects: ServerApi.CallCollectionFunction<ServerApi.EffectRecord>;
|
|
37
|
+
readonly offers: ServerApi.CallCollectionFunction<ServerApi.OfferRecord>;
|
|
38
|
+
readonly operations: ServerApi.CallCollectionFunction<ServerApi.OperationRecord>;
|
|
39
|
+
readonly payments: ServerApi.CallCollectionFunction<ServerApi.PaymentOperationRecord>;
|
|
40
|
+
readonly trades: ServerApi.CallCollectionFunction<ServerApi.TradeRecord>;
|
|
41
|
+
private readonly _baseAccount;
|
|
42
|
+
constructor(response: ServerApi.AccountRecord);
|
|
43
|
+
/**
|
|
44
|
+
* Get Stellar account public key ex. `GB3KJPLFUYN5VL6R3GU3EGCGVCKFDSD7BEDX42HWG5BWFKB3KQGJJRMA`
|
|
45
|
+
* @returns {string} accountId
|
|
46
|
+
*/
|
|
47
|
+
accountId(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Get the current sequence number
|
|
50
|
+
* @returns {string} sequenceNumber
|
|
51
|
+
*/
|
|
52
|
+
sequenceNumber(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Increments sequence number in this object by one.
|
|
55
|
+
* @returns {void}
|
|
56
|
+
*/
|
|
57
|
+
incrementSequenceNumber(): void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AccountResponse = void 0;
|
|
7
|
+
var _stellarBase = require("@stellar/stellar-base");
|
|
8
|
+
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); }
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
17
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
18
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
19
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
20
|
+
var AccountResponse = exports.AccountResponse = function () {
|
|
21
|
+
function AccountResponse(response) {
|
|
22
|
+
var _this = this;
|
|
23
|
+
_classCallCheck(this, AccountResponse);
|
|
24
|
+
this._baseAccount = new _stellarBase.Account(response.account_id, response.sequence);
|
|
25
|
+
Object.entries(response).forEach(function (_ref) {
|
|
26
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
27
|
+
key = _ref2[0],
|
|
28
|
+
value = _ref2[1];
|
|
29
|
+
_this[key] = value;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
_createClass(AccountResponse, [{
|
|
33
|
+
key: "accountId",
|
|
34
|
+
value: function accountId() {
|
|
35
|
+
return this._baseAccount.accountId();
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "sequenceNumber",
|
|
39
|
+
value: function sequenceNumber() {
|
|
40
|
+
return this._baseAccount.sequenceNumber();
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: "incrementSequenceNumber",
|
|
44
|
+
value: function incrementSequenceNumber() {
|
|
45
|
+
this._baseAccount.incrementSequenceNumber();
|
|
46
|
+
this.sequence = this._baseAccount.sequenceNumber();
|
|
47
|
+
}
|
|
48
|
+
}]);
|
|
49
|
+
return AccountResponse;
|
|
50
|
+
}();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="urijs" />
|
|
2
|
+
import { CallBuilder } from "./call_builder";
|
|
3
|
+
import { ServerApi } from "./server_api";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new {@link AssetsCallBuilder} pointed to server defined by serverUrl.
|
|
6
|
+
*
|
|
7
|
+
* Do not create this object directly, use {@link Server#assets}.
|
|
8
|
+
* @class AssetsCallBuilder
|
|
9
|
+
* @constructor
|
|
10
|
+
* @extends CallBuilder
|
|
11
|
+
* @param {string} serverUrl Horizon server URL.
|
|
12
|
+
*/
|
|
13
|
+
export declare class AssetsCallBuilder extends CallBuilder<ServerApi.CollectionPage<ServerApi.AssetRecord>> {
|
|
14
|
+
constructor(serverUrl: URI);
|
|
15
|
+
/**
|
|
16
|
+
* This endpoint filters all assets by the asset code.
|
|
17
|
+
* @param {string} value For example: `USD`
|
|
18
|
+
* @returns {AssetsCallBuilder} current AssetCallBuilder instance
|
|
19
|
+
*/
|
|
20
|
+
forCode(value: string): AssetsCallBuilder;
|
|
21
|
+
/**
|
|
22
|
+
* This endpoint filters all assets by the asset issuer.
|
|
23
|
+
* @param {string} value For example: `GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD`
|
|
24
|
+
* @returns {AssetsCallBuilder} current AssetCallBuilder instance
|
|
25
|
+
*/
|
|
26
|
+
forIssuer(value: string): AssetsCallBuilder;
|
|
27
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
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); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.AssetsCallBuilder = void 0;
|
|
8
|
+
var _call_builder = require("./call_builder");
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
15
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
16
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
17
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
19
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
|
+
var AssetsCallBuilder = exports.AssetsCallBuilder = function (_CallBuilder) {
|
|
22
|
+
_inherits(AssetsCallBuilder, _CallBuilder);
|
|
23
|
+
var _super = _createSuper(AssetsCallBuilder);
|
|
24
|
+
function AssetsCallBuilder(serverUrl) {
|
|
25
|
+
var _this;
|
|
26
|
+
_classCallCheck(this, AssetsCallBuilder);
|
|
27
|
+
_this = _super.call(this, serverUrl);
|
|
28
|
+
_this.url.segment("assets");
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
_createClass(AssetsCallBuilder, [{
|
|
32
|
+
key: "forCode",
|
|
33
|
+
value: function forCode(value) {
|
|
34
|
+
this.url.setQuery("asset_code", value);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "forIssuer",
|
|
39
|
+
value: function forIssuer(value) {
|
|
40
|
+
this.url.setQuery("asset_issuer", value);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
}]);
|
|
44
|
+
return AssetsCallBuilder;
|
|
45
|
+
}(_call_builder.CallBuilder);
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import URI from "urijs";
|
|
2
|
+
import { HorizonApi } from "./horizon_api";
|
|
3
|
+
import { ServerApi } from "./server_api";
|
|
4
|
+
export interface EventSourceOptions<T> {
|
|
5
|
+
onmessage?: (value: T) => void;
|
|
6
|
+
onerror?: (event: MessageEvent) => void;
|
|
7
|
+
reconnectTimeout?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new {@link CallBuilder} pointed to server defined by serverUrl.
|
|
11
|
+
*
|
|
12
|
+
* This is an **abstract** class. Do not create this object directly, use {@link Server} class.
|
|
13
|
+
* @param {string} serverUrl URL of Horizon server
|
|
14
|
+
* @class CallBuilder
|
|
15
|
+
*/
|
|
16
|
+
export declare class CallBuilder<T extends HorizonApi.FeeStatsResponse | HorizonApi.BaseResponse | ServerApi.CollectionPage<HorizonApi.BaseResponse>> {
|
|
17
|
+
protected url: URI;
|
|
18
|
+
filter: string[][];
|
|
19
|
+
protected originalSegments: string[];
|
|
20
|
+
protected neighborRoot: string;
|
|
21
|
+
constructor(serverUrl: URI, neighborRoot?: string);
|
|
22
|
+
/**
|
|
23
|
+
* Triggers a HTTP request using this builder's current configuration.
|
|
24
|
+
* @returns {Promise} a Promise that resolves to the server's response.
|
|
25
|
+
*/
|
|
26
|
+
call(): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an EventSource that listens for incoming messages from the server. To stop listening for new
|
|
29
|
+
* events call the function returned by this method.
|
|
30
|
+
* @see [Horizon Response Format](https://developers.stellar.org/api/introduction/response-format/)
|
|
31
|
+
* @see [MDN EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource)
|
|
32
|
+
* @param {object} [options] EventSource options.
|
|
33
|
+
* @param {function} [options.onmessage] Callback function to handle incoming messages.
|
|
34
|
+
* @param {function} [options.onerror] Callback function to handle errors.
|
|
35
|
+
* @param {number} [options.reconnectTimeout] Custom stream connection timeout in ms, default is 15 seconds.
|
|
36
|
+
* @returns {function} Close function. Run to close the connection and stop listening for new events.
|
|
37
|
+
*/
|
|
38
|
+
stream(options?: EventSourceOptions<T>): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Sets `cursor` parameter for the current call. Returns the CallBuilder object on which this method has been called.
|
|
41
|
+
* @see [Paging](https://developers.stellar.org/api/introduction/pagination/)
|
|
42
|
+
* @param {string} cursor A cursor is a value that points to a specific location in a collection of resources.
|
|
43
|
+
* @returns {object} current CallBuilder instance
|
|
44
|
+
*/
|
|
45
|
+
cursor(cursor: string): this;
|
|
46
|
+
/**
|
|
47
|
+
* Sets `limit` parameter for the current call. Returns the CallBuilder object on which this method has been called.
|
|
48
|
+
* @see [Paging](https://developers.stellar.org/api/introduction/pagination/)
|
|
49
|
+
* @param {number} number Number of records the server should return.
|
|
50
|
+
* @returns {object} current CallBuilder instance
|
|
51
|
+
*/
|
|
52
|
+
limit(recordsNumber: number): this;
|
|
53
|
+
/**
|
|
54
|
+
* Sets `order` parameter for the current call. Returns the CallBuilder object on which this method has been called.
|
|
55
|
+
* @param {"asc"|"desc"} direction Sort direction
|
|
56
|
+
* @returns {object} current CallBuilder instance
|
|
57
|
+
*/
|
|
58
|
+
order(direction: "asc" | "desc"): this;
|
|
59
|
+
/**
|
|
60
|
+
* Sets `join` parameter for the current call. The `join` parameter
|
|
61
|
+
* includes the requested resource in the response. Currently, the
|
|
62
|
+
* only valid value for the parameter is `transactions` and is only
|
|
63
|
+
* supported on the operations and payments endpoints. The response
|
|
64
|
+
* will include a `transaction` field for each operation in the
|
|
65
|
+
* response.
|
|
66
|
+
*
|
|
67
|
+
* @param {"transactions"} join Records to be included in the response.
|
|
68
|
+
* @returns {object} current CallBuilder instance.
|
|
69
|
+
*/
|
|
70
|
+
join(include: "transactions"): this;
|
|
71
|
+
/**
|
|
72
|
+
* A helper method to craft queries to "neighbor" endpoints.
|
|
73
|
+
*
|
|
74
|
+
* For example, we have an `/effects` suffix endpoint on many different
|
|
75
|
+
* "root" endpoints, such as `/transactions/:id` and `/accounts/:id`. So,
|
|
76
|
+
* it's helpful to be able to conveniently create queries to the
|
|
77
|
+
* `/accounts/:id/effects` endpoint:
|
|
78
|
+
*
|
|
79
|
+
* this.forEndpoint("accounts", accountId)`.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} endpoint neighbor endpoint in question, like /operations
|
|
82
|
+
* @param {string} param filter parameter, like an operation ID
|
|
83
|
+
*
|
|
84
|
+
* @returns {CallBuilder} this CallBuilder instance
|
|
85
|
+
*/
|
|
86
|
+
protected forEndpoint(endpoint: string, param: string): this;
|
|
87
|
+
/**
|
|
88
|
+
* @private
|
|
89
|
+
* @returns {void}
|
|
90
|
+
*/
|
|
91
|
+
private checkFilter;
|
|
92
|
+
/**
|
|
93
|
+
* Convert a link object to a function that fetches that link.
|
|
94
|
+
* @private
|
|
95
|
+
* @param {object} link A link object
|
|
96
|
+
* @param {bool} link.href the URI of the link
|
|
97
|
+
* @param {bool} [link.templated] Whether the link is templated
|
|
98
|
+
* @returns {function} A function that requests the link
|
|
99
|
+
*/
|
|
100
|
+
private _requestFnForLink;
|
|
101
|
+
/**
|
|
102
|
+
* Given the json response, find and convert each link into a function that
|
|
103
|
+
* calls that link.
|
|
104
|
+
* @private
|
|
105
|
+
* @param {object} json JSON response
|
|
106
|
+
* @returns {object} JSON response with string links replaced with functions
|
|
107
|
+
*/
|
|
108
|
+
private _parseRecord;
|
|
109
|
+
private _sendNormalRequest;
|
|
110
|
+
/**
|
|
111
|
+
* @private
|
|
112
|
+
* @param {object} json Response object
|
|
113
|
+
* @returns {object} Extended response
|
|
114
|
+
*/
|
|
115
|
+
private _parseResponse;
|
|
116
|
+
/**
|
|
117
|
+
* @private
|
|
118
|
+
* @param {object} json Response object
|
|
119
|
+
* @returns {object} Extended response object
|
|
120
|
+
*/
|
|
121
|
+
private _toCollectionPage;
|
|
122
|
+
/**
|
|
123
|
+
* @private
|
|
124
|
+
* @param {object} error Network error object
|
|
125
|
+
* @returns {Promise<Error>} Promise that rejects with a human-readable error
|
|
126
|
+
*/
|
|
127
|
+
private _handleNetworkError;
|
|
128
|
+
}
|