Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #387 from lumberj/no-paths-xrp
Browse files Browse the repository at this point in the history
Don't set paths on direct payment
  • Loading branch information
alandotcom committed Jul 29, 2015
2 parents fd7c391 + 8c10e95 commit 6d7ea8c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
22 changes: 12 additions & 10 deletions api/transaction/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ var utils = require('./utils');
var validate = require('../lib/validate');
var wrapCatch = require('../lib/utils').wrapCatch;

function isSendMaxAllowed(payment) {
function isSendMaxAndPathsAllowed(payment) {
var srcAmt = payment.source_amount;
var dstAmt = payment.destination_amount;

// Don't set SendMax for XRP->XRP payment
// Don't set SendMax or Paths for XRP->XRP payment
// temREDUNDANT_SEND_MAX removed in:
// https://github.com/ripple/rippled/commit/
// c522ffa6db2648f1d8a987843e7feabf1a0b7de8/
Expand Down Expand Up @@ -72,8 +72,9 @@ function createPaymentTransaction(account, payment) {
transaction.destinationTag(parseInt(payment.destination_tag, 10));
}

// SendMax
if (isSendMaxAllowed(payment)) {
// SendMax and Paths
if (isSendMaxAndPathsAllowed(payment)) {
// SendMax
var max_value = new BigNumber(payment.source_amount.value)
.plus(payment.source_slippage || 0).toString();

Expand All @@ -86,15 +87,16 @@ function createPaymentTransaction(account, payment) {
issuer: payment.source_amount.issuer
});
}
}

// Paths
if (typeof payment.paths === 'string') {
transaction.paths(JSON.parse(payment.paths));
} else if (typeof payment.paths === 'object') {
transaction.paths(payment.paths);
// Paths
if (typeof payment.paths === 'string') {
transaction.paths(JSON.parse(payment.paths));
} else if (typeof payment.paths === 'object') {
transaction.paths(payment.paths);
}
}


// Memos
if (payment.memos && Array.isArray(payment.memos)) {
for (var m = 0; m < payment.memos.length; m++) {
Expand Down
1 change: 1 addition & 0 deletions test/unit/create-payment-tx-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ suite('unit - createPaymentTransaction', function() {
var transaction = createPaymentTransaction(ACCOUNT,
fixtures.paymentRestXRPtoXRP);
assert.strictEqual(transaction.tx_json.SendMax, undefined);
assert.strictEqual(transaction.tx_json.Paths, undefined);
});

test(' payment XRP to non-XRP', function() {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/fixtures/rest-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module.exports.paymentRestXRPtoXRP = {
'value': '1',
'currency': 'XRP',
'issuer': ''
}
},
'paths': '[]'
};

module.exports.paymentRestComplex = {
Expand Down

0 comments on commit 6d7ea8c

Please sign in to comment.