Update dependencies (#121)

This commit is contained in:
Aaron Dewes 2021-01-04 13:49:42 +01:00 committed by GitHub
parent b8cd8d05b0
commit cf40d77b01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 10738 additions and 4687 deletions

View File

@ -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"
}
]
},

View File

@ -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);
},

View File

@ -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);
@ -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);
});
@ -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));
});
@ -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);
});

View File

@ -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);
});
@ -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');
}
/**
@ -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));
}
}

View File

@ -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));
});
});
@ -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');
@ -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);
@ -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);
@ -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);
@ -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))) {
@ -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);
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);
info.pay_req = info.payment_request; // client backwards compatibility
await u.saveUserInvoice(info);
await invoice.savePreimage(r_preimage);
res.send(info);
});
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);
@ -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);
@ -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) {
@ -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);
@ -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);
@ -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]);
@ -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))) {
@ -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))) {
@ -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))) {
@ -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))) {
@ -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))) {
@ -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);
});

View File

@ -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;
@ -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');
@ -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');
});

View File

@ -1,4 +1,4 @@
process.on('uncaughtException', function(err) {
process.on('uncaughtException', function (err) {
console.error(err);
console.log('Node NOT Exiting...');
});
@ -6,7 +6,7 @@ process.on('uncaughtException', function(err) {
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) {
@ -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();
});
@ -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;

View File

@ -1,8 +1,18 @@
// setup lnd rpc
const config = require('./config');
var fs = require('fs');
var grpc = require('grpc');
var lnrpc = grpc.load('rpc.proto').lnrpc;
var grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true
};
const packageDefinition = protoLoader.loadSync('rpc.proto', loaderOptions);
var lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
var lndCert;
if (process.env.TLSCERT) {
@ -19,7 +29,7 @@ if (process.env.MACAROON) {
macaroon = fs.readFileSync('admin.macaroon').toString('hex');
}
process.env.VERBOSE && console.log('using macaroon', macaroon);
let macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let macaroonCreds = grpc.credentials.createFromMetadataGenerator(function (args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
@ -34,7 +44,7 @@ if (config.lnd.password) {
{
wallet_password: Buffer.from(config.lnd.password).toString('base64'),
},
function(err, response) {
function (err, response) {
if (err) {
process.env.VERBOSE && console.log('unlockWallet failed, probably because its been aleady unlocked');
} else {

11757
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,31 +12,32 @@
"author": "Igor Korsakov <overtorment@gmail.com>",
"license": "MIT",
"dependencies": {
"@babel/core": "^7.0.0",
"@babel/cli": "^7.0.0",
"babel-eslint": "^10.1.0",
"@babel/node": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/eslint-parser": "^7.12.1",
"@babel/node": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/register": "^7.12.10",
"@grpc/grpc-js": "^1.2.2",
"@grpc/proto-loader": "^0.5.5",
"bignumber.js": "^9.0.1",
"bolt11": "^1.2.6",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"express": "^4.16.4",
"bolt11": "^1.2.7",
"core-js": "^3.8.1",
"eslint": "^7.16.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-prettier": "^3.3.0",
"express": "^4.17.1",
"express-rate-limit": "^5.2.3",
"frisbee": "^3.1.4",
"grpc": "^1.24.4",
"ioredis": "^4.19.2",
"jayson": "^3.3.4",
"morgan": "^1.9.1",
"mustache": "^4.0.1",
"node-uuid": "^1.4.8",
"prettier": "^2.2.0",
"ioredis": "^4.19.4",
"jayson": "^3.4.4",
"morgan": "^1.10.0",
"mustache": "^4.1.0",
"prettier": "^2.2.1",
"qr-image": "3.2.0",
"request": "^2.88.0",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"uuid": "^8.3.2",
"winston": "^3.3.3"
}
}

3468
rpc.proto

File diff suppressed because it is too large Load Diff

View File

@ -59,7 +59,7 @@ const important_channels = {
let lightning = require('../lightning');
lightning.listChannels({}, function(err, response) {
lightning.listChannels({}, function (err, response) {
console.log();
if (err) {
console.error('lnd failure:', err);

View File

@ -38,7 +38,7 @@ let lightning = require('../lightning');
let payment = new Paym(redis, bitcoinclient, lightning);
payment.setInvoice(lockedPayment.pay_req);
if (daysPassed > (1 / 24) && daysPassed <= 1) {
if (daysPassed > 1 / 24 && daysPassed <= 1) {
// if (!await payment.isExpired()) {
let sendResult;
console.log('attempting to pay to route');

View File

@ -5,7 +5,7 @@ const config = require('../config');
var Redis = require('ioredis');
var redis = new Redis(config.redis);
redis.info(function(err, info) {
redis.info(function (err, info) {
if (err || !info) {
console.error('redis failure');
process.exit(5);

View File

@ -12,7 +12,7 @@
<meta content="800" property="og:image:width">
<meta content="800" property="og:image:height">
<link rel="icon" href="/static/favicon.png">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<title>LNDhub - Open source Bank</title>
<!-- Custom styles for this template -->
<link href="/static/css/lndhub.css" rel="stylesheet">
@ -91,6 +91,6 @@
<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
</body>
</html>

View File

@ -7,16 +7,13 @@
*
+ + + + + + + + + + + + + + + + + + + + + */
let fs = require('fs');
let winston = require('winston');
let createLogger = winston.createLogger;
let format = winston.format;
let transports = winston.transports;
import { createLogger, format, transports } from 'winston';
/* + + + + + + + + + + + + + + + + + + + + +
// Start
+ + + + + + + + + + + + + + + + + + + + + */
const { combine, timestamp, printf } = format;
const logFormat = printf(info => {
const logFormat = printf((info) => {
return `${info.timestamp} : ${info.level}: [${info.label}] : ${info.message}`;
});
const logger = createLogger({