diff --git a/class/Lock.js b/class/Lock.js index e696624..db0209c 100644 --- a/class/Lock.js +++ b/class/Lock.js @@ -24,7 +24,7 @@ export class Lock { } // success - got lock - await this._redis.expire(this._lock_key, 5 * 60); + await this._redis.expire(this._lock_key, 10 * 60); // lock expires in 5 mins just for any case return true; } diff --git a/class/User.js b/class/User.js index 7042b66..7eb1c3a 100644 --- a/class/User.js +++ b/class/User.js @@ -261,6 +261,7 @@ export class User { /** * User's onchain txs that are >= 3 confs + * Queries bitcoind RPC. * * @returns {Promise} */ diff --git a/controllers/api.js b/controllers/api.js index 53e6f66..c8e6753 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -109,7 +109,7 @@ router.post('/payinvoice', async function(req, res) { return errorBadAuth(res); } - logger.log('/payinvoice', [req.id, 'userid: ' + u.getUserId()]); + logger.log('/payinvoice', [req.id, 'userid: ' + u.getUserId(), 'invoice: ' + req.body.invoice]); if (!req.body.invoice) return errorBadArguments(res); let freeAmount = false; @@ -137,6 +137,8 @@ router.post('/payinvoice', async function(req, res) { info.num_satoshis = freeAmount; } + logger.log('/payinvoice', [req.id, 'userBalance: ' + userBalance, 'num_satoshis: ' + info.num_satoshis]); + if (userBalance >= info.num_satoshis) { // got enough balance @@ -181,14 +183,14 @@ router.post('/payinvoice', async function(req, res) { // else - regular lightning network payment: var call = lightning.sendPayment(); - call.on('data', function(payment) { + call.on('data', async function(payment) { // payment callback if (payment && payment.payment_route && payment.payment_route.total_amt_msat) { userBalance -= +payment.payment_route.total_fees + +payment.payment_route.total_amt; u.saveBalance(userBalance); payment.pay_req = req.body.invoice; payment.decoded = info; - u.savePaidLndInvoice(payment); + await u.savePaidLndInvoice(payment); lock.releaseLock(); res.send(payment); } else { diff --git a/controllers/website.js b/controllers/website.js index cc437d0..4363df2 100644 --- a/controllers/website.js +++ b/controllers/website.js @@ -67,6 +67,7 @@ const pubkey2name = { '036a54f02d2186de192e4bcec3f7b47adb43b1fa965793387cd2471990ce1d236b': 'capacity.network', '026c7d28784791a4b31a64eb34d9ab01552055b795919165e6ae886de637632efb': 'LivingRoomOfSatoshi.com_LND_1', '02816caed43171d3c9854e3b0ab2cf0c42be086ff1bd4005acc2a5f7db70d83774': 'ln.pizza', + '024a2e265cd66066b78a788ae615acdc84b5b0dec9efac36d7ac87513015eaf6ed': 'Bitrefill.com/lightning', }; router.get('/', function(req, res) {