Repository navigation
feat(backend): add asset pair canonical key builder module (#372) - #472
Open
jdjioe5-cpu wants to merge 1 commit into
Open
jdjioe5-cpu wants to merge 1 commit into
jdjioe5-cpu wants to merge 1 commit into
Conversation
- Implement backend/src/assetPairKeyBuilder.js to build order-independent canonical keys for trading asset pairs - Support native (normalized to native) and credit assets (normalized to CODE:ISSUER) - Export constants CANONICAL_NATIVE_ASSET, ASSET_PAIR_SEPARATOR, and ASSET_PAIR_KEY_ERROR - Provide parseAssetPairKey to decompose canonical keys back into assets - Handle both positional and options object inputs - Add 9 single-behavior node:test test files covering order-independence, object inputs, parsing, constants, and invalid code/issuer validations - Add documentation under docs/features/assetPairKeyBuilder.md Closes Kitewell-lab#372
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the canonical asset pair key builder in
backend/src/assetPairKeyBuilder.jsto build order-independent keys for trading asset pairs (e.g.native/CODE:ISSUER) per #372.Changes
backend/src/assetPairKeyBuilder.jsexportingbuildAssetPairKey,canonicalizeAsset,parseAssetPairKey, andassetPairKeyBuilderalias"native","XLM",{ type: "native" }) and credit assets ("CODE:ISSUER","CODE-ISSUER",{ code, issuer })canonA.localeCompare(canonB) <= 0)backend/src/assetPairKeyBuilderConstants.js(CANONICAL_NATIVE_ASSET,ASSET_PAIR_SEPARATOR,ASSET_PAIR_KEY_ERROR)node:testtest files inbackend/src/:assetPairKeyBuilder-order-independent.test.js(order independence between base and counter)assetPairKeyBuilder-native-credit.test.js(native and credit pair keys)assetPairKeyBuilder-two-credits.test.js(two credit assets pair sorting)assetPairKeyBuilder-options-object.test.js(options object with assetA/assetB, base/counter, selling/buying)assetPairKeyBuilder-object-inputs.test.js(asset objects inputs)assetPairKeyBuilder-parse.test.js(decomposing key back into canonical assets)assetPairKeyBuilder-invalid-inputs.test.js(missing and invalid format input rejection)assetPairKeyBuilder-invalid-issuer.test.js(invalid code length and issuer public key rejection)assetPairKeyBuilder-constants.test.js(constant immutability verification)docs/features/assetPairKeyBuilder.mdVerification
npm testrun frombackend/passes 395/395 tests cleanCloses #372