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 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 __importDefault = (this && this.__importDefault) || function (mod) {
  22. return (mod && mod.__esModule) ? mod : { "default": mod };
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. const _ = __importStar(require("lodash"));
  26. const assert = __importStar(require("assert"));
  27. const common_1 = require("../../common");
  28. const AccountFlags = common_1.constants.AccountFlags;
  29. const fields_1 = __importDefault(require("./fields"));
  30. function getAccountRootModifiedNode(tx) {
  31. const modifiedNodes = tx.meta.AffectedNodes.filter(node => { var _a; return ((_a = node.ModifiedNode) === null || _a === void 0 ? void 0 : _a.LedgerEntryType) === 'AccountRoot'; });
  32. assert.ok(modifiedNodes.length === 1);
  33. return modifiedNodes[0].ModifiedNode;
  34. }
  35. function parseFlags(tx) {
  36. const settings = {};
  37. if (tx.TransactionType !== 'AccountSet') {
  38. return settings;
  39. }
  40. const node = getAccountRootModifiedNode(tx);
  41. const oldFlags = _.get(node.PreviousFields, 'Flags');
  42. const newFlags = _.get(node.FinalFields, 'Flags');
  43. if (oldFlags != null && newFlags != null) {
  44. const changedFlags = oldFlags ^ newFlags;
  45. const setFlags = newFlags & changedFlags;
  46. const clearedFlags = oldFlags & changedFlags;
  47. Object.entries(AccountFlags).forEach(entry => {
  48. const [flagName, flagValue] = entry;
  49. if (setFlags & flagValue) {
  50. settings[flagName] = true;
  51. }
  52. else if (clearedFlags & flagValue) {
  53. settings[flagName] = false;
  54. }
  55. });
  56. }
  57. const oldField = _.get(node.PreviousFields, 'AccountTxnID');
  58. const newField = _.get(node.FinalFields, 'AccountTxnID');
  59. if (newField && !oldField) {
  60. settings.enableTransactionIDTracking = true;
  61. }
  62. else if (oldField && !newField) {
  63. settings.enableTransactionIDTracking = false;
  64. }
  65. return settings;
  66. }
  67. function parseSettings(tx) {
  68. const txType = tx.TransactionType;
  69. assert.ok(txType === 'AccountSet' ||
  70. txType === 'SetRegularKey' ||
  71. txType === 'SignerListSet');
  72. return Object.assign({}, parseFlags(tx), fields_1.default(tx));
  73. }
  74. exports.default = parseSettings;
  75. //# sourceMappingURL=settings.js.map