mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-07 22:35:48 +00:00
Add API and Test section to README.md (#91)
Update README.md to describe ripple-binary-codec API
This commit is contained in:
@@ -1,5 +1,95 @@
|
||||
# ripple-binary-codec
|
||||
# ripple-binary-codec [](https://npmjs.org/package/ripple-binary-codec)
|
||||
|
||||
encode/decode to/from the ripple binary serialization format
|
||||
Functions to encode/decode to/from the ripple [binary serialization format](https://xrpl.org/serialization.html)
|
||||
|
||||
[](https://www.npmjs.org/package/ripple-binary-codec)
|
||||
|
||||
## API
|
||||
```js
|
||||
> const api = require('ripple-binary-codec')
|
||||
```
|
||||
|
||||
|
||||
### decode(binary: string): JsonObject
|
||||
Decode a hex-string into a transaction object.
|
||||
```js
|
||||
> api.decode('1100612200000000240000000125000000072D0000000055DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF6240000002540BE4008114D0F5430B66E06498D4CEEC816C7B3337F9982337')
|
||||
{
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
PreviousTxnLgrSeq: 7,
|
||||
OwnerCount: 0,
|
||||
PreviousTxnID: 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Balance: '10000000000',
|
||||
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv'
|
||||
}
|
||||
```
|
||||
|
||||
### encode(json: JsonObject): string
|
||||
Encode a transaction object into a hex-string.
|
||||
```js
|
||||
> api.encode({
|
||||
LedgerEntryType: 'AccountRoot',
|
||||
Flags: 0,
|
||||
Sequence: 1,
|
||||
PreviousTxnLgrSeq: 7,
|
||||
OwnerCount: 0,
|
||||
PreviousTxnID: 'DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF',
|
||||
Balance: '10000000000',
|
||||
Account: 'rLs1MzkFWCxTbuAHgjeTZK4fcCDDnf2KRv'
|
||||
})
|
||||
'1100612200000000240000000125000000072D0000000055DF530FB14C5304852F20080B0A8EEF3A6BDD044F41F4EBBD68B8B321145FE4FF6240000002540BE4008114D0F5430B66E06498D4CEEC816C7B3337F9982337'
|
||||
```
|
||||
|
||||
### encodeForSigning(json: JsonObject): string
|
||||
|
||||
Encode the transaction object for signing.
|
||||
|
||||
### encodeForSigningClaim(json: ClaimObject): string
|
||||
|
||||
Encode the transaction object for payment channel claim.
|
||||
|
||||
### encodeForMultisigning(json: JsonObject, signer: string): string
|
||||
|
||||
Encode the transaction object for multi-signing.
|
||||
|
||||
### encodeQuality(value: string): string
|
||||
```js
|
||||
> api.encodeQuality('195796912.5171664')
|
||||
'5D06F4C3362FE1D0'
|
||||
```
|
||||
|
||||
### decodeQuality(value: string): string
|
||||
```js
|
||||
> api.decodeQuality('5D06F4C3362FE1D0')
|
||||
'195796912.5171664'
|
||||
```
|
||||
|
||||
### decodeLedgerData(binary: string): ledgerObject
|
||||
```js
|
||||
> 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:
|
||||
|
||||
yarn test
|
||||
|
||||
Use `--coverage` to generate and display code coverage information:
|
||||
|
||||
yarn test --coverage
|
||||
|
||||
This tells jest to output code coverage info in the `./coverage` directory, in addition to showing it on the command line.
|
||||
@@ -34,7 +34,7 @@
|
||||
"scripts": {
|
||||
"compile": "tsc && cp ./src/enums/definitions.json ./dist/enums",
|
||||
"prepare": "npm run compile && npm test",
|
||||
"test": "jest --coverage=true",
|
||||
"test": "jest",
|
||||
"lint": "eslint . --ext .ts --fix"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user