Switch back to ripple_path_find

This commit is contained in:
Chris Clark
2015-10-22 15:37:50 -07:00
parent 9a759e7ef1
commit 391a9fd260
4 changed files with 339 additions and 333 deletions

View File

@@ -25,12 +25,13 @@ export type PathFind = {
} }
} }
export type PathFindParams = { export type PathFindRequest = {
src_account: string, command: string,
dst_amount: RippledAmount, source_account: string,
dst_account: string, destination_amount: RippledAmount,
src_amount?: RippledAmount, destination_account: string,
src_currencies?: Array<string> source_amount?: RippledAmount,
source_currencies?: Array<string>
} }
export type RippledPathsResponse = { export type RippledPathsResponse = {

View File

@@ -10,34 +10,36 @@ const NotFoundError = utils.common.errors.NotFoundError;
const ValidationError = utils.common.errors.ValidationError; const ValidationError = utils.common.errors.ValidationError;
import type {Remote} from '../../core/remote'; import type {Remote} from '../../core/remote';
import type {RippledAmount} from '../common/types.js'; import type {RippledAmount} from '../common/types.js';
import type {GetPaths, PathFind, PathFindParams, import type {GetPaths, PathFind, RippledPathsResponse, PathFindRequest}
RippledPathsResponse} from './pathfind-types.js'; from './pathfind-types.js';
function addParams(params: PathFindParams, result: RippledPathsResponse) { function addParams(request: PathFindRequest, result: RippledPathsResponse) {
return _.defaults(_.assign({}, result, { return _.defaults(_.assign({}, result, {
source_account: params.src_account, source_account: request.source_account,
source_currencies: params.src_currencies source_currencies: request.source_currencies
}), {destination_amount: params.dst_amount}); }), {destination_amount: request.destination_amount});
} }
function requestPathFind(remote: Remote, pathfind: PathFind, callback) { function requestPathFind(remote: Remote, pathfind: PathFind, callback) {
const destinationAmount = _.assign({value: -1}, pathfind.destination.amount); const destinationAmount = _.assign({value: -1}, pathfind.destination.amount);
const params: PathFindParams = { const request: PathFindRequest = {
src_account: pathfind.source.address, command: 'ripple_path_find',
dst_account: pathfind.destination.address, source_account: pathfind.source.address,
dst_amount: toRippledAmount(destinationAmount) 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 // Convert blank issuer to sender's address
// (Ripple convention for 'any issuer') // (Ripple convention for 'any issuer')
// https://ripple.com/build/transactions/ // https://ripple.com/build/transactions/
// #special-issuer-values-for-sendmax-and-amount // #special-issuer-values-for-sendmax-and-amount
// https://ripple.com/build/ripple-rest/#counterparties-in-payments // 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) { 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')); _.omit(toRippledAmount(amount), 'value'));
} }
if (pathfind.source.amount) { if (pathfind.source.amount) {
@@ -45,14 +47,14 @@ function requestPathFind(remote: Remote, pathfind: PathFind, callback) {
throw new ValidationError('Cannot specify both source.amount' throw new ValidationError('Cannot specify both source.amount'
+ ' and destination.amount.value in getPaths'); + ' and destination.amount.value in getPaths');
} }
params.src_amount = toRippledAmount(pathfind.source.amount); request.source_amount = toRippledAmount(pathfind.source.amount);
if (params.src_amount.currency && !params.src_amount.issuer) { if (request.source_amount.currency && !request.source_amount.issuer) {
params.src_amount.issuer = pathfind.source.address; request.source_amount.issuer = pathfind.source.address;
} }
} }
remote.createPathFind(params, remote.rawRequest(request,
composeAsync(_.partial(addParams, params), convertErrors(callback))); composeAsync(_.partial(addParams, request), convertErrors(callback)));
} }
function addDirectXrpPath(paths: RippledPathsResponse, xrpBalance: string function addDirectXrpPath(paths: RippledPathsResponse, xrpBalance: string

View File

@@ -1,4 +1,5 @@
{ {
"result": {
"alternatives": [ "alternatives": [
{ {
"destination_amount": { "destination_amount": {
@@ -307,7 +308,9 @@
"value": "-1" "value": "-1"
}, },
"full_reply": true, "full_reply": true,
"id": 1, "source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
"source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59", },
"type": "path_find" "type": "response",
"status": "success",
"id": 1
} }

View File

@@ -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; let response = null;
if (request.subcommand === 'close') { if (request.subcommand === 'close') { // for path_find command
return; return;
} }
if (request.source_account === addresses.NOTFOUND) { if (request.source_account === addresses.NOTFOUND) {