UNPKG

@bithomp/xrpl-api

Version:

A Bithomp JavaScript/TypeScript library for interacting with the XRP Ledger

49 lines (48 loc) 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseUNLReportChanges = parseUNLReportChanges; const common_1 = require("../../common"); const utils_1 = require("../utils"); function summarizeUNLReport(tx, node) { const final = node.diffType === "CreatedNode" ? node.newFields : node.finalFields; if (tx.ImportVLKey && final.ImportVLKeys) { for (const vlKey of final.ImportVLKeys) { if (vlKey.ImportVLKey.PublicKey === tx.ImportVLKey.PublicKey) { const summary = { status: "added", importVLKey: { account: vlKey.ImportVLKey.Account, publicKey: vlKey.ImportVLKey.PublicKey, }, }; return (0, common_1.removeUndefined)(summary); } } } if (tx.ActiveValidator && final.ActiveValidators) { for (const activeValidator of final.ActiveValidators) { if (activeValidator.ActiveValidator.PublicKey === tx.ActiveValidator.PublicKey) { const summary = { status: "added", activeValidator: { account: activeValidator.ActiveValidator.Account, publicKey: activeValidator.ActiveValidator.PublicKey, }, }; return (0, common_1.removeUndefined)(summary); } } } return undefined; } function parseUNLReportChanges(tx) { const affectedNodes = tx.meta.AffectedNodes.filter((affectedNode) => { const node = affectedNode.CreatedNode || affectedNode.ModifiedNode || affectedNode.DeletedNode; return node.LedgerEntryType === "UNLReport"; }); if (affectedNodes.length !== 1) { return undefined; } const normalizedNode = (0, utils_1.normalizeNode)(affectedNodes[0]); return summarizeUNLReport(tx, normalizedNode); }