mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import * as _ from 'lodash'
|
|
import * as assert from 'assert'
|
|
import * as utils from './utils'
|
|
import {txFlags, removeUndefined} from '../../common'
|
|
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
|
|
}
|
|
|
|
function parsePayment(tx: any): Object {
|
|
assert(tx.TransactionType === 'Payment')
|
|
|
|
const source = {
|
|
address: tx.Account,
|
|
maxAmount: removeGenericCounterparty(
|
|
parseAmount(tx.SendMax || tx.Amount), tx.Account),
|
|
tag: tx.SourceTag
|
|
}
|
|
|
|
const destination = {
|
|
address: tx.Destination,
|
|
amount: removeGenericCounterparty(parseAmount(tx.Amount), tx.Destination),
|
|
tag: tx.DestinationTag
|
|
}
|
|
|
|
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
|