Updated npm packages to latest version

Remove blockcount check for regtest
FIX
FIX: change default ln invoice expiry hour -> day
REF
FIX: added some caching; skip checking old invoices
Update README.md
This commit is contained in:
Agustin Kassis 2020-01-14 13:25:51 -03:00
commit 6507de9770
7 changed files with 48 additions and 25 deletions

View File

@ -31,6 +31,12 @@ Add config vars :
* `MACAROON`: hex-encoded `admin.macaroon`
* `TLSCERT`: hex-encoded `tls.cert`
### Reference client implementation
Can be used in ReactNative or Nodejs environment
* https://github.com/BlueWallet/BlueWallet/blob/master/class/lightning-custodian-wallet.js
### Tests

View File

@ -4,6 +4,11 @@ var crypto = require('crypto');
var lightningPayReq = require('bolt11');
import { BigNumber } from 'bignumber.js';
// static cache:
let _invoice_ispaid_cache = {};
let _listtransactions_cache = false;
let _listtransactions_cache_expiry_ts = 0;
export class User {
/**
*
@ -244,18 +249,22 @@ export class User {
invoice.payment_hash = tag.data;
}
}
invoice.ispaid = !!(await this.getPaymentHashPaid(invoice.payment_hash));
invoice.ispaid = _invoice_ispaid_cache[invoice.payment_hash] || !!(await this.getPaymentHashPaid(invoice.payment_hash));
if (!invoice.ispaid) {
// TODO: check if expired
// attempting to lookup invoice
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;
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();
}
}
} else {
_invoice_ispaid_cache[invoice.payment_hash] = true;
}
invoice.amt = decoded.satoshis;
invoice.expire_time = 3600;
@ -333,16 +342,19 @@ export class User {
* @private
*/
async _listtransactions() {
const key = 'listtransactions';
let response = await this._redis.get(key);
let response = _listtransactions_cache;
if (response) {
if (+new Date() > _listtransactions_cache_expiry_ts) {
// invalidate cache
response = _listtransactions_cache = false;
} else {
try {
let json = JSON.parse(response);
return json;
return JSON.parse(response);
} catch (_) {
// nop
}
}
}
let txs = await this._bitcoindrpc.request('listtransactions', ['*', 100500, 0, true]);
// now, compacting response a bit
@ -356,8 +368,9 @@ export class User {
time: tx.time,
});
}
await this._redis.set(key, JSON.stringify(ret));
await this._redis.expire(key, 5 * 60);
_listtransactions_cache = JSON.stringify(ret);
_listtransactions_cache_expiry_ts = +new Date() + 5 * 60 * 1000; // 5 min
this._redis.set('listtransactions', _listtransactions_cache); // backup, will use later TODO
return ret;
}

View File

@ -100,7 +100,7 @@ router.post('/addinvoice', postLimiter, async function(req, res) {
if (!req.body.amt || /*stupid NaN*/ !(req.body.amt > 0)) return errorBadArguments(res);
lightning.addInvoice({ memo: req.body.memo, value: req.body.amt }, async function(err, info) {
lightning.addInvoice({ memo: req.body.memo, value: req.body.amt, expiry: 3600 * 24 }, async function(err, info) {
if (err) return errorLnd(res);
info.pay_req = info.payment_request; // client backwards compatibility

View File

@ -66,7 +66,7 @@ const pubkey2name = {
'0237fefbe8626bf888de0cad8c73630e32746a22a2c4faa91c1d9877a3826e1174': '1.ln.aantonop.com',
'026c7d28784791a4b31a64eb34d9ab01552055b795919165e6ae886de637632efb': 'LivingRoomOfSatoshi',
'02816caed43171d3c9854e3b0ab2cf0c42be086ff1bd4005acc2a5f7db70d83774': 'ln.pizza',
'024a2e265cd66066b78a788ae615acdc84b5b0dec9efac36d7ac87513015eaf6ed': 'Bitrefill.com/lightning',
'0254ff808f53b2f8c45e74b70430f336c6c76ba2f4af289f48d6086ae6e60462d3': 'bitrefill thor',
'02a0bc43557fae6af7be8e3a29fdebda819e439bea9c0f8eb8ed6a0201f3471ca9': 'LightningPeachHub',
'02d4531a2f2e6e5a9033d37d548cff4834a3898e74c3abe1985b493c42ebbd707d': 'coinfinity.co',
'02d23fa6794d8fd056c757f3c8f4877782138dafffedc831fc570cab572620dc61': 'paywithmoon.com',

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "LndHub",
"version": "1.1.1",
"version": "1.1.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "LndHub",
"version": "1.1.1",
"version": "1.1.3",
"description": "",
"main": "index.js",
"scripts": {

View File

@ -3,8 +3,12 @@ let important_channels = {
'03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f': 'ACINQ',
'03abf6f44c355dec0d5aa155bdbdd6e0c8fefe318eff402de65c6eb2e1be55dc3e': 'OpenNode',
'0242a4ae0c5bef18048fbecf995094b74bfb0f7391418d71ed394784373f41e4f3': 'coingate.com',
'0232e20e7b68b9b673fb25f48322b151a93186bffe4550045040673797ceca43cf': 'zigzag.io',
'024a2e265cd66066b78a788ae615acdc84b5b0dec9efac36d7ac87513015eaf6ed': 'Bitrefill.com/lightning',
'0254ff808f53b2f8c45e74b70430f336c6c76ba2f4af289f48d6086ae6e60462d3': 'bitrefill thor',
'025f1456582e70c4c06b61d5c8ed3ce229e6d0db538be337a2dc6d163b0ebc05a5': 'paywithmoon.com',
'02c91d6aa51aa940608b497b6beebcb1aec05be3c47704b682b3889424679ca490': 'lnbig 21',
'0279c22ed7a068d10dc1a38ae66d2d6461e269226c60258c021b1ddcdfe4b00bc4': 'ln1.satoshilabs.com',
'026c7d28784791a4b31a64eb34d9ab01552055b795919165e6ae886de637632efb': 'LivingRoomOfSatoshi',
'02816caed43171d3c9854e3b0ab2cf0c42be086ff1bd4005acc2a5f7db70d83774': 'ln.pizza',
};
let lightning = require('../lightning');
@ -16,7 +20,7 @@ lightning.listChannels({}, function(err, response) {
}
let lightningListChannels = response;
for (let channel of lightningListChannels.channels) {
if (channel.capacity < 5000000) {
if (0 && channel.capacity < 5000000) {
console.log(
'lncli closechannel',
channel.channel_point.replace(':', ' '),