import express, { Response, Request, Router, NextFunction } from 'express' import lnService from 'ln-service' import { NodeInfo } from '../typings' const router: Router = express.Router() /** * ## Route GET /node * @description Retrieve relevant connection info about lightning node * @param {Request} req - expressjs request object decorated for middleware * @param {Response} res - expressjs response object * @returns {Promise} returns an express response with the node information */ export const getNodeInfo = async ( req: Request, res: Response, next: NextFunction ): Promise => { try { let nodeInfo: NodeInfo if (req.lnd) { const { public_key: pubKey, alias, active_channels_count: activeChannelsCount, peers_count: peersCount, uris, } = await lnService.getWalletInfo({ lnd: req.lnd, }) nodeInfo = { pubKey, alias, uris, activeChannelsCount, peersCount, } } else if (req.opennode) // this is a kind of stand-in, a best guess at what the pubkey for the opennode // node is. Probably need to change this or find another way to get better // connected with the paywall's node. Also need to differentiate between main and testnet nodeInfo = { pubKey: '02eadbd9e7557375161df8b646776a547c5cbc2e95b3071ec81553f8ec2cea3b8c', uris: [ '02eadbd9e7557375161df8b646776a547c5cbc2e95b3071ec81553f8ec2cea3b8c@18.191.253.246:9735', ], alias: 'OpenNode', } else { res.status(404) return next({ message: 'No public key information found for node' }) } res.status(200) return res.json(nodeInfo) } catch (e) { req.logger.error('Problem connecting to node:', e) res.status(500) return next({ message: 'Problem connecting to lightning node provider.', }) } } router.route('*/node').get(getNodeInfo) export default router