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.

balance-sheet.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. const common_1 = require("../common");
  13. const utils_1 = require("./utils");
  14. function formatBalanceSheet(balanceSheet) {
  15. const result = {};
  16. if (balanceSheet.balances != null) {
  17. result.balances = [];
  18. Object.entries(balanceSheet.balances).forEach(entry => {
  19. const [counterparty, balances] = entry;
  20. balances.forEach((balance) => {
  21. result.balances.push(Object.assign({ counterparty }, balance));
  22. });
  23. });
  24. }
  25. if (balanceSheet.assets != null) {
  26. result.assets = [];
  27. Object.entries(balanceSheet.assets).forEach(([counterparty, assets]) => {
  28. assets.forEach((balance) => {
  29. result.assets.push(Object.assign({ counterparty }, balance));
  30. });
  31. });
  32. }
  33. if (balanceSheet.obligations != null) {
  34. result.obligations = Object.entries(balanceSheet.obligations).map(([currency, value]) => ({ currency, value }));
  35. }
  36. return result;
  37. }
  38. function getBalanceSheet(address, options = {}) {
  39. return __awaiter(this, void 0, void 0, function* () {
  40. common_1.validate.getBalanceSheet({ address, options });
  41. options = yield utils_1.ensureLedgerVersion.call(this, options);
  42. const response = yield this.request('gateway_balances', {
  43. account: address,
  44. strict: true,
  45. hotwallet: options.excludeAddresses,
  46. ledger_index: options.ledgerVersion
  47. });
  48. return formatBalanceSheet(response);
  49. });
  50. }
  51. exports.default = getBalanceSheet;
  52. //# sourceMappingURL=balance-sheet.js.map