Merge branch 'master' of github.com:BlueWallet/LndHub

This commit is contained in:
Overtorment 2020-05-04 14:10:22 +01:00
commit b125d68fff
4 changed files with 539 additions and 517 deletions

View File

@ -238,6 +238,17 @@ export class User {
return await this._redis.get('ispaid_' + payment_hash);
}
async syncInvoicePaid(payment_hash) {
const invoice = await this.lookupInvoice(payment_hash);
const ispaid = invoice.settled; // TODO: start using `state` instead as its future proof, and this one might get deprecated
if (ispaid) {
// so invoice was paid after all
await this.setPaymentHashPaid(payment_hash);
await this.clearBalanceCache();
}
return ispaid;
}
async getUserInvoices(limit) {
let range = await this._redis.lrange('userinvoices_for_' + this._userid, 0, -1);
if (limit && !isNaN(parseInt(limit))) {
@ -265,13 +276,7 @@ export class User {
if (!invoice.ispaid) {
if (decoded && decoded.timestamp > +new Date() / 1000 - 3600 * 24 * 5) {
// if invoice is not too old we query lnd to find out if its paid
let lookup_info = await this.lookupInvoice(invoice.payment_hash);
invoice.ispaid = lookup_info.settled; // TODO: start using `state` instead as its future proof, and this one might get deprecated
if (invoice.ispaid) {
// so invoice was paid after all
await this.setPaymentHashPaid(invoice.payment_hash);
await this.clearBalanceCache();
}
invoice.ispaid = await this.syncInvoicePaid(invoice.payment_hash);
}
} else {
_invoice_ispaid_cache[invoice.payment_hash] = true;

View File

@ -20,7 +20,7 @@ let identity_pubkey = false;
bitcoinclient.request('getblockchaininfo', false, function(err, info) {
if (info && info.result && info.result.blocks) {
if (info.result.blocks < 550000) {
if (info.result.chain === 'mainnet' && info.result.blocks < 550000) {
console.error('bitcoind is not caught up');
process.exit(1);
}
@ -33,9 +33,11 @@ bitcoinclient.request('getblockchaininfo', false, function(err, info) {
lightning.getInfo({}, function(err, info) {
if (err) {
console.error('lnd failure');
console.dir(err);
process.exit(3);
}
if (info) {
console.info(info);
if (!info.synced_to_chain) {
console.error('lnd not synced');
process.exit(4);
@ -264,8 +266,11 @@ router.get('/checkpayment/:payment_hash', async function(req, res) {
return errorBadAuth(res);
}
let paid = !!(await u.getPaymentHashPaid(req.params.payment_hash));
res.send({ paid: paid });
let paid = true;
if (!(await u.getPaymentHashPaid(req.params.payment_hash))) { // Not found on cache
paid = await u.syncInvoicePaid(req.params.payment_hash);
}
res.send({paid: paid});
});
router.get('/balance', postLimiter, async function(req, res) {

1008
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,20 +19,20 @@
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-register": "^6.26.0",
"bignumber.js": "^8.0.1",
"bolt11": "https://github.com/bitcoinjs/bolt11",
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0",
"bignumber.js": "^9.0.0",
"bolt11": "^1.2.6",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
"express": "^4.16.4",
"express-rate-limit": "^3.4.0",
"express-rate-limit": "^5.0.0",
"grpc": "^1.17.0-pre1",
"ioredis": "^4.16.0",
"jayson": "^2.1.0",
"ioredis": "^4.16.2",
"jayson": "^3.1.2",
"morgan": "^1.9.1",
"mustache": "^3.2.1",
"mustache": "^4.0.1",
"node-uuid": "^1.4.8",
"prettier": "^1.19.1",
"prettier": "^2.0.4",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"winston": "^3.1.0"