mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
* Removed deprecated functions from client.ts * Renamed files to be camelCase * Created top-level utils folder and tied all sub-references to it * Grouped tests for those utils into their own section Co-authored-by: Nathan Nichols <natenichols@cox.net>
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import _ from 'lodash'
|
|
import * as assert from 'assert'
|
|
import * as utils from './utils'
|
|
import {txFlags} from '../../common'
|
|
import {removeUndefined} from '../../utils'
|
|
import parseAmount from './amount'
|
|
|
|
function isNoDirectRipple(tx) {
|
|
return (tx.Flags & txFlags.Payment.NoRippleDirect) !== 0
|
|
}
|
|
|
|
function isQualityLimited(tx) {
|
|
return (tx.Flags & txFlags.Payment.LimitQuality) !== 0
|
|
}
|
|
|
|
function removeGenericCounterparty(amount, address) {
|
|
return amount.counterparty === address
|
|
? _.omit(amount, 'counterparty')
|
|
: amount
|
|
}
|
|
|
|
// Payment specification
|
|
function parsePayment(tx: any): object {
|
|
assert.ok(tx.TransactionType === 'Payment')
|
|
|
|
const source = {
|
|
address: tx.Account,
|
|
maxAmount: removeGenericCounterparty(
|
|
parseAmount(tx.SendMax || tx.Amount),
|
|
tx.Account
|
|
),
|
|
tag: tx.SourceTag
|
|
}
|
|
|
|
const destination: {
|
|
address: string
|
|
tag: number | undefined
|
|
} = {
|
|
address: tx.Destination,
|
|
tag: tx.DestinationTag
|
|
// Notice that `amount` is omitted to prevent misinterpretation
|
|
}
|
|
|
|
return removeUndefined({
|
|
source: removeUndefined(source),
|
|
destination: removeUndefined(destination),
|
|
memos: utils.parseMemos(tx),
|
|
invoiceID: tx.InvoiceID,
|
|
paths: tx.Paths ? JSON.stringify(tx.Paths) : undefined,
|
|
allowPartialPayment: utils.isPartialPayment(tx) || undefined,
|
|
noDirectRipple: isNoDirectRipple(tx) || undefined,
|
|
limitQuality: isQualityLimited(tx) || undefined
|
|
})
|
|
}
|
|
|
|
export default parsePayment
|