/** * Protocol parsing functions. * * @author n1474335 [n1474335@gmail.com] * @copyright Crown Copyright 2022 * @license Apache-2.0 */ import BigNumber from "bignumber.js"; import {toHexFast} from "../lib/Hex.mjs"; /** * Recursively displays a JSON object as an HTML table * * @param {Object} obj * @returns string */ export function objToTable(obj, nested=false) { let html = ``; if (!nested) html += ``; for (const key in obj) { html += ``; if (typeof obj[key] === "object") html += ``; else html += ``; html += ""; } html += "
Field Value
${key}${objToTable(obj[key], true)}${obj[key]}
"; return html; } /** * Converts bytes into a BigNumber string * @param {Uint8Array} bs * @returns {string} */ export function bytesToLargeNumber(bs) { return BigNumber(toHexFast(bs), 16).toString(); }