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.

settings.js 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. var __importDefault = (this && this.__importDefault) || function (mod) {
  12. return (mod && mod.__esModule) ? mod : { "default": mod };
  13. };
  14. Object.defineProperty(exports, "__esModule", { value: true });
  15. exports.getSettings = exports.parseAccountFlags = void 0;
  16. const fields_1 = __importDefault(require("./parse/fields"));
  17. const common_1 = require("../common");
  18. const AccountFlags = common_1.constants.AccountFlags;
  19. function parseAccountFlags(value, options = {}) {
  20. const settings = {};
  21. for (const flagName in AccountFlags) {
  22. if (value & AccountFlags[flagName]) {
  23. settings[flagName] = true;
  24. }
  25. else {
  26. if (!options.excludeFalse) {
  27. settings[flagName] = false;
  28. }
  29. }
  30. }
  31. return settings;
  32. }
  33. exports.parseAccountFlags = parseAccountFlags;
  34. function formatSettings(response) {
  35. const data = response.account_data;
  36. const parsedFlags = parseAccountFlags(data.Flags, { excludeFalse: true });
  37. const parsedFields = fields_1.default(data);
  38. return Object.assign({}, parsedFlags, parsedFields);
  39. }
  40. function getSettings(address, options = {}) {
  41. return __awaiter(this, void 0, void 0, function* () {
  42. common_1.validate.getSettings({ address, options });
  43. address = common_1.ensureClassicAddress(address);
  44. const response = yield this.request('account_info', {
  45. account: address,
  46. ledger_index: options.ledgerVersion || 'validated',
  47. signer_lists: true
  48. });
  49. return formatSettings(response);
  50. });
  51. }
  52. exports.getSettings = getSettings;
  53. //# sourceMappingURL=settings.js.map