From 2e4ed0c96323a8271cc1d389546999ced22f7824 Mon Sep 17 00:00:00 2001 From: Shahana Farooqui Date: Tue, 2 May 2023 17:34:41 -0700 Subject: [PATCH] Fixing Server lint bugs Fixing Server lint bugs --- backend/controllers/eclair/channels.js | 20 ++++++++------ backend/controllers/eclair/invoices.js | 6 ++-- backend/controllers/eclair/network.js | 6 ++-- backend/controllers/eclair/payments.js | 6 ++-- server/controllers/eclair/channels.ts | 38 ++++++++++++++------------ server/controllers/eclair/invoices.ts | 6 ++-- server/controllers/eclair/network.ts | 8 ++---- server/controllers/eclair/payments.ts | 6 ++-- 8 files changed, 44 insertions(+), 52 deletions(-) diff --git a/backend/controllers/eclair/channels.js b/backend/controllers/eclair/channels.js index ffd771fa..69b544d4 100644 --- a/backend/controllers/eclair/channels.js +++ b/backend/controllers/eclair/channels.js @@ -171,24 +171,26 @@ export const circularRebalance = (req, res, next) => { const tillToday = (Math.round(new Date(Date.now()).getTime() / 1000)).toString(); // Check if unpaid Invoice exists already listPendingInvoicesRequestCall(req.session.selectedNode).then((callRes) => { - const foundExistingInvoice = callRes.find(inv => inv.description.includes(crInvDescription) && inv.amount === req.body.amountMsat && inv.expiry && inv.timestamp && ((inv.expiry + inv.timestamp) >= tillToday)); + const foundExistingInvoice = callRes.find((inv) => inv.description.includes(crInvDescription) && inv.amount === req.body.amountMsat && inv.expiry && inv.timestamp && ((inv.expiry + inv.timestamp) >= tillToday)); // Create new invoice if doesn't exist already const requestCalls = foundExistingInvoice && foundExistingInvoice.serialized ? [findRouteBetweenNodesRequestCall(req.session.selectedNode, req.body.amountMsat, req.body.sourceNodeId, req.body.targetNodeId, req.body.ignoreNodeIds, req.body.format)] : [findRouteBetweenNodesRequestCall(req.session.selectedNode, req.body.amountMsat, req.body.sourceNodeId, req.body.targetNodeId, req.body.ignoreNodeIds, req.body.format), createInvoiceRequestCall(req.session.selectedNode, crInvDescription, req.body.amountMsat)]; Promise.all(requestCalls).then((values) => { - let routes = values[0]?.routes?.filter(route => { + // eslint-disable-next-line arrow-body-style + const routes = values[0]?.routes?.filter((route) => { return !((route.shortChannelIds[0] === req.body.sourceShortChannelId && route.shortChannelIds[1] === req.body.targetShortChannelId) || (route.shortChannelIds[1] === req.body.sourceShortChannelId && route.shortChannelIds[0] === req.body.targetShortChannelId)); }); - let firstRoute = routes[0].shortChannelIds.join() || ''; - let shortChannelIds = req.body.sourceShortChannelId + ',' + firstRoute + ',' + req.body.targetShortChannelId; - let invoice = (foundExistingInvoice && foundExistingInvoice.serialized ? foundExistingInvoice.serialized : (values[1] ? values[1].serialized : '')) || ''; - let paymentHash = (foundExistingInvoice && foundExistingInvoice.paymentHash ? foundExistingInvoice.paymentHash : (values[1] ? values[1].paymentHash : '') || ''); - return sendPaymentToRouteRequestCall(req.session.selectedNode, shortChannelIds, invoice, req.body.amountMsat).then(payToRouteCallRes => { + const firstRoute = routes[0].shortChannelIds.join() || ''; + const shortChannelIds = req.body.sourceShortChannelId + ',' + firstRoute + ',' + req.body.targetShortChannelId; + const invoice = (foundExistingInvoice && foundExistingInvoice.serialized ? foundExistingInvoice.serialized : (values[1] ? values[1].serialized : '')) || ''; + const paymentHash = (foundExistingInvoice && foundExistingInvoice.paymentHash ? foundExistingInvoice.paymentHash : (values[1] ? values[1].paymentHash : '') || ''); + return sendPaymentToRouteRequestCall(req.session.selectedNode, shortChannelIds, invoice, req.body.amountMsat).then((payToRouteCallRes) => { + // eslint-disable-next-line arrow-body-style setTimeout(() => { - return getSentInfoFromPaymentRequest(req.session.selectedNode, paymentHash).then(sentInfoCallRes => { - let payStatus = sentInfoCallRes.length && sentInfoCallRes.length > 0 ? sentInfoCallRes[sentInfoCallRes.length - 1].status : sentInfoCallRes; + return getSentInfoFromPaymentRequest(req.session.selectedNode, paymentHash).then((sentInfoCallRes) => { + const payStatus = sentInfoCallRes.length && sentInfoCallRes.length > 0 ? sentInfoCallRes[sentInfoCallRes.length - 1].status : sentInfoCallRes; return res.status(201).json({ flgReusingInvoice: !!foundExistingInvoice, invoice: invoice, paymentHash: paymentHash, paymentDetails: payToRouteCallRes, paymentStatus: payStatus }); }).catch((errRes) => { const err = common.handleError(errRes, 'Channels', 'Channel Rebalance From Sent Info Error', req.session.selectedNode); diff --git a/backend/controllers/eclair/invoices.js b/backend/controllers/eclair/invoices.js index 18adfd27..45310605 100644 --- a/backend/controllers/eclair/invoices.js +++ b/backend/controllers/eclair/invoices.js @@ -140,9 +140,7 @@ export const createInvoice = (req, res, next) => { if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); } - createInvoiceRequestCall(req.session.selectedNode, req.body.description, req.body.amountMsat).then(invRes => { + createInvoiceRequestCall(req.session.selectedNode, req.body.description, req.body.amountMsat).then((invRes) => { res.status(201).json(invRes); - }).catch((err) => { - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - }); + }).catch((err) => res.status(err.statusCode).json({ message: err.message, error: err.error })); }; diff --git a/backend/controllers/eclair/network.js b/backend/controllers/eclair/network.js index f7040eaa..1cd0aae3 100644 --- a/backend/controllers/eclair/network.js +++ b/backend/controllers/eclair/network.js @@ -39,9 +39,7 @@ export const findRouteBetweenNodes = (req, res, next) => { if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); } - findRouteBetweenNodesRequestCall(req.session.selectedNode, req.body.amountMsat, req.body.sourceNodeId, req.body.targetNodeId, req.body.ignoreNodeIds, req.body.format).then(callRes => { + findRouteBetweenNodesRequestCall(req.session.selectedNode, req.body.amountMsat, req.body.sourceNodeId, req.body.targetNodeId, req.body.ignoreNodeIds, req.body.format).then((callRes) => { res.status(200).json(callRes); - }).catch((err) => { - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - }); + }).catch((err) => res.status(err.statusCode).json({ message: err.message, error: err.error })); }; diff --git a/backend/controllers/eclair/payments.js b/backend/controllers/eclair/payments.js index d83db5e3..38922282 100644 --- a/backend/controllers/eclair/payments.js +++ b/backend/controllers/eclair/payments.js @@ -147,9 +147,7 @@ export const sendPaymentToRoute = (req, res, next) => { if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); } - sendPaymentToRouteRequestCall(req.session.selectedNode, req.body.shortChannelIds, req.body.invoice, req.body.amountMsat).then(callRes => { + sendPaymentToRouteRequestCall(req.session.selectedNode, req.body.shortChannelIds, req.body.invoice, req.body.amountMsat).then((callRes) => { res.status(200).json(callRes); - }).catch((err) => { - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - }); + }).catch((err) => res.status(err.statusCode).json({ message: err.message, error: err.error })); }; diff --git a/server/controllers/eclair/channels.ts b/server/controllers/eclair/channels.ts index b3f335a4..a280e31a 100644 --- a/server/controllers/eclair/channels.ts +++ b/server/controllers/eclair/channels.ts @@ -166,30 +166,32 @@ export const circularRebalance = (req, res, next) => { const tillToday = (Math.round(new Date(Date.now()).getTime() / 1000)).toString(); // Check if unpaid Invoice exists already listPendingInvoicesRequestCall(req.session.selectedNode).then((callRes: any[]) => { - const foundExistingInvoice = callRes.find(inv => inv.description.includes(crInvDescription) && inv.amount === req.body.amountMsat && inv.expiry && inv.timestamp && ((inv.expiry + inv.timestamp) >= tillToday)); + const foundExistingInvoice = callRes.find((inv) => inv.description.includes(crInvDescription) && inv.amount === req.body.amountMsat && inv.expiry && inv.timestamp && ((inv.expiry + inv.timestamp) >= tillToday)); // Create new invoice if doesn't exist already - const requestCalls = foundExistingInvoice && foundExistingInvoice.serialized ? + const requestCalls = foundExistingInvoice && foundExistingInvoice.serialized ? [findRouteBetweenNodesRequestCall(req.session.selectedNode, req.body.amountMsat, req.body.sourceNodeId, req.body.targetNodeId, req.body.ignoreNodeIds, req.body.format)] : [findRouteBetweenNodesRequestCall(req.session.selectedNode, req.body.amountMsat, req.body.sourceNodeId, req.body.targetNodeId, req.body.ignoreNodeIds, req.body.format), createInvoiceRequestCall(req.session.selectedNode, crInvDescription, req.body.amountMsat)]; Promise.all(requestCalls).then((values: any[]) => { - let routes = values[0]?.routes?.filter(route => { - return !((route.shortChannelIds[0] === req.body.sourceShortChannelId && route.shortChannelIds[1] === req.body.targetShortChannelId) || + // eslint-disable-next-line arrow-body-style + const routes = values[0]?.routes?.filter((route) => { + return !((route.shortChannelIds[0] === req.body.sourceShortChannelId && route.shortChannelIds[1] === req.body.targetShortChannelId) || (route.shortChannelIds[1] === req.body.sourceShortChannelId && route.shortChannelIds[0] === req.body.targetShortChannelId)); }); - let firstRoute = routes[0].shortChannelIds.join() || ''; - let shortChannelIds=req.body.sourceShortChannelId + ',' + firstRoute + ',' + req.body.targetShortChannelId; - let invoice = (foundExistingInvoice && foundExistingInvoice.serialized ? foundExistingInvoice.serialized : (values[1] ? values[1].serialized : '')) || ''; - let paymentHash = (foundExistingInvoice && foundExistingInvoice.paymentHash ? foundExistingInvoice.paymentHash : (values[1] ? values[1].paymentHash : '') || ''); - return sendPaymentToRouteRequestCall(req.session.selectedNode, shortChannelIds, invoice, req.body.amountMsat).then(payToRouteCallRes => { - setTimeout(() => { - return getSentInfoFromPaymentRequest(req.session.selectedNode, paymentHash).then(sentInfoCallRes => { - let payStatus = sentInfoCallRes.length && sentInfoCallRes.length > 0 ? sentInfoCallRes[sentInfoCallRes.length-1].status : sentInfoCallRes; - return res.status(201).json({ flgReusingInvoice: !!foundExistingInvoice, invoice: invoice, paymentHash: paymentHash, paymentDetails: payToRouteCallRes, paymentStatus: payStatus }); - }).catch((errRes) => { - const err = common.handleError(errRes, 'Channels', 'Channel Rebalance From Sent Info Error', req.session.selectedNode); - return res.status(err.statusCode).json({ flgReusingInvoice: !!foundExistingInvoice, invoice: invoice, paymentHash: paymentHash, paymentDetails: payToRouteCallRes, paymentStatus: { message: err.message, error: err.error } }); - }); - }, 3000); + const firstRoute = routes[0].shortChannelIds.join() || ''; + const shortChannelIds = req.body.sourceShortChannelId + ',' + firstRoute + ',' + req.body.targetShortChannelId; + const invoice = (foundExistingInvoice && foundExistingInvoice.serialized ? foundExistingInvoice.serialized : (values[1] ? values[1].serialized : '')) || ''; + const paymentHash = (foundExistingInvoice && foundExistingInvoice.paymentHash ? foundExistingInvoice.paymentHash : (values[1] ? values[1].paymentHash : '') || ''); + return sendPaymentToRouteRequestCall(req.session.selectedNode, shortChannelIds, invoice, req.body.amountMsat).then((payToRouteCallRes) => { + // eslint-disable-next-line arrow-body-style + setTimeout(() => { + return getSentInfoFromPaymentRequest(req.session.selectedNode, paymentHash).then((sentInfoCallRes) => { + const payStatus = sentInfoCallRes.length && sentInfoCallRes.length > 0 ? sentInfoCallRes[sentInfoCallRes.length - 1].status : sentInfoCallRes; + return res.status(201).json({ flgReusingInvoice: !!foundExistingInvoice, invoice: invoice, paymentHash: paymentHash, paymentDetails: payToRouteCallRes, paymentStatus: payStatus }); + }).catch((errRes) => { + const err = common.handleError(errRes, 'Channels', 'Channel Rebalance From Sent Info Error', req.session.selectedNode); + return res.status(err.statusCode).json({ flgReusingInvoice: !!foundExistingInvoice, invoice: invoice, paymentHash: paymentHash, paymentDetails: payToRouteCallRes, paymentStatus: { message: err.message, error: err.error } }); + }); + }, 3000); }).catch((errRes) => { const err = common.handleError(errRes, 'Channels', 'Channel Rebalance From Send Payment To Route Error', req.session.selectedNode); return res.status(err.statusCode).json({ flgReusingInvoice: !!foundExistingInvoice, invoice: invoice, paymentHash: paymentHash, paymentDetails: {}, paymentStatus: { message: err.message, error: err.error } }); diff --git a/server/controllers/eclair/invoices.ts b/server/controllers/eclair/invoices.ts index 7dd1a0a7..4b21b9b7 100644 --- a/server/controllers/eclair/invoices.ts +++ b/server/controllers/eclair/invoices.ts @@ -134,9 +134,7 @@ export const createInvoice = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Invoices', msg: 'Creating Invoice..' }); options = common.getOptions(req); if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); } - createInvoiceRequestCall(req.session.selectedNode, req.body.description, req.body.amountMsat).then(invRes => { + createInvoiceRequestCall(req.session.selectedNode, req.body.description, req.body.amountMsat).then((invRes) => { res.status(201).json(invRes); - }).catch((err) => { - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - }); + }).catch((err) => res.status(err.statusCode).json({ message: err.message, error: err.error })); }; diff --git a/server/controllers/eclair/network.ts b/server/controllers/eclair/network.ts index 3fdad0c2..3b347eb8 100644 --- a/server/controllers/eclair/network.ts +++ b/server/controllers/eclair/network.ts @@ -25,7 +25,7 @@ export const findRouteBetweenNodesRequestCall = (selectedNode: CommonSelectedNod logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Network', msg: 'Find Route Between Nodes..' }); options = selectedNode.options; options.url = selectedNode.ln_server_url + '/findroutebetweennodes'; - options.form = { amountMsat: amountMsat, sourceNodeId: sourceNodeId, targetNodeId: targetNodeId, ignoreNodeIds: ignoreNodeIds, format: format }; + options.form = { amountMsat: amountMsat, sourceNodeId: sourceNodeId, targetNodeId: targetNodeId, ignoreNodeIds: ignoreNodeIds, format: format }; return new Promise((resolve, reject) => { request.post(options).then((body) => { logger.log({ selectedNode: selectedNode, level: 'INFO', fileName: 'Network', msg: 'Route Lookup Between Nodes Finished', data: body }); @@ -39,9 +39,7 @@ export const findRouteBetweenNodesRequestCall = (selectedNode: CommonSelectedNod export const findRouteBetweenNodes = (req, res, next) => { options = common.getOptions(req); if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); } - findRouteBetweenNodesRequestCall(req.session.selectedNode, req.body.amountMsat, req.body.sourceNodeId, req.body.targetNodeId, req.body.ignoreNodeIds, req.body.format).then(callRes => { + findRouteBetweenNodesRequestCall(req.session.selectedNode, req.body.amountMsat, req.body.sourceNodeId, req.body.targetNodeId, req.body.ignoreNodeIds, req.body.format).then((callRes) => { res.status(200).json(callRes); - }).catch((err) => { - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - }); + }).catch((err) => res.status(err.statusCode).json({ message: err.message, error: err.error })); }; diff --git a/server/controllers/eclair/payments.ts b/server/controllers/eclair/payments.ts index eea361b2..06c4ea0d 100644 --- a/server/controllers/eclair/payments.ts +++ b/server/controllers/eclair/payments.ts @@ -138,9 +138,7 @@ export const sendPaymentToRoute = (req, res, next) => { logger.log({ selectedNode: req.session.selectedNode, level: 'INFO', fileName: 'Payments', msg: 'Send Payment To Route..' }); options = common.getOptions(req); if (options.error) { return res.status(options.statusCode).json({ message: options.message, error: options.error }); } - sendPaymentToRouteRequestCall(req.session.selectedNode, req.body.shortChannelIds, req.body.invoice, req.body.amountMsat).then(callRes => { + sendPaymentToRouteRequestCall(req.session.selectedNode, req.body.shortChannelIds, req.body.invoice, req.body.amountMsat).then((callRes) => { res.status(200).json(callRes); - }).catch((err) => { - return res.status(err.statusCode).json({ message: err.message, error: err.error }); - }); + }).catch((err) => res.status(err.statusCode).json({ message: err.message, error: err.error })); };