|
|
|
@ -6,13 +6,7 @@ const logger = Logger;
|
|
|
|
|
const common = Common;
|
|
|
|
|
export const loopOut = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looping Out..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Loop Out Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/out';
|
|
|
|
|
options.uri = '/v1/loop/out';
|
|
|
|
|
options.body = {
|
|
|
|
|
amt: req.body.amount,
|
|
|
|
|
sweep_conf_target: req.body.targetConf,
|
|
|
|
@ -41,13 +35,7 @@ export const loopOut = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const loopOutTerms = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Terms..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Loop Out Terms Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/out/terms';
|
|
|
|
|
options.uri = '/v1/loop/out/terms';
|
|
|
|
|
request(options).then((body) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Out Terms Received', data: body });
|
|
|
|
|
res.status(200).json(body);
|
|
|
|
@ -58,13 +46,7 @@ export const loopOutTerms = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const loopOutQuote = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Quotes..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Loop Out Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/out/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
options.uri = '/v1/loop/out/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Quote URL', data: options.url });
|
|
|
|
|
request(options).then((quoteRes) => {
|
|
|
|
|
quoteRes.amount = +req.params.amount;
|
|
|
|
@ -78,19 +60,13 @@ export const loopOutQuote = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const loopOutTermsAndQuotes = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Terms & Quotes..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Loop Out Terms & Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/out/terms';
|
|
|
|
|
options.uri = '/v1/loop/out/terms';
|
|
|
|
|
request(options).then((terms) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Terms Received', data: terms });
|
|
|
|
|
const options1 = common.getSwapServerOptions(req);
|
|
|
|
|
const options2 = common.getSwapServerOptions(req);
|
|
|
|
|
options1.url = options1.url + '/v1/loop/out/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
options2.url = options2.url + '/v1/loop/out/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
const options1 = options;
|
|
|
|
|
const options2 = options;
|
|
|
|
|
options1.uri = '/v1/loop/out/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
options2.uri = '/v1/loop/out/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Min Quote Options', data: options1 });
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Max Quote Options', data: options2 });
|
|
|
|
|
return Promise.all([request(options1), request(options2)]).then((values) => {
|
|
|
|
@ -112,13 +88,7 @@ export const loopOutTermsAndQuotes = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const loopIn = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looping In..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Loop In Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/in';
|
|
|
|
|
options.uri = '/v1/loop/in';
|
|
|
|
|
options.body = {
|
|
|
|
|
amt: req.body.amount,
|
|
|
|
|
max_swap_fee: req.body.swapFee,
|
|
|
|
@ -136,13 +106,7 @@ export const loopIn = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const loopInTerms = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Terms..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Loop In Terms Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/in/terms';
|
|
|
|
|
options.uri = '/v1/loop/in/terms';
|
|
|
|
|
request(options).then((body) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Terms Received', data: body });
|
|
|
|
|
res.status(200).json(body);
|
|
|
|
@ -153,13 +117,7 @@ export const loopInTerms = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const loopInQuote = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Quotes..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Loop In Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/in/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
options.uri = '/v1/loop/in/quote/' + req.params.amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Quote Options', data: options.url });
|
|
|
|
|
request(options).then((body) => {
|
|
|
|
|
body.amount = +req.params.amount;
|
|
|
|
@ -173,19 +131,13 @@ export const loopInQuote = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const loopInTermsAndQuotes = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Terms & Quotes..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Loop In Terms & Quotes Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/in/terms';
|
|
|
|
|
options.uri = '/v1/loop/in/terms';
|
|
|
|
|
request(options).then((terms) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Terms Received', data: terms });
|
|
|
|
|
const options1 = common.getSwapServerOptions(req);
|
|
|
|
|
const options2 = common.getSwapServerOptions(req);
|
|
|
|
|
options1.url = options1.url + '/v1/loop/in/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
options2.url = options2.url + '/v1/loop/in/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
const options1 = options;
|
|
|
|
|
const options2 = options;
|
|
|
|
|
options1.uri = '/v1/loop/in/quote/' + terms.min_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
options2.uri = '/v1/loop/in/quote/' + terms.max_swap_amount + '?conf_target=' + (req.query.targetConf ? req.query.targetConf : '2') + '&swap_publication_deadline=' + req.query.swapPublicationDeadline;
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Min Quote Options', data: options1 });
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Max Quote Options', data: options2 });
|
|
|
|
|
return Promise.all([request(options1), request(options2)]).then((values) => {
|
|
|
|
@ -207,13 +159,12 @@ export const loopInTermsAndQuotes = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const swaps = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting List Swaps..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'List Swaps Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/swaps';
|
|
|
|
|
options.uri = '/v1/loop/swaps';
|
|
|
|
|
request(options).then((body) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Swaps Received', data: body });
|
|
|
|
|
res.status(200).json(body.swaps);
|
|
|
|
@ -224,18 +175,29 @@ export const swaps = (req, res, next) => {
|
|
|
|
|
};
|
|
|
|
|
export const swap = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Swap Information..' });
|
|
|
|
|
options = common.getSwapServerOptions(req);
|
|
|
|
|
options.uri = '/v1/loop/swap/' + req.params.id;
|
|
|
|
|
request(options).then((body) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Swap Information Received', data: body });
|
|
|
|
|
res.status(200).json(body);
|
|
|
|
|
}).catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Loop', 'Get Swap Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
export const loopInfo = (req, res, next) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Information..' });
|
|
|
|
|
options = common.setSwapServerOptions(req);
|
|
|
|
|
if (options.url === '') {
|
|
|
|
|
const errMsg = 'Loop Server URL is missing in the configuration.';
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Get Swap Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
const err = common.handleError({ statusCode: 500, message: 'Get Loop Info Error', error: errMsg }, 'Loop', errMsg, req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
}
|
|
|
|
|
options.url = options.url + '/v1/loop/swap/' + req.params.id;
|
|
|
|
|
options.uri = '/v1/loop/info';
|
|
|
|
|
request(options).then((body) => {
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Swap Information Received', data: body });
|
|
|
|
|
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Information Received', data: body });
|
|
|
|
|
res.status(200).json(body);
|
|
|
|
|
}).catch((errRes) => {
|
|
|
|
|
const err = common.handleError(errRes, 'Loop', 'Get Swap Error', req.session.selectedNode);
|
|
|
|
|
const err = common.handleError(errRes, 'Loop', 'Get Loop Info Error', req.session.selectedNode);
|
|
|
|
|
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|