Skip to content

Commit

Permalink
Don't set paths for XRP to XRP payment
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Clark committed Jul 30, 2015
1 parent fe9c1ad commit c4b2033
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 35 deletions.
26 changes: 13 additions & 13 deletions src/api/transaction/payment.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down
23 changes: 1 addition & 22 deletions test/fixtures/api/responses/prepare-payment-all-options.json
Expand Up @@ -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": {
Expand All @@ -40,4 +19,4 @@
"LastLedgerSequence": 8820051,
"Fee": "12",
"Sequence": 23
}
}

0 comments on commit c4b2033

Please sign in to comment.