diff --git a/class/User.js b/class/User.js index d9f3ade..2c519ce 100644 --- a/class/User.js +++ b/class/User.js @@ -149,6 +149,16 @@ export class User { return await this._redis.set('ispaid_' + payment_hash, 1); } + async lookupInvoice(payment_hash) { + let that = this; + return new Promise(function(resolve, reject) { + that._lightning.lookupInvoice({ r_hash_str: payment_hash }, function(err, response) { + if (err) resolve({}); + resolve(response); + }); + }); + } + /** * Doent belong here, FIXME */ @@ -172,6 +182,12 @@ export class User { } } invoice.ispaid = !!(await this.getPaymentHashPaid(invoice.payment_hash)); + if (!invoice.ispaid) { + // attempting to lookup invoice + let lookup_info = await this.lookupInvoice(invoice.payment_hash); + invoice.ispaid = lookup_info.settled; + } + invoice.amt = decoded.satoshis; result.push(invoice); } diff --git a/controllers/api.js b/controllers/api.js index 0bda17c..156521b 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -96,7 +96,6 @@ router.post('/addinvoice', async function(req, res) { if (err) return errorLnd(res); info.pay_req = info.payment_request; // client backwards compatibility - console.log(info); await u.saveUserInvoice(info); res.send(info); @@ -118,7 +117,6 @@ router.post('/payinvoice', async function(req, res) { if (userBalance >= info.num_satoshis) { // got enough balance - console.log('infoinfoinfoinfoinfoinfoinfoinfoinfoinfo', info); if (identity_pubkey === info.destination) { // this is internal invoice // now, receiver add balance