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.

fields.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const bignumber_js_1 = __importDefault(require("bignumber.js"));
  7. const common_1 = require("../../common");
  8. const AccountFields = common_1.constants.AccountFields;
  9. function parseField(info, value) {
  10. if (info.encoding === 'hex' && !info.length) {
  11. return Buffer.from(value, 'hex').toString('ascii');
  12. }
  13. if (info.shift) {
  14. return new bignumber_js_1.default(value).shiftedBy(-info.shift).toNumber();
  15. }
  16. return value;
  17. }
  18. function parseFields(data) {
  19. const settings = {};
  20. for (const fieldName in AccountFields) {
  21. const fieldValue = data[fieldName];
  22. if (fieldValue != null) {
  23. const info = AccountFields[fieldName];
  24. settings[info.name] = parseField(info, fieldValue);
  25. }
  26. }
  27. if (data.RegularKey) {
  28. settings.regularKey = data.RegularKey;
  29. }
  30. if (data.signer_lists && data.signer_lists.length === 1) {
  31. settings.signers = {};
  32. if (data.signer_lists[0].SignerQuorum) {
  33. settings.signers.threshold = data.signer_lists[0].SignerQuorum;
  34. }
  35. if (data.signer_lists[0].SignerEntries) {
  36. settings.signers.weights = data.signer_lists[0].SignerEntries.map((entry) => {
  37. return {
  38. address: entry.SignerEntry.Account,
  39. weight: entry.SignerEntry.SignerWeight
  40. };
  41. });
  42. }
  43. }
  44. return settings;
  45. }
  46. exports.default = parseFields;
  47. //# sourceMappingURL=fields.js.map