UNPKG

@bithomp/xrpl-api

Version:

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

70 lines (69 loc) 2.81 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const _ = __importStar(require("lodash")); const assert = __importStar(require("assert")); const xrpl_1 = require("xrpl"); const utils_1 = require("./utils"); const common_1 = require("../../common"); const amount_1 = __importDefault(require("./amount")); const memos_1 = __importDefault(require("./memos")); function isNoDirectRipple(tx) { return (tx.Flags & xrpl_1.PaymentFlags.tfNoDirectRipple) !== 0; } function isQualityLimited(tx) { return (tx.Flags & xrpl_1.PaymentFlags.tfLimitQuality) !== 0; } function removeGenericCounterparty(amount, address) { return amount.counterparty === address ? _.omit(amount, 'counterparty') : amount; } function parsePayment(tx) { assert.ok(tx.TransactionType === 'Payment'); const source = { address: tx.Account, maxAmount: removeGenericCounterparty((0, amount_1.default)(tx.SendMax || tx.Amount), tx.Account), tag: tx.SourceTag }; const destination = { address: tx.Destination, tag: tx.DestinationTag }; return (0, common_1.removeUndefined)({ source: (0, common_1.removeUndefined)(source), destination: (0, common_1.removeUndefined)(destination), memos: (0, memos_1.default)(tx), invoiceID: tx.InvoiceID, paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined, allowPartialPayment: (0, utils_1.isPartialPayment)(tx) || undefined, noDirectRipple: isNoDirectRipple(tx) || undefined, limitQuality: isQualityLimited(tx) || undefined }); } exports.default = parsePayment;