Skip to content

Commit

Permalink
Fix Payment source & destination types (#870)
Browse files Browse the repository at this point in the history
Payment `source` and `destination` are defined as intersection types, `Adjustment & MaxAdjustment` and  `Adjustment & MinAdjustment` respectively. But they should be union types instead. This problem was introduced during js to ts conversion.

Fixes #866
  • Loading branch information
darkmemo authored and intelliot committed Mar 20, 2018
1 parent 71a0c16 commit a72041a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/transaction/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {Amount, Adjustment, MaxAdjustment,


export type Payment = {
source: Adjustment & MaxAdjustment,
destination: Adjustment & MinAdjustment,
source: Adjustment | MaxAdjustment,
destination: Adjustment | MinAdjustment,
paths?: string,
memos?: Array<Memo>,
// A 256-bit hash that can be used to identify a particular payment
Expand Down Expand Up @@ -74,8 +74,8 @@ function createPaymentTransaction(address: string, paymentArgument: Payment
throw new ValidationError('address must match payment.source.address')
}

if ((payment.source.maxAmount && payment.destination.minAmount) ||
(payment.source.amount && payment.destination.amount)) {
if (((<MaxAdjustment>payment.source).maxAmount && (<MinAdjustment>payment.destination).minAmount) ||
((<Adjustment>payment.source).amount && (<Adjustment>payment.destination).amount)) {
throw new ValidationError('payment must specify either (source.maxAmount '
+ 'and destination.amount) or (source.amount and destination.minAmount)')
}
Expand All @@ -86,9 +86,9 @@ function createPaymentTransaction(address: string, paymentArgument: Payment
// send the whole source amount, so we set the destination amount to the
// maximum possible amount. otherwise it's possible that the destination
// cap could be hit before the source cap.
const amount = payment.destination.minAmount && !isXRPToXRPPayment(payment) ?
createMaximalAmount(payment.destination.minAmount) :
(payment.destination.amount || payment.destination.minAmount)
const amount = (<MinAdjustment>payment.destination).minAmount && !isXRPToXRPPayment(payment) ?
createMaximalAmount((<MinAdjustment>payment.destination).minAmount) :
((<Adjustment>payment.destination).amount || (<MinAdjustment>payment.destination).minAmount)

const txJSON: any = {
TransactionType: 'Payment',
Expand Down Expand Up @@ -122,15 +122,15 @@ function createPaymentTransaction(address: string, paymentArgument: Payment
// https://github.com/ripple/rippled/commit/
// c522ffa6db2648f1d8a987843e7feabf1a0b7de8/
if (payment.allowPartialPayment === true
|| payment.destination.minAmount !== undefined) {
|| (<MinAdjustment>payment.destination).minAmount !== undefined) {
txJSON.Flags |= paymentFlags.PartialPayment
}

txJSON.SendMax = toRippledAmount(
payment.source.maxAmount || payment.source.amount)
(<MaxAdjustment>payment.source).maxAmount || (<Adjustment>payment.source).amount)

if (payment.destination.minAmount !== undefined) {
txJSON.DeliverMin = toRippledAmount(payment.destination.minAmount)
if ((<MinAdjustment>payment.destination).minAmount !== undefined) {
txJSON.DeliverMin = toRippledAmount((<MinAdjustment>payment.destination).minAmount)
}

if (payment.paths !== undefined) {
Expand Down

0 comments on commit a72041a

Please sign in to comment.