You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

trustlines.js 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  5. }) : (function(o, m, k, k2) {
  6. if (k2 === undefined) k2 = k;
  7. o[k2] = m[k];
  8. }));
  9. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  10. Object.defineProperty(o, "default", { enumerable: true, value: v });
  11. }) : function(o, v) {
  12. o["default"] = v;
  13. });
  14. var __importStar = (this && this.__importStar) || function (mod) {
  15. if (mod && mod.__esModule) return mod;
  16. var result = {};
  17. if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  18. __setModuleDefault(result, mod);
  19. return result;
  20. };
  21. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  22. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  23. return new (P || (P = Promise))(function (resolve, reject) {
  24. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  25. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  26. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  27. step((generator = generator.apply(thisArg, _arguments || [])).next());
  28. });
  29. };
  30. var __importDefault = (this && this.__importDefault) || function (mod) {
  31. return (mod && mod.__esModule) ? mod : { "default": mod };
  32. };
  33. Object.defineProperty(exports, "__esModule", { value: true });
  34. const _ = __importStar(require("lodash"));
  35. const common_1 = require("../common");
  36. const account_trustline_1 = __importDefault(require("./parse/account-trustline"));
  37. function currencyFilter(currency, trustline) {
  38. return currency === null || trustline.specification.currency === currency;
  39. }
  40. function getTrustlines(address, options = {}) {
  41. var _a;
  42. return __awaiter(this, void 0, void 0, function* () {
  43. common_1.validate.getTrustlines({ address, options });
  44. address = common_1.ensureClassicAddress(address);
  45. const responses = yield this._requestAll('account_lines', {
  46. account: address,
  47. ledger_index: (_a = options.ledgerVersion) !== null && _a !== void 0 ? _a : yield this.getLedgerVersion(),
  48. limit: options.limit,
  49. peer: options.counterparty
  50. });
  51. const trustlines = _.flatMap(responses, (response) => response.lines);
  52. return trustlines.map(account_trustline_1.default).filter((trustline) => {
  53. return currencyFilter(options.currency || null, trustline);
  54. });
  55. });
  56. }
  57. exports.default = getTrustlines;
  58. //# sourceMappingURL=trustlines.js.map