mirror of
https://github.com/Ride-The-Lightning/RTL.git
synced 2026-08-13 12:33:07 +02:00
Fix controllers and socket for axios migration (incomplete)
This commit is contained in:
parent
39a2204324
commit
537ac43af5
78 changed files with 1206 additions and 833 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { getAlias } from './network.js';
|
||||
|
|
@ -7,12 +7,13 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const listPeerChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Peer Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listpeerchannels';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Peer Channels List Received', data: body.channels });
|
||||
const getPeerAliasesTasks = body.channels.map((channel) => () => {
|
||||
channel.to_them_msat = channel.total_msat - channel.to_us_msat;
|
||||
|
|
@ -30,14 +31,15 @@ export const listPeerChannels = (req, res, next) => {
|
|||
};
|
||||
export const openChannel = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Opening Channel..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/fundchannel';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Open Channel Options', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Opened', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -47,14 +49,15 @@ export const openChannel = (req, res, next) => {
|
|||
};
|
||||
export const setChannelFee = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Setting Channel Fee..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/setchannel';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Update Channel Policy Options', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Updated Channel Policy', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -65,14 +68,15 @@ export const setChannelFee = (req, res, next) => {
|
|||
export const closeChannel = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Closing Channel..' });
|
||||
req.setTimeout(60000 * 10); // timeout 10 mins
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/close';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Closing Channel', data: options.url });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Closed', data: body });
|
||||
res.status(204).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -83,13 +87,14 @@ export const closeChannel = (req, res, next) => {
|
|||
export const listForwards = (req, res, next) => {
|
||||
const { status } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Channel List Forwards..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listforwards';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Forwarding History Received For Status ' + status, data: body });
|
||||
body.forwards = !body.forwards ? [] : (status === 'failed' || status === 'local_failed') ? body.forwards.slice(Math.max(0, body.forwards.length - 1000), Math.max(1000, body.forwards.length)).reverse() : body.forwards.reverse();
|
||||
res.status(200).json(body.forwards);
|
||||
|
|
@ -100,14 +105,15 @@ export const listForwards = (req, res, next) => {
|
|||
};
|
||||
export const funderUpdatePolicy = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting or Updating Funder Policy..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/funderupdate';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Funder Update Body', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Funder Policy Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,29 +1,30 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { CLWSClient } from './webSocketClient.js';
|
||||
let options = null;
|
||||
const logger = Logger;
|
||||
const common = Common;
|
||||
const clWsClient = CLWSClient;
|
||||
export const getInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Getting Core Lightning Node Information..' });
|
||||
common.logEnvVariables(req);
|
||||
common.setOptions(req);
|
||||
options = common.getOptions(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/getinfo';
|
||||
common.setAxiosConfig(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
const url = req.session.selectedNode.settings.lnServerUrl + '/v1/getinfo';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Selected Node ' + req.session.selectedNode.lnNode });
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Calling Info from Core Lightning server url ' + options.url });
|
||||
if (!options.headers || !options.headers.rune) {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Calling Info from Core Lightning server url ' + url });
|
||||
if (!axiosConfig.headers || !axiosConfig.headers?.rune) {
|
||||
const errMsg = 'Core lightning get info failed due to missing rune!';
|
||||
const err = common.handleError({ statusCode: 502, message: 'Bad rune', error: errMsg }, 'GetInfo', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
else {
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(url, null, axiosConfig).then((body) => {
|
||||
body = body.data;
|
||||
body = body.data;
|
||||
body = body.data;
|
||||
body = body.data;
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'GetInfo', msg: 'Node Information Before Update', data: body });
|
||||
body.lnImplementation = 'Core Lightning';
|
||||
const chainObj = { chain: '', network: '' };
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,13 +6,14 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const deleteExpiredInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Deleting Expired Invoices..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/autoclean-once';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoices Deleted', data: body });
|
||||
res.status(201).json({ status: 'Cleaned Invoices: ' + body.autoclean.expiredinvoices.cleaned + ', Uncleaned Invoices: ' + body.autoclean.expiredinvoices.uncleaned });
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -22,14 +23,15 @@ export const deleteExpiredInvoice = (req, res, next) => {
|
|||
};
|
||||
export const listInvoices = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Getting Invoices..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listinvoices';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List URL', data: options.url });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -39,13 +41,14 @@ export const listInvoices = (req, res, next) => {
|
|||
};
|
||||
export const addInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoice';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Created', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,13 +7,14 @@ const common = Common;
|
|||
const aliasCache = new Map();
|
||||
export const getRoute = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Getting Network Routes..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/getroute';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Network Routes Received', data: body });
|
||||
return Promise.all(body.route?.map((rt) => getAlias(req.session.selectedNode, rt, 'id'))).then((values) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Network Routes with Alias Received', data: body });
|
||||
|
|
@ -26,13 +27,14 @@ export const getRoute = (req, res, next) => {
|
|||
};
|
||||
export const listChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Channel Lookup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listchannels';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Channel Lookup Finished', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -43,13 +45,14 @@ export const listChannels = (req, res, next) => {
|
|||
export const feeRates = (req, res, next) => {
|
||||
const { style } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Getting Network Fee Rates..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/feerates';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Network Fee Rates Received for ' + style, data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -61,14 +64,15 @@ export const listNodes = (req, res, next) => {
|
|||
const filter_liquidity_ads = !!req.body.liquidity_ads;
|
||||
delete req.body.liquidity_ads;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'List Nodes..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listnodes';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Network', msg: 'List Nodes URL' + options.url });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'List Nodes Finished', data: body });
|
||||
let response = body.nodes;
|
||||
if (filter_liquidity_ads) {
|
||||
|
|
@ -93,7 +97,8 @@ export const getAlias = (selNode, peer, id) => {
|
|||
}
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/listnodes';
|
||||
options.body = { id: peerId };
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Network', msg: 'Peer Alias Finished', data: body });
|
||||
const alias = body.nodes?.[0]?.alias || peerId.substring(0, 20);
|
||||
aliasCache.set(peerId, alias);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { Database } from '../../utils/database.js';
|
||||
|
|
@ -10,6 +10,7 @@ const databaseService = Database;
|
|||
export const listOfferBookmarks = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Getting Offer Bookmarks..' });
|
||||
databaseService.find(req.session.selectedNode, CollectionsEnum.OFFERS).then((offers) => {
|
||||
offers = offers.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offer Bookmarks Received', data: offers });
|
||||
res.status(200).json(offers);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -30,13 +31,14 @@ export const deleteOfferBookmark = (req, res, next) => {
|
|||
};
|
||||
export const listOffers = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Getting Offers..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listoffers';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Offers', msg: 'Offers List URL', data: options.url });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offers List Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -46,13 +48,14 @@ export const listOffers = (req, res, next) => {
|
|||
};
|
||||
export const createOffer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Creating Offer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/offer';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offer Created', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -62,14 +65,15 @@ export const createOffer = (req, res, next) => {
|
|||
};
|
||||
export const fetchOfferInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Getting Offer Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/fetchinvoice';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Offers', msg: 'Offer Invoice Body', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offer Invoice Received', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -79,13 +83,14 @@ export const fetchOfferInvoice = (req, res, next) => {
|
|||
};
|
||||
export const disableOffer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Disabling Offer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/disableoffer';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offer Disabled', data: body });
|
||||
res.status(202).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,13 +6,14 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getNewAddress = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Generating New Address..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/newaddr';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'New Address Generated', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -22,14 +23,15 @@ export const getNewAddress = (req, res, next) => {
|
|||
};
|
||||
export const onChainWithdraw = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Withdrawing from On Chain..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/withdraw';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'OnChain', msg: 'OnChain Withdraw Options', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Withdraw Finished', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -39,12 +41,13 @@ export const onChainWithdraw = (req, res, next) => {
|
|||
};
|
||||
export const getUTXOs = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Listing Funds..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listfunds';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Funds List Received', data: body });
|
||||
// Local Remote Balance Calculation
|
||||
let lrBalance = { localBalance: 0, remoteBalance: 0, inactiveBalance: 0, pendingBalance: 0 };
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { Database } from '../../utils/database.js';
|
||||
|
|
@ -10,7 +10,8 @@ const databaseService = Database;
|
|||
export const getMemo = (selNode, payment) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/decode';
|
||||
options.body = { string: payment.bolt11 };
|
||||
return request.post(options).then((res) => {
|
||||
return axios.post(options).then((res) => {
|
||||
res = res.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Payments', msg: 'Payment Decode Received', data: res });
|
||||
payment.memo = res.description || '';
|
||||
return payment;
|
||||
|
|
@ -77,12 +78,13 @@ function groupBy(payments) {
|
|||
}
|
||||
export const listPayments = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'List Payments..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listsendpays';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Payment List Received', data: body.payments });
|
||||
body.payments = body.payments && body.payments.length && body.payments.length > 0 ? groupBy(body.payments) : [];
|
||||
return Promise.all(body.payments?.map((payment) => ((payment.bolt11) ? getMemo(req.session.selectedNode, payment) : (payment.memo = '')))).then((values) => {
|
||||
|
|
@ -96,7 +98,7 @@ export const listPayments = (req, res, next) => {
|
|||
};
|
||||
export const postPayment = (req, res, next) => {
|
||||
const { paymentType, saveToDB, bolt12, zeroAmtOffer, amount_msat, title, issuer, description } = req.body;
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -146,7 +148,8 @@ export const postPayment = (req, res, next) => {
|
|||
options.body = options_body;
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/pay';
|
||||
}
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Sent', data: body });
|
||||
if (paymentType === 'OFFER') {
|
||||
if (saveToDB && bolt12) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { getAlias } from './network.js';
|
||||
|
|
@ -7,12 +7,13 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getPeers = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'List Peers..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listpeers';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List Received', data: body });
|
||||
const peers = !body.peers ? [] : body.peers;
|
||||
return Promise.all(peers?.map((peer) => getAlias(req.session.selectedNode, peer, 'id'))).then((values) => {
|
||||
|
|
@ -26,17 +27,16 @@ export const getPeers = (req, res, next) => {
|
|||
};
|
||||
export const postPeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Connecting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/connect';
|
||||
options.body = req.body;
|
||||
request.post(options).then((connectRes) => {
|
||||
axios.post(req.session.selectedNode.settings.lnServerUrl + '/v1/connect', req.body, options).then((connectRes) => {
|
||||
connectRes = connectRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peer Connected', data: connectRes });
|
||||
const listOptions = common.getOptions(req);
|
||||
listOptions.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listpeers';
|
||||
request.post(listOptions).then((listPeersRes) => {
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
axios.post(req.session.selectedNode.settings.lnServerUrl + '/v1/listpeers', null, options).then((listPeersRes) => {
|
||||
listPeersRes = listPeersRes.data;
|
||||
const peers = listPeersRes && listPeersRes.peers ? common.newestOnTop(listPeersRes.peers, 'id', connectRes.id) : [];
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peers List after Connect Received', data: peers });
|
||||
res.status(201).json(peers);
|
||||
|
|
@ -51,13 +51,9 @@ export const postPeer = (req, res, next) => {
|
|||
};
|
||||
export const deletePeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Disconnecting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/disconnect';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
axios.post(req.session.selectedNode.settings.lnServerUrl + '/v1/disconnect', req.body, axiosConfig).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconnected', data: body });
|
||||
res.status(204).json({});
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,13 +6,14 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const decodePayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Decoding Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/decode';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Decoded', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -22,13 +23,14 @@ export const decodePayment = (req, res, next) => {
|
|||
};
|
||||
export const signMessage = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Signing Message..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/signmessage';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Message Signed', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -38,13 +40,13 @@ export const signMessage = (req, res, next) => {
|
|||
};
|
||||
export const verifyMessage = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Verifying Message..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/checkmessage';
|
||||
options.body = req.body;
|
||||
request.post(options, (error, response, body) => {
|
||||
axios.post(options, (error, response, body) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Message Verified', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -54,12 +56,13 @@ export const verifyMessage = (req, res, next) => {
|
|||
};
|
||||
export const listConfigs = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Utility', msg: 'List Configs..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listconfigs';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Utility', msg: 'List Configs Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ export class CLWebSocketClient {
|
|||
if (!newClient) {
|
||||
newClient = { selectedNode: null, reConnect: true, webSocketClient: null };
|
||||
}
|
||||
newClient.selectedNode = JSON.parse(JSON.stringify(newSelectedNode));
|
||||
newClient.selectedNode = newSelectedNode;
|
||||
this.webSocketClients[clientIdx] = newClient;
|
||||
};
|
||||
this.wsServer.eventEmitterCLN.on('CONNECT', (nodeIndex) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { createInvoiceRequestCall, listPendingInvoicesRequestCall } from './invoices.js';
|
||||
|
|
@ -30,7 +30,8 @@ export const simplifyAllChannels = (selNode, channels) => {
|
|||
options.url = selNode.settings.lnServerUrl + '/nodes';
|
||||
options.form = channelNodeIds;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Channels', msg: 'Node Ids to find alias', data: channelNodeIds });
|
||||
return request.post(options).then((nodes) => {
|
||||
return axios.post(options).then((nodes) => {
|
||||
nodes = nodes.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Channels', msg: 'Filtered Nodes Received', data: nodes });
|
||||
let foundPeer = null;
|
||||
simplifiedChannels?.map((channel) => {
|
||||
|
|
@ -43,7 +44,7 @@ export const simplifyAllChannels = (selNode, channels) => {
|
|||
};
|
||||
export const getChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'List Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -58,17 +59,18 @@ export const getChannels = (req, res, next) => {
|
|||
common.getDummyData('Channels', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(data); });
|
||||
}
|
||||
else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Channels List Received', data: body });
|
||||
if (body && body.length) {
|
||||
return simplifyAllChannels(req.session.selectedNode, body).then((simplifiedChannels) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Simplified Channels with Alias Received', data: simplifiedChannels });
|
||||
res.status(200).json(simplifiedChannels);
|
||||
return res.status(200).json(simplifiedChannels);
|
||||
});
|
||||
}
|
||||
else {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Empty Channels List Received' });
|
||||
res.status(200).json([]);
|
||||
return res.status(200).json([]);
|
||||
}
|
||||
}).
|
||||
catch((errRes) => {
|
||||
|
|
@ -79,7 +81,7 @@ export const getChannels = (req, res, next) => {
|
|||
};
|
||||
export const getChannelStats = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Channel States..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -91,7 +93,8 @@ export const getChannelStats = (req, res, next) => {
|
|||
from: fromLastMonth,
|
||||
to: tillToday
|
||||
};
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel States Received', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -101,14 +104,15 @@ export const getChannelStats = (req, res, next) => {
|
|||
};
|
||||
export const openChannel = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Opening Channel..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/open';
|
||||
options.form = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Open Channel Params', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Opened', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -118,14 +122,15 @@ export const openChannel = (req, res, next) => {
|
|||
};
|
||||
export const updateChannelRelayFee = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Updating Channel Relay Fee..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/updaterelayfee';
|
||||
options.form = req.query;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Update Relay Fee Params', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Relay Fee Updated', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -134,7 +139,7 @@ export const updateChannelRelayFee = (req, res, next) => {
|
|||
});
|
||||
};
|
||||
export const closeChannel = (req, res, next) => {
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -149,7 +154,8 @@ export const closeChannel = (req, res, next) => {
|
|||
options.form = { channelId: req.query.channelId };
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Close URL', data: options.url });
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Close Params', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Closed', data: body });
|
||||
res.status(204).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -160,7 +166,7 @@ export const closeChannel = (req, res, next) => {
|
|||
export const circularRebalance = (req, res, next) => {
|
||||
const { amountMsat, sourceNodeId, targetNodeId, ignoreNodeIds, format, sourceShortChannelId, targetShortChannelId } = req.body;
|
||||
const crInvDescription = 'Circular rebalancing invoice for ' + (amountMsat / 1000) + ' Sats';
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -95,7 +95,7 @@ export const arrangePayments = (selNode, body) => {
|
|||
};
|
||||
export const getFees = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Getting Fees..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -112,7 +112,8 @@ export const getFees = (req, res, next) => {
|
|||
common.getDummyData('Fees', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(arrangeFees(req.session.selectedNode, data, Math.round((new Date().getTime())))); });
|
||||
}
|
||||
else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Fee Received', data: body });
|
||||
res.status(200).json(arrangeFees(req.session.selectedNode, body, Math.round((new Date().getTime()))));
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -123,7 +124,7 @@ export const getFees = (req, res, next) => {
|
|||
};
|
||||
export const getPayments = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Getting Payments..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -140,7 +141,8 @@ export const getPayments = (req, res, next) => {
|
|||
common.getDummyData('Payments', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(arrangePayments(req.session.selectedNode, data)); });
|
||||
}
|
||||
else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Payments Received', data: body });
|
||||
res.status(200).json(arrangePayments(req.session.selectedNode, body));
|
||||
}).
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { ECLWSClient } from './webSocketClient.js';
|
||||
|
|
@ -9,8 +9,8 @@ const eclWsClient = ECLWSClient;
|
|||
export const getInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Getting Eclair Node Information..' });
|
||||
common.logEnvVariables(req);
|
||||
common.setOptions(req);
|
||||
options = common.getOptions(req);
|
||||
common.setAxiosConfig(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -31,7 +31,8 @@ export const getInfo = (req, res, next) => {
|
|||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
else {
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Connecting to the Eclair\'s Websocket Server.' });
|
||||
body.lnImplementation = 'Eclair';
|
||||
req.session.selectedNode.lnVersion = body.version.split('-')[0] || '';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -15,7 +15,8 @@ export const getReceivedPaymentInfo = (lnServerUrl, invoice) => {
|
|||
if (idx < 0) {
|
||||
options.url = lnServerUrl + '/getreceivedinfo';
|
||||
options.form = { paymentHash: invoice.paymentHash };
|
||||
return request(options).then((response) => {
|
||||
return axios(options).then((response) => {
|
||||
response = response.data;
|
||||
invoice.status = response.status.type;
|
||||
if (response.status && response.status.type === 'received') {
|
||||
invoice.amountSettled = response.status.amount ? Math.round(response.status.amount / 1000) : 0;
|
||||
|
|
@ -35,13 +36,14 @@ export const getReceivedPaymentInfo = (lnServerUrl, invoice) => {
|
|||
};
|
||||
export const getInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/getinvoice';
|
||||
options.form = { paymentHash: req.params.paymentHash };
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Found', data: body });
|
||||
const current_time = (Math.round(new Date(Date.now()).getTime() / 1000));
|
||||
body.amount = body.amount ? body.amount / 1000 : 0;
|
||||
|
|
@ -55,18 +57,17 @@ export const getInvoice = (req, res, next) => {
|
|||
};
|
||||
export const listPendingInvoicesRequestCall = (selectedNode, count, skip) => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'List Pending Invoices..' });
|
||||
options = selectedNode.authentication.options;
|
||||
options.url = selectedNode.settings.lnServerUrl + '/listpendinginvoices';
|
||||
options.form = { from: 0, to: (Math.round(new Date(Date.now()).getTime() / 1000)).toString() };
|
||||
const form = { from: 0, to: (Math.round(new Date(Date.now()).getTime() / 1000)).toString() };
|
||||
// Limit the number of invoices till provided count
|
||||
if (count) {
|
||||
options.form.count = count;
|
||||
form.count = count;
|
||||
}
|
||||
if (skip) {
|
||||
options.form.skip = skip;
|
||||
form.skip = skip;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
request.post(options).then((pendingInvoicesResponse) => {
|
||||
axios.post(selectedNode.settings.lnServerUrl + '/listpendinginvoices', form, selectedNode.axiosConfig).then((pendingInvoicesResponse) => {
|
||||
pendingInvoicesResponse = pendingInvoicesResponse.data;
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Pending Invoices List ', data: pendingInvoicesResponse });
|
||||
resolve(pendingInvoicesResponse);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -76,7 +77,7 @@ export const listPendingInvoicesRequestCall = (selectedNode, count, skip) => {
|
|||
};
|
||||
export const listInvoices = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Getting List Invoices..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -95,13 +96,14 @@ export const listInvoices = (req, res, next) => {
|
|||
options2.form = { from: 0, to: tillToday };
|
||||
if (common.read_dummy_data) {
|
||||
return common.getDummyData('Invoices', req.session.selectedNode.lnImplementation).then(([invoices, pendingInvoicesRes]) => {
|
||||
pendingInvoices = pendingInvoicesRes;
|
||||
invoices = invoices.data;
|
||||
pendingInvoices = pendingInvoicesRes.data;
|
||||
return Promise.all(invoices?.map((invoice) => getReceivedPaymentInfo(req.session.selectedNode.settings.lnServerUrl, invoice))).
|
||||
then((values) => res.status(200).json(invoices));
|
||||
});
|
||||
}
|
||||
else {
|
||||
return Promise.all([request(options1), request(options2)]).
|
||||
return Promise.all([axios(options1), axios(options2)]).
|
||||
then(([invoices, pendingInvoicesRes]) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List Received', data: invoices });
|
||||
// pendingInvoices will be used to get the status (paid/unpaid) of the invoice via getReceivedPaymentInfo
|
||||
|
|
@ -130,11 +132,10 @@ export const listInvoices = (req, res, next) => {
|
|||
};
|
||||
export const createInvoiceRequestCall = (selectedNode, description, amount) => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
||||
options = selectedNode.authentication.options;
|
||||
options.url = selectedNode.settings.lnServerUrl + '/createinvoice';
|
||||
options.form = { description: description, amountMsat: amount };
|
||||
const form = { description: description, amountMsat: amount };
|
||||
return new Promise((resolve, reject) => {
|
||||
request.post(options).then((invResponse) => {
|
||||
axios.post(selectedNode.settings.lnServerUrl + '/createinvoice', form, selectedNode.axiosConfig).then((invResponse) => {
|
||||
invResponse = invResponse.data;
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Created', data: invResponse });
|
||||
if (invResponse.amount) {
|
||||
invResponse.amount = Math.round(invResponse.amount / 1000);
|
||||
|
|
@ -148,7 +149,7 @@ export const createInvoiceRequestCall = (selectedNode, description, amount) => {
|
|||
export const createInvoice = (req, res, next) => {
|
||||
const { description, amountMsat } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,13 +6,14 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getNodes = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Node Lookup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/nodes';
|
||||
options.form = { nodeIds: req.params.id };
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Node Lookup Finished', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -22,11 +23,10 @@ export const getNodes = (req, res, next) => {
|
|||
};
|
||||
export const findRouteBetweenNodesRequestCall = (selectedNode, amountMsat, sourceNodeId, targetNodeId, ignoreNodeIds = [], format = 'shortChannelId') => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Network', msg: 'Find Route Between Nodes..' });
|
||||
options = selectedNode.authentication.options;
|
||||
options.url = selectedNode.settings.lnServerUrl + '/findroutebetweennodes';
|
||||
options.form = { amountMsat: amountMsat, sourceNodeId: sourceNodeId, targetNodeId: targetNodeId, ignoreNodeIds: ignoreNodeIds, format: format };
|
||||
const form = { amountMsat: amountMsat, sourceNodeId: sourceNodeId, targetNodeId: targetNodeId, ignoreNodeIds: ignoreNodeIds, format: format };
|
||||
return new Promise((resolve, reject) => {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(selectedNode.settings.lnServerUrl + '/findroutebetweennodes', form, selectedNode.axiosConfig).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Network', msg: 'Route Lookup Between Nodes Finished', data: body });
|
||||
resolve(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -36,7 +36,7 @@ export const findRouteBetweenNodesRequestCall = (selectedNode, amountMsat, sourc
|
|||
};
|
||||
export const findRouteBetweenNodes = (req, res, next) => {
|
||||
const { amountMsat, sourceNodeId, targetNodeId, ignoreNodeIds, format } = req.body;
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -17,13 +17,14 @@ export const arrangeBalances = (body) => {
|
|||
};
|
||||
export const getNewAddress = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Generating New Address..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/getnewaddress';
|
||||
options.form = {};
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'New Address Generated', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -33,7 +34,7 @@ export const getNewAddress = (req, res, next) => {
|
|||
};
|
||||
export const getBalance = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Getting On Chain Balance..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -43,7 +44,8 @@ export const getBalance = (req, res, next) => {
|
|||
common.getDummyData('OnChainBalance', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(arrangeBalances(data)); });
|
||||
}
|
||||
else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'On Chain Balance Received', data: body });
|
||||
res.status(200).json(arrangeBalances(body));
|
||||
}).
|
||||
|
|
@ -55,7 +57,7 @@ export const getBalance = (req, res, next) => {
|
|||
};
|
||||
export const getTransactions = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Getting On Chain Transactions..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -65,7 +67,8 @@ export const getTransactions = (req, res, next) => {
|
|||
skip: req.query.skip
|
||||
};
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Getting On Chain Transactions Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'On Chain Transactions Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -76,14 +79,15 @@ export const getTransactions = (req, res, next) => {
|
|||
export const sendFunds = (req, res, next) => {
|
||||
const { address, amount, blocks } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Sending On Chain Funds..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/sendonchain';
|
||||
options.form = { address: address, amountSatoshis: amount, confirmationTarget: blocks };
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Onchain', msg: 'Send Funds Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Onchain', msg: 'On Chain Funds Sent', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,7 +7,8 @@ const common = Common;
|
|||
export const getSentInfoFromPaymentRequest = (selNode, payment) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/getsentinfo';
|
||||
options.form = { paymentHash: payment };
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Payments', msg: 'Payment Sent Information Received', data: body });
|
||||
body.forEach((sentPayment) => {
|
||||
if (sentPayment.amount) {
|
||||
|
|
@ -23,20 +24,21 @@ export const getSentInfoFromPaymentRequest = (selNode, payment) => {
|
|||
export const getQueryNodes = (selNode, nodeIds) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/nodes';
|
||||
options.form = { nodeIds: nodeIds?.reduce((acc, curr) => acc + ',' + curr) };
|
||||
return request.post(options).then((nodes) => {
|
||||
return axios.post(options).then((nodes) => {
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Payments', msg: 'Query Nodes Received', data: nodes });
|
||||
return nodes;
|
||||
}).catch((err) => []);
|
||||
};
|
||||
export const decodePayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Decoding Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/parseinvoice';
|
||||
options.form = { invoice: req.params.invoice };
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Decoded', data: body });
|
||||
if (body.amount) {
|
||||
body.amount = Math.round(body.amount / 1000);
|
||||
|
|
@ -49,14 +51,15 @@ export const decodePayment = (req, res, next) => {
|
|||
};
|
||||
export const postPayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Paying Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/payinvoice';
|
||||
options.form = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Send Payment Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Invoice Paid', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -66,7 +69,7 @@ export const postPayment = (req, res, next) => {
|
|||
};
|
||||
export const queryPaymentRoute = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Querying Payment Route..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -76,7 +79,8 @@ export const queryPaymentRoute = (req, res, next) => {
|
|||
amountMsat: req.query.amountMsat
|
||||
};
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Query Payment Route Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Query Payment Route Received', data: body });
|
||||
if (body && body.routes && body.routes.length) {
|
||||
let allRoutesNodeIds = [];
|
||||
|
|
@ -91,12 +95,12 @@ export const queryPaymentRoute = (req, res, next) => {
|
|||
});
|
||||
});
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Query Routes with Alias Received', data: body });
|
||||
res.status(200).json(body);
|
||||
return res.status(200).json(body);
|
||||
});
|
||||
}
|
||||
else {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Empty Payment Route Information Received' });
|
||||
res.status(200).json({ routes: [] });
|
||||
return res.status(200).json({ routes: [] });
|
||||
}
|
||||
}).catch((errRes) => {
|
||||
const err = common.handleError(errRes, 'Payments', 'Query Route Error', req.session.selectedNode);
|
||||
|
|
@ -106,7 +110,7 @@ export const queryPaymentRoute = (req, res, next) => {
|
|||
export const getSentPaymentsInformation = (req, res, next) => {
|
||||
const { payments } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Getting Sent Payment Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -129,12 +133,11 @@ export const getSentPaymentsInformation = (req, res, next) => {
|
|||
};
|
||||
export const sendPaymentToRouteRequestCall = (selectedNode, shortChannelIds, invoice, amountMsat) => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
||||
options = selectedNode.authentication.options;
|
||||
options.url = selectedNode.settings.lnServerUrl + '/sendtoroute';
|
||||
options.form = { shortChannelIds: shortChannelIds, amountMsat: amountMsat, invoice: invoice };
|
||||
const form = { shortChannelIds: shortChannelIds, amountMsat: amountMsat, invoice: invoice };
|
||||
return new Promise((resolve, reject) => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Send Payment To Route Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(selectedNode.settings.lnServerUrl + '/sendtoroute', form, selectedNode.axiosConfig).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Sent To Route', data: body });
|
||||
resolve(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -145,7 +148,7 @@ export const sendPaymentToRouteRequestCall = (selectedNode, shortChannelIds, inv
|
|||
export const sendPaymentToRoute = (req, res, next) => {
|
||||
const { shortChannelIds, invoice, amountMsat } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Send Payment To Route..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,14 +7,14 @@ const common = Common;
|
|||
export const getFilteredNodes = (selNode, peersNodeIds) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/nodes';
|
||||
options.form = { nodeIds: peersNodeIds };
|
||||
return request.post(options).then((nodes) => {
|
||||
return axios.post(options).then((nodes) => {
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Peers', msg: 'Filtered Nodes Received', data: nodes });
|
||||
return nodes;
|
||||
}).catch((err) => []);
|
||||
};
|
||||
export const getPeers = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Getting Peers..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -24,7 +24,8 @@ export const getPeers = (req, res, next) => {
|
|||
common.getDummyData('Peers', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(data); });
|
||||
}
|
||||
else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List Received', data: body });
|
||||
if (body && body.length) {
|
||||
let peersNodeIds = '';
|
||||
|
|
@ -43,7 +44,7 @@ export const getPeers = (req, res, next) => {
|
|||
}
|
||||
else {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Empty Peers Received' });
|
||||
res.status(200).json([]);
|
||||
return res.status(200).json([]);
|
||||
}
|
||||
}).
|
||||
catch((errRes) => {
|
||||
|
|
@ -54,7 +55,7 @@ export const getPeers = (req, res, next) => {
|
|||
};
|
||||
export const connectPeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Conneting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -64,7 +65,8 @@ export const connectPeer = (req, res, next) => {
|
|||
options.form = req.query;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Connect Peer Params', data: options.form });
|
||||
}
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peer Connected', data: body });
|
||||
if (typeof body === 'string' && body.includes('already connected')) {
|
||||
const err = common.handleError({ statusCode: 500, message: 'Connect Peer Error', error: body }, 'Peers', body, req.session.selectedNode);
|
||||
|
|
@ -76,7 +78,8 @@ export const connectPeer = (req, res, next) => {
|
|||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/peers';
|
||||
options.form = {};
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List after Connect', data: body });
|
||||
if (body && body.length) {
|
||||
let peersNodeIds = '';
|
||||
|
|
@ -91,11 +94,11 @@ export const connectPeer = (req, res, next) => {
|
|||
});
|
||||
const peers = common.newestOnTop(body || [], 'nodeId', req.query.nodeId ? req.query.nodeId : req.query.uri ? req.query.uri.substring(0, req.query.uri.indexOf('@')) : '');
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peers List after Connect Received', data: peers });
|
||||
res.status(201).json(peers);
|
||||
return res.status(201).json(peers);
|
||||
});
|
||||
}
|
||||
else {
|
||||
res.status(201).json([]);
|
||||
return res.status(201).json([]);
|
||||
}
|
||||
}).catch((errRes) => {
|
||||
const err = common.handleError(errRes, 'Peers', 'Connect Peer Error', req.session.selectedNode);
|
||||
|
|
@ -108,7 +111,7 @@ export const connectPeer = (req, res, next) => {
|
|||
};
|
||||
export const deletePeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Disconneting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -118,7 +121,8 @@ export const deletePeer = (req, res, next) => {
|
|||
options.form = { nodeId: req.params.nodeId };
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Disconnect Peer Params', data: options.form });
|
||||
}
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconnected', data: body });
|
||||
res.status(204).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ export class ECLWebSocketClient {
|
|||
if (!newClient) {
|
||||
newClient = { selectedNode: null, reConnect: true, webSocketClient: null };
|
||||
}
|
||||
newClient.selectedNode = JSON.parse(JSON.stringify(newSelectedNode));
|
||||
newClient.selectedNode = newSelectedNode;
|
||||
this.webSocketClients[clientIdx] = newClient;
|
||||
};
|
||||
this.heartbeat = (eclWsClt) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,15 +6,16 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getBlockchainBalance = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Balance', msg: 'Getting Balance..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/balance/blockchain';
|
||||
options.qs = req.query;
|
||||
options.params = req.query;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Balance', msg: 'Request params', data: req.params });
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Balance', msg: 'Request Query', data: req.query });
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
if (body) {
|
||||
if (!body.total_balance) {
|
||||
body.total_balance = 0;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,7 +7,8 @@ const common = Common;
|
|||
export const getAliasForChannel = (selNode, channel) => {
|
||||
const pubkey = (channel.remote_pubkey) ? channel.remote_pubkey : (channel.remote_node_pub) ? channel.remote_node_pub : '';
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/graph/node/' + pubkey;
|
||||
return request(options).then((aliasBody) => {
|
||||
return axios(options).then((aliasBody) => {
|
||||
aliasBody = aliasBody.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Channels', msg: 'Alias Received', data: aliasBody.node.alias });
|
||||
channel.remote_alias = aliasBody.node.alias && aliasBody.node.alias !== '' ? aliasBody.node.alias : aliasBody.node.pub_key.slice(0, 20);
|
||||
return channel;
|
||||
|
|
@ -18,16 +19,17 @@ export const getAliasForChannel = (selNode, channel) => {
|
|||
};
|
||||
export const getAllChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels';
|
||||
options.qs = req.query;
|
||||
options.params = req.query;
|
||||
let local = 0;
|
||||
let remote = 0;
|
||||
let total = 0;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Channels List Received', data: body });
|
||||
if (body.channels) {
|
||||
return Promise.all(body.channels?.map((channel) => {
|
||||
|
|
@ -56,13 +58,14 @@ export const getAllChannels = (req, res, next) => {
|
|||
};
|
||||
export const getPendingChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Pending Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels/pending';
|
||||
options.qs = req.query;
|
||||
request(options).then((body) => {
|
||||
options.params = req.query;
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
if (!body.total_limbo_balance) {
|
||||
body.total_limbo_balance = 0;
|
||||
}
|
||||
|
|
@ -94,13 +97,14 @@ export const getPendingChannels = (req, res, next) => {
|
|||
};
|
||||
export const getClosedChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Closed Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels/closed';
|
||||
options.qs = req.query;
|
||||
request(options).then((body) => {
|
||||
options.params = req.query;
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
if (body.channels && body.channels.length > 0) {
|
||||
return Promise.all(body.channels?.map((channel) => {
|
||||
channel.close_type = (!channel.close_type) ? 'COOPERATIVE_CLOSE' : channel.close_type;
|
||||
|
|
@ -125,7 +129,7 @@ export const getClosedChannels = (req, res, next) => {
|
|||
export const postChannel = (req, res, next) => {
|
||||
const { node_pubkey, private: privateChannel, spend_unconfirmed, local_funding_amount, trans_type, trans_type_value, commitment_type } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Opening Channel..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -147,7 +151,8 @@ export const postChannel = (req, res, next) => {
|
|||
}
|
||||
options.form = JSON.stringify(options.form);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Channel Open Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Opened', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -162,7 +167,7 @@ export const closeChannel = (req, res, next) => {
|
|||
const err = common.handleError({ message: 'Session Expired after a day\'s inactivity.', statusCode: 401 }, 'Session Expired', 'Session Expiry Error', null);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -175,7 +180,7 @@ export const closeChannel = (req, res, next) => {
|
|||
options.url = options.url + '&sat_per_byte=' + req.query.sat_per_byte;
|
||||
}
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Closing Channel Options URL', data: options.url });
|
||||
request.delete(options);
|
||||
axios.delete(options);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Close Requested' });
|
||||
res.status(202).json({ message: 'Close channel request has been submitted.' });
|
||||
}
|
||||
|
|
@ -187,7 +192,7 @@ export const closeChannel = (req, res, next) => {
|
|||
export const postChanPolicy = (req, res, next) => {
|
||||
const { chanPoint, baseFeeMsat, feeRate, timeLockDelta, max_htlc_msat, min_htlc_msat } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Updating Channel Policy..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -220,7 +225,8 @@ export const postChanPolicy = (req, res, next) => {
|
|||
options.form = JSON.stringify(optionsBody);
|
||||
}
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Update Channel Policy Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Policy Updated', data: body });
|
||||
if (body.failed_updates && body.failed_updates.length && body.failed_updates[0].update_error) {
|
||||
const err = common.handleError({ error: body.failed_updates[0].update_error }, 'Channels', 'Update Channel Policy Error', req.session.selectedNode);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as fs from 'fs';
|
||||
import { sep } from 'path';
|
||||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -32,7 +32,7 @@ function getFilesList(channelBackupPath, callback) {
|
|||
}
|
||||
export const getBackup = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'ChannelBackup', msg: 'Getting Channel Backup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -63,7 +63,8 @@ export const getBackup = (req, res, next) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'ChannelsBackup', msg: 'Channel Backup Received', data: body });
|
||||
fs.writeFile(channel_backup_file, JSON.stringify(body), (errRes) => {
|
||||
if (errRes) {
|
||||
|
|
@ -82,7 +83,7 @@ export const getBackup = (req, res, next) => {
|
|||
};
|
||||
export const postBackupVerify = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'ChannelBackup', msg: 'Verifying Channel Backup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -130,7 +131,8 @@ export const postBackupVerify = (req, res, next) => {
|
|||
}
|
||||
}
|
||||
if (verify_backup !== '') {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'ChannelBackup', msg: 'Channel Backup Verified', data: body });
|
||||
res.status(201).json({ message: message });
|
||||
}).
|
||||
|
|
@ -142,7 +144,7 @@ export const postBackupVerify = (req, res, next) => {
|
|||
};
|
||||
export const postRestore = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'ChannelBackup', msg: 'Restoring Channel Backup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -202,7 +204,8 @@ export const postRestore = (req, res, next) => {
|
|||
}
|
||||
}
|
||||
if (restore_backup !== '') {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'ChannelBackup', msg: 'Channel Restored', data: body });
|
||||
if (req.params.channelPoint === 'ALL') {
|
||||
channel_restore_file = channel_restore_file + 'channel-all.bak';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { getAllForwardingEvents } from './switch.js';
|
||||
|
|
@ -7,12 +7,13 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getFees = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Getting Fees..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/fees';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Fee Received', data: body });
|
||||
const today = new Date(Date.now());
|
||||
const start_date = new Date(today.getFullYear(), today.getMonth(), 1, 0, 0, 0);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { LNDWSClient } from './webSocketClient.js';
|
||||
|
|
@ -9,8 +9,8 @@ const lndWsClient = LNDWSClient;
|
|||
export const getInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Getting LND Node Information..' });
|
||||
common.logEnvVariables(req);
|
||||
common.setOptions(req);
|
||||
options = common.getOptions(req);
|
||||
common.setAxiosConfig(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -29,7 +29,8 @@ export const getInfo = (req, res, next) => {
|
|||
}
|
||||
return node;
|
||||
});
|
||||
return request(options).then((body) => {
|
||||
return axios(options).then((body) => {
|
||||
body = body.data;
|
||||
const body_str = (!body) ? '' : JSON.stringify(body);
|
||||
const search_idx = (!body) ? -1 : body_str.search('Not Found');
|
||||
if (!body || search_idx > -1 || body.error) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,7 +6,8 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getAliasFromPubkey = (selNode, pubkey) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/graph/node/' + pubkey;
|
||||
return request(options).then((res) => {
|
||||
return axios(options).then((res) => {
|
||||
res = res.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Graph', msg: 'Alias Received', data: res.node.alias });
|
||||
return res.node.alias;
|
||||
}).
|
||||
|
|
@ -14,12 +15,13 @@ export const getAliasFromPubkey = (selNode, pubkey) => {
|
|||
};
|
||||
export const getDescribeGraph = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Network Graph..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph';
|
||||
request.get(options).then((body) => {
|
||||
axios.get(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Network Graph Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -29,12 +31,13 @@ export const getDescribeGraph = (req, res, next) => {
|
|||
};
|
||||
export const getGraphInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/info';
|
||||
request.get(options).then((body) => {
|
||||
axios.get(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -44,12 +47,13 @@ export const getGraphInfo = (req, res, next) => {
|
|||
};
|
||||
export const getGraphNode = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Node Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/node/' + req.params.pubKey;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Node Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -59,12 +63,13 @@ export const getGraphNode = (req, res, next) => {
|
|||
};
|
||||
export const getGraphEdge = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Edge Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/edge/' + req.params.chanid;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Edge Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -74,7 +79,7 @@ export const getGraphEdge = (req, res, next) => {
|
|||
};
|
||||
export const getQueryRoutes = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Routes..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -83,7 +88,8 @@ export const getQueryRoutes = (req, res, next) => {
|
|||
options.url = options.url + '?outgoing_chan_id=' + req.query.outgoing_chan_id;
|
||||
}
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Query Routes URL', data: options.url });
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Query Routes Received', data: body });
|
||||
if (body.routes && body.routes.length && body.routes.length > 0 && body.routes[0].hops && body.routes[0].hops.length && body.routes[0].hops.length > 0) {
|
||||
return Promise.all(body.routes[0].hops?.map((hop) => getAliasFromPubkey(req.session.selectedNode, hop.pub_key))).
|
||||
|
|
@ -112,12 +118,13 @@ export const getQueryRoutes = (req, res, next) => {
|
|||
};
|
||||
export const getRemoteFeePolicy = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Remote Fee Policy..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/edge/' + req.params.chanid;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Edge Info Received', data: body });
|
||||
let remoteNodeFee = {};
|
||||
if (body.node1_pub === req.params.localPubkey) {
|
||||
|
|
@ -142,7 +149,7 @@ export const getRemoteFeePolicy = (req, res, next) => {
|
|||
});
|
||||
};
|
||||
export const getAliasesForPubkeys = (req, res, next) => {
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
import { LNDWSClient } from './webSocketClient.js';
|
||||
|
|
@ -8,7 +8,7 @@ const common = Common;
|
|||
const lndWsClient = LNDWSClient;
|
||||
export const invoiceLookup = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Getting Invoice Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -19,7 +19,8 @@ export const invoiceLookup = (req, res, next) => {
|
|||
else {
|
||||
options.url = options.url + '?payment_hash=' + req.query.payment_hash;
|
||||
}
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
body.r_preimage = body.r_preimage ? Buffer.from(body.r_preimage, 'base64').toString('hex') : '';
|
||||
body.r_hash = body.r_hash ? Buffer.from(body.r_hash, 'base64').toString('hex') : '';
|
||||
body.description_hash = body.description_hash ? Buffer.from(body.description_hash, 'base64').toString('hex') : null;
|
||||
|
|
@ -32,13 +33,14 @@ export const invoiceLookup = (req, res, next) => {
|
|||
};
|
||||
export const listInvoices = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Getting List Invoices..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoices?num_max_invoices=' + req.query.num_max_invoices + '&index_offset=' + req.query.index_offset +
|
||||
'&reversed=' + req.query.reversed;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List Received', data: body });
|
||||
if (body.invoices && body.invoices.length > 0) {
|
||||
body.invoices.forEach((invoice) => {
|
||||
|
|
@ -56,13 +58,14 @@ export const listInvoices = (req, res, next) => {
|
|||
};
|
||||
export const addInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Adding Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoices';
|
||||
options.form = JSON.stringify(req.body);
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Added', data: body });
|
||||
try {
|
||||
if (body.r_hash) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,7 +7,7 @@ const common = Common;
|
|||
export const signMessage = (req, res, next) => {
|
||||
const { message } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Signing Message..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -15,7 +15,8 @@ export const signMessage = (req, res, next) => {
|
|||
options.form = JSON.stringify({
|
||||
msg: Buffer.from(message).toString('base64')
|
||||
});
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Message Signed', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -26,7 +27,7 @@ export const signMessage = (req, res, next) => {
|
|||
export const verifyMessage = (req, res, next) => {
|
||||
const { message, signature } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Verifying Message..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -35,7 +36,8 @@ export const verifyMessage = (req, res, next) => {
|
|||
msg: Buffer.from(message).toString('base64'),
|
||||
signature: signature
|
||||
});
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Message Verified', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,12 +6,13 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getNewAddress = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'NewAddress', msg: 'Getting New Address..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/newaddress?type=' + req.query.type;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'NewAddress', msg: 'New Address Generated', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,19 +6,21 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const decodePaymentFromPaymentRequest = (selNode, payment) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/payreq/' + payment;
|
||||
return request(options).then((res) => {
|
||||
return axios(options).then((res) => {
|
||||
res = res.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'PayReq', msg: 'Description Received', data: res.description });
|
||||
return res;
|
||||
}).catch((err) => { });
|
||||
};
|
||||
export const decodePayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'PayRequest', msg: 'Decoding Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/payreq/' + req.params.payRequest;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'PayRequest', msg: 'Payment Decoded', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -29,7 +31,7 @@ export const decodePayment = (req, res, next) => {
|
|||
export const decodePayments = (req, res, next) => {
|
||||
const { payments } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'PayRequest', msg: 'Decoding Payments List..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -52,12 +54,13 @@ export const decodePayments = (req, res, next) => {
|
|||
};
|
||||
export const getPayments = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Getting Payments List..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/payments?max_payments=' + req.query.max_payments + '&index_offset=' + req.query.index_offset + '&reversed=' + req.query.reversed;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Payment List Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -67,14 +70,16 @@ export const getPayments = (req, res, next) => {
|
|||
};
|
||||
export const getAllLightningTransactions = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Getting All Lightning Transactions..' });
|
||||
const options1 = JSON.parse(JSON.stringify(common.getOptions(req)));
|
||||
const options2 = JSON.parse(JSON.stringify(common.getOptions(req)));
|
||||
const options1 = JSON.parse(JSON.stringify(common.getAxiosConfig(req)));
|
||||
const options2 = JSON.parse(JSON.stringify(common.getAxiosConfig(req)));
|
||||
// options1.url = req.session.selectedNode.settings.lnServerUrl + '/v1/payments?max_payments=100000&index_offset=0&reversed=true';
|
||||
options2.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoices?num_max_invoices=100000&index_offset=0&reversed=true';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'All Payments Options', data: options1 });
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'All Invoices Options', data: options2 });
|
||||
// return Promise.all([request(options1), request(options2)]).then((values) => {
|
||||
return Promise.all([{ payments: [] }, request(options2)]).then((values) => {
|
||||
// return Promise.all([axios(options1), axios(options2)]).then((values) => {
|
||||
return Promise.all([{ payments: [] }, axios(options2)]).then((values) => {
|
||||
values[0] = values[0].data;
|
||||
values[1] = values[1].data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'All Lightning Transactions Received', data: ({ totalPayments: values[0].payments.length || 0, totalInvoices: values[1].invoices.length || 0 }) });
|
||||
res.status(200).json({ listPaymentsAll: values[0], listInvoicesAll: values[1] });
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -84,12 +89,13 @@ export const getAllLightningTransactions = (req, res, next) => {
|
|||
};
|
||||
export const paymentLookup = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Looking up Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/router/track/' + req.params.paymentHash;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Information Received for ' + req.params.paymentHash, data: body });
|
||||
res.status(200).json(body.result || body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -99,7 +105,7 @@ export const paymentLookup = (req, res, next) => {
|
|||
};
|
||||
export const sendPayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Sending Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -111,7 +117,8 @@ export const sendPayment = (req, res, next) => {
|
|||
req.body.timeout_seconds = req.body.timeout_seconds || 600;
|
||||
options.form = JSON.stringify(req.body);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Send Payment Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
const results = body.split('\n').filter(Boolean).map((jsonString) => JSON.parse(jsonString));
|
||||
body = results.length > 0 ? results[results.length - 1] : { result: { status: 'UNKNOWN' } };
|
||||
if (body.result.status === 'FAILED') {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,7 +6,8 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getAliasForPeers = (selNode, peer) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/graph/node/' + peer.pub_key;
|
||||
return request(options).then((aliasBody) => {
|
||||
return axios(options).then((aliasBody) => {
|
||||
aliasBody = aliasBody.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Peers', msg: 'Alias Received', data: aliasBody.node.alias });
|
||||
peer.alias = aliasBody.node.alias;
|
||||
return aliasBody.node.alias;
|
||||
|
|
@ -17,12 +18,13 @@ export const getAliasForPeers = (selNode, peer) => {
|
|||
};
|
||||
export const getPeers = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Getting Peers..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List Received', data: body });
|
||||
const peers = !body.peers ? [] : body.peers;
|
||||
return Promise.all(peers?.map((peer) => getAliasForPeers(req.session.selectedNode, peer))).then((values) => {
|
||||
|
|
@ -37,7 +39,7 @@ export const getPeers = (req, res, next) => {
|
|||
export const postPeer = (req, res, next) => {
|
||||
const { host, pubkey, perm } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Connecting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -46,10 +48,12 @@ export const postPeer = (req, res, next) => {
|
|||
addr: { host: host, pubkey: pubkey },
|
||||
perm: perm
|
||||
});
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peer Connected', data: body });
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
const peers = (!body.peers) ? [] : body.peers;
|
||||
return Promise.all(peers?.map((peer) => getAliasForPeers(req.session.selectedNode, peer))).then((values) => {
|
||||
if (body.peers) {
|
||||
|
|
@ -72,13 +76,14 @@ export const postPeer = (req, res, next) => {
|
|||
};
|
||||
export const deletePeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Disconnecting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers/' + req.params.peerPubKey;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconnect Pubkey', data: req.params.peerPubKey });
|
||||
request.delete(options).then((body) => {
|
||||
axios.delete(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconneted', data: body });
|
||||
res.status(204).json({});
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -26,7 +26,7 @@ export const getAllForwardingEvents = (req, start, end, offset, caller, callback
|
|||
const err = common.handleError({ message: 'Session Expired after a day\'s inactivity.', statusCode: 401 }, 'Balance', 'Get Balance Error', req.session.selectedNode);
|
||||
return callback({ message: err.message, error: err.error, statusCode: err.statusCode });
|
||||
}
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/switch';
|
||||
options.form = {};
|
||||
if (start) {
|
||||
|
|
@ -39,7 +39,8 @@ export const getAllForwardingEvents = (req, start, end, offset, caller, callback
|
|||
options.form.index_offset = offset;
|
||||
options.form = JSON.stringify(options.form);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Switch', msg: 'Forwarding Events Params', data: options.form });
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Switch', msg: 'Forwarding Events Received', data: body });
|
||||
if (body.forwarding_events) {
|
||||
responseData[caller].forwarding_events.push(...body.forwarding_events);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,12 +6,13 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getTransactions = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Transactions', msg: 'Getting Transactions..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/transactions';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Transactions', msg: 'Transactions List Received', data: body });
|
||||
res.status(200).json(body.transactions);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -22,7 +23,7 @@ export const getTransactions = (req, res, next) => {
|
|||
export const postTransactions = (req, res, next) => {
|
||||
const { amount, address, fees, blocks, sendAll } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Transactions', msg: 'Sending Transaction..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -37,7 +38,8 @@ export const postTransactions = (req, res, next) => {
|
|||
options.form.send_all = sendAll;
|
||||
}
|
||||
options.form = JSON.stringify(options.form);
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Transactions', msg: 'Transaction Sent', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import atob from 'atob';
|
||||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,7 +7,7 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const genSeed = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Generating Seed..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -17,7 +17,8 @@ export const genSeed = (req, res, next) => {
|
|||
else {
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/genseed';
|
||||
}
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Seed Generated', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -28,7 +29,7 @@ export const genSeed = (req, res, next) => {
|
|||
export const operateWallet = (req, res, next) => {
|
||||
const { wallet_password, aezeed_passphrase, cipher_seed_mnemonic } = req.body;
|
||||
let err_message = '';
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -59,7 +60,8 @@ export const operateWallet = (req, res, next) => {
|
|||
}
|
||||
err_message = 'Initializing wallet failed!';
|
||||
}
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
const body_str = (!body) ? '' : JSON.stringify(body);
|
||||
const search_idx = (!body) ? -1 : body_str.search('Not Found');
|
||||
if (!body) {
|
||||
|
|
@ -95,12 +97,12 @@ export const operateWallet = (req, res, next) => {
|
|||
});
|
||||
};
|
||||
export const updateSelNodeOptions = (req, res, next) => {
|
||||
const response = common.updateSelectedNodeOptions(req);
|
||||
const response = common.updateSelectedNodeAxiosConfig(req);
|
||||
res.status(response.status).json({ updateMessage: response.message });
|
||||
};
|
||||
export const getUTXOs = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Getting UTXOs..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -111,7 +113,8 @@ export const getUTXOs = (req, res, next) => {
|
|||
else {
|
||||
options.url = options.url + '?max_confs=' + req.query.max_confs;
|
||||
}
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'UTXOs List Received', data: body });
|
||||
res.status(200).json(body.utxos ? body.utxos : []);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -122,7 +125,7 @@ export const getUTXOs = (req, res, next) => {
|
|||
export const bumpFee = (req, res, next) => {
|
||||
const { txid, outputIndex, targetConf, satPerByte } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Bumping Fee..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -139,7 +142,8 @@ export const bumpFee = (req, res, next) => {
|
|||
options.form.sat_per_byte = satPerByte;
|
||||
}
|
||||
options.form = JSON.stringify(options.form);
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Fee Bumped', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -149,14 +153,15 @@ export const bumpFee = (req, res, next) => {
|
|||
};
|
||||
export const labelTransaction = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Labelling Transaction..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/wallet/tx/label';
|
||||
options.form = JSON.stringify(req.body);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Wallet', msg: 'Label Transaction Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Transaction Labelled', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -167,7 +172,7 @@ export const labelTransaction = (req, res, next) => {
|
|||
export const leaseUTXO = (req, res, next) => {
|
||||
const { txid, outputIndex } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Leasing UTXO..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -180,7 +185,8 @@ export const leaseUTXO = (req, res, next) => {
|
|||
};
|
||||
options.form = JSON.stringify(options.form);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Wallet', msg: 'UTXO Lease Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'UTXO Leased', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -191,7 +197,7 @@ export const leaseUTXO = (req, res, next) => {
|
|||
export const releaseUTXO = (req, res, next) => {
|
||||
const { txid, outputIndex } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Releasing UTXO..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) {
|
||||
return res.status(options.statusCode).json({ message: options.message, error: options.error });
|
||||
}
|
||||
|
|
@ -203,7 +209,8 @@ export const releaseUTXO = (req, res, next) => {
|
|||
output_index: outputIndex
|
||||
};
|
||||
options.form = JSON.stringify(options.form);
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'UTXO Released', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import request from 'request-promise';
|
||||
import axios, { AxiosHeaders } from 'axios';
|
||||
import https from 'https';
|
||||
import * as fs from 'fs';
|
||||
import { join } from 'path';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
|
|
@ -24,9 +25,9 @@ export class LNDWebSocketClient {
|
|||
};
|
||||
this.fetchUnpaidInvoices = (selectedNode) => {
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Getting Unpaid Invoices..' });
|
||||
const options = this.setOptionsForSelNode(selectedNode);
|
||||
options.url = selectedNode.settings.lnServerUrl + '/v1/invoices?pending_only=true';
|
||||
return request(options).then((body) => {
|
||||
const options = this.setAxiosConfigForSelNode(selectedNode);
|
||||
return axios(selectedNode.settings.lnServerUrl + '/v1/invoices?pending_only=true', options).then((body) => {
|
||||
body = body.data;
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Unpaid Invoices Received', data: body });
|
||||
if (body.invoices && body.invoices.length > 0) {
|
||||
body.invoices.forEach((invoice) => {
|
||||
|
|
@ -45,7 +46,8 @@ export class LNDWebSocketClient {
|
|||
rHash = rHash?.replace(/\+/g, '-')?.replace(/[/]/g, '_');
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Subscribing to Invoice ' + rHash + ' ..' });
|
||||
options.url = selectedNode.settings.lnServerUrl + '/v2/invoices/subscribe/' + rHash;
|
||||
request(options).then((msg) => {
|
||||
axios(options).then((msg) => {
|
||||
msg = msg.data;
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Invoice Information Received for ' + rHash });
|
||||
if (typeof msg === 'string') {
|
||||
const results = msg.split('\n');
|
||||
|
|
@ -68,7 +70,8 @@ export class LNDWebSocketClient {
|
|||
this.subscribeToPayment = (options, selectedNode, paymentHash) => {
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Subscribing to Payment ' + paymentHash + ' ..' });
|
||||
options.url = selectedNode.settings.lnServerUrl + '/v2/router/track/' + paymentHash;
|
||||
request(options).then((msg) => {
|
||||
axios(options).then((msg) => {
|
||||
msg = msg.data;
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Payment Information Received for ' + paymentHash });
|
||||
msg['type'] = 'payment';
|
||||
msg['source'] = 'LND';
|
||||
|
|
@ -81,10 +84,16 @@ export class LNDWebSocketClient {
|
|||
this.wsServer.sendErrorToAllLNClients(errStr, selectedNode);
|
||||
});
|
||||
};
|
||||
this.setOptionsForSelNode = (selectedNode) => {
|
||||
const options = { url: '', rejectUnauthorized: false, json: true, form: null };
|
||||
this.setAxiosConfigForSelNode = (selectedNode) => {
|
||||
const headers = new AxiosHeaders();
|
||||
const options = {
|
||||
baseURL: selectedNode.settings.lnServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
try {
|
||||
options['headers'] = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(selectedNode.authentication.macaroonPath, 'admin.macaroon')).toString('hex') };
|
||||
options['headers'] = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(selectedNode.authentication.macaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
}
|
||||
catch (err) {
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'ERROR', fileName: 'WebSocketClient', msg: 'Set Options Error', error: JSON.stringify(err) });
|
||||
|
|
@ -105,7 +114,7 @@ export class LNDWebSocketClient {
|
|||
if (!newClient) {
|
||||
newClient = { selectedNode: null };
|
||||
}
|
||||
newClient.selectedNode = JSON.parse(JSON.stringify(newSelectedNode));
|
||||
newClient.selectedNode = newSelectedNode;
|
||||
this.webSocketClients[clientIdx] = newClient;
|
||||
if (this.webSocketClients[clientIdx].selectedNode.lnVersion === '' || !this.webSocketClients[clientIdx].selectedNode.lnVersion || this.common.isVersionCompatible(this.webSocketClients[clientIdx].selectedNode.lnVersion, '0.11.0')) {
|
||||
this.fetchUnpaidInvoices(this.webSocketClients[clientIdx].selectedNode);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as fs from 'fs';
|
|||
import { sep } from 'path';
|
||||
import ini from 'ini';
|
||||
import parseHocon from 'hocon-parser';
|
||||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Database } from '../../utils/database.js';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
|
|
@ -23,14 +23,16 @@ export const getExplorerFeesRecommended = (req, res, next) => {
|
|||
options.url = (blockExplorerUrl === '') ?
|
||||
req.session.selectedNode.settings.blockExplorerUrl + '/api/v1/fees/recommended' :
|
||||
blockExplorerUrl + '/api/v1/fees/recommended';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
blockExplorerUrl = req.session.selectedNode.settings.blockExplorerUrl;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Recommended Fee Rates Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
blockExplorerUrl = 'https://mempool.space';
|
||||
options.url = blockExplorerUrl + '/api/v1/fees/recommended';
|
||||
return request(options).then((body) => {
|
||||
return axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Recommended Fee Rates Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -45,14 +47,16 @@ export const getExplorerTransaction = (req, res, next) => {
|
|||
options.url = (blockExplorerUrl === '') ?
|
||||
req.session.selectedNode.settings.blockExplorerUrl + '/api/tx/' + req.params.txid :
|
||||
blockExplorerUrl + '/api/tx/' + req.params.txid;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
blockExplorerUrl = req.session.selectedNode.settings.blockExplorerUrl;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Transaction From Block Explorer Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
blockExplorerUrl = 'https://mempool.space';
|
||||
options.url = blockExplorerUrl + '/api/tx/' + req.params.txid;
|
||||
return request(options).then((body) => {
|
||||
return axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Transaction From Block Explorer Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -65,7 +69,8 @@ export const getExplorerTransaction = (req, res, next) => {
|
|||
export const getCurrencyRates = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting Currency Rates..' });
|
||||
options.url = 'https://blockchain.info/ticker';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Currency Rates Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -6,14 +6,15 @@ const logger = Logger;
|
|||
const common = Common;
|
||||
export const getInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Getting Boltz Information..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Get Info Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/info';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -23,14 +24,15 @@ export const getInfo = (req, res, next) => {
|
|||
};
|
||||
export const getServiceInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Getting Service Information..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Get Service Information Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/serviceinfo';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Get Service Info Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -40,14 +42,15 @@ export const getServiceInfo = (req, res, next) => {
|
|||
};
|
||||
export const listSwaps = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Getting List Swaps..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'List Swaps Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/listswaps';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz List Swaps Received', data: body });
|
||||
if (body && body.swaps && body.swaps.length && body.swaps.length > 0) {
|
||||
body.swaps = body.swaps.reverse();
|
||||
|
|
@ -63,14 +66,15 @@ export const listSwaps = (req, res, next) => {
|
|||
};
|
||||
export const getSwapInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Getting Swap Information..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Get Swap Information Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/swap/' + req.params.swapId;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Swap Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -81,7 +85,7 @@ export const getSwapInfo = (req, res, next) => {
|
|||
export const createSwap = (req, res, next) => {
|
||||
const { amount, sendFromInternal, address, refundAddress } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Creating Swap..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Create Swap Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
|
|
@ -96,7 +100,8 @@ export const createSwap = (req, res, next) => {
|
|||
options.body.address = address;
|
||||
}
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Boltz', msg: 'Create Swap Options Body', data: options.body });
|
||||
request.post(options).then((createSwapRes) => {
|
||||
axios.post(options).then((createSwapRes) => {
|
||||
createSwapRes = createSwapRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Swap Created', data: createSwapRes });
|
||||
res.status(201).json(createSwapRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -107,7 +112,7 @@ export const createSwap = (req, res, next) => {
|
|||
export const createReverseSwap = (req, res, next) => {
|
||||
const { amount, acceptZeroConf, address } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Creating Reverse Swap..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Create Reverse Swap Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
|
|
@ -119,7 +124,8 @@ export const createReverseSwap = (req, res, next) => {
|
|||
options.body.address = address;
|
||||
}
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Boltz', msg: 'Create Reverse Swap Body', data: options.body });
|
||||
request.post(options).then((createReverseSwapRes) => {
|
||||
axios.post(options).then((createReverseSwapRes) => {
|
||||
createReverseSwapRes = createReverseSwapRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Reverse Swap Created', data: createReverseSwapRes });
|
||||
res.status(201).json(createReverseSwapRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -130,7 +136,7 @@ export const createReverseSwap = (req, res, next) => {
|
|||
export const createChannel = (req, res, next) => {
|
||||
const { amount, address } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Creating Boltz Channel..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Create Channel Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
|
|
@ -142,7 +148,8 @@ export const createChannel = (req, res, next) => {
|
|||
options.body.address = address;
|
||||
}
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Boltz', msg: 'Create Channel Options Body', data: options.body });
|
||||
request.post(options).then((createChannelRes) => {
|
||||
axios.post(options).then((createChannelRes) => {
|
||||
createChannelRes = createChannelRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Channel Created', data: createChannelRes });
|
||||
res.status(201).json(createChannelRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -152,14 +159,15 @@ export const createChannel = (req, res, next) => {
|
|||
};
|
||||
export const deposit = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Deposit Start..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Deposit Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/deposit';
|
||||
request.post(options).then((depositRes) => {
|
||||
axios.post(options).then((depositRes) => {
|
||||
depositRes = depositRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Deposit Finished', data: depositRes });
|
||||
res.status(201).json(depositRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger } from '../../utils/logger.js';
|
||||
import { Common } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -26,7 +26,8 @@ export const loopOut = (req, res, next) => {
|
|||
options.body['dest'] = destAddress;
|
||||
}
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Body', data: options.body });
|
||||
request.post(options).then((loopOutRes) => {
|
||||
axios.post(options).then((loopOutRes) => {
|
||||
loopOutRes = loopOutRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looped Out', data: loopOutRes });
|
||||
res.status(201).json(loopOutRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -37,7 +38,8 @@ 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.uri = '/v1/loop/out/terms';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Out Terms Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -49,7 +51,8 @@ export const loopOutQuote = (req, res, next) => {
|
|||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Quotes..' });
|
||||
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) => {
|
||||
axios(options).then((quoteRes) => {
|
||||
quoteRes = quoteRes.data;
|
||||
quoteRes.amount = +req.params.amount;
|
||||
quoteRes.swap_payment_dest = quoteRes.swap_payment_dest ? Buffer.from(quoteRes.swap_payment_dest, 'base64').toString('hex') : '';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Out Quote Received', data: quoteRes });
|
||||
|
|
@ -62,7 +65,8 @@ 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.uri = '/v1/loop/out/terms';
|
||||
request(options).then((terms) => {
|
||||
axios(options).then((terms) => {
|
||||
terms = terms.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Terms Received', data: terms });
|
||||
const options1 = options;
|
||||
const options2 = options;
|
||||
|
|
@ -70,7 +74,9 @@ export const loopOutTermsAndQuotes = (req, res, next) => {
|
|||
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) => {
|
||||
return Promise.all([axios(options1), axios(options2)]).then((values) => {
|
||||
values[0] = values[0].data;
|
||||
values[1] = values[1].data;
|
||||
values[0].amount = +terms.min_swap_amount;
|
||||
values[1].amount = +terms.max_swap_amount;
|
||||
values[0].swap_payment_dest = values[0].swap_payment_dest ? Buffer.from(values[0].swap_payment_dest, 'base64').toString('hex') : '';
|
||||
|
|
@ -98,7 +104,8 @@ export const loopIn = (req, res, next) => {
|
|||
initiator: 'RTL'
|
||||
};
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Body', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looped In', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -109,7 +116,8 @@ 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.uri = '/v1/loop/in/terms';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Terms Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -121,7 +129,8 @@ export const loopInQuote = (req, res, next) => {
|
|||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Quotes..' });
|
||||
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) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
body.amount = +req.params.amount;
|
||||
body.swap_payment_dest = body.swap_payment_dest ? Buffer.from(body.swap_payment_dest, 'base64').toString('hex') : '';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Qoutes Received', data: body });
|
||||
|
|
@ -134,7 +143,7 @@ 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.uri = '/v1/loop/in/terms';
|
||||
request(options).then((terms) => {
|
||||
axios(options).then((terms) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Terms Received', data: terms });
|
||||
const options1 = options;
|
||||
const options2 = options;
|
||||
|
|
@ -142,7 +151,9 @@ export const loopInTermsAndQuotes = (req, res, next) => {
|
|||
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) => {
|
||||
return Promise.all([axios(options1), axios(options2)]).then((values) => {
|
||||
values[0] = values[0].data;
|
||||
values[1] = values[1].data;
|
||||
values[0].amount = +terms.min_swap_amount;
|
||||
values[1].amount = +terms.max_swap_amount;
|
||||
values[0].swap_payment_dest = values[0].swap_payment_dest ? Buffer.from(values[0].swap_payment_dest, 'base64').toString('hex') : '';
|
||||
|
|
@ -167,7 +178,8 @@ export const swaps = (req, res, next) => {
|
|||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.uri = '/v1/loop/swaps';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Swaps Received', data: body });
|
||||
res.status(200).json(body.swaps);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -178,7 +190,8 @@ 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.uri = '/v1/loop/swap/' + req.params.id;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Swap Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -188,14 +201,15 @@ export const swap = (req, res, next) => {
|
|||
};
|
||||
export const loopInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Information..' });
|
||||
options = common.setSwapServerOptions(req);
|
||||
options = common.getSwapServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Loop Server URL is missing in the configuration.';
|
||||
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.uri = '/v1/loop/info';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -27,8 +27,7 @@ export class Settings {
|
|||
}
|
||||
}
|
||||
export class Authentication {
|
||||
constructor(options, configPath, macaroonPath, macaroonValue, runePath, runeValue, lnApiPassword, swapMacaroonPath, boltzMacaroonPath) {
|
||||
this.options = options;
|
||||
constructor(configPath, macaroonPath, macaroonValue, runePath, runeValue, lnApiPassword, swapMacaroonPath, boltzMacaroonPath) {
|
||||
this.configPath = configPath;
|
||||
this.macaroonPath = macaroonPath;
|
||||
this.macaroonValue = macaroonValue;
|
||||
|
|
@ -56,7 +55,7 @@ export class ApplicationConfig {
|
|||
}
|
||||
}
|
||||
export class SelectedNode {
|
||||
constructor(logLevel, logFile, index, lnNode, lnImplementation, lnVersion, settings, authentication) {
|
||||
constructor(logLevel, logFile, index, lnNode, lnImplementation, lnVersion, settings, authentication, axiosConfig) {
|
||||
this.logLevel = logLevel;
|
||||
this.logFile = logFile;
|
||||
this.index = index;
|
||||
|
|
@ -65,6 +64,7 @@ export class SelectedNode {
|
|||
this.lnVersion = lnVersion;
|
||||
this.settings = settings;
|
||||
this.authentication = authentication;
|
||||
this.axiosConfig = axiosConfig;
|
||||
}
|
||||
}
|
||||
export class LogJSONObj {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import * as fs from 'fs';
|
|||
import { join, dirname, isAbsolute, resolve, sep } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import * as crypto from 'crypto';
|
||||
import request from 'request-promise';
|
||||
import axios, { AxiosHeaders } from 'axios';
|
||||
import https from 'https';
|
||||
import { Logger } from './logger.js';
|
||||
export class CommonService {
|
||||
constructor() {
|
||||
|
|
@ -41,11 +42,8 @@ export class CommonService {
|
|||
};
|
||||
this.removeAuthSecureData = (node) => {
|
||||
if (node.authentication) {
|
||||
delete node.authentication.macaroonPath;
|
||||
delete node.authentication.runePath;
|
||||
delete node.authentication.runeValue;
|
||||
delete node.authentication.lnApiPassword;
|
||||
delete node.authentication.options;
|
||||
const { configPath } = node.authentication;
|
||||
node.authentication = { configPath };
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
|
@ -85,62 +83,54 @@ export class CommonService {
|
|||
});
|
||||
return config;
|
||||
};
|
||||
this.setSwapServerOptions = (req) => {
|
||||
const swapOptions = {
|
||||
baseUrl: req.session.selectedNode.settings.swapServerUrl,
|
||||
uri: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: { 'Grpc-Metadata-macaroon': '' }
|
||||
this.getSwapServerConfig = (req) => {
|
||||
const headers = new AxiosHeaders();
|
||||
const swapConfig = {
|
||||
baseURL: req.session.selectedNode.settings.swapServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
if (req.session.selectedNode.authentication.swapMacaroonPath) {
|
||||
try {
|
||||
swapOptions.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(req.session.selectedNode.authentication.swapMacaroonPath, 'loop.macaroon')).toString('hex') };
|
||||
swapConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(req.session.selectedNode.authentication.swapMacaroonPath, 'loop.macaroon')).toString('hex'));
|
||||
}
|
||||
catch (err) {
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Loop macaroon Error', error: err });
|
||||
}
|
||||
}
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Swap Options', data: swapOptions });
|
||||
return swapOptions;
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Swap Axios Config', data: swapConfig });
|
||||
return swapConfig;
|
||||
};
|
||||
this.getBoltzServerOptions = (req) => {
|
||||
const boltzOptions = {
|
||||
url: req.session.selectedNode.settings.boltzServerUrl,
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: { 'Grpc-Metadata-macaroon': '' }
|
||||
this.getBoltzServerConfig = (req) => {
|
||||
const headers = new AxiosHeaders();
|
||||
const boltzConfig = {
|
||||
baseURL: req.session.selectedNode.settings.swapServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
if (req.session.selectedNode.authentication.boltzMacaroonPath) {
|
||||
try {
|
||||
boltzOptions.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(req.session.selectedNode.authentication.boltzMacaroonPath, 'admin.macaroon')).toString('hex') };
|
||||
boltzConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(req.session.selectedNode.authentication.boltzMacaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
}
|
||||
catch (err) {
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Boltz macaroon Error', error: err });
|
||||
}
|
||||
}
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Boltz Options', data: boltzOptions });
|
||||
return boltzOptions;
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Boltz Axios Config', data: boltzConfig });
|
||||
return boltzConfig;
|
||||
};
|
||||
this.getOptions = (req) => {
|
||||
if (req.session.selectedNode && req.session.selectedNode.authentication.options) {
|
||||
req.session.selectedNode.authentication.options.method = (req.session.selectedNode.lnImplementation && req.session.selectedNode.lnImplementation.toUpperCase() === 'LND') ? 'GET' : 'POST';
|
||||
delete req.session.selectedNode.authentication.options.form;
|
||||
delete req.session.selectedNode.authentication.options.body;
|
||||
req.session.selectedNode.authentication.options.qs = {};
|
||||
return req.session.selectedNode.authentication.options;
|
||||
}
|
||||
return this.handleError({ statusCode: 401, message: 'Session expired after a day\'s inactivity' }, 'Session Expired', 'Session Expiry Error', this.selectedNode);
|
||||
};
|
||||
this.updateSelectedNodeOptions = (req) => {
|
||||
this.updateSelectedNodeAxiosConfig = (req) => {
|
||||
if (!req.session.selectedNode) {
|
||||
req.session.selectedNode = {};
|
||||
}
|
||||
req.session.selectedNode.authentication.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
form: null
|
||||
const headers = new AxiosHeaders();
|
||||
req.session.selectedNode.axiosConfig = {
|
||||
baseURL: '',
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
try {
|
||||
if (req.session.selectedNode && req.session.selectedNode.lnImplementation) {
|
||||
|
|
@ -150,31 +140,31 @@ export class CommonService {
|
|||
if (!req.session.selectedNode.authentication.runeValue) {
|
||||
req.session.selectedNode.authentication.runeValue = this.getRuneValue(req.session.selectedNode.authentication.runePath);
|
||||
}
|
||||
req.session.selectedNode.authentication.options.headers = { rune: req.session.selectedNode.authentication.runeValue };
|
||||
req.session.selectedNode.axiosConfig.headers = headers.set('rune', req.session.selectedNode.authentication.runeValue);
|
||||
}
|
||||
catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
break;
|
||||
case 'ECL':
|
||||
req.session.selectedNode.authentication.options.headers = { authorization: 'Basic ' + Buffer.from(':' + req.session.selectedNode.authentication.lnApiPassword).toString('base64') };
|
||||
req.session.selectedNode.axiosConfig.headers = headers.set('authorization', 'Basic ' + Buffer.from(':' + req.session.selectedNode.authentication.lnApiPassword).toString('base64'));
|
||||
break;
|
||||
default:
|
||||
req.session.selectedNode.authentication.options.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(req.session.selectedNode.authentication.macaroonPath, 'admin.macaroon')).toString('hex') };
|
||||
req.session.selectedNode.axiosConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(req.session.selectedNode.authentication.macaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (req.session.selectedNode) {
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Updated Node Options for ' + req.session.selectedNode.lnNode, data: req.session.selectedNode.authentication.options });
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Updated Node Options for ' + req.session.selectedNode.lnNode, data: req.session.selectedNode.axiosConfig });
|
||||
}
|
||||
return { status: 200, message: 'Updated Successfully' };
|
||||
}
|
||||
catch (err) {
|
||||
req.session.selectedNode.authentication.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
form: null
|
||||
req.session.selectedNode.axiosConfig = {
|
||||
baseURL: '',
|
||||
headers: new AxiosHeaders(),
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Update Selected Node Options Error', error: err });
|
||||
return { status: 502, message: err };
|
||||
|
|
@ -191,17 +181,52 @@ export class CommonService {
|
|||
throw new Error('Rune not found in the file.');
|
||||
}
|
||||
};
|
||||
this.setOptions = (req) => {
|
||||
if (this.nodes[0].authentication.options && this.nodes[0].authentication.options.headers) {
|
||||
this.getAxiosConfig = (req) => {
|
||||
if (!req.session.selectedNode) {
|
||||
return this.handleError({ statusCode: 401, message: 'Session expired after a day\'s inactivity' }, 'Session Expired', 'Session Expiry Error', this.selectedNode);
|
||||
}
|
||||
return this.generateAxiosConfig(req.session.selectedNode);
|
||||
};
|
||||
this.generateAxiosConfig = (node) => {
|
||||
const headers = new AxiosHeaders();
|
||||
const axiosConfig = {
|
||||
baseURL: node.settings.lnServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
try {
|
||||
if (node.lnImplementation) {
|
||||
switch (node.lnImplementation.toUpperCase()) {
|
||||
case 'CLN':
|
||||
axiosConfig.headers = headers.set('rune', node.authentication.runeValue);
|
||||
break;
|
||||
case 'ECL':
|
||||
axiosConfig.headers = headers.set('authorization', 'Basic ' + Buffer.from(':' + node.authentication.lnApiPassword).toString('base64'));
|
||||
break;
|
||||
default:
|
||||
axiosConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(node.authentication.macaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return axiosConfig;
|
||||
}
|
||||
catch (err) {
|
||||
return this.handleError({ statusCode: 502, message: err.message }, 'Common', 'Config Generation Error', node);
|
||||
}
|
||||
};
|
||||
this.setAxiosConfig = (req) => {
|
||||
if (this.nodes[0].axiosConfig && this.nodes[0].axiosConfig.headers) {
|
||||
return;
|
||||
}
|
||||
if (this.nodes && this.nodes.length > 0) {
|
||||
this.nodes.forEach((node) => {
|
||||
node.authentication.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
form: null
|
||||
const headers = new AxiosHeaders();
|
||||
node.axiosConfig = {
|
||||
baseURL: node.settings.lnServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
try {
|
||||
if (node.lnImplementation) {
|
||||
|
|
@ -211,33 +236,33 @@ export class CommonService {
|
|||
if (!node.authentication.runeValue) {
|
||||
node.authentication.runeValue = this.getRuneValue(node.authentication.runePath);
|
||||
}
|
||||
node.authentication.options.headers = { rune: node.authentication.runeValue };
|
||||
node.axiosConfig.headers = headers.set('rune', node.authentication.runeValue);
|
||||
}
|
||||
catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
break;
|
||||
case 'ECL':
|
||||
node.authentication.options.headers = { authorization: 'Basic ' + Buffer.from(':' + node.authentication.lnApiPassword).toString('base64') };
|
||||
node.axiosConfig.headers = headers.set('authorization', 'Basic ' + Buffer.from(':' + node.authentication.lnApiPassword).toString('base64'));
|
||||
break;
|
||||
default:
|
||||
node.authentication.options.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(node.authentication.macaroonPath, 'admin.macaroon')).toString('hex') };
|
||||
node.axiosConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(node.authentication.macaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Common Set Options Error', error: err });
|
||||
node.authentication.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
form: ''
|
||||
node.axiosConfig = {
|
||||
baseURL: '',
|
||||
headers: new AxiosHeaders(),
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
}
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Set Node Options for ' + node.lnNode, data: node.authentication.options });
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Set Node Options for ' + node.lnNode, data: node.axiosConfig });
|
||||
});
|
||||
this.updateSelectedNodeOptions(req);
|
||||
this.updateSelectedNodeAxiosConfig(req);
|
||||
}
|
||||
};
|
||||
this.findNode = (selNodeIndex) => this.nodes.find((node) => node.index === selNodeIndex);
|
||||
|
|
@ -305,7 +330,26 @@ export class CommonService {
|
|||
}
|
||||
};
|
||||
this.handleError = (errRes, fileName, errMsg, selectedNode) => {
|
||||
const err = JSON.parse(JSON.stringify(errRes));
|
||||
let err;
|
||||
if (errRes.isAxiosError || errRes.response) {
|
||||
err = {
|
||||
statusCode: errRes.response?.status || 500,
|
||||
message: errRes.message,
|
||||
error: errRes.response?.data || errRes.message,
|
||||
options: errRes.config ? {
|
||||
headers: errRes.config.headers,
|
||||
url: errRes.config.url
|
||||
} : {},
|
||||
response: errRes.response ? {
|
||||
request: {
|
||||
headers: errRes.response.config?.headers
|
||||
}
|
||||
} : {}
|
||||
};
|
||||
}
|
||||
else {
|
||||
err = JSON.parse(JSON.stringify(errRes));
|
||||
}
|
||||
if (!selectedNode) {
|
||||
selectedNode = this.selectedNode;
|
||||
}
|
||||
|
|
@ -469,14 +513,16 @@ export class CommonService {
|
|||
};
|
||||
this.getAllNodeAllChannelBackup = (node) => {
|
||||
const channel_backup_file = node.settings.channelBackupPath + sep + 'channel-all.bak';
|
||||
const headers = new AxiosHeaders();
|
||||
const options = {
|
||||
url: node.settings.lnServerUrl + '/v1/channels/backup',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: { 'Grpc-Metadata-macaroon': fs.readFileSync(node.authentication.macaroonPath + '/admin.macaroon').toString('hex') }
|
||||
baseURL: node.settings.lnServerUrl,
|
||||
headers: headers.set('Grpc-Metadata-macaroon', fs.readFileSync(node.authentication.macaroonPath + '/admin.macaroon').toString('hex')),
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Getting Channel Backup for Node ' + node.lnNode + '..' });
|
||||
request(options).then((body) => {
|
||||
axios('/v1/channels/backup', options).then((body) => {
|
||||
body = body.data;
|
||||
fs.writeFile(channel_backup_file, JSON.stringify(body), (err) => {
|
||||
if (err) {
|
||||
if (node.lnNode) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { getAlias } from './network.js';
|
||||
|
|
@ -9,10 +9,11 @@ const common: CommonService = Common;
|
|||
|
||||
export const listPeerChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Peer Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listpeerchannels';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Peer Channels List Received', data: body.channels });
|
||||
const getPeerAliasesTasks = body.channels.map((channel) => () => {
|
||||
channel.to_them_msat = channel.total_msat - channel.to_us_msat;
|
||||
|
|
@ -31,12 +32,13 @@ export const listPeerChannels = (req, res, next) => {
|
|||
|
||||
export const openChannel = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Opening Channel..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/fundchannel';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Open Channel Options', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Opened', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -47,12 +49,13 @@ export const openChannel = (req, res, next) => {
|
|||
|
||||
export const setChannelFee = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Setting Channel Fee..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/setchannel';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Update Channel Policy Options', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Updated Channel Policy', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -64,12 +67,13 @@ export const setChannelFee = (req, res, next) => {
|
|||
export const closeChannel = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Closing Channel..' });
|
||||
req.setTimeout(60000 * 10); // timeout 10 mins
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/close';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Closing Channel', data: options.url });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Closed', data: body });
|
||||
res.status(204).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -81,11 +85,12 @@ export const closeChannel = (req, res, next) => {
|
|||
export const listForwards = (req, res, next) => {
|
||||
const { status } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Channel List Forwards..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listforwards';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Forwarding History Received For Status ' + status, data: body });
|
||||
body.forwards = !body.forwards ? [] : (status === 'failed' || status === 'local_failed') ? body.forwards.slice(Math.max(0, body.forwards.length - 1000), Math.max(1000, body.forwards.length)).reverse() : body.forwards.reverse();
|
||||
res.status(200).json(body.forwards);
|
||||
|
|
@ -97,12 +102,13 @@ export const listForwards = (req, res, next) => {
|
|||
|
||||
export const funderUpdatePolicy = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting or Updating Funder Policy..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/funderupdate';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Funder Update Body', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Funder Policy Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { CLWSClient, CLWebSocketClient } from './webSocketClient.js';
|
||||
|
||||
let options = null;
|
||||
const logger: LoggerService = Logger;
|
||||
const common: CommonService = Common;
|
||||
const clWsClient: CLWebSocketClient = CLWSClient;
|
||||
|
|
@ -11,18 +10,22 @@ const clWsClient: CLWebSocketClient = CLWSClient;
|
|||
export const getInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Getting Core Lightning Node Information..' });
|
||||
common.logEnvVariables(req);
|
||||
common.setOptions(req);
|
||||
options = common.getOptions(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/getinfo';
|
||||
common.setAxiosConfig(req);
|
||||
const axiosConfig: any = common.getAxiosConfig(req);
|
||||
const url = req.session.selectedNode.settings.lnServerUrl + '/v1/getinfo';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Selected Node ' + req.session.selectedNode.lnNode });
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Calling Info from Core Lightning server url ' + options.url });
|
||||
if (!options.headers || !options.headers.rune) {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Calling Info from Core Lightning server url ' + url });
|
||||
if (!axiosConfig.headers || !axiosConfig.headers?.rune) {
|
||||
const errMsg = 'Core lightning get info failed due to missing rune!';
|
||||
const err = common.handleError({ statusCode: 502, message: 'Bad rune', error: errMsg }, 'GetInfo', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
} else {
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(url, null, axiosConfig).then((body: any) => {
|
||||
body = body.data;
|
||||
body = body.data;
|
||||
body = body.data;
|
||||
body = body.data;
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'GetInfo', msg: 'Node Information Before Update', data: body });
|
||||
body.lnImplementation = 'Core Lightning';
|
||||
const chainObj = { chain: '', network: '' };
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,11 +7,12 @@ const common: CommonService = Common;
|
|||
|
||||
export const deleteExpiredInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Deleting Expired Invoices..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/autoclean-once';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoices Deleted', data: body });
|
||||
res.status(201).json({ status: 'Cleaned Invoices: ' + body.autoclean.expiredinvoices.cleaned + ', Uncleaned Invoices: ' + body.autoclean.expiredinvoices.uncleaned });
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -22,12 +23,13 @@ export const deleteExpiredInvoice = (req, res, next) => {
|
|||
|
||||
export const listInvoices = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Getting Invoices..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listinvoices';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List URL', data: options.url });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -38,11 +40,12 @@ export const listInvoices = (req, res, next) => {
|
|||
|
||||
export const addInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoice';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Created', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -10,11 +10,12 @@ const aliasCache = new Map<string, string>();
|
|||
|
||||
export const getRoute = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Getting Network Routes..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/getroute';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Network Routes Received', data: body });
|
||||
return Promise.all(body.route?.map((rt) => getAlias(req.session.selectedNode, rt, 'id'))).then((values) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Network Routes with Alias Received', data: body });
|
||||
|
|
@ -28,11 +29,12 @@ export const getRoute = (req, res, next) => {
|
|||
|
||||
export const listChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Channel Lookup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listchannels';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Channel Lookup Finished', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -44,11 +46,12 @@ export const listChannels = (req, res, next) => {
|
|||
export const feeRates = (req, res, next) => {
|
||||
const { style } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Getting Network Fee Rates..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/feerates';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Network Fee Rates Received for ' + style, data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -61,12 +64,13 @@ export const listNodes = (req, res, next) => {
|
|||
const filter_liquidity_ads = !!req.body.liquidity_ads;
|
||||
delete req.body.liquidity_ads;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'List Nodes..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listnodes';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Network', msg: 'List Nodes URL' + options.url });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'List Nodes Finished', data: body });
|
||||
let response = body.nodes;
|
||||
if (filter_liquidity_ads) {
|
||||
|
|
@ -95,7 +99,8 @@ export const getAlias = (selNode: SelectedNode, peer: any, id: string) => {
|
|||
options.url = selNode.settings.lnServerUrl + '/v1/listnodes';
|
||||
options.body = { id: peerId };
|
||||
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Network', msg: 'Peer Alias Finished', data: body });
|
||||
const alias = body.nodes?.[0]?.alias || peerId.substring(0, 20);
|
||||
aliasCache.set(peerId, alias);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { Database, DatabaseService } from '../../utils/database.js';
|
||||
|
|
@ -12,6 +12,7 @@ const databaseService: DatabaseService = Database;
|
|||
export const listOfferBookmarks = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Getting Offer Bookmarks..' });
|
||||
databaseService.find(req.session.selectedNode, CollectionsEnum.OFFERS).then((offers: any) => {
|
||||
offers = offers.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offer Bookmarks Received', data: offers });
|
||||
res.status(200).json(offers);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -34,11 +35,12 @@ export const deleteOfferBookmark = (req, res, next) => {
|
|||
|
||||
export const listOffers = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Getting Offers..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listoffers';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Offers', msg: 'Offers List URL', data: options.url });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offers List Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -49,11 +51,12 @@ export const listOffers = (req, res, next) => {
|
|||
|
||||
export const createOffer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Creating Offer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/offer';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offer Created', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -64,12 +67,13 @@ export const createOffer = (req, res, next) => {
|
|||
|
||||
export const fetchOfferInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Getting Offer Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/fetchinvoice';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Offers', msg: 'Offer Invoice Body', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offer Invoice Received', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -80,11 +84,12 @@ export const fetchOfferInvoice = (req, res, next) => {
|
|||
|
||||
export const disableOffer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Disabling Offer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/disableoffer';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Offers', msg: 'Offer Disabled', data: body });
|
||||
res.status(202).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,11 +7,12 @@ const common: CommonService = Common;
|
|||
|
||||
export const getNewAddress = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Generating New Address..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/newaddr';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'New Address Generated', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -22,12 +23,13 @@ export const getNewAddress = (req, res, next) => {
|
|||
|
||||
export const onChainWithdraw = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Withdrawing from On Chain..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/withdraw';
|
||||
options.body = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'OnChain', msg: 'OnChain Withdraw Options', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Withdraw Finished', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -38,10 +40,11 @@ export const onChainWithdraw = (req, res, next) => {
|
|||
|
||||
export const getUTXOs = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Listing Funds..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listfunds';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Funds List Received', data: body });
|
||||
// Local Remote Balance Calculation
|
||||
let lrBalance = { localBalance: 0, remoteBalance: 0, inactiveBalance: 0, pendingBalance: 0 };
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { Database, DatabaseService } from '../../utils/database.js';
|
||||
|
|
@ -13,7 +13,8 @@ const databaseService: DatabaseService = Database;
|
|||
export const getMemo = (selNode: SelectedNode, payment: any) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/decode';
|
||||
options.body = { string: payment.bolt11 };
|
||||
return request.post(options).then((res) => {
|
||||
return axios.post(options).then((res: any) => {
|
||||
res = res.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Payments', msg: 'Payment Decode Received', data: res });
|
||||
payment.memo = res.description || '';
|
||||
return payment;
|
||||
|
|
@ -72,10 +73,11 @@ function groupBy(payments) {
|
|||
|
||||
export const listPayments = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'List Payments..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listsendpays';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Payment List Received', data: body.payments });
|
||||
body.payments = body.payments && body.payments.length && body.payments.length > 0 ? groupBy(body.payments) : [];
|
||||
return Promise.all(body.payments?.map((payment) => ((payment.bolt11) ? getMemo(req.session.selectedNode, payment) : (payment.memo = '')))).then((values) => {
|
||||
|
|
@ -90,7 +92,7 @@ export const listPayments = (req, res, next) => {
|
|||
|
||||
export const postPayment = (req, res, next) => {
|
||||
const { paymentType, saveToDB, bolt12, zeroAmtOffer, amount_msat, title, issuer, description } = req.body;
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
const options_body = JSON.parse(JSON.stringify(req.body));
|
||||
if (paymentType === 'KEYSEND') {
|
||||
|
|
@ -136,7 +138,8 @@ export const postPayment = (req, res, next) => {
|
|||
options.body = options_body;
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/pay';
|
||||
}
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Sent', data: body });
|
||||
if (paymentType === 'OFFER') {
|
||||
if (saveToDB && bolt12) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { getAlias } from './network.js';
|
||||
|
|
@ -9,10 +9,11 @@ const common: CommonService = Common;
|
|||
|
||||
export const getPeers = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'List Peers..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listpeers';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List Received', data: body });
|
||||
const peers = !body.peers ? [] : body.peers;
|
||||
return Promise.all(peers?.map((peer) => getAlias(req.session.selectedNode, peer, 'id'))).then((values) => {
|
||||
|
|
@ -27,15 +28,14 @@ export const getPeers = (req, res, next) => {
|
|||
|
||||
export const postPeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Connecting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/connect';
|
||||
options.body = req.body;
|
||||
request.post(options).then((connectRes) => {
|
||||
axios.post(req.session.selectedNode.settings.lnServerUrl + '/v1/connect', req.body, options).then((connectRes: any) => {
|
||||
connectRes = connectRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peer Connected', data: connectRes });
|
||||
const listOptions = common.getOptions(req);
|
||||
listOptions.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listpeers';
|
||||
request.post(listOptions).then((listPeersRes) => {
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
axios.post(req.session.selectedNode.settings.lnServerUrl + '/v1/listpeers', null, options).then((listPeersRes: any) => {
|
||||
listPeersRes = listPeersRes.data;
|
||||
const peers = listPeersRes && listPeersRes.peers ? common.newestOnTop(listPeersRes.peers, 'id', connectRes.id) : [];
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peers List after Connect Received', data: peers });
|
||||
res.status(201).json(peers);
|
||||
|
|
@ -51,11 +51,9 @@ export const postPeer = (req, res, next) => {
|
|||
|
||||
export const deletePeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Disconnecting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/disconnect';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
const axiosConfig: any = common.getAxiosConfig(req);
|
||||
axios.post(req.session.selectedNode.settings.lnServerUrl + '/v1/disconnect', req.body, axiosConfig).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconnected', data: body });
|
||||
res.status(204).json({});
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
|
||||
|
|
@ -8,11 +8,12 @@ const common: CommonService = Common;
|
|||
|
||||
export const decodePayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Decoding Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/decode';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Decoded', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -23,11 +24,12 @@ export const decodePayment = (req, res, next) => {
|
|||
|
||||
export const signMessage = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Signing Message..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/signmessage';
|
||||
options.body = req.body;
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Message Signed', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -38,11 +40,11 @@ export const signMessage = (req, res, next) => {
|
|||
|
||||
export const verifyMessage = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Verifying Message..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/checkmessage';
|
||||
options.body = req.body;
|
||||
request.post(options, (error, response, body) => {
|
||||
axios.post(options, (error, response, body) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Message Verified', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -53,10 +55,11 @@ export const verifyMessage = (req, res, next) => {
|
|||
|
||||
export const listConfigs = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Utility', msg: 'List Configs..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/listconfigs';
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Utility', msg: 'List Configs Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ export class CLWebSocketClient {
|
|||
const clientIdx = this.webSocketClients.findIndex((wsc) => +wsc.selectedNode.index === +newSelectedNode.index);
|
||||
let newClient = this.webSocketClients[clientIdx];
|
||||
if (!newClient) { newClient = { selectedNode: null, reConnect: true, webSocketClient: null }; }
|
||||
newClient.selectedNode = JSON.parse(JSON.stringify(newSelectedNode));
|
||||
newClient.selectedNode = newSelectedNode;
|
||||
this.webSocketClients[clientIdx] = newClient;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -33,10 +33,11 @@ export const simplifyAllChannels = (selNode: SelectedNode, channels) => {
|
|||
options.url = selNode.settings.lnServerUrl + '/nodes';
|
||||
options.form = channelNodeIds;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Channels', msg: 'Node Ids to find alias', data: channelNodeIds });
|
||||
return request.post(options).then((nodes) => {
|
||||
return axios.post(options).then((nodes: any) => {
|
||||
nodes = nodes.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Channels', msg: 'Filtered Nodes Received', data: nodes });
|
||||
let foundPeer = null;
|
||||
simplifiedChannels?.map((channel) => {
|
||||
simplifiedChannels?.map((channel: any) => {
|
||||
foundPeer = nodes.find((channelWithAlias) => channel.nodeId === channelWithAlias.nodeId);
|
||||
channel.alias = foundPeer ? foundPeer.alias : channel.nodeId.substring(0, 20);
|
||||
return channel;
|
||||
|
|
@ -47,7 +48,7 @@ export const simplifyAllChannels = (selNode: SelectedNode, channels) => {
|
|||
|
||||
export const getChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'List Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/channels';
|
||||
options.form = {};
|
||||
|
|
@ -59,16 +60,17 @@ export const getChannels = (req, res, next) => {
|
|||
if (common.read_dummy_data) {
|
||||
common.getDummyData('Channels', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(data); });
|
||||
} else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Channels List Received', data: body });
|
||||
if (body && body.length) {
|
||||
return simplifyAllChannels(req.session.selectedNode, body).then((simplifiedChannels) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Simplified Channels with Alias Received', data: simplifiedChannels });
|
||||
res.status(200).json(simplifiedChannels);
|
||||
return res.status(200).json(simplifiedChannels);
|
||||
});
|
||||
} else {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Empty Channels List Received' });
|
||||
res.status(200).json([]);
|
||||
return res.status(200).json([]);
|
||||
}
|
||||
}).
|
||||
catch((errRes) => {
|
||||
|
|
@ -80,7 +82,7 @@ export const getChannels = (req, res, next) => {
|
|||
|
||||
export const getChannelStats = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Channel States..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/channelstats';
|
||||
const today = new Date(Date.now());
|
||||
|
|
@ -90,7 +92,8 @@ export const getChannelStats = (req, res, next) => {
|
|||
from: fromLastMonth,
|
||||
to: tillToday
|
||||
};
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel States Received', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -101,12 +104,13 @@ export const getChannelStats = (req, res, next) => {
|
|||
|
||||
export const openChannel = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Opening Channel..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/open';
|
||||
options.form = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Open Channel Params', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Opened', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -117,12 +121,13 @@ export const openChannel = (req, res, next) => {
|
|||
|
||||
export const updateChannelRelayFee = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Updating Channel Relay Fee..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/updaterelayfee';
|
||||
options.form = req.query;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Update Relay Fee Params', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Relay Fee Updated', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -132,7 +137,7 @@ export const updateChannelRelayFee = (req, res, next) => {
|
|||
};
|
||||
|
||||
export const closeChannel = (req, res, next) => {
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
if (req.query.force !== 'true') {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Closing Channel..' });
|
||||
|
|
@ -144,7 +149,8 @@ export const closeChannel = (req, res, next) => {
|
|||
options.form = { channelId: req.query.channelId };
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Close URL', data: options.url });
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Close Params', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Closed', data: body });
|
||||
res.status(204).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -156,7 +162,7 @@ export const closeChannel = (req, res, next) => {
|
|||
export const circularRebalance = (req, res, next) => {
|
||||
const { amountMsat, sourceNodeId, targetNodeId, ignoreNodeIds, format, sourceShortChannelId, targetShortChannelId } = req.body;
|
||||
const crInvDescription = 'Circular rebalancing invoice for ' + (amountMsat / 1000) + ' Sats';
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.form = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Rebalance Params', data: options.form });
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -82,7 +82,7 @@ export const arrangePayments = (selNode: SelectedNode, body) => {
|
|||
|
||||
export const getFees = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Getting Fees..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/audit';
|
||||
const today = new Date(Date.now());
|
||||
|
|
@ -96,7 +96,8 @@ export const getFees = (req, res, next) => {
|
|||
if (common.read_dummy_data) {
|
||||
common.getDummyData('Fees', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(arrangeFees(req.session.selectedNode, data, Math.round((new Date().getTime())))); });
|
||||
} else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Fee Received', data: body });
|
||||
res.status(200).json(arrangeFees(req.session.selectedNode, body, Math.round((new Date().getTime()))));
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -108,7 +109,7 @@ export const getFees = (req, res, next) => {
|
|||
|
||||
export const getPayments = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Getting Payments..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/audit';
|
||||
const tillToday = (Math.round(new Date(Date.now()).getTime() / 1000)).toString();
|
||||
|
|
@ -118,7 +119,8 @@ export const getPayments = (req, res, next) => {
|
|||
if (common.read_dummy_data) {
|
||||
common.getDummyData('Payments', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(arrangePayments(req.session.selectedNode, data)); });
|
||||
} else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Payments Received', data: body });
|
||||
res.status(200).json(arrangePayments(req.session.selectedNode, body));
|
||||
}).
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { ECLWSClient, ECLWebSocketClient } from './webSocketClient.js';
|
||||
|
|
@ -11,8 +11,8 @@ const eclWsClient: ECLWebSocketClient = ECLWSClient;
|
|||
export const getInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Getting Eclair Node Information..' });
|
||||
common.logEnvVariables(req);
|
||||
common.setOptions(req);
|
||||
options = common.getOptions(req);
|
||||
common.setAxiosConfig(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/getinfo';
|
||||
options.form = {};
|
||||
|
|
@ -29,7 +29,8 @@ export const getInfo = (req, res, next) => {
|
|||
const err = common.handleError({ statusCode: 502, message: 'Missing or Wrong Password', error: errMsg }, 'GetInfo', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
} else {
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Connecting to the Eclair\'s Websocket Server.' });
|
||||
body.lnImplementation = 'Eclair';
|
||||
req.session.selectedNode.lnVersion = body.version.split('-')[0] || '';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from 'server/models/config.model.js';
|
||||
|
|
@ -15,7 +15,8 @@ export const getReceivedPaymentInfo = (lnServerUrl, invoice) => {
|
|||
if (idx < 0) {
|
||||
options.url = lnServerUrl + '/getreceivedinfo';
|
||||
options.form = { paymentHash: invoice.paymentHash };
|
||||
return request(options).then((response) => {
|
||||
return axios(options).then((response: any) => {
|
||||
response = response.data;
|
||||
invoice.status = response.status.type;
|
||||
if (response.status && response.status.type === 'received') {
|
||||
invoice.amountSettled = response.status.amount ? Math.round(response.status.amount / 1000) : 0;
|
||||
|
|
@ -35,11 +36,12 @@ export const getReceivedPaymentInfo = (lnServerUrl, invoice) => {
|
|||
|
||||
export const getInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/getinvoice';
|
||||
options.form = { paymentHash: req.params.paymentHash };
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Found', data: body });
|
||||
const current_time = (Math.round(new Date(Date.now()).getTime() / 1000));
|
||||
body.amount = body.amount ? body.amount / 1000 : 0;
|
||||
|
|
@ -54,14 +56,13 @@ export const getInvoice = (req, res, next) => {
|
|||
|
||||
export const listPendingInvoicesRequestCall = (selectedNode: SelectedNode, count?: number, skip?: number) => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'List Pending Invoices..' });
|
||||
options = selectedNode.authentication.options;
|
||||
options.url = selectedNode.settings.lnServerUrl + '/listpendinginvoices';
|
||||
options.form = { from: 0, to: (Math.round(new Date(Date.now()).getTime() / 1000)).toString() };
|
||||
const form: any = { from: 0, to: (Math.round(new Date(Date.now()).getTime() / 1000)).toString() };
|
||||
// Limit the number of invoices till provided count
|
||||
if (count) { options.form.count = count; }
|
||||
if (skip) { options.form.skip = skip; }
|
||||
if (count) { form.count = count; }
|
||||
if (skip) { form.skip = skip; }
|
||||
return new Promise((resolve, reject) => {
|
||||
request.post(options).then((pendingInvoicesResponse) => {
|
||||
axios.post(selectedNode.settings.lnServerUrl + '/listpendinginvoices', form, selectedNode.axiosConfig).then((pendingInvoicesResponse) => {
|
||||
pendingInvoicesResponse = pendingInvoicesResponse.data;
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Pending Invoices List ', data: pendingInvoicesResponse });
|
||||
resolve(pendingInvoicesResponse);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -72,7 +73,7 @@ export const listPendingInvoicesRequestCall = (selectedNode: SelectedNode, count
|
|||
|
||||
export const listInvoices = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Getting List Invoices..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
const tillToday = (Math.round(new Date(Date.now()).getTime() / 1000)).toString();
|
||||
const options1 = JSON.parse(JSON.stringify(options));
|
||||
|
|
@ -85,13 +86,14 @@ export const listInvoices = (req, res, next) => {
|
|||
options2.form = { from: 0, to: tillToday };
|
||||
if (common.read_dummy_data) {
|
||||
return common.getDummyData('Invoices', req.session.selectedNode.lnImplementation).then(([invoices, pendingInvoicesRes]: any[]) => {
|
||||
pendingInvoices = pendingInvoicesRes;
|
||||
invoices = invoices.data;
|
||||
pendingInvoices = pendingInvoicesRes.data;
|
||||
return Promise.all(invoices?.map((invoice) => getReceivedPaymentInfo(req.session.selectedNode.settings.lnServerUrl, invoice))).
|
||||
then((values) => res.status(200).json(invoices));
|
||||
});
|
||||
} else {
|
||||
return Promise.all([request(options1), request(options2)]).
|
||||
then(([invoices, pendingInvoicesRes]) => {
|
||||
return Promise.all([axios(options1), axios(options2)]).
|
||||
then(([invoices, pendingInvoicesRes]: [any, any]) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List Received', data: invoices });
|
||||
// pendingInvoices will be used to get the status (paid/unpaid) of the invoice via getReceivedPaymentInfo
|
||||
pendingInvoices = pendingInvoicesRes;
|
||||
|
|
@ -119,11 +121,10 @@ export const listInvoices = (req, res, next) => {
|
|||
|
||||
export const createInvoiceRequestCall = (selectedNode: SelectedNode, description: string, amount: number) => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
||||
options = selectedNode.authentication.options;
|
||||
options.url = selectedNode.settings.lnServerUrl + '/createinvoice';
|
||||
options.form = { description: description, amountMsat: amount };
|
||||
const form = { description: description, amountMsat: amount };
|
||||
return new Promise((resolve, reject) => {
|
||||
request.post(options).then((invResponse) => {
|
||||
axios.post(selectedNode.settings.lnServerUrl + '/createinvoice', form, selectedNode.axiosConfig).then((invResponse: any) => {
|
||||
invResponse = invResponse.data;
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Created', data: invResponse });
|
||||
if (invResponse.amount) { invResponse.amount = Math.round(invResponse.amount / 1000); }
|
||||
resolve(invResponse);
|
||||
|
|
@ -136,7 +137,7 @@ export const createInvoiceRequestCall = (selectedNode: SelectedNode, description
|
|||
export const createInvoice = (req, res, next) => {
|
||||
const { description, amountMsat } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
createInvoiceRequestCall(req.session.selectedNode, description, amountMsat).then((invRes) => {
|
||||
res.status(201).json(invRes);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from 'server/models/config.model.js';
|
||||
|
|
@ -8,11 +8,12 @@ const common: CommonService = Common;
|
|||
|
||||
export const getNodes = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Node Lookup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/nodes';
|
||||
options.form = { nodeIds: req.params.id };
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Network', msg: 'Node Lookup Finished', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -23,11 +24,10 @@ export const getNodes = (req, res, next) => {
|
|||
|
||||
export const findRouteBetweenNodesRequestCall = (selectedNode: SelectedNode, amountMsat: number, sourceNodeId: string, targetNodeId: string, ignoreNodeIds: string[] = [], format: string = 'shortChannelId') => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Network', msg: 'Find Route Between Nodes..' });
|
||||
options = selectedNode.authentication.options;
|
||||
options.url = selectedNode.settings.lnServerUrl + '/findroutebetweennodes';
|
||||
options.form = { amountMsat: amountMsat, sourceNodeId: sourceNodeId, targetNodeId: targetNodeId, ignoreNodeIds: ignoreNodeIds, format: format };
|
||||
const form = { amountMsat: amountMsat, sourceNodeId: sourceNodeId, targetNodeId: targetNodeId, ignoreNodeIds: ignoreNodeIds, format: format };
|
||||
return new Promise((resolve, reject) => {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(selectedNode.settings.lnServerUrl + '/findroutebetweennodes', form, selectedNode.axiosConfig).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Network', msg: 'Route Lookup Between Nodes Finished', data: body });
|
||||
resolve(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -38,7 +38,7 @@ export const findRouteBetweenNodesRequestCall = (selectedNode: SelectedNode, amo
|
|||
|
||||
export const findRouteBetweenNodes = (req, res, next) => {
|
||||
const { amountMsat, sourceNodeId, targetNodeId, ignoreNodeIds, format } = req.body;
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
findRouteBetweenNodesRequestCall(req.session.selectedNode, amountMsat, sourceNodeId, targetNodeId, ignoreNodeIds, format).then((callRes) => {
|
||||
res.status(200).json(callRes);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -15,11 +15,12 @@ export const arrangeBalances = (body) => {
|
|||
|
||||
export const getNewAddress = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Generating New Address..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/getnewaddress';
|
||||
options.form = {};
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'New Address Generated', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -30,14 +31,15 @@ export const getNewAddress = (req, res, next) => {
|
|||
|
||||
export const getBalance = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Getting On Chain Balance..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/onchainbalance';
|
||||
options.form = {};
|
||||
if (common.read_dummy_data) {
|
||||
common.getDummyData('OnChainBalance', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(arrangeBalances(data)); });
|
||||
} else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'On Chain Balance Received', data: body });
|
||||
res.status(200).json(arrangeBalances(body));
|
||||
}).
|
||||
|
|
@ -50,7 +52,7 @@ export const getBalance = (req, res, next) => {
|
|||
|
||||
export const getTransactions = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Getting On Chain Transactions..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/onchaintransactions';
|
||||
options.form = {
|
||||
|
|
@ -58,7 +60,8 @@ export const getTransactions = (req, res, next) => {
|
|||
skip: req.query.skip
|
||||
};
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Getting On Chain Transactions Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'On Chain Transactions Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -70,12 +73,13 @@ export const getTransactions = (req, res, next) => {
|
|||
export const sendFunds = (req, res, next) => {
|
||||
const { address, amount, blocks } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'OnChain', msg: 'Sending On Chain Funds..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/sendonchain';
|
||||
options.form = { address: address, amountSatoshis: amount, confirmationTarget: blocks };
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Onchain', msg: 'Send Funds Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Onchain', msg: 'On Chain Funds Sent', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -9,7 +9,8 @@ const common: CommonService = Common;
|
|||
export const getSentInfoFromPaymentRequest = (selNode: SelectedNode, payment) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/getsentinfo';
|
||||
options.form = { paymentHash: payment };
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Payments', msg: 'Payment Sent Information Received', data: body });
|
||||
body.forEach((sentPayment) => {
|
||||
if (sentPayment.amount) { sentPayment.amount = Math.round(sentPayment.amount / 1000); }
|
||||
|
|
@ -22,7 +23,7 @@ export const getSentInfoFromPaymentRequest = (selNode: SelectedNode, payment) =>
|
|||
export const getQueryNodes = (selNode: SelectedNode, nodeIds) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/nodes';
|
||||
options.form = { nodeIds: nodeIds?.reduce((acc, curr) => acc + ',' + curr) };
|
||||
return request.post(options).then((nodes) => {
|
||||
return axios.post(options).then((nodes) => {
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Payments', msg: 'Query Nodes Received', data: nodes });
|
||||
return nodes;
|
||||
}).catch((err) => []);
|
||||
|
|
@ -30,11 +31,12 @@ export const getQueryNodes = (selNode: SelectedNode, nodeIds) => {
|
|||
|
||||
export const decodePayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Decoding Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/parseinvoice';
|
||||
options.form = { invoice: req.params.invoice };
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Decoded', data: body });
|
||||
if (body.amount) { body.amount = Math.round(body.amount / 1000); }
|
||||
res.status(200).json(body);
|
||||
|
|
@ -46,12 +48,13 @@ export const decodePayment = (req, res, next) => {
|
|||
|
||||
export const postPayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Paying Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/payinvoice';
|
||||
options.form = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Send Payment Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Invoice Paid', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -62,7 +65,7 @@ export const postPayment = (req, res, next) => {
|
|||
|
||||
export const queryPaymentRoute = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Querying Payment Route..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/findroutetonode';
|
||||
options.form = {
|
||||
|
|
@ -70,12 +73,13 @@ export const queryPaymentRoute = (req, res, next) => {
|
|||
amountMsat: req.query.amountMsat
|
||||
};
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Query Payment Route Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Query Payment Route Received', data: body });
|
||||
if (body && body.routes && body.routes.length) {
|
||||
let allRoutesNodeIds = [];
|
||||
allRoutesNodeIds = body.routes?.reduce((accRoutes, currRoute) => [...new Set([...accRoutes, ...currRoute.nodeIds])], []);
|
||||
return getQueryNodes(req.session.selectedNode, allRoutesNodeIds).then((nodesWithAlias) => {
|
||||
return getQueryNodes(req.session.selectedNode, allRoutesNodeIds).then((nodesWithAlias: any) => {
|
||||
let foundPeer = null;
|
||||
body.routes.forEach((route, i) => {
|
||||
route.nodeIds?.map((node, j) => {
|
||||
|
|
@ -85,11 +89,11 @@ export const queryPaymentRoute = (req, res, next) => {
|
|||
});
|
||||
});
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Query Routes with Alias Received', data: body });
|
||||
res.status(200).json(body);
|
||||
return res.status(200).json(body);
|
||||
});
|
||||
} else {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Empty Payment Route Information Received' });
|
||||
res.status(200).json({ routes: [] });
|
||||
return res.status(200).json({ routes: [] });
|
||||
}
|
||||
}).catch((errRes) => {
|
||||
const err = common.handleError(errRes, 'Payments', 'Query Route Error', req.session.selectedNode);
|
||||
|
|
@ -100,7 +104,7 @@ export const queryPaymentRoute = (req, res, next) => {
|
|||
export const getSentPaymentsInformation = (req, res, next) => {
|
||||
const { payments } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Getting Sent Payment Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
if (payments) {
|
||||
const paymentsArr = payments.split(',');
|
||||
|
|
@ -121,12 +125,11 @@ export const getSentPaymentsInformation = (req, res, next) => {
|
|||
|
||||
export const sendPaymentToRouteRequestCall = (selectedNode: SelectedNode, shortChannelIds: string, invoice: string, amountMsat: number) => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' });
|
||||
options = selectedNode.authentication.options;
|
||||
options.url = selectedNode.settings.lnServerUrl + '/sendtoroute';
|
||||
options.form = { shortChannelIds: shortChannelIds, amountMsat: amountMsat, invoice: invoice };
|
||||
const form = { shortChannelIds: shortChannelIds, amountMsat: amountMsat, invoice: invoice };
|
||||
return new Promise((resolve, reject) => {
|
||||
logger.log({ selectedNode: selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Send Payment To Route Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(selectedNode.settings.lnServerUrl + '/sendtoroute', form, selectedNode.axiosConfig).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Sent To Route', data: body });
|
||||
resolve(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -138,7 +141,7 @@ export const sendPaymentToRouteRequestCall = (selectedNode: SelectedNode, shortC
|
|||
export const sendPaymentToRoute = (req, res, next) => {
|
||||
const { shortChannelIds, invoice, amountMsat } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Send Payment To Route..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
sendPaymentToRouteRequestCall(req.session.selectedNode, shortChannelIds, invoice, amountMsat).then((callRes) => {
|
||||
res.status(200).json(callRes);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -9,7 +9,7 @@ const common: CommonService = Common;
|
|||
export const getFilteredNodes = (selNode: SelectedNode, peersNodeIds) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/nodes';
|
||||
options.form = { nodeIds: peersNodeIds };
|
||||
return request.post(options).then((nodes) => {
|
||||
return axios.post(options).then((nodes) => {
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Peers', msg: 'Filtered Nodes Received', data: nodes });
|
||||
return nodes;
|
||||
}).catch((err) => []);
|
||||
|
|
@ -17,20 +17,21 @@ export const getFilteredNodes = (selNode: SelectedNode, peersNodeIds) => {
|
|||
|
||||
export const getPeers = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Getting Peers..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/peers';
|
||||
options.form = {};
|
||||
if (common.read_dummy_data) {
|
||||
common.getDummyData('Peers', req.session.selectedNode.lnImplementation).then((data) => { res.status(200).json(data); });
|
||||
} else {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List Received', data: body });
|
||||
if (body && body.length) {
|
||||
let peersNodeIds = '';
|
||||
body.forEach((peer) => { peersNodeIds = peersNodeIds + ',' + peer.nodeId; });
|
||||
peersNodeIds = peersNodeIds.substring(1);
|
||||
return getFilteredNodes(req.session.selectedNode, peersNodeIds).then((peersWithAlias) => {
|
||||
return getFilteredNodes(req.session.selectedNode, peersNodeIds).then((peersWithAlias: any) => {
|
||||
let foundPeer = null;
|
||||
body?.map((peer) => {
|
||||
foundPeer = peersWithAlias.find((peerWithAlias) => peer.nodeId === peerWithAlias.nodeId);
|
||||
|
|
@ -42,7 +43,7 @@ export const getPeers = (req, res, next) => {
|
|||
});
|
||||
} else {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Empty Peers Received' });
|
||||
res.status(200).json([]);
|
||||
return res.status(200).json([]);
|
||||
}
|
||||
}).
|
||||
catch((errRes) => {
|
||||
|
|
@ -54,7 +55,7 @@ export const getPeers = (req, res, next) => {
|
|||
|
||||
export const connectPeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Conneting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/connect';
|
||||
options.form = {};
|
||||
|
|
@ -62,7 +63,8 @@ export const connectPeer = (req, res, next) => {
|
|||
options.form = req.query;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Connect Peer Params', data: options.form });
|
||||
}
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peer Connected', data: body });
|
||||
if (typeof body === 'string' && body.includes('already connected')) {
|
||||
const err = common.handleError({ statusCode: 500, message: 'Connect Peer Error', error: body }, 'Peers', body, req.session.selectedNode);
|
||||
|
|
@ -73,13 +75,14 @@ export const connectPeer = (req, res, next) => {
|
|||
}
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/peers';
|
||||
options.form = {};
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List after Connect', data: body });
|
||||
if (body && body.length) {
|
||||
let peersNodeIds = '';
|
||||
body.forEach((peer) => { peersNodeIds = peersNodeIds + ',' + peer.nodeId; });
|
||||
peersNodeIds = peersNodeIds.substring(1);
|
||||
return getFilteredNodes(req.session.selectedNode, peersNodeIds).then((peersWithAlias) => {
|
||||
return getFilteredNodes(req.session.selectedNode, peersNodeIds).then((peersWithAlias: any) => {
|
||||
let foundPeer = null;
|
||||
body?.map((peer) => {
|
||||
foundPeer = peersWithAlias.find((peerWithAlias) => peer.nodeId === peerWithAlias.nodeId);
|
||||
|
|
@ -88,10 +91,10 @@ export const connectPeer = (req, res, next) => {
|
|||
});
|
||||
const peers = common.newestOnTop(body || [], 'nodeId', req.query.nodeId ? req.query.nodeId : req.query.uri ? req.query.uri.substring(0, req.query.uri.indexOf('@')) : '');
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peers List after Connect Received', data: peers });
|
||||
res.status(201).json(peers);
|
||||
return res.status(201).json(peers);
|
||||
});
|
||||
} else {
|
||||
res.status(201).json([]);
|
||||
return res.status(201).json([]);
|
||||
}
|
||||
}).catch((errRes) => {
|
||||
const err = common.handleError(errRes, 'Peers', 'Connect Peer Error', req.session.selectedNode);
|
||||
|
|
@ -105,7 +108,7 @@ export const connectPeer = (req, res, next) => {
|
|||
|
||||
export const deletePeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Disconneting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/disconnect';
|
||||
options.form = {};
|
||||
|
|
@ -113,7 +116,8 @@ export const deletePeer = (req, res, next) => {
|
|||
options.form = { nodeId: req.params.nodeId };
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Disconnect Peer Params', data: options.form });
|
||||
}
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconnected', data: body });
|
||||
res.status(204).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ export class ECLWebSocketClient {
|
|||
const clientIdx = this.webSocketClients.findIndex((wsc) => +wsc.selectedNode.index === +newSelectedNode.index);
|
||||
let newClient = this.webSocketClients[clientIdx];
|
||||
if (!newClient) { newClient = { selectedNode: null, reConnect: true, webSocketClient: null }; }
|
||||
newClient.selectedNode = JSON.parse(JSON.stringify(newSelectedNode));
|
||||
newClient.selectedNode = newSelectedNode;
|
||||
this.webSocketClients[clientIdx] = newClient;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,13 +7,14 @@ const common: CommonService = Common;
|
|||
|
||||
export const getBlockchainBalance = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Balance', msg: 'Getting Balance..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/balance/blockchain';
|
||||
options.qs = req.query;
|
||||
options.params = req.query;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Balance', msg: 'Request params', data: req.params });
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Balance', msg: 'Request Query', data: req.query });
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
if (body) {
|
||||
if (!body.total_balance) { body.total_balance = 0; }
|
||||
if (!body.confirmed_balance) { body.confirmed_balance = 0; }
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -9,7 +9,8 @@ const common: CommonService = Common;
|
|||
export const getAliasForChannel = (selNode: SelectedNode, channel) => {
|
||||
const pubkey = (channel.remote_pubkey) ? channel.remote_pubkey : (channel.remote_node_pub) ? channel.remote_node_pub : '';
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/graph/node/' + pubkey;
|
||||
return request(options).then((aliasBody) => {
|
||||
return axios(options).then((aliasBody: any) => {
|
||||
aliasBody = aliasBody.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Channels', msg: 'Alias Received', data: aliasBody.node.alias });
|
||||
channel.remote_alias = aliasBody.node.alias && aliasBody.node.alias !== '' ? aliasBody.node.alias : aliasBody.node.pub_key.slice(0, 20);
|
||||
return channel;
|
||||
|
|
@ -21,14 +22,15 @@ export const getAliasForChannel = (selNode: SelectedNode, channel) => {
|
|||
|
||||
export const getAllChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels';
|
||||
options.qs = req.query;
|
||||
options.params = req.query;
|
||||
let local = 0;
|
||||
let remote = 0;
|
||||
let total = 0;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Channels List Received', data: body });
|
||||
if (body.channels) {
|
||||
return Promise.all(
|
||||
|
|
@ -59,11 +61,12 @@ export const getAllChannels = (req, res, next) => {
|
|||
|
||||
export const getPendingChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Pending Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels/pending';
|
||||
options.qs = req.query;
|
||||
request(options).then((body) => {
|
||||
options.params = req.query;
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
if (!body.total_limbo_balance) {
|
||||
body.total_limbo_balance = 0;
|
||||
}
|
||||
|
|
@ -96,11 +99,12 @@ export const getPendingChannels = (req, res, next) => {
|
|||
|
||||
export const getClosedChannels = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Getting Closed Channels..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels/closed';
|
||||
options.qs = req.query;
|
||||
request(options).then((body) => {
|
||||
options.params = req.query;
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
if (body.channels && body.channels.length > 0) {
|
||||
return Promise.all(
|
||||
body.channels?.map((channel) => {
|
||||
|
|
@ -127,7 +131,7 @@ export const getClosedChannels = (req, res, next) => {
|
|||
export const postChannel = (req, res, next) => {
|
||||
const { node_pubkey, private: privateChannel, spend_unconfirmed, local_funding_amount, trans_type, trans_type_value, commitment_type } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Opening Channel..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels';
|
||||
options.form = {
|
||||
|
|
@ -146,7 +150,8 @@ export const postChannel = (req, res, next) => {
|
|||
}
|
||||
options.form = JSON.stringify(options.form);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Channel Open Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Opened', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -162,14 +167,14 @@ export const closeChannel = (req, res, next) => {
|
|||
const err = common.handleError({ message: 'Session Expired after a day\'s inactivity.', statusCode: 401 }, 'Session Expired', 'Session Expiry Error', null);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
const channelpoint = req.params.channelPoint?.replace(':', '/');
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels/' + channelpoint + '?force=' + req.query.force;
|
||||
if (req.query.target_conf) { options.url = options.url + '&target_conf=' + req.query.target_conf; }
|
||||
if (req.query.sat_per_byte) { options.url = options.url + '&sat_per_byte=' + req.query.sat_per_byte; }
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Closing Channel Options URL', data: options.url });
|
||||
request.delete(options);
|
||||
axios.delete(options);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Close Requested' });
|
||||
res.status(202).json({ message: 'Close channel request has been submitted.' });
|
||||
} catch (error: any) {
|
||||
|
|
@ -181,7 +186,7 @@ export const closeChannel = (req, res, next) => {
|
|||
export const postChanPolicy = (req, res, next) => {
|
||||
const { chanPoint, baseFeeMsat, feeRate, timeLockDelta, max_htlc_msat, min_htlc_msat } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Updating Channel Policy..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/chanpolicy';
|
||||
if (chanPoint === 'all') {
|
||||
|
|
@ -212,7 +217,8 @@ export const postChanPolicy = (req, res, next) => {
|
|||
}
|
||||
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Channels', msg: 'Update Channel Policy Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Channels', msg: 'Channel Policy Updated', data: body });
|
||||
if (body.failed_updates && body.failed_updates.length && body.failed_updates[0].update_error) {
|
||||
const err = common.handleError({ error: body.failed_updates[0].update_error }, 'Channels', 'Update Channel Policy Error', req.session.selectedNode);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as fs from 'fs';
|
||||
import { sep } from 'path';
|
||||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -34,7 +34,7 @@ function getFilesList(channelBackupPath, callback) {
|
|||
|
||||
export const getBackup = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'ChannelBackup', msg: 'Getting Channel Backup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
let channel_backup_file = '';
|
||||
let message = '';
|
||||
|
|
@ -60,7 +60,8 @@ export const getBackup = (req, res, next) => {
|
|||
}
|
||||
}
|
||||
}
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'ChannelsBackup', msg: 'Channel Backup Received', data: body });
|
||||
fs.writeFile(channel_backup_file, JSON.stringify(body), (errRes) => {
|
||||
if (errRes) {
|
||||
|
|
@ -79,7 +80,7 @@ export const getBackup = (req, res, next) => {
|
|||
|
||||
export const postBackupVerify = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'ChannelBackup', msg: 'Verifying Channel Backup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels/backup/verify';
|
||||
let channel_verify_file = '';
|
||||
|
|
@ -121,7 +122,8 @@ export const postBackupVerify = (req, res, next) => {
|
|||
}
|
||||
}
|
||||
if (verify_backup !== '') {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'ChannelBackup', msg: 'Channel Backup Verified', data: body });
|
||||
res.status(201).json({ message: message });
|
||||
}).
|
||||
|
|
@ -134,7 +136,7 @@ export const postBackupVerify = (req, res, next) => {
|
|||
|
||||
export const postRestore = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'ChannelBackup', msg: 'Restoring Channel Backup..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/channels/backup/restore';
|
||||
let channel_restore_file = '';
|
||||
|
|
@ -186,7 +188,8 @@ export const postRestore = (req, res, next) => {
|
|||
}
|
||||
}
|
||||
if (restore_backup !== '') {
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'ChannelBackup', msg: 'Channel Restored', data: body });
|
||||
if (req.params.channelPoint === 'ALL') { channel_restore_file = channel_restore_file + 'channel-all.bak'; }
|
||||
fs.rename(channel_restore_file, channel_restore_file + '.restored', () => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { getAllForwardingEvents } from './switch.js';
|
||||
|
|
@ -8,10 +8,11 @@ const common: CommonService = Common;
|
|||
|
||||
export const getFees = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Getting Fees..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/fees';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Fees', msg: 'Fee Received', data: body });
|
||||
const today = new Date(Date.now());
|
||||
const start_date = new Date(today.getFullYear(), today.getMonth(), 1, 0, 0, 0);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { LNDWSClient, LNDWebSocketClient } from './webSocketClient.js';
|
||||
|
|
@ -11,8 +11,8 @@ const lndWsClient: LNDWebSocketClient = LNDWSClient;
|
|||
export const getInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Getting LND Node Information..' });
|
||||
common.logEnvVariables(req);
|
||||
common.setOptions(req);
|
||||
options = common.getOptions(req);
|
||||
common.setAxiosConfig(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/getinfo';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'GetInfo', msg: 'Selected Node ' + req.session.selectedNode.lnNode });
|
||||
|
|
@ -28,7 +28,8 @@ export const getInfo = (req, res, next) => {
|
|||
}
|
||||
return node;
|
||||
});
|
||||
return request(options).then((body) => {
|
||||
return axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
const body_str = (!body) ? '' : JSON.stringify(body);
|
||||
const search_idx = (!body) ? -1 : body_str.search('Not Found');
|
||||
if (!body || search_idx > -1 || body.error) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -8,7 +8,8 @@ const common: CommonService = Common;
|
|||
|
||||
export const getAliasFromPubkey = (selNode: SelectedNode, pubkey) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/graph/node/' + pubkey;
|
||||
return request(options).then((res) => {
|
||||
return axios(options).then((res: any) => {
|
||||
res = res.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Graph', msg: 'Alias Received', data: res.node.alias });
|
||||
return res.node.alias;
|
||||
}).
|
||||
|
|
@ -17,10 +18,11 @@ export const getAliasFromPubkey = (selNode: SelectedNode, pubkey) => {
|
|||
|
||||
export const getDescribeGraph = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Network Graph..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph';
|
||||
request.get(options).then((body) => {
|
||||
axios.get(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Network Graph Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -31,10 +33,11 @@ export const getDescribeGraph = (req, res, next) => {
|
|||
|
||||
export const getGraphInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/info';
|
||||
request.get(options).then((body) => {
|
||||
axios.get(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -45,10 +48,11 @@ export const getGraphInfo = (req, res, next) => {
|
|||
|
||||
export const getGraphNode = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Node Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/node/' + req.params.pubKey;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Node Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -59,10 +63,11 @@ export const getGraphNode = (req, res, next) => {
|
|||
|
||||
export const getGraphEdge = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Edge Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/edge/' + req.params.chanid;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Graph Edge Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -73,14 +78,15 @@ export const getGraphEdge = (req, res, next) => {
|
|||
|
||||
export const getQueryRoutes = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Graph Routes..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/routes/' + req.params.destPubkey + '/' + req.params.amount;
|
||||
if (req.query.outgoing_chan_id) {
|
||||
options.url = options.url + '?outgoing_chan_id=' + req.query.outgoing_chan_id;
|
||||
}
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Query Routes URL', data: options.url });
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Query Routes Received', data: body });
|
||||
if (body.routes && body.routes.length && body.routes.length > 0 && body.routes[0].hops && body.routes[0].hops.length && body.routes[0].hops.length > 0) {
|
||||
return Promise.all(body.routes[0].hops?.map((hop) => getAliasFromPubkey(req.session.selectedNode, hop.pub_key))).
|
||||
|
|
@ -109,10 +115,11 @@ export const getQueryRoutes = (req, res, next) => {
|
|||
|
||||
export const getRemoteFeePolicy = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Graph', msg: 'Getting Remote Fee Policy..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/graph/edge/' + req.params.chanid;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Graph', msg: 'Edge Info Received', data: body });
|
||||
let remoteNodeFee = {};
|
||||
if (body.node1_pub === req.params.localPubkey) {
|
||||
|
|
@ -137,7 +144,7 @@ export const getRemoteFeePolicy = (req, res, next) => {
|
|||
};
|
||||
|
||||
export const getAliasesForPubkeys = (req, res, next) => {
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
if (req.query.pubkeys) {
|
||||
const pubkeyArr = req.query.pubkeys.split(',');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { LNDWSClient, LNDWebSocketClient } from './webSocketClient.js';
|
||||
|
|
@ -10,7 +10,7 @@ const lndWsClient: LNDWebSocketClient = LNDWSClient;
|
|||
|
||||
export const invoiceLookup = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Getting Invoice Information..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/invoices/lookup';
|
||||
if (req.query.payment_addr) {
|
||||
|
|
@ -18,7 +18,8 @@ export const invoiceLookup = (req, res, next) => {
|
|||
} else {
|
||||
options.url = options.url + '?payment_hash=' + req.query.payment_hash;
|
||||
}
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
body.r_preimage = body.r_preimage ? Buffer.from(body.r_preimage, 'base64').toString('hex') : '';
|
||||
body.r_hash = body.r_hash ? Buffer.from(body.r_hash, 'base64').toString('hex') : '';
|
||||
body.description_hash = body.description_hash ? Buffer.from(body.description_hash, 'base64').toString('hex') : null;
|
||||
|
|
@ -32,11 +33,12 @@ export const invoiceLookup = (req, res, next) => {
|
|||
|
||||
export const listInvoices = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Getting List Invoices..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoices?num_max_invoices=' + req.query.num_max_invoices + '&index_offset=' + req.query.index_offset +
|
||||
'&reversed=' + req.query.reversed;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Invoice', msg: 'Invoices List Received', data: body });
|
||||
if (body.invoices && body.invoices.length > 0) {
|
||||
body.invoices.forEach((invoice) => {
|
||||
|
|
@ -55,11 +57,12 @@ export const listInvoices = (req, res, next) => {
|
|||
|
||||
export const addInvoice = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Adding Invoice..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoices';
|
||||
options.form = JSON.stringify(req.body);
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoice', msg: 'Invoice Added', data: body });
|
||||
try {
|
||||
if (body.r_hash) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -8,13 +8,14 @@ const common: CommonService = Common;
|
|||
export const signMessage = (req, res, next) => {
|
||||
const { message } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Signing Message..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/signmessage';
|
||||
options.form = JSON.stringify({
|
||||
msg: Buffer.from(message).toString('base64')
|
||||
});
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Message Signed', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -26,14 +27,15 @@ export const signMessage = (req, res, next) => {
|
|||
export const verifyMessage = (req, res, next) => {
|
||||
const { message, signature } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Verifying Message..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/verifymessage';
|
||||
options.form = JSON.stringify({
|
||||
msg: Buffer.from(message).toString('base64'),
|
||||
signature: signature
|
||||
});
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Message', msg: 'Message Verified', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,10 +7,11 @@ const common: CommonService = Common;
|
|||
|
||||
export const getNewAddress = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'NewAddress', msg: 'Getting New Address..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/newaddress?type=' + req.query.type;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'NewAddress', msg: 'New Address Generated', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -9,7 +9,8 @@ const common: CommonService = Common;
|
|||
|
||||
export const decodePaymentFromPaymentRequest = (selNode: SelectedNode, payment) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/payreq/' + payment;
|
||||
return request(options).then((res) => {
|
||||
return axios(options).then((res: any) => {
|
||||
res = res.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'PayReq', msg: 'Description Received', data: res.description });
|
||||
return res;
|
||||
}).catch((err) => { });
|
||||
|
|
@ -17,10 +18,11 @@ export const decodePaymentFromPaymentRequest = (selNode: SelectedNode, payment)
|
|||
|
||||
export const decodePayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'PayRequest', msg: 'Decoding Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/payreq/' + req.params.payRequest;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'PayRequest', msg: 'Payment Decoded', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -32,7 +34,7 @@ export const decodePayment = (req, res, next) => {
|
|||
export const decodePayments = (req, res, next) => {
|
||||
const { payments } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'PayRequest', msg: 'Decoding Payments List..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
if (payments) {
|
||||
const paymentsArr = payments.split(',');
|
||||
|
|
@ -53,10 +55,11 @@ export const decodePayments = (req, res, next) => {
|
|||
|
||||
export const getPayments = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Getting Payments List..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/payments?max_payments=' + req.query.max_payments + '&index_offset=' + req.query.index_offset + '&reversed=' + req.query.reversed;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Payment List Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -67,14 +70,16 @@ export const getPayments = (req, res, next) => {
|
|||
|
||||
export const getAllLightningTransactions = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Getting All Lightning Transactions..' });
|
||||
const options1 = JSON.parse(JSON.stringify(common.getOptions(req)));
|
||||
const options2 = JSON.parse(JSON.stringify(common.getOptions(req)));
|
||||
const options1 = JSON.parse(JSON.stringify(common.getAxiosConfig(req)));
|
||||
const options2 = JSON.parse(JSON.stringify(common.getAxiosConfig(req)));
|
||||
// options1.url = req.session.selectedNode.settings.lnServerUrl + '/v1/payments?max_payments=100000&index_offset=0&reversed=true';
|
||||
options2.url = req.session.selectedNode.settings.lnServerUrl + '/v1/invoices?num_max_invoices=100000&index_offset=0&reversed=true';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'All Payments Options', data: options1 });
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'All Invoices Options', data: options2 });
|
||||
// return Promise.all([request(options1), request(options2)]).then((values) => {
|
||||
return Promise.all([{ payments: [] }, request(options2)]).then((values) => {
|
||||
// return Promise.all([axios(options1), axios(options2)]).then((values) => {
|
||||
return Promise.all([{ payments: [] }, axios(options2)]).then((values: any[]) => {
|
||||
values[0] = values[0].data;
|
||||
values[1] = values[1].data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'All Lightning Transactions Received', data: ({ totalPayments: values[0].payments.length || 0, totalInvoices: values[1].invoices.length || 0 }) });
|
||||
res.status(200).json({ listPaymentsAll: values[0], listInvoicesAll: values[1] });
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -85,10 +90,11 @@ export const getAllLightningTransactions = (req, res, next) => {
|
|||
|
||||
export const paymentLookup = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Looking up Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/router/track/' + req.params.paymentHash;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Payment Information Received for ' + req.params.paymentHash, data: body });
|
||||
res.status(200).json(body.result || body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -99,7 +105,7 @@ export const paymentLookup = (req, res, next) => {
|
|||
|
||||
export const sendPayment = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Sending Payment..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/router/send';
|
||||
if (req.body.last_hop_pubkey) {
|
||||
|
|
@ -109,7 +115,8 @@ export const sendPayment = (req, res, next) => {
|
|||
req.body.timeout_seconds = req.body.timeout_seconds || 600;
|
||||
options.form = JSON.stringify(req.body);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Payments', msg: 'Send Payment Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
const results = body.split('\n').filter(Boolean).map((jsonString) => JSON.parse(jsonString));
|
||||
body = results.length > 0 ? results[results.length - 1] : { result: { status: 'UNKNOWN' } };
|
||||
if (body.result.status === 'FAILED') {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
import { SelectedNode } from '../../models/config.model.js';
|
||||
|
|
@ -8,7 +8,8 @@ const common: CommonService = Common;
|
|||
|
||||
export const getAliasForPeers = (selNode: SelectedNode, peer) => {
|
||||
options.url = selNode.settings.lnServerUrl + '/v1/graph/node/' + peer.pub_key;
|
||||
return request(options).then((aliasBody) => {
|
||||
return axios(options).then((aliasBody: any) => {
|
||||
aliasBody = aliasBody.data;
|
||||
logger.log({ selectedNode: selNode, level: 'DEBUG', fileName: 'Peers', msg: 'Alias Received', data: aliasBody.node.alias });
|
||||
peer.alias = aliasBody.node.alias;
|
||||
return aliasBody.node.alias;
|
||||
|
|
@ -20,10 +21,11 @@ export const getAliasForPeers = (selNode: SelectedNode, peer) => {
|
|||
|
||||
export const getPeers = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Getting Peers..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peers List Received', data: body });
|
||||
const peers = !body.peers ? [] : body.peers;
|
||||
return Promise.all(peers?.map((peer) => getAliasForPeers(req.session.selectedNode, peer))).then((values) => {
|
||||
|
|
@ -39,17 +41,19 @@ export const getPeers = (req, res, next) => {
|
|||
export const postPeer = (req, res, next) => {
|
||||
const { host, pubkey, perm } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Connecting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers';
|
||||
options.form = JSON.stringify({
|
||||
addr: { host: host, pubkey: pubkey },
|
||||
perm: perm
|
||||
});
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Peers', msg: 'Peer Connected', data: body });
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
const peers = (!body.peers) ? [] : body.peers;
|
||||
return Promise.all(peers?.map((peer) => getAliasForPeers(req.session.selectedNode, peer))).then((values) => {
|
||||
if (body.peers) {
|
||||
|
|
@ -73,11 +77,12 @@ export const postPeer = (req, res, next) => {
|
|||
|
||||
export const deletePeer = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Disconnecting Peer..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/peers/' + req.params.peerPubKey;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconnect Pubkey', data: req.params.peerPubKey });
|
||||
request.delete(options).then((body) => {
|
||||
axios.delete(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Peers', msg: 'Peer Disconneted', data: body });
|
||||
res.status(204).json({});
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -24,7 +24,7 @@ export const getAllForwardingEvents = (req, start, end, offset, caller, callback
|
|||
if (!req.session.selectedNode) {
|
||||
const err = common.handleError({ message: 'Session Expired after a day\'s inactivity.', statusCode: 401 }, 'Balance', 'Get Balance Error', req.session.selectedNode);
|
||||
return callback({ message: err.message, error: err.error, statusCode: err.statusCode });
|
||||
} options = common.getOptions(req);
|
||||
} const axiosConfig = common.getAxiosConfig(req);
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/switch';
|
||||
options.form = {};
|
||||
if (start) { options.form.start_time = start; }
|
||||
|
|
@ -33,7 +33,8 @@ export const getAllForwardingEvents = (req, start, end, offset, caller, callback
|
|||
options.form.index_offset = offset;
|
||||
options.form = JSON.stringify(options.form);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Switch', msg: 'Forwarding Events Params', data: options.form });
|
||||
return request.post(options).then((body) => {
|
||||
return axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Switch', msg: 'Forwarding Events Received', data: body });
|
||||
if (body.forwarding_events) {
|
||||
responseData[caller].forwarding_events.push(...body.forwarding_events);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,10 +7,11 @@ const common: CommonService = Common;
|
|||
|
||||
export const getTransactions = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Transactions', msg: 'Getting Transactions..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/transactions';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Transactions', msg: 'Transactions List Received', data: body });
|
||||
res.status(200).json(body.transactions);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -22,7 +23,7 @@ export const getTransactions = (req, res, next) => {
|
|||
export const postTransactions = (req, res, next) => {
|
||||
const { amount, address, fees, blocks, sendAll } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Transactions', msg: 'Sending Transaction..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/transactions';
|
||||
options.form = {
|
||||
|
|
@ -33,7 +34,8 @@ export const postTransactions = (req, res, next) => {
|
|||
};
|
||||
if (sendAll) { options.form.send_all = sendAll; }
|
||||
options.form = JSON.stringify(options.form);
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Transactions', msg: 'Transaction Sent', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import atob from 'atob';
|
||||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -8,14 +8,15 @@ const common: CommonService = Common;
|
|||
|
||||
export const genSeed = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Generating Seed..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
if (req.params.passphrase) {
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/genseed?aezeed_passphrase=' + Buffer.from(atob(req.params.passphrase)).toString('base64');
|
||||
} else {
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v1/genseed';
|
||||
}
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Seed Generated', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -27,7 +28,7 @@ export const genSeed = (req, res, next) => {
|
|||
export const operateWallet = (req, res, next) => {
|
||||
const { wallet_password, aezeed_passphrase, cipher_seed_mnemonic } = req.body;
|
||||
let err_message = '';
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.method = 'POST';
|
||||
if (!req.params.operation || req.params.operation === 'unlockwallet') {
|
||||
|
|
@ -54,7 +55,8 @@ export const operateWallet = (req, res, next) => {
|
|||
}
|
||||
err_message = 'Initializing wallet failed!';
|
||||
}
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
const body_str = (!body) ? '' : JSON.stringify(body);
|
||||
const search_idx = (!body) ? -1 : body_str.search('Not Found');
|
||||
if (!body) {
|
||||
|
|
@ -86,13 +88,13 @@ export const operateWallet = (req, res, next) => {
|
|||
};
|
||||
|
||||
export const updateSelNodeOptions = (req, res, next) => {
|
||||
const response = common.updateSelectedNodeOptions(req);
|
||||
const response = common.updateSelectedNodeAxiosConfig(req);
|
||||
res.status(response.status).json({ updateMessage: response.message });
|
||||
};
|
||||
|
||||
export const getUTXOs = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Getting UTXOs..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/wallet/utxos';
|
||||
if (common.isVersionCompatible(req.session.selectedNode.lnVersion, '0.14.0')) {
|
||||
|
|
@ -100,7 +102,8 @@ export const getUTXOs = (req, res, next) => {
|
|||
} else {
|
||||
options.url = options.url + '?max_confs=' + req.query.max_confs;
|
||||
}
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'UTXOs List Received', data: body });
|
||||
res.status(200).json(body.utxos ? body.utxos : []);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -112,7 +115,7 @@ export const getUTXOs = (req, res, next) => {
|
|||
export const bumpFee = (req, res, next) => {
|
||||
const { txid, outputIndex, targetConf, satPerByte } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Bumping Fee..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/wallet/bumpfee';
|
||||
options.form = {};
|
||||
|
|
@ -126,7 +129,8 @@ export const bumpFee = (req, res, next) => {
|
|||
options.form.sat_per_byte = satPerByte;
|
||||
}
|
||||
options.form = JSON.stringify(options.form);
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Fee Bumped', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -137,12 +141,13 @@ export const bumpFee = (req, res, next) => {
|
|||
|
||||
export const labelTransaction = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Labelling Transaction..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/wallet/tx/label';
|
||||
options.form = JSON.stringify(req.body);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Wallet', msg: 'Label Transaction Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Transaction Labelled', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -154,7 +159,7 @@ export const labelTransaction = (req, res, next) => {
|
|||
export const leaseUTXO = (req, res, next) => {
|
||||
const { txid, outputIndex } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Leasing UTXO..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/wallet/utxos/lease';
|
||||
options.form = {};
|
||||
|
|
@ -165,7 +170,8 @@ export const leaseUTXO = (req, res, next) => {
|
|||
};
|
||||
options.form = JSON.stringify(options.form);
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Wallet', msg: 'UTXO Lease Options', data: options.form });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'UTXO Leased', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -177,7 +183,7 @@ export const leaseUTXO = (req, res, next) => {
|
|||
export const releaseUTXO = (req, res, next) => {
|
||||
const { txid, outputIndex } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'Releasing UTXO..' });
|
||||
options = common.getOptions(req);
|
||||
const axiosConfig = common.getAxiosConfig(req);
|
||||
if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); }
|
||||
options.url = req.session.selectedNode.settings.lnServerUrl + '/v2/wallet/utxos/release';
|
||||
options.form = {};
|
||||
|
|
@ -187,7 +193,8 @@ export const releaseUTXO = (req, res, next) => {
|
|||
output_index: outputIndex
|
||||
};
|
||||
options.form = JSON.stringify(options.form);
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Wallet', msg: 'UTXO Released', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import request from 'request-promise';
|
||||
import axios, { AxiosHeaders } from 'axios';
|
||||
import https from 'https';
|
||||
import * as fs from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
|
|
@ -37,9 +38,9 @@ export class LNDWebSocketClient {
|
|||
|
||||
public fetchUnpaidInvoices = (selectedNode: SelectedNode) => {
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Getting Unpaid Invoices..' });
|
||||
const options = this.setOptionsForSelNode(selectedNode);
|
||||
options.url = selectedNode.settings.lnServerUrl + '/v1/invoices?pending_only=true';
|
||||
return request(options).then((body) => {
|
||||
const options = this.setAxiosConfigForSelNode(selectedNode);
|
||||
return axios(selectedNode.settings.lnServerUrl + '/v1/invoices?pending_only=true', options).then((body: any) => {
|
||||
body = body.data;
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Unpaid Invoices Received', data: body });
|
||||
if (body.invoices && body.invoices.length > 0) {
|
||||
body.invoices.forEach((invoice) => {
|
||||
|
|
@ -59,7 +60,8 @@ export class LNDWebSocketClient {
|
|||
rHash = rHash?.replace(/\+/g, '-')?.replace(/[/]/g, '_');
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Subscribing to Invoice ' + rHash + ' ..' });
|
||||
options.url = selectedNode.settings.lnServerUrl + '/v2/invoices/subscribe/' + rHash;
|
||||
request(options).then((msg) => {
|
||||
axios(options).then((msg: any) => {
|
||||
msg = msg.data;
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Invoice Information Received for ' + rHash });
|
||||
if (typeof msg === 'string') {
|
||||
const results = msg.split('\n');
|
||||
|
|
@ -83,7 +85,8 @@ export class LNDWebSocketClient {
|
|||
public subscribeToPayment = (options: any, selectedNode: SelectedNode, paymentHash: string) => {
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Subscribing to Payment ' + paymentHash + ' ..' });
|
||||
options.url = selectedNode.settings.lnServerUrl + '/v2/router/track/' + paymentHash;
|
||||
request(options).then((msg) => {
|
||||
axios(options).then((msg) => {
|
||||
msg = msg.data;
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'WebSocketClient', msg: 'Payment Information Received for ' + paymentHash });
|
||||
msg['type'] = 'payment';
|
||||
msg['source'] = 'LND';
|
||||
|
|
@ -97,10 +100,16 @@ export class LNDWebSocketClient {
|
|||
});
|
||||
};
|
||||
|
||||
public setOptionsForSelNode = (selectedNode: SelectedNode) => {
|
||||
const options = { url: '', rejectUnauthorized: false, json: true, form: null };
|
||||
public setAxiosConfigForSelNode = (selectedNode: SelectedNode) => {
|
||||
const headers = new AxiosHeaders();
|
||||
const options = {
|
||||
baseURL: selectedNode.settings.lnServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
try {
|
||||
options['headers'] = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(selectedNode.authentication.macaroonPath, 'admin.macaroon')).toString('hex') };
|
||||
options['headers'] = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(selectedNode.authentication.macaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
} catch (err) {
|
||||
this.logger.log({ selectedNode: selectedNode, level: 'ERROR', fileName: 'WebSocketClient', msg: 'Set Options Error', error: JSON.stringify(err) });
|
||||
}
|
||||
|
|
@ -120,7 +129,7 @@ export class LNDWebSocketClient {
|
|||
const clientIdx = this.webSocketClients.findIndex((wsc) => +wsc.selectedNode.index === +newSelectedNode.index);
|
||||
let newClient = this.webSocketClients[clientIdx];
|
||||
if (!newClient) { newClient = { selectedNode: null }; }
|
||||
newClient.selectedNode = JSON.parse(JSON.stringify(newSelectedNode));
|
||||
newClient.selectedNode = newSelectedNode;
|
||||
this.webSocketClients[clientIdx] = newClient;
|
||||
if (this.webSocketClients[clientIdx].selectedNode.lnVersion === '' || !this.webSocketClients[clientIdx].selectedNode.lnVersion || this.common.isVersionCompatible(this.webSocketClients[clientIdx].selectedNode.lnVersion, '0.11.0')) {
|
||||
this.fetchUnpaidInvoices(this.webSocketClients[clientIdx].selectedNode);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as fs from 'fs';
|
|||
import { sep } from 'path';
|
||||
import ini from 'ini';
|
||||
import parseHocon from 'hocon-parser';
|
||||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Database, DatabaseService } from '../../utils/database.js';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
|
|
@ -25,14 +25,16 @@ export const getExplorerFeesRecommended = (req, res, next) => {
|
|||
options.url = (blockExplorerUrl === '') ?
|
||||
req.session.selectedNode.settings.blockExplorerUrl + '/api/v1/fees/recommended' :
|
||||
blockExplorerUrl + '/api/v1/fees/recommended';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
blockExplorerUrl = req.session.selectedNode.settings.blockExplorerUrl;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Recommended Fee Rates Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
blockExplorerUrl = 'https://mempool.space';
|
||||
options.url = blockExplorerUrl + '/api/v1/fees/recommended';
|
||||
return request(options).then((body) => {
|
||||
return axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Recommended Fee Rates Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -48,14 +50,16 @@ export const getExplorerTransaction = (req, res, next) => {
|
|||
options.url = (blockExplorerUrl === '') ?
|
||||
req.session.selectedNode.settings.blockExplorerUrl + '/api/tx/' + req.params.txid :
|
||||
blockExplorerUrl + '/api/tx/' + req.params.txid;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
blockExplorerUrl = req.session.selectedNode.settings.blockExplorerUrl;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Transaction From Block Explorer Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
blockExplorerUrl = 'https://mempool.space';
|
||||
options.url = blockExplorerUrl + '/api/tx/' + req.params.txid;
|
||||
return request(options).then((body) => {
|
||||
return axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Transaction From Block Explorer Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -69,7 +73,8 @@ export const getExplorerTransaction = (req, res, next) => {
|
|||
export const getCurrencyRates = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Getting Currency Rates..' });
|
||||
options.url = 'https://blockchain.info/ticker';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'RTLConf', msg: 'Currency Rates Received', data: body });
|
||||
res.status(200).json(JSON.parse(body));
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -7,14 +7,15 @@ const common: CommonService = Common;
|
|||
|
||||
export const getInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Getting Boltz Information..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Get Info Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/info';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -25,14 +26,15 @@ export const getInfo = (req, res, next) => {
|
|||
|
||||
export const getServiceInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Getting Service Information..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Get Service Information Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/serviceinfo';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Get Service Info Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -43,14 +45,15 @@ export const getServiceInfo = (req, res, next) => {
|
|||
|
||||
export const listSwaps = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Getting List Swaps..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'List Swaps Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/listswaps';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz List Swaps Received', data: body });
|
||||
if (body && body.swaps && body.swaps.length && body.swaps.length > 0) { body.swaps = body.swaps.reverse(); }
|
||||
if (body && body.reverseSwaps && body.reverseSwaps.length && body.reverseSwaps.length > 0) { body.reverseSwaps = body.reverseSwaps.reverse(); }
|
||||
|
|
@ -63,14 +66,15 @@ export const listSwaps = (req, res, next) => {
|
|||
|
||||
export const getSwapInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Getting Swap Information..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Get Swap Information Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/swap/' + req.params.swapId;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Swap Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -82,7 +86,7 @@ export const getSwapInfo = (req, res, next) => {
|
|||
export const createSwap = (req, res, next) => {
|
||||
const { amount, sendFromInternal, address, refundAddress } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Creating Swap..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Create Swap Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
|
|
@ -93,7 +97,8 @@ export const createSwap = (req, res, next) => {
|
|||
if (sendFromInternal) { options.body.send_from_internal = sendFromInternal; }
|
||||
if (address && address !== '') { options.body.address = address; }
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Boltz', msg: 'Create Swap Options Body', data: options.body });
|
||||
request.post(options).then((createSwapRes) => {
|
||||
axios.post(options).then((createSwapRes) => {
|
||||
createSwapRes = createSwapRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Swap Created', data: createSwapRes });
|
||||
res.status(201).json(createSwapRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -105,7 +110,7 @@ export const createSwap = (req, res, next) => {
|
|||
export const createReverseSwap = (req, res, next) => {
|
||||
const { amount, acceptZeroConf, address } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Creating Reverse Swap..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Create Reverse Swap Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
|
|
@ -115,7 +120,8 @@ export const createReverseSwap = (req, res, next) => {
|
|||
options.body = { amount: amount, accept_zero_conf: acceptZeroConf || false };
|
||||
if (address && address !== '') { options.body.address = address; }
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Boltz', msg: 'Create Reverse Swap Body', data: options.body });
|
||||
request.post(options).then((createReverseSwapRes) => {
|
||||
axios.post(options).then((createReverseSwapRes) => {
|
||||
createReverseSwapRes = createReverseSwapRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Reverse Swap Created', data: createReverseSwapRes });
|
||||
res.status(201).json(createReverseSwapRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -127,7 +133,7 @@ export const createReverseSwap = (req, res, next) => {
|
|||
export const createChannel = (req, res, next) => {
|
||||
const { amount, address } = req.body;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Creating Boltz Channel..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Create Channel Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
|
|
@ -137,7 +143,8 @@ export const createChannel = (req, res, next) => {
|
|||
options.body = { amount: amount };
|
||||
if (address && address !== '') { options.body.address = address; }
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Boltz', msg: 'Create Channel Options Body', data: options.body });
|
||||
request.post(options).then((createChannelRes) => {
|
||||
axios.post(options).then((createChannelRes) => {
|
||||
createChannelRes = createChannelRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Channel Created', data: createChannelRes });
|
||||
res.status(201).json(createChannelRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -148,14 +155,15 @@ export const createChannel = (req, res, next) => {
|
|||
|
||||
export const deposit = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Deposit Start..' });
|
||||
options = common.getBoltzServerOptions(req);
|
||||
options = common.getBoltzServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Boltz Server URL is missing in the configuration.';
|
||||
const err = common.handleError({ statusCode: 500, message: 'Deposit Error', error: errMsg }, 'Boltz', errMsg, req.session.selectedNode);
|
||||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.url = options.url + '/v1/deposit';
|
||||
request.post(options).then((depositRes) => {
|
||||
axios.post(options).then((depositRes) => {
|
||||
depositRes = depositRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Boltz', msg: 'Boltz Deposit Finished', data: depositRes });
|
||||
res.status(201).json(depositRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import request from 'request-promise';
|
||||
import axios from 'axios';
|
||||
import { Logger, LoggerService } from '../../utils/logger.js';
|
||||
import { Common, CommonService } from '../../utils/common.js';
|
||||
let options = null;
|
||||
|
|
@ -23,7 +23,8 @@ export const loopOut = (req, res, next) => {
|
|||
if (chanId !== '') { options.body['loop_out_channel'] = chanId; }
|
||||
if (destAddress !== '') { options.body['dest'] = destAddress; }
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Body', data: options.body });
|
||||
request.post(options).then((loopOutRes) => {
|
||||
axios.post(options).then((loopOutRes) => {
|
||||
loopOutRes = loopOutRes.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looped Out', data: loopOutRes });
|
||||
res.status(201).json(loopOutRes);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -35,7 +36,8 @@ 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.uri = '/v1/loop/out/terms';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Out Terms Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -48,7 +50,8 @@ export const loopOutQuote = (req, res, next) => {
|
|||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Out Quotes..' });
|
||||
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) => {
|
||||
axios(options).then((quoteRes: any) => {
|
||||
quoteRes = quoteRes.data;
|
||||
quoteRes.amount = +req.params.amount;
|
||||
quoteRes.swap_payment_dest = quoteRes.swap_payment_dest ? Buffer.from(quoteRes.swap_payment_dest, 'base64').toString('hex') : '';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Out Quote Received', data: quoteRes });
|
||||
|
|
@ -62,14 +65,17 @@ 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.uri = '/v1/loop/out/terms';
|
||||
request(options).then((terms) => {
|
||||
axios(options).then((terms: any) => {
|
||||
terms = terms.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Out Terms Received', data: terms });
|
||||
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) => {
|
||||
return Promise.all([axios(options1), axios(options2)]).then((values: any[]) => {
|
||||
values[0] = values[0].data;
|
||||
values[1] = values[1].data;
|
||||
values[0].amount = +terms.min_swap_amount;
|
||||
values[1].amount = +terms.max_swap_amount;
|
||||
values[0].swap_payment_dest = values[0].swap_payment_dest ? Buffer.from(values[0].swap_payment_dest, 'base64').toString('hex') : '';
|
||||
|
|
@ -98,7 +104,8 @@ export const loopIn = (req, res, next) => {
|
|||
initiator: 'RTL'
|
||||
};
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Body', data: options.body });
|
||||
request.post(options).then((body) => {
|
||||
axios.post(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Looped In', data: body });
|
||||
res.status(201).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -110,7 +117,8 @@ 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.uri = '/v1/loop/in/terms';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Terms Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -123,7 +131,8 @@ export const loopInQuote = (req, res, next) => {
|
|||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop In Quotes..' });
|
||||
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) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
body.amount = +req.params.amount;
|
||||
body.swap_payment_dest = body.swap_payment_dest ? Buffer.from(body.swap_payment_dest, 'base64').toString('hex') : '';
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop In Qoutes Received', data: body });
|
||||
|
|
@ -137,14 +146,16 @@ 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.uri = '/v1/loop/in/terms';
|
||||
request(options).then((terms) => {
|
||||
axios(options).then((terms: any) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop In Terms Received', data: terms });
|
||||
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) => {
|
||||
return Promise.all([axios(options1), axios(options2)]).then((values: any[]) => {
|
||||
values[0] = values[0].data;
|
||||
values[1] = values[1].data;
|
||||
values[0].amount = +terms.min_swap_amount;
|
||||
values[1].amount = +terms.max_swap_amount;
|
||||
values[0].swap_payment_dest = values[0].swap_payment_dest ? Buffer.from(values[0].swap_payment_dest, 'base64').toString('hex') : '';
|
||||
|
|
@ -170,7 +181,8 @@ export const swaps = (req, res, next) => {
|
|||
return res.status(err.statusCode).json({ message: err.message, error: err.error });
|
||||
}
|
||||
options.uri = '/v1/loop/swaps';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'DEBUG', fileName: 'Loop', msg: 'Loop Swaps Received', data: body });
|
||||
res.status(200).json(body.swaps);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -182,7 +194,8 @@ 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.uri = '/v1/loop/swap/' + req.params.id;
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Swap Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
@ -193,14 +206,15 @@ export const swap = (req, res, next) => {
|
|||
|
||||
export const loopInfo = (req, res, next) => {
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Getting Loop Information..' });
|
||||
options = common.setSwapServerOptions(req);
|
||||
options = common.getSwapServerConfig(req);
|
||||
if (options.url === '') {
|
||||
const errMsg = 'Loop Server URL is missing in the configuration.';
|
||||
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.uri = '/v1/loop/info';
|
||||
request(options).then((body) => {
|
||||
axios(options).then((body: any) => {
|
||||
body = body.data;
|
||||
logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Loop', msg: 'Loop Information Received', data: body });
|
||||
res.status(200).json(body);
|
||||
}).catch((errRes) => {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ export class Settings {
|
|||
export class Authentication {
|
||||
|
||||
constructor(
|
||||
public options?: any,
|
||||
public configPath?: string,
|
||||
public macaroonPath?: string,
|
||||
public macaroonValue?: string,
|
||||
|
|
@ -77,7 +76,8 @@ export class SelectedNode {
|
|||
public lnImplementation?: string,
|
||||
public lnVersion?: string,
|
||||
public settings?: Settings,
|
||||
public authentication?: Authentication
|
||||
public authentication?: Authentication,
|
||||
public axiosConfig?: any
|
||||
) { }
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import * as fs from 'fs';
|
|||
import { join, dirname, isAbsolute, resolve, sep } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import * as crypto from 'crypto';
|
||||
import request from 'request-promise';
|
||||
import axios, { AxiosHeaders } from 'axios';
|
||||
import https from 'https';
|
||||
import { Logger, LoggerService } from './logger.js';
|
||||
import { ApplicationConfig, SelectedNode } from '../models/config.model.js';
|
||||
|
||||
|
|
@ -48,11 +49,8 @@ export class CommonService {
|
|||
|
||||
public removeAuthSecureData = (node: SelectedNode) => {
|
||||
if (node.authentication) {
|
||||
delete node.authentication.macaroonPath;
|
||||
delete node.authentication.runePath;
|
||||
delete node.authentication.runeValue;
|
||||
delete node.authentication.lnApiPassword;
|
||||
delete node.authentication.options;
|
||||
const { configPath } = node.authentication;
|
||||
node.authentication = { configPath };
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
|
@ -95,63 +93,54 @@ export class CommonService {
|
|||
return config;
|
||||
};
|
||||
|
||||
public setSwapServerOptions = (req) => {
|
||||
const swapOptions = {
|
||||
baseUrl: req.session.selectedNode.settings.swapServerUrl,
|
||||
uri: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: { 'Grpc-Metadata-macaroon': '' }
|
||||
public getSwapServerConfig = (req) => {
|
||||
const headers = new AxiosHeaders();
|
||||
const swapConfig = {
|
||||
baseURL: req.session.selectedNode.settings.swapServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
if (req.session.selectedNode.authentication.swapMacaroonPath) {
|
||||
try {
|
||||
swapOptions.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(req.session.selectedNode.authentication.swapMacaroonPath, 'loop.macaroon')).toString('hex') };
|
||||
swapConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(req.session.selectedNode.authentication.swapMacaroonPath, 'loop.macaroon')).toString('hex'));
|
||||
} catch (err) {
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Loop macaroon Error', error: err });
|
||||
}
|
||||
}
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Swap Options', data: swapOptions });
|
||||
return swapOptions;
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Swap Axios Config', data: swapConfig });
|
||||
return swapConfig;
|
||||
};
|
||||
|
||||
public getBoltzServerOptions = (req) => {
|
||||
const boltzOptions = {
|
||||
url: req.session.selectedNode.settings.boltzServerUrl,
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: { 'Grpc-Metadata-macaroon': '' }
|
||||
public getBoltzServerConfig = (req) => {
|
||||
const headers = new AxiosHeaders();
|
||||
const boltzConfig = {
|
||||
baseURL: req.session.selectedNode.settings.swapServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
if (req.session.selectedNode.authentication.boltzMacaroonPath) {
|
||||
try {
|
||||
boltzOptions.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(req.session.selectedNode.authentication.boltzMacaroonPath, 'admin.macaroon')).toString('hex') };
|
||||
boltzConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(req.session.selectedNode.authentication.boltzMacaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
} catch (err) {
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Boltz macaroon Error', error: err });
|
||||
}
|
||||
}
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Boltz Options', data: boltzOptions });
|
||||
return boltzOptions;
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Boltz Axios Config', data: boltzConfig });
|
||||
return boltzConfig;
|
||||
};
|
||||
|
||||
public getOptions = (req) => {
|
||||
if (req.session.selectedNode && req.session.selectedNode.authentication.options) {
|
||||
req.session.selectedNode.authentication.options.method = (req.session.selectedNode.lnImplementation && req.session.selectedNode.lnImplementation.toUpperCase() === 'LND') ? 'GET' : 'POST';
|
||||
delete req.session.selectedNode.authentication.options.form;
|
||||
delete req.session.selectedNode.authentication.options.body;
|
||||
req.session.selectedNode.authentication.options.qs = {};
|
||||
return req.session.selectedNode.authentication.options;
|
||||
}
|
||||
return this.handleError({ statusCode: 401, message: 'Session expired after a day\'s inactivity' }, 'Session Expired', 'Session Expiry Error', this.selectedNode);
|
||||
};
|
||||
|
||||
public updateSelectedNodeOptions = (req) => {
|
||||
public updateSelectedNodeAxiosConfig = (req) => {
|
||||
if (!req.session.selectedNode) {
|
||||
req.session.selectedNode = {};
|
||||
}
|
||||
req.session.selectedNode.authentication.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
form: null
|
||||
const headers = new AxiosHeaders();
|
||||
req.session.selectedNode.axiosConfig = {
|
||||
baseURL: '',
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
try {
|
||||
if (req.session.selectedNode && req.session.selectedNode.lnImplementation) {
|
||||
|
|
@ -161,31 +150,31 @@ export class CommonService {
|
|||
if (!req.session.selectedNode.authentication.runeValue) {
|
||||
req.session.selectedNode.authentication.runeValue = this.getRuneValue(req.session.selectedNode.authentication.runePath);
|
||||
}
|
||||
req.session.selectedNode.authentication.options.headers = { rune: req.session.selectedNode.authentication.runeValue };
|
||||
req.session.selectedNode.axiosConfig.headers = headers.set('rune', req.session.selectedNode.authentication.runeValue);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'ECL':
|
||||
req.session.selectedNode.authentication.options.headers = { authorization: 'Basic ' + Buffer.from(':' + req.session.selectedNode.authentication.lnApiPassword).toString('base64') };
|
||||
req.session.selectedNode.axiosConfig.headers = headers.set('authorization', 'Basic ' + Buffer.from(':' + req.session.selectedNode.authentication.lnApiPassword).toString('base64'));
|
||||
break;
|
||||
|
||||
default:
|
||||
req.session.selectedNode.authentication.options.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(req.session.selectedNode.authentication.macaroonPath, 'admin.macaroon')).toString('hex') };
|
||||
req.session.selectedNode.axiosConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(req.session.selectedNode.authentication.macaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (req.session.selectedNode) {
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Updated Node Options for ' + req.session.selectedNode.lnNode, data: req.session.selectedNode.authentication.options });
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Updated Node Options for ' + req.session.selectedNode.lnNode, data: req.session.selectedNode.axiosConfig });
|
||||
}
|
||||
return { status: 200, message: 'Updated Successfully' };
|
||||
} catch (err) {
|
||||
req.session.selectedNode.authentication.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
form: null
|
||||
req.session.selectedNode.axiosConfig = {
|
||||
baseURL: '',
|
||||
headers: new AxiosHeaders(),
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Update Selected Node Options Error', error: err });
|
||||
return { status: 502, message: err };
|
||||
|
|
@ -203,15 +192,71 @@ export class CommonService {
|
|||
}
|
||||
};
|
||||
|
||||
public setOptions = (req) => {
|
||||
if (this.nodes[0].authentication.options && this.nodes[0].authentication.options.headers) { return; }
|
||||
public getAxiosConfig = (req) => {
|
||||
if (!req.session.selectedNode) {
|
||||
return this.handleError(
|
||||
{ statusCode: 401, message: 'Session expired after a day\'s inactivity' },
|
||||
'Session Expired',
|
||||
'Session Expiry Error',
|
||||
this.selectedNode
|
||||
);
|
||||
}
|
||||
return this.generateAxiosConfig(req.session.selectedNode);
|
||||
};
|
||||
|
||||
public generateAxiosConfig = (node: SelectedNode) => {
|
||||
const headers = new AxiosHeaders();
|
||||
const axiosConfig = {
|
||||
baseURL: node.settings.lnServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
|
||||
try {
|
||||
if (node.lnImplementation) {
|
||||
switch (node.lnImplementation.toUpperCase()) {
|
||||
case 'CLN':
|
||||
axiosConfig.headers = headers.set('rune', node.authentication.runeValue);
|
||||
break;
|
||||
|
||||
case 'ECL':
|
||||
axiosConfig.headers = headers.set(
|
||||
'authorization',
|
||||
'Basic ' + Buffer.from(':' + node.authentication.lnApiPassword).toString('base64')
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
axiosConfig.headers = headers.set(
|
||||
'Grpc-Metadata-macaroon',
|
||||
fs.readFileSync(join(node.authentication.macaroonPath, 'admin.macaroon')).toString('hex')
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return axiosConfig;
|
||||
} catch (err) {
|
||||
return this.handleError(
|
||||
{ statusCode: 502, message: err.message },
|
||||
'Common',
|
||||
'Config Generation Error',
|
||||
node
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public setAxiosConfig = (req) => {
|
||||
if (this.nodes[0].axiosConfig && this.nodes[0].axiosConfig.headers) { return; }
|
||||
if (this.nodes && this.nodes.length > 0) {
|
||||
this.nodes.forEach((node) => {
|
||||
node.authentication.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
form: null
|
||||
const headers = new AxiosHeaders();
|
||||
node.axiosConfig = {
|
||||
baseURL: node.settings.lnServerUrl,
|
||||
headers,
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
try {
|
||||
if (node.lnImplementation) {
|
||||
|
|
@ -221,33 +266,33 @@ export class CommonService {
|
|||
if (!node.authentication.runeValue) {
|
||||
node.authentication.runeValue = this.getRuneValue(node.authentication.runePath);
|
||||
}
|
||||
node.authentication.options.headers = { rune: node.authentication.runeValue };
|
||||
node.axiosConfig.headers = headers.set('rune', node.authentication.runeValue);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'ECL':
|
||||
node.authentication.options.headers = { authorization: 'Basic ' + Buffer.from(':' + node.authentication.lnApiPassword).toString('base64') };
|
||||
node.axiosConfig.headers = headers.set('authorization', 'Basic ' + Buffer.from(':' + node.authentication.lnApiPassword).toString('base64'));
|
||||
break;
|
||||
|
||||
default:
|
||||
node.authentication.options.headers = { 'Grpc-Metadata-macaroon': fs.readFileSync(join(node.authentication.macaroonPath, 'admin.macaroon')).toString('hex') };
|
||||
node.axiosConfig.headers = headers.set('Grpc-Metadata-macaroon', fs.readFileSync(join(node.authentication.macaroonPath, 'admin.macaroon')).toString('hex'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'ERROR', fileName: 'Common', msg: 'Common Set Options Error', error: err });
|
||||
node.authentication.options = {
|
||||
url: '',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
form: ''
|
||||
node.axiosConfig = {
|
||||
baseURL: '',
|
||||
headers: new AxiosHeaders(),
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
}
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Set Node Options for ' + node.lnNode, data: node.authentication.options });
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Set Node Options for ' + node.lnNode, data: node.axiosConfig });
|
||||
});
|
||||
this.updateSelectedNodeOptions(req);
|
||||
this.updateSelectedNodeAxiosConfig(req);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -325,7 +370,25 @@ export class CommonService {
|
|||
};
|
||||
|
||||
public handleError = (errRes, fileName, errMsg, selectedNode: SelectedNode) => {
|
||||
const err = JSON.parse(JSON.stringify(errRes));
|
||||
let err: any;
|
||||
if (errRes.isAxiosError || errRes.response) {
|
||||
err = {
|
||||
statusCode: errRes.response?.status || 500,
|
||||
message: errRes.message,
|
||||
error: errRes.response?.data || errRes.message,
|
||||
options: errRes.config ? {
|
||||
headers: errRes.config.headers,
|
||||
url: errRes.config.url
|
||||
} : {},
|
||||
response: errRes.response ? {
|
||||
request: {
|
||||
headers: errRes.response.config?.headers
|
||||
}
|
||||
} : {}
|
||||
};
|
||||
} else {
|
||||
err = JSON.parse(JSON.stringify(errRes));
|
||||
}
|
||||
if (!selectedNode) { selectedNode = this.selectedNode; }
|
||||
switch (selectedNode.lnImplementation) {
|
||||
case 'LND':
|
||||
|
|
@ -484,14 +547,16 @@ export class CommonService {
|
|||
|
||||
public getAllNodeAllChannelBackup = (node: SelectedNode) => {
|
||||
const channel_backup_file = node.settings.channelBackupPath + sep + 'channel-all.bak';
|
||||
const headers = new AxiosHeaders();
|
||||
const options = {
|
||||
url: node.settings.lnServerUrl + '/v1/channels/backup',
|
||||
rejectUnauthorized: false,
|
||||
json: true,
|
||||
headers: { 'Grpc-Metadata-macaroon': fs.readFileSync(node.authentication.macaroonPath + '/admin.macaroon').toString('hex') }
|
||||
baseURL: node.settings.lnServerUrl,
|
||||
headers: headers.set('Grpc-Metadata-macaroon', fs.readFileSync(node.authentication.macaroonPath + '/admin.macaroon').toString('hex')),
|
||||
params: {},
|
||||
httpsAgent: new https.Agent({ rejectUnauthorized: false })
|
||||
};
|
||||
this.logger.log({ selectedNode: this.selectedNode, level: 'INFO', fileName: 'Common', msg: 'Getting Channel Backup for Node ' + node.lnNode + '..' });
|
||||
request(options).then((body) => {
|
||||
axios('/v1/channels/backup', options).then((body: any) => {
|
||||
body = body.data;
|
||||
fs.writeFile(channel_backup_file, JSON.stringify(body), (err) => {
|
||||
if (err) {
|
||||
if (node.lnNode) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue