Skip to content

Commit

Permalink
Update dependencies (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronDewes authored Jan 4, 2021
1 parent b8cd8d0 commit cf40d77
Show file tree
Hide file tree
Showing 16 changed files with 10,877 additions and 4,826 deletions.
12 changes: 6 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"parser": "babel-eslint",
"parser": "@babel/eslint-parser",
"plugins": [
"prettier"
],
"extends": ["prettier"],
"rules": {
'prettier/prettier': [
'warn',
"prettier/prettier": [
"warn",
{
singleQuote: true,
printWidth: 140,
trailingComma: 'all'
"singleQuote": true,
"printWidth": 140,
"trailingComma": "all"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion class/Invo.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Invo {
num_max_invoices: 99000111,
reversed: true,
},
function(err, response) {
function (err, response) {
if (err) return reject(err);
resolve(response);
},
Expand Down
14 changes: 7 additions & 7 deletions class/Paym.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class Paym {

async decodePayReqViaRpc(invoice) {
let that = this;
return new Promise(function(resolve, reject) {
that._lightning.decodePayReq({ pay_req: invoice }, function(err, info) {
return new Promise(function (resolve, reject) {
that._lightning.decodePayReq({ pay_req: invoice }, function (err, info) {
if (err) return reject(err);
that._decoded = info;
return resolve(info);
Expand All @@ -42,8 +42,8 @@ export class Paym {
fee_limit: { fixed: Math.floor(this._decoded.num_satoshis * 0.01) + 1 },
};
let that = this;
return new Promise(function(resolve, reject) {
that._lightning.queryRoutes(request, function(err, response) {
return new Promise(function (resolve, reject) {
that._lightning.queryRoutes(request, function (err, response) {
if (err) return reject(err);
resolve(response);
});
Expand All @@ -62,8 +62,8 @@ export class Paym {
console.log('sendToRouteSync:', { request });

let that = this;
return new Promise(function(resolve, reject) {
that._lightning.sendToRouteSync(request, function(err, response) {
return new Promise(function (resolve, reject) {
that._lightning.sendToRouteSync(request, function (err, response) {
if (err) reject(err);
resolve(that.processSendPaymentResponse(response));
});
Expand Down Expand Up @@ -133,7 +133,7 @@ export class Paym {

async listPayments() {
return new Promise((resolve, reject) => {
this._lightning.listPayments({}, function(err, response) {
this._lightning.listPayments({}, function (err, response) {
if (err) return reject(err);
resolve(response);
});
Expand Down
12 changes: 4 additions & 8 deletions class/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ export class User {

async lookupInvoice(payment_hash) {
let that = this;
return new Promise(function(resolve, reject) {
that._lightning.lookupInvoice({ r_hash_str: payment_hash }, function(err, response) {
return new Promise(function (resolve, reject) {
that._lightning.lookupInvoice({ r_hash_str: payment_hash }, function (err, response) {
if (err) resolve({});
resolve(response);
});
Expand Down Expand Up @@ -557,11 +557,7 @@ export class User {
}

_hash(string) {
return crypto
.createHash('sha256')
.update(string)
.digest()
.toString('hex');
return crypto.createHash('sha256').update(string).digest().toString('hex');
}

/**
Expand All @@ -577,6 +573,6 @@ export class User {
}

static async _sleep(s) {
return new Promise(r => setTimeout(r, s * 1000));
return new Promise((r) => setTimeout(r, s * 1000));
}
}
70 changes: 37 additions & 33 deletions controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ console.log('using config', JSON.stringify(config));

var Redis = require('ioredis');
var redis = new Redis(config.redis);
redis.monitor(function(err, monitor) {
monitor.on('monitor', function(time, args, source, database) {
redis.monitor(function (err, monitor) {
monitor.on('monitor', function (time, args, source, database) {
// console.log('REDIS', JSON.stringify(args));
});
});
Expand All @@ -19,7 +19,7 @@ let lightning = require('../lightning');
let identity_pubkey = false;
// ###################### SMOKE TESTS ########################

bitcoinclient.request('getblockchaininfo', false, function(err, info) {
bitcoinclient.request('getblockchaininfo', false, function (err, info) {
if (info && info.result && info.result.blocks) {
if (info.result.chain === 'mainnet' && info.result.blocks < 550000) {
console.error('bitcoind is not caught up');
Expand All @@ -31,7 +31,7 @@ bitcoinclient.request('getblockchaininfo', false, function(err, info) {
}
});

lightning.getInfo({}, function(err, info) {
lightning.getInfo({}, function (err, info) {
if (err) {
console.error('lnd failure');
console.dir(err);
Expand Down Expand Up @@ -111,7 +111,7 @@ const postLimiter = rateLimit({
max: 100,
});

router.post('/create', postLimiter, async function(req, res) {
router.post('/create', postLimiter, async function (req, res) {
logger.log('/create', [req.id]);
if (!(req.body.partnerid && req.body.partnerid === 'bluewallet' && req.body.accounttype)) return errorBadArguments(res);

Expand All @@ -121,7 +121,7 @@ router.post('/create', postLimiter, async function(req, res) {
res.send({ login: u.getLogin(), password: u.getPassword() });
});

router.post('/auth', postLimiter, async function(req, res) {
router.post('/auth', postLimiter, async function (req, res) {
logger.log('/auth', [req.id]);
if (!((req.body.login && req.body.password) || req.body.refresh_token)) return errorBadArguments(res);

Expand All @@ -142,7 +142,7 @@ router.post('/auth', postLimiter, async function(req, res) {
}
});

router.post('/addinvoice', postLimiter, async function(req, res) {
router.post('/addinvoice', postLimiter, async function (req, res) {
logger.log('/addinvoice', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
Expand All @@ -154,18 +154,21 @@ router.post('/addinvoice', postLimiter, async function(req, res) {

const invoice = new Invo(redis, bitcoinclient, lightning);
const r_preimage = invoice.makePreimageHex();
lightning.addInvoice({ memo: req.body.memo, value: req.body.amt, expiry: 3600 * 24, r_preimage: Buffer.from(r_preimage, 'hex').toString('base64') }, async function(err, info) {
if (err) return errorLnd(res);

info.pay_req = info.payment_request; // client backwards compatibility
await u.saveUserInvoice(info);
await invoice.savePreimage(r_preimage);

res.send(info);
});
lightning.addInvoice(
{ memo: req.body.memo, value: req.body.amt, expiry: 3600 * 24, r_preimage: Buffer.from(r_preimage, 'hex').toString('base64') },
async function (err, info) {
if (err) return errorLnd(res);

info.pay_req = info.payment_request; // client backwards compatibility
await u.saveUserInvoice(info);
await invoice.savePreimage(r_preimage);

res.send(info);
},
);
});

router.post('/payinvoice', async function(req, res) {
router.post('/payinvoice', async function (req, res) {
let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
return errorBadAuth(res);
Expand Down Expand Up @@ -195,7 +198,7 @@ router.post('/payinvoice', async function(req, res) {
return errorTryAgainLater(res);
}

lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) {
lightning.decodePayReq({ pay_req: req.body.invoice }, async function (err, info) {
if (err) {
await lock.releaseLock();
return errorNotAValidInvoice(res);
Expand Down Expand Up @@ -263,7 +266,7 @@ router.post('/payinvoice', async function(req, res) {
// else - regular lightning network payment:

var call = lightning.sendPayment();
call.on('data', async function(payment) {
call.on('data', async function (payment) {
// payment callback
await u.unlockFunds(req.body.invoice);
if (payment && payment.payment_route && payment.payment_route.total_amt_msat) {
Expand Down Expand Up @@ -305,7 +308,7 @@ router.post('/payinvoice', async function(req, res) {
});
});

router.get('/getbtc', async function(req, res) {
router.get('/getbtc', async function (req, res) {
logger.log('/getbtc', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
await u.loadByAuthorization(req.headers.authorization);
Expand All @@ -324,7 +327,7 @@ router.get('/getbtc', async function(req, res) {
res.send([{ address }]);
});

router.get('/checkpayment/:payment_hash', async function(req, res) {
router.get('/checkpayment/:payment_hash', async function (req, res) {
logger.log('/checkpayment', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
await u.loadByAuthorization(req.headers.authorization);
Expand All @@ -334,13 +337,14 @@ router.get('/checkpayment/:payment_hash', async function(req, res) {
}

let paid = true;
if (!(await u.getPaymentHashPaid(req.params.payment_hash))) { // Not found on cache
if (!(await u.getPaymentHashPaid(req.params.payment_hash))) {
// Not found on cache
paid = await u.syncInvoicePaid(req.params.payment_hash);
}
res.send({paid: paid});
res.send({ paid: paid });
});

router.get('/balance', postLimiter, async function(req, res) {
router.get('/balance', postLimiter, async function (req, res) {
let u = new User(redis, bitcoinclient, lightning);
try {
logger.log('/balance', [req.id]);
Expand All @@ -360,20 +364,20 @@ router.get('/balance', postLimiter, async function(req, res) {
}
});

router.get('/getinfo', postLimiter, async function(req, res) {
router.get('/getinfo', postLimiter, async function (req, res) {
logger.log('/getinfo', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
return errorBadAuth(res);
}

lightning.getInfo({}, function(err, info) {
lightning.getInfo({}, function (err, info) {
if (err) return errorLnd(res);
res.send(info);
});
});

router.get('/gettxs', async function(req, res) {
router.get('/gettxs', async function (req, res) {
logger.log('/gettxs', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
Expand Down Expand Up @@ -402,7 +406,7 @@ router.get('/gettxs', async function(req, res) {
}
});

router.get('/getuserinvoices', postLimiter, async function(req, res) {
router.get('/getuserinvoices', postLimiter, async function (req, res) {
logger.log('/getuserinvoices', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
Expand All @@ -419,7 +423,7 @@ router.get('/getuserinvoices', postLimiter, async function(req, res) {
}
});

router.get('/getpending', async function(req, res) {
router.get('/getpending', async function (req, res) {
logger.log('/getpending', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
Expand All @@ -433,7 +437,7 @@ router.get('/getpending', async function(req, res) {
res.send(txs);
});

router.get('/decodeinvoice', async function(req, res) {
router.get('/decodeinvoice', async function (req, res) {
logger.log('/decodeinvoice', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
Expand All @@ -442,13 +446,13 @@ router.get('/decodeinvoice', async function(req, res) {

if (!req.query.invoice) return errorGeneralServerError(res);

lightning.decodePayReq({ pay_req: req.query.invoice }, function(err, info) {
lightning.decodePayReq({ pay_req: req.query.invoice }, function (err, info) {
if (err) return errorNotAValidInvoice(res);
res.send(info);
});
});

router.get('/checkrouteinvoice', async function(req, res) {
router.get('/checkrouteinvoice', async function (req, res) {
logger.log('/checkrouteinvoice', [req.id]);
let u = new User(redis, bitcoinclient, lightning);
if (!(await u.loadByAuthorization(req.headers.authorization))) {
Expand All @@ -459,7 +463,7 @@ router.get('/checkrouteinvoice', async function(req, res) {

// at the momment does nothing.
// TODO: decode and query actual route to destination
lightning.decodePayReq({ pay_req: req.query.invoice }, function(err, info) {
lightning.decodePayReq({ pay_req: req.query.invoice }, function (err, info) {
if (err) return errorNotAValidInvoice(res);
res.send(info);
});
Expand Down
8 changes: 4 additions & 4 deletions controllers/website.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ let lightningListChannels = {};
function updateLightning() {
console.log('updateLightning()');
try {
lightning.getInfo({}, function(err, info) {
lightning.getInfo({}, function (err, info) {
if (err) {
console.error('lnd failure:', err);
}
lightningGetInfo = info;
});

lightning.listChannels({}, function(err, response) {
lightning.listChannels({}, function (err, response) {
if (err) {
console.error('lnd failure:', err);
return;
Expand Down Expand Up @@ -79,7 +79,7 @@ const pubkey2name = {
'037cc5f9f1da20ac0d60e83989729a204a33cc2d8e80438969fadf35c1c5f1233b': 'lnd2.bluewallet.io',
};

router.get('/', function(req, res) {
router.get('/', function (req, res) {
logger.log('/', [req.id]);
if (!lightningGetInfo) {
console.error('lnd failure');
Expand All @@ -104,7 +104,7 @@ router.get('/about', function(req, res) {
return res.status(200).send(mustache.render(html, {}));
});

router.use(function(req, res) {
router.use(function (req, res) {
res.status(404).send('404');
});

Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
process.on('uncaughtException', function(err) {
process.on('uncaughtException', function (err) {
console.error(err);
console.log('Node NOT Exiting...');
});

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
let express = require('express');
let morgan = require('morgan');
let uuid = require('node-uuid');
import { v4 as uuidv4 } from 'uuid';
let logger = require('./utils/logger');

morgan.token('id', function getId(req) {
Expand All @@ -23,8 +23,8 @@ const limiter = rateLimit({
});
app.use(limiter);

app.use(function(req, res, next) {
req.id = uuid.v4();
app.use(function (req, res, next) {
req.id = uuidv4();
next();
});

Expand All @@ -44,7 +44,7 @@ app.use('/static', express.static('static'));
app.use(require('./controllers/api'));
app.use(require('./controllers/website'));

let server = app.listen(process.env.PORT || 3000, function() {
let server = app.listen(process.env.PORT || 3000, function () {
logger.log('BOOTING UP', 'Listening on port ' + (process.env.PORT || 3000));
});
module.exports = server;
Loading

0 comments on commit cf40d77

Please sign in to comment.