mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-12 16:45:49 +00:00
30 lines
755 B
JavaScript
30 lines
755 B
JavaScript
/* @flow */
|
|
'use strict';
|
|
const _ = require('lodash');
|
|
const parseAmount = require('./amount');
|
|
|
|
function parsePaths(paths) {
|
|
return paths.map(steps => steps.map(step =>
|
|
_.omit(step, ['type', 'type_hex'])));
|
|
}
|
|
|
|
function parsePathfind(sourceAddress: string,
|
|
destinationAmount: Object, pathfindResult: Object
|
|
): Object {
|
|
return pathfindResult.alternatives.map(function(alternative) {
|
|
return {
|
|
source: {
|
|
address: sourceAddress,
|
|
maxAmount: parseAmount(alternative.source_amount)
|
|
},
|
|
destination: {
|
|
address: pathfindResult.destination_account,
|
|
amount: destinationAmount
|
|
},
|
|
paths: JSON.stringify(parsePaths(alternative.paths_computed))
|
|
};
|
|
});
|
|
}
|
|
|
|
module.exports = parsePathfind;
|