UNPKG

@bithomp/xrpl-api

Version:

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

50 lines (49 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toRippledAmount = toRippledAmount; exports.getClassicAccountAndTag = getClassicAccountAndTag; 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 ("currency" in amount) { if (amount.currency === (0, client_1.getNativeCurrency)()) { return (0, common_1.xrpToDrops)(amount.value); } else if (amount.currency === "drops") { return amount.value; } const issuer = amount.counterparty || amount.issuer; return { currency: amount.currency, issuer, value: amount.value, }; } if ("mpt_issuance_id" in amount) { return { value: amount.value, mpt_issuance_id: amount.mpt_issuance_id, }; } } 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, }; } }