From ed0b5017162f9c3efd57ee79f7fb33e7e079baa5 Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Thu, 30 Jul 2015 13:40:07 -0700 Subject: [PATCH] Don't set paths for XRP to XRP payment --- src/api/transaction/payment.js | 26 +++++++++---------- .../prepare-payment-all-options.json | 23 +--------------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/api/transaction/payment.js b/src/api/transaction/payment.js index c8d19d54..15346a51 100644 --- a/src/api/transaction/payment.js +++ b/src/api/transaction/payment.js @@ -7,15 +7,10 @@ const validate = utils.common.validate; const toRippledAmount = utils.common.toRippledAmount; const Transaction = utils.common.core.Transaction; -function isSendMaxAllowed(payment) { - const srcAmt = payment.source.amount; - const dstAmt = payment.destination.amount; - - // Don't set SendMax for XRP->XRP payment - // temREDUNDANT_SEND_MAX removed in: - // https://github.com/ripple/rippled/commit/ - // c522ffa6db2648f1d8a987843e7feabf1a0b7de8/ - return srcAmt && !(srcAmt.currency === 'XRP' && dstAmt.currency === 'XRP'); +function isXRPToXRPPayment(payment) { + const sourceCurrency = _.get(payment, 'source.amount.currency'); + const destinationCurrency = _.get(payment, 'destination.amount.currency'); + return sourceCurrency === 'XRP' && destinationCurrency === 'XRP'; } function isIOUWithoutCounterparty(amount) { @@ -58,9 +53,6 @@ function createPaymentTransaction(account, payment) { if (payment.destination.tag) { transaction.destinationTag(payment.destination.tag); } - if (payment.paths) { - transaction.paths(JSON.parse(payment.paths)); - } if (payment.memos) { _.forEach(payment.memos, memo => transaction.addMemo(memo.type, memo.format, memo.data) @@ -75,11 +67,19 @@ function createPaymentTransaction(account, payment) { if (payment.limitQuality) { transaction.setFlags(['LimitQuality']); } - if (isSendMaxAllowed(payment)) { + if (!isXRPToXRPPayment(payment)) { + // Don't set SendMax for XRP->XRP payment + // temREDUNDANT_SEND_MAX removed in: + // https://github.com/ripple/rippled/commit/ + // c522ffa6db2648f1d8a987843e7feabf1a0b7de8/ const maxValue = new BigNumber(payment.source.amount.value) .plus(payment.source.slippage || 0).toString(); const maxAmount = _.assign({}, payment.source.amount, {value: maxValue}); transaction.sendMax(toRippledAmount(maxAmount)); + + if (payment.paths) { + transaction.paths(JSON.parse(payment.paths)); + } } return transaction; diff --git a/test/fixtures/api/responses/prepare-payment-all-options.json b/test/fixtures/api/responses/prepare-payment-all-options.json index 644bd081..89df281b 100644 --- a/test/fixtures/api/responses/prepare-payment-all-options.json +++ b/test/fixtures/api/responses/prepare-payment-all-options.json @@ -7,27 +7,6 @@ "InvoiceID": "A98FD36C17BE2B8511AD36DC335478E7E89F06262949F36EB88E2D683BBCC50A", "SourceTag": 14, "DestinationTag": 58, - "Paths": [ - [ - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "currency": "USD", - "type_hex": "0000000000000031" - }, - { - "issuer": "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", - "currency": "LTC", - "type_hex": "0000000000000030" - }, - { - "account": "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", - "issuer": "rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX", - "currency": "LTC", - "type_hex": "0000000000000031" - } - ] - ], "Memos": [ { "Memo": { @@ -40,4 +19,4 @@ "LastLedgerSequence": 8820051, "Fee": "12", "Sequence": 23 -} \ No newline at end of file +}