UNPKG

@bithomp/xrpl-api

Version:

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

43 lines (42 loc) 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getClassicAccountAndTag = exports.toRippledAmount = void 0; const ripple_address_codec_1 = require("ripple-address-codec"); const common_1 = require("../../common"); const client_1 = require("../../client"); function toRippledAmount(amount) { if (typeof amount === "string") return amount; if (amount.currency === (0, client_1.getNativeCurrency)()) { return (0, common_1.xrpToDrops)(amount.value); } if (amount.currency === "drops") { return amount.value; } const issuer = amount.counterparty || amount.issuer; return { currency: amount.currency, issuer, value: amount.value, }; } exports.toRippledAmount = toRippledAmount; function getClassicAccountAndTag(Account, expectedTag) { if ((0, ripple_address_codec_1.isValidXAddress)(Account)) { const classic = (0, ripple_address_codec_1.xAddressToClassicAddress)(Account); if (expectedTag != null && classic.tag !== expectedTag) { throw new Error("address includes a tag that does not match the tag specified in the transaction"); } return { classicAccount: classic.classicAddress, tag: classic.tag, }; } else { return { classicAccount: Account, tag: expectedTag, }; } } exports.getClassicAccountAndTag = getClassicAccountAndTag;