Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

xrpl-definitions-base.js 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.BytesLookup = exports.Bytes = exports.FieldLookup = exports.XrplDefinitionsBase = void 0;
  4. const bytes_1 = require("./bytes");
  5. Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return bytes_1.Bytes; } });
  6. Object.defineProperty(exports, "BytesLookup", { enumerable: true, get: function () { return bytes_1.BytesLookup; } });
  7. const field_1 = require("./field");
  8. Object.defineProperty(exports, "FieldLookup", { enumerable: true, get: function () { return field_1.FieldLookup; } });
  9. const constants_1 = require("./constants");
  10. /**
  11. * Stores the various types and fields for rippled to be used to encode/decode information later on.
  12. * XrplDefinitions should be instantiated instead of this class.
  13. */
  14. class XrplDefinitionsBase {
  15. /**
  16. * Present rippled types in a typed and updatable format.
  17. * For an example of the input format see `definitions.json`
  18. * To generate a new definitions file from rippled source code, use this tool: https://github.com/RichardAH/xrpl-codec-gen
  19. *
  20. * See the definitions.test.js file for examples of how to create your own updated definitions.json.
  21. *
  22. * @param enums - A json encoding of the core types, transaction types, transaction results, transaction names, and fields.
  23. * @param types - A list of type objects with the same name as the fields defined.
  24. * You can use the coreTypes object if you are not adding new types.
  25. */
  26. constructor(enums, types) {
  27. // Helps catch errors early in JavaScript code.
  28. if (types == undefined) {
  29. throw new TypeError('You passed in an undefined `types` parameter, but `types` must be defined since it contains logic for encoding/decoding transaction data. ' +
  30. 'If you have NOT added/modified any data types, you can import and use `coreTypes` from the types folder.');
  31. }
  32. this.type = new bytes_1.BytesLookup(enums.TYPES, constants_1.TYPE_WIDTH);
  33. this.ledgerEntryType = new bytes_1.BytesLookup(enums.LEDGER_ENTRY_TYPES, constants_1.LEDGER_ENTRY_WIDTH);
  34. this.transactionType = new bytes_1.BytesLookup(enums.TRANSACTION_TYPES, constants_1.TRANSACTION_TYPE_WIDTH);
  35. this.transactionResult = new bytes_1.BytesLookup(enums.TRANSACTION_RESULTS, constants_1.TRANSACTION_RESULT_WIDTH);
  36. this.field = new field_1.FieldLookup(enums.FIELDS, enums.TYPES);
  37. this.transactionNames = Object.entries(enums.TRANSACTION_TYPES)
  38. .filter(([_key, value]) => value >= 0)
  39. .map(([key, _value]) => key);
  40. this.dataTypes = {}; // Filled in via associateTypes
  41. this.associateTypes(types);
  42. }
  43. /**
  44. * Associates each Field to a corresponding class that TypeScript can recognize.
  45. *
  46. * @param types a list of type objects with the same name as the fields defined.
  47. * Defaults to xrpl.js's core type definitions.
  48. */
  49. associateTypes(types) {
  50. // Overwrite any existing type definitions with the given types
  51. this.dataTypes = Object.assign({}, this.dataTypes, types);
  52. Object.values(this.field).forEach((field) => {
  53. field.associatedType = this.dataTypes[field.type.name];
  54. });
  55. this.field['TransactionType'].associatedType = this.transactionType;
  56. this.field['TransactionResult'].associatedType = this.transactionResult;
  57. this.field['LedgerEntryType'].associatedType = this.ledgerEntryType;
  58. }
  59. getAssociatedTypes() {
  60. return this.dataTypes;
  61. }
  62. }
  63. exports.XrplDefinitionsBase = XrplDefinitionsBase;
  64. //# sourceMappingURL=xrpl-definitions-base.js.map