2.6 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	Code structure
enumscontains 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.mdserdescontains the two main classes of this repoBinarySerializerandBinaryParserwhich actually do the serializing / deserializing.typesdefines how the library should convert between objects and binary data for each data type. These are then used by theBinarySerializerandBinaryParserto serialize / deserialize rippled data.- At the top-level, we have helper functions for specific situations (like 
encodeForMultisigningin index.ts). These functions are generally what are used by consumers of the library (withBinarySerializerandBinaryParserbeing 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:
- Create a new class that extends 
SerializedType 
- If your type is intended to be comparable to native values like 
number, you should extendComparable<YourObjectType | nativeValue>. See uint-64.ts for an example of this. 
- Add your new subclass of 
SerializableTypetocoreTypesin packages/xahau-binary-codec/src/types/index.ts 
- The 
coreTypesvariable is used byBinaryParserandBinarySerializerto understand what possible types exist when reading / writing binary data. 
- Write a unit tests for this type that demonstrates it can properly serialize / deserialize and throw the proper errors (see Adding Tests)