mirror of
https://github.com/Xahau/xahau.js.git
synced 2026-06-03 08:46:40 +00:00
* update definitions.json * add AMMInstanceCreate * renamed LPTokens to LPToken in definitions.json * update HISTORY.md * add amm_info RPC command * add AMMDeposit * use null check for missing fields * add AMMWithdraw * add AMMVote * fix lint error * add max trading fee check to AMMVote * refactor MAX_TRADING_FEE to be in one place * add AMMBid * add AuthAccount interface to AMMBid * refactor tests * add AMMID to AMMInfoResponse * update amm_info docstrings * fix EPrice type to be Amount * update EPrice validation error message and add missing tests * update definitions to fix AMM in LEDGER_ENTRY_TYPES * add missing test case Asset1In and Asset2In valid * add missing test case Asset1Out and Asset2Out valid * add negative FeeVal check * update HISTORY.md to specify XLS-30 * update wording on AMMDeposit & AMMWithdraw validation errors * add negative TradingFee check * fix ammInfo response * add AMMID as optional param in ammInfo response * fix EPrice validation checks in AMMDeposit & AMMWithdraw * add VoteSlots as optional param in AMMInfoResponse * update VoteEntry interface * fix deposit and withdraw tests * fix AMMBid ValidationError * update definitions.json with different AuthAccounts number * Change amm_info asset parameters to Currency type * API name changes with updated definitions.json * rename amm_info param asset1 -> asset * fix typo * change AMM_MAX_TRADING_FEE to 1% * Use Asset/Asset2 instead of AMMID for Deposit/Withdraw/Bid/Vote * add Deposit/Withdraw flags * rename FeeVal -> TradingFee in VoteEntry * rename MinBidPrice -> BidMin and MaxBidPrice -> BidMax * update definitions to change Asset & Asset2 nth values to 3 & 4 * update definitions * add Issue type and tests for Asset/Asset2 * remove AMMID from amm_info and use Issue type * update amm_info fields * fix lint errors * update unit tests * add AMM codec-fixtures * update Issue type * add one asset and withdraw all tests * refactor amm_info response fields to match AMMDevnet * update definitions.json with refactored error codes * update ammInfo.ts response model * remove invalid fields from ammInfo.ts response model * update time_interval description * rename test model names and fix lint errors * add Owner Reserve Fee for AMMCreate transaction * add missing asset_frozen field * replace Issue with IssuedCurrency * refactor: convert flags to number * update asset pair to use Currency type * refactor isIssue to isCurrency --------- Co-authored-by: Omar Khan <khancodegt@gmail.com>
ripple-binary-codec 
Functions to encode/decode to/from the ripple binary serialization format
API
> const api = require('ripple-binary-codec')
decode(binary: string): object
Decode a hex-string into a transaction object.
> api.decode('1100612200000000240000000125000000072D0000000055DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF6240000002540BE4008114D0F5430B66E06498D4CEEC816C7B3337F9982337')
{
LedgerEntryType: 'AccountRoot',
Flags: 0,
Sequence: 1,
PreviousTxnLgrSeq: 7,
OwnerCount: 0,
PreviousTxnID: 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
Balance: '10000000000',
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv'
}
encode(json: object): string
Encode a transaction object into a hex-string. Note that encode filters out fields with undefined values.
> api.encode({
LedgerEntryType: 'AccountRoot',
Flags: 0,
Sequence: 1,
PreviousTxnLgrSeq: 7,
OwnerCount: 0,
PreviousTxnID: 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
Balance: '10000000000',
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv'
})
'1100612200000000240000000125000000072D0000000055DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF6240000002540BE4008114D0F5430B66E06498D4CEEC816C7B3337F9982337'
X-Address Compatibility
- ripple-binary-codec handles X-addresses by looking for a few specific files (Account/SourceTag, Destination/DestinationTag).
- If other fields (in the future) must to support X-addresses with tags, this library will need to be updated.
- When decoding rippled binary, the output will always output classic address + tag, with no X-addresses. X-address support only applies when encoding to binary.
Encoding Currency Codes
- The standard format for currency codes is a three-letter string such as
USD. This is intended for use with ISO 4217 Currency Codes. - Currency codes must be exactly 3 ASCII characters in length and there are a few other rules.
- ripple-binary-codec allows any 3-character ASCII string to be encoded as a currency code, although rippled may enforce tighter restrictions.
- When decoding, if a currency code is three uppercase letters or numbers (
/^[A-Z0-9]{3}$/), then it will be decoded into that string. For example,0000000000000000000000004142430000000000decodes asABC. - When decoding, if a currency code is does not match the regex, then it is not considered to be an ISO 4217 or pseudo-ISO currency. ripple-binary-codec will return a 160-bit hex-string (40 hex characters). For example,
0000000000000000000000006142430000000000(aBC) decodes as0000000000000000000000006142430000000000because it contains a lowercase letter.
encodeForSigning(json: object): string
Encode the transaction object for signing.
encodeForSigningClaim(json: object): string
Encode the transaction object for payment channel claim.
encodeForMultisigning(json: object, signer: string): string
Encode the transaction object for multi-signing.
encodeQuality(value: string): string
> api.encodeQuality('195796912.5171664')
'5D06F4C3362FE1D0'
decodeQuality(value: string): string
> api.decodeQuality('5D06F4C3362FE1D0')
'195796912.5171664'
decodeLedgerData(binary: string): object
> api.decodeLedgerData("01E91435016340767BF1C4A3EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F873B5C3E520634D343EF5D9D9A4246643D64DAD278BA95DC0EAC6EB5350CF970D521276CDE21276CE60A00")
{
ledger_index: 32052277,
total_coins: '99994494362043555',
parent_hash: 'EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6',
transaction_hash: 'DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F87',
account_hash: '3B5C3E520634D343EF5D9D9A4246643D64DAD278BA95DC0EAC6EB5350CF970D5',
parent_close_time: 556231902,
close_time: 556231910,
close_time_resolution: 10,
close_flags: 0
}
Tests
Run unit tests with:
npm test
Use --coverage to generate and display code coverage information:
npm test --coverage
This tells jest to output code coverage info in the ./coverage directory, in addition to showing it on the command line.
