mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 04:05:52 +00:00
Decode binary ledger header data
This commit is contained in:
@@ -6,7 +6,24 @@ const {quality,
|
|||||||
signingClaimData,
|
signingClaimData,
|
||||||
multiSigningData,
|
multiSigningData,
|
||||||
binaryToJSON,
|
binaryToJSON,
|
||||||
serializeObject}} = coreTypes;
|
serializeObject,
|
||||||
|
BinaryParser}} = coreTypes;
|
||||||
|
|
||||||
|
function decodeLedgerData(binary) {
|
||||||
|
assert(typeof binary === 'string', 'binary must be a hex string');
|
||||||
|
const parser = new BinaryParser(binary)
|
||||||
|
return {
|
||||||
|
ledger_index: parser.readUInt32(),
|
||||||
|
total_coins: parser.readType(coreTypes.UInt64).valueOf().toString(),
|
||||||
|
parent_hash: parser.readType(coreTypes.Hash256).toHex(),
|
||||||
|
transaction_hash: parser.readType(coreTypes.Hash256).toHex(),
|
||||||
|
account_hash: parser.readType(coreTypes.Hash256).toHex(),
|
||||||
|
parent_close_time: parser.readUInt32(),
|
||||||
|
close_time: parser.readUInt32(),
|
||||||
|
close_time_resolution: parser.readUInt8(),
|
||||||
|
close_flags: parser.readUInt8()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function decode(binary) {
|
function decode(binary) {
|
||||||
assert(typeof binary === 'string', 'binary must be a hex string');
|
assert(typeof binary === 'string', 'binary must be a hex string');
|
||||||
@@ -51,5 +68,6 @@ module.exports = {
|
|||||||
encodeForSigningClaim,
|
encodeForSigningClaim,
|
||||||
encodeForMultisigning,
|
encodeForMultisigning,
|
||||||
encodeQuality,
|
encodeQuality,
|
||||||
decodeQuality
|
decodeQuality,
|
||||||
|
decodeLedgerData
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const fixtures = require('./fixtures/codec-fixtures.json');
|
const fixtures = require('./fixtures/codec-fixtures.json');
|
||||||
const {decode, encode} = require('../src');
|
const {decode, encode, decodeLedgerData} = require('../src');
|
||||||
|
|
||||||
function json(object) {
|
function json(object) {
|
||||||
return JSON.stringify(object);
|
return JSON.stringify(object);
|
||||||
@@ -24,4 +24,14 @@ describe('ripple-binary-codec', function() {
|
|||||||
}
|
}
|
||||||
makeSuite('transactions', fixtures.transactions);
|
makeSuite('transactions', fixtures.transactions);
|
||||||
makeSuite('accountState', fixtures.accountState);
|
makeSuite('accountState', fixtures.accountState);
|
||||||
|
|
||||||
|
describe('ledgerData', function() {
|
||||||
|
fixtures.ledgerData.forEach((t, test_n) => {
|
||||||
|
it(`ledgerData[${test_n}] can decode ${t.binary} to ${json(t.json)}`,
|
||||||
|
() => {
|
||||||
|
const decoded = decodeLedgerData(t.binary);
|
||||||
|
assert.deepEqual(t.json, decoded);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4448,5 +4448,19 @@
|
|||||||
"Flags": 0,
|
"Flags": 0,
|
||||||
"Sequence": 62
|
"Sequence": 62
|
||||||
}
|
}
|
||||||
|
}],
|
||||||
|
"ledgerData": [{
|
||||||
|
"binary": "01E91435016340767BF1C4A3EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F873B5C3E520634D343EF5D9D9A4246643D64DAD278BA95DC0EAC6EB5350CF970D521276CDE21276CE60A00",
|
||||||
|
"json": {
|
||||||
|
"account_hash": "3B5C3E520634D343EF5D9D9A4246643D64DAD278BA95DC0EAC6EB5350CF970D5",
|
||||||
|
"close_flags": 0,
|
||||||
|
"close_time": 556231910,
|
||||||
|
"close_time_resolution": 10,
|
||||||
|
"ledger_index": 32052277,
|
||||||
|
"parent_close_time": 556231902,
|
||||||
|
"parent_hash": "EACEB081770D8ADE216C85445DD6FB002C6B5A2930F2DECE006DA18150CB18F6",
|
||||||
|
"total_coins": "99994494362043555",
|
||||||
|
"transaction_hash": "DD33F6F0990754C962A7CCE62F332FF9C13939B03B864117F0BDA86B6E9B4F87"
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user