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 = {
src_account: string,
dst_amount: RippledAmount,
dst_account: string,
src_amount?: RippledAmount,
src_currencies?: Array<string>
export type PathFindRequest = {
command: string,
source_account: string,
destination_amount: RippledAmount,
destination_account: string,
source_amount?: RippledAmount,
source_currencies?: Array<string>
}
export type RippledPathsResponse = {

View File

@@ -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

View File

@@ -1,4 +1,5 @@
{
"result": {
"alternatives": [
{
"destination_amount": {
@@ -307,7 +308,9 @@
"value": "-1"
},
"full_reply": true,
"id": 1,
"source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59",
"type": "path_find"
"source_account": "r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59"
},
"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;
if (request.subcommand === 'close') {
if (request.subcommand === 'close') { // for path_find command
return;
}
if (request.source_account === addresses.NOTFOUND) {