Files
xahau.js/packages/xahau-binary-codec/CONTRIBUTING.md
Denis Angell 7916a14be2 refactor
2025-03-11 14:31:34 +01:00

2.6 KiB

Code structure

  • enums contains the logic for mapping types to their numerical id in rippled, which is used to serialize / deserialize later on. For more details, see its specific README.md
  • serdes contains the two main classes of this repo BinarySerializer and BinaryParser which actually do the serializing / deserializing.
  • types defines how the library should convert between objects and binary data for each data type. These are then used by the BinarySerializer and BinaryParser to serialize / deserialize rippled data.
  • At the top-level, we have helper functions for specific situations (like encodeForMultisigning in index.ts). These functions are generally what are used by consumers of the library (with BinarySerializer and BinaryParser being used as the implementation under the hood)

Running tests

You can run tests for this repo with: npm i to install necessary dependencies followed by either:

  • npm test - Run unit tests in Node.
  • npm test:browser - Run unit tests in the browser.

Adding tests

All tests should be added to the test folder, with long test data added to the test/fixtures folder.

For a good example unit test file, look at test/hash.test.ts.

If you add a new serializable type, please add a new file with tests that ensure it can be encoded / decoded, and that it throws any relevant errors.

Adding new serializable types

To add a new serializable type, first read through enum's README.md as it explains how to update definitions.json which ties TransactionTypes and Fields to specific ids rippled understands.

After that, if you need to add a new type of data to be serialized / deserialized (for example adding a bigger int than uint-64.ts) you can follow these steps:

  1. Create a new class that extends SerializedType
  • If your type is intended to be comparable to native values like number, you should extend Comparable<YourObjectType | nativeValue>. See uint-64.ts for an example of this.
  1. Add your new subclass of SerializableType to coreTypes in packages/ripple-binary-codec/src/types/index.ts
  • The coreTypes variable is used by BinaryParser and BinarySerializer to understand what possible types exist when reading / writing binary data.
  1. Write a unit tests for this type that demonstrates it can properly serialize / deserialize and throw the proper errors (see Adding Tests)