From 391a9fd260757e456fd5f198741d1cd70cc8f6d2 Mon Sep 17 00:00:00 2001 From: Chris Clark Date: Thu, 22 Oct 2015 15:37:50 -0700 Subject: [PATCH] Switch back to ripple_path_find --- src/api/ledger/pathfind-types.js | 13 +- src/api/ledger/pathfind.js | 38 +- .../api/rippled/path-find-send-all.json | 617 +++++++++--------- test/mock-rippled.js | 4 +- 4 files changed, 339 insertions(+), 333 deletions(-) diff --git a/src/api/ledger/pathfind-types.js b/src/api/ledger/pathfind-types.js index c497f58d..236f0ee3 100644 --- a/src/api/ledger/pathfind-types.js +++ b/src/api/ledger/pathfind-types.js @@ -25,12 +25,13 @@ export type PathFind = { } } -export type PathFindParams = { - src_account: string, - dst_amount: RippledAmount, - dst_account: string, - src_amount?: RippledAmount, - src_currencies?: Array +export type PathFindRequest = { + command: string, + source_account: string, + destination_amount: RippledAmount, + destination_account: string, + source_amount?: RippledAmount, + source_currencies?: Array } export type RippledPathsResponse = { diff --git a/src/api/ledger/pathfind.js b/src/api/ledger/pathfind.js index 8fbe10f8..06d6c881 100644 --- a/src/api/ledger/pathfind.js +++ b/src/api/ledger/pathfind.js @@ -10,34 +10,36 @@ const NotFoundError = utils.common.errors.NotFoundError; const ValidationError = utils.common.errors.ValidationError; import type {Remote} from '../../core/remote'; import type {RippledAmount} from '../common/types.js'; -import type {GetPaths, PathFind, PathFindParams, - RippledPathsResponse} from './pathfind-types.js'; +import type {GetPaths, PathFind, RippledPathsResponse, PathFindRequest} + from './pathfind-types.js'; -function addParams(params: PathFindParams, result: RippledPathsResponse) { +function addParams(request: PathFindRequest, result: RippledPathsResponse) { return _.defaults(_.assign({}, result, { - source_account: params.src_account, - source_currencies: params.src_currencies - }), {destination_amount: params.dst_amount}); + source_account: request.source_account, + source_currencies: request.source_currencies + }), {destination_amount: request.destination_amount}); } function requestPathFind(remote: Remote, pathfind: PathFind, callback) { const destinationAmount = _.assign({value: -1}, pathfind.destination.amount); - const params: PathFindParams = { - src_account: pathfind.source.address, - dst_account: pathfind.destination.address, - dst_amount: toRippledAmount(destinationAmount) + const request: PathFindRequest = { + command: 'ripple_path_find', + source_account: pathfind.source.address, + destination_account: pathfind.destination.address, + destination_amount: toRippledAmount(destinationAmount) }; - if (typeof params.dst_amount === 'object' && !params.dst_amount.issuer) { + if (typeof request.destination_amount === 'object' + && !request.destination_amount.issuer) { // Convert blank issuer to sender's address // (Ripple convention for 'any issuer') // https://ripple.com/build/transactions/ // #special-issuer-values-for-sendmax-and-amount // https://ripple.com/build/ripple-rest/#counterparties-in-payments - params.dst_amount.issuer = params.dst_account; + request.destination_amount.issuer = request.destination_account; } if (pathfind.source.currencies && pathfind.source.currencies.length > 0) { - params.src_currencies = pathfind.source.currencies.map(amount => + request.source_currencies = pathfind.source.currencies.map(amount => _.omit(toRippledAmount(amount), 'value')); } if (pathfind.source.amount) { @@ -45,14 +47,14 @@ function requestPathFind(remote: Remote, pathfind: PathFind, callback) { throw new ValidationError('Cannot specify both source.amount' + ' and destination.amount.value in getPaths'); } - params.src_amount = toRippledAmount(pathfind.source.amount); - if (params.src_amount.currency && !params.src_amount.issuer) { - params.src_amount.issuer = pathfind.source.address; + request.source_amount = toRippledAmount(pathfind.source.amount); + if (request.source_amount.currency && !request.source_amount.issuer) { + request.source_amount.issuer = pathfind.source.address; } } - remote.createPathFind(params, - composeAsync(_.partial(addParams, params), convertErrors(callback))); + remote.rawRequest(request, + composeAsync(_.partial(addParams, request), convertErrors(callback))); } function addDirectXrpPath(paths: RippledPathsResponse, xrpBalance: string diff --git a/test/fixtures/api/rippled/path-find-send-all.json b/test/fixtures/api/rippled/path-find-send-all.json index 1e7317cd..f66e8102 100644 --- a/test/fixtures/api/rippled/path-find-send-all.json +++ b/test/fixtures/api/rippled/path-find-send-all.json @@ -1,313 +1,316 @@ { - "alternatives": [ - { - "destination_amount": { - "currency": "USD", - "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "value": "4.93463759481038" - }, - "paths_computed": [ - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010" - }, - { - "currency": "USD", - "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "type": 1, - "type_hex": "0000000000000001" - } + "result": { + "alternatives": [ + { + "destination_amount": { + "currency": "USD", + "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "value": "4.93463759481038" + }, + "paths_computed": [ + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "XRP", + "type": 16, + "type_hex": "0000000000000010" + }, + { + "currency": "USD", + "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "type": 1, + "type_hex": "0000000000000001" + } + ], + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "XRP", + "type": 16, + "type_hex": "0000000000000010" + }, + { + "currency": "USD", + "issuer": "rfsEoNBUBbvkf4jPcFe2u9CyaQagLVHGfP", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rfsEoNBUBbvkf4jPcFe2u9CyaQagLVHGfP", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 1, + "type_hex": "0000000000000001" + } + ] ], - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010" - }, - { - "currency": "USD", - "issuer": "rfsEoNBUBbvkf4jPcFe2u9CyaQagLVHGfP", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rfsEoNBUBbvkf4jPcFe2u9CyaQagLVHGfP", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001" - } - ] - ], - "source_amount": { - "currency": "USD", - "issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", - "value": "5" + "source_amount": { + "currency": "USD", + "issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + "value": "5" + } + }, + { + "destination_amount": { + "currency": "USD", + "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "value": "4.93463759481038" + }, + "paths_computed": [ + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "XRP", + "type": 16, + "type_hex": "0000000000000010" + }, + { + "currency": "USD", + "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "type": 1, + "type_hex": "0000000000000001" + } + ], + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "EUR", + "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "currency": "USD", + "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 1, + "type_hex": "0000000000000001" + } + ], + [ + { + "account": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "USD", + "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + } + ] + ], + "source_amount": { + "currency": "USD", + "issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + "value": "5" + } + }, + { + "destination_amount": { + "currency": "USD", + "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "value": "4.93463759481038" + }, + "paths_computed": [ + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "XRP", + "type": 16, + "type_hex": "0000000000000010" + }, + { + "currency": "USD", + "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "type": 1, + "type_hex": "0000000000000001" + } + ], + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "XRP", + "type": 16, + "type_hex": "0000000000000010" + }, + { + "currency": "USD", + "issuer": "rfsEoNBUBbvkf4jPcFe2u9CyaQagLVHGfP", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rfsEoNBUBbvkf4jPcFe2u9CyaQagLVHGfP", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 1, + "type_hex": "0000000000000001" + } + ], + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "JPY", + "issuer": "rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "currency": "USD", + "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 1, + "type_hex": "0000000000000001" + } + ] + ], + "source_amount": { + "currency": "USD", + "issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + "value": "5" + } + }, + { + "destination_amount": { + "currency": "USD", + "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "value": "4.990019960079841" + }, + "paths_computed": [ + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + } + ], + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", + "type": 1, + "type_hex": "0000000000000001" + } + ], + [ + { + "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", + "type": 1, + "type_hex": "0000000000000001" + }, + { + "currency": "USD", + "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 48, + "type_hex": "0000000000000030" + }, + { + "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", + "type": 1, + "type_hex": "0000000000000001" + } + ] + ], + "source_amount": { + "currency": "USD", + "issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", + "value": "5" + } } + ], + "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "destination_amount": { + "currency": "USD", + "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", + "value": "-1" }, - { - "destination_amount": { - "currency": "USD", - "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "value": "4.93463759481038" - }, - "paths_computed": [ - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010" - }, - { - "currency": "USD", - "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "type": 1, - "type_hex": "0000000000000001" - } - ], - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "EUR", - "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "currency": "USD", - "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001" - } - ], - [ - { - "account": "rLEsXccBGNR3UPuPu2hUXPjziKC3qKSBun", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "USD", - "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - } - ] - ], - "source_amount": { - "currency": "USD", - "issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", - "value": "5" - } - }, - { - "destination_amount": { - "currency": "USD", - "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "value": "4.93463759481038" - }, - "paths_computed": [ - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010" - }, - { - "currency": "USD", - "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "type": 1, - "type_hex": "0000000000000001" - } - ], - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "XRP", - "type": 16, - "type_hex": "0000000000000010" - }, - { - "currency": "USD", - "issuer": "rfsEoNBUBbvkf4jPcFe2u9CyaQagLVHGfP", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rfsEoNBUBbvkf4jPcFe2u9CyaQagLVHGfP", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001" - } - ], - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "JPY", - "issuer": "rMAz5ZnK73nyNUL4foAvaxdreczCkG3vA6", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "currency": "USD", - "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001" - } - ] - ], - "source_amount": { - "currency": "USD", - "issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", - "value": "5" - } - }, - { - "destination_amount": { - "currency": "USD", - "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "value": "4.990019960079841" - }, - "paths_computed": [ - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - } - ], - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "account": "rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn", - "type": 1, - "type_hex": "0000000000000001" - } - ], - [ - { - "account": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B", - "type": 1, - "type_hex": "0000000000000001" - }, - { - "currency": "USD", - "issuer": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 48, - "type_hex": "0000000000000030" - }, - { - "account": "rMwjYedjc7qqtKYVLiAccJSmCwih4LnE2q", - "type": 1, - "type_hex": "0000000000000001" - } - ] - ], - "source_amount": { - "currency": "USD", - "issuer": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", - "value": "5" - } - } - ], - "destination_account": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "destination_amount": { - "currency": "USD", - "issuer": "ra5nK24KXen9AHvsdFTKHSANinZseWnPcX", - "value": "-1" + "full_reply": true, + "source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59" }, - "full_reply": true, - "id": 1, - "source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", - "type": "path_find" + "type": "response", + "status": "success", + "id": 1 } diff --git a/test/mock-rippled.js b/test/mock-rippled.js index a92d21c7..0465f879 100644 --- a/test/mock-rippled.js +++ b/test/mock-rippled.js @@ -254,9 +254,9 @@ module.exports = function(port) { } }); - mock.on('request_path_find', function(request, conn) { + mock.on('request_ripple_path_find', function(request, conn) { let response = null; - if (request.subcommand === 'close') { + if (request.subcommand === 'close') { // for path_find command return; } if (request.source_account === addresses.NOTFOUND) {