1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.quality = void 0;
|
7 | const types_1 = require("./types");
|
8 | const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
9 | const utils_1 = require("@xrplf/isomorphic/utils");
|
10 |
|
11 |
|
12 |
|
13 | class quality {
|
14 | |
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | static encode(quality) {
|
21 | const decimal = (0, bignumber_js_1.default)(quality);
|
22 | const exponent = ((decimal === null || decimal === void 0 ? void 0 : decimal.e) || 0) - 15;
|
23 | const qualityString = decimal.times(`1e${-exponent}`).abs().toString();
|
24 | const bytes = types_1.coreTypes.UInt64.from(BigInt(qualityString)).toBytes();
|
25 | bytes[0] = exponent + 100;
|
26 | return bytes;
|
27 | }
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | static decode(quality) {
|
35 | const bytes = (0, utils_1.hexToBytes)(quality).slice(-8);
|
36 | const exponent = bytes[0] - 100;
|
37 | const mantissa = new bignumber_js_1.default(`0x${(0, utils_1.bytesToHex)(bytes.slice(1))}`);
|
38 | return mantissa.times(`1e${exponent}`);
|
39 | }
|
40 | }
|
41 | exports.quality = quality;
|
42 |
|
\ | No newline at end of file |