ADD: paid invoices via ln
This commit is contained in:
		
							parent
							
								
									fbd605b4cc
								
							
						
					
					
						commit
						dee89114a3
					
				@ -149,6 +149,16 @@ export class User {
 | 
				
			|||||||
    return await this._redis.set('ispaid_' + payment_hash, 1);
 | 
					    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
 | 
					   * Doent belong here, FIXME
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
@ -172,6 +182,12 @@ export class User {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      invoice.ispaid = !!(await this.getPaymentHashPaid(invoice.payment_hash));
 | 
					      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;
 | 
					      invoice.amt = decoded.satoshis;
 | 
				
			||||||
      result.push(invoice);
 | 
					      result.push(invoice);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -96,7 +96,6 @@ router.post('/addinvoice', async function(req, res) {
 | 
				
			|||||||
    if (err) return errorLnd(res);
 | 
					    if (err) return errorLnd(res);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    info.pay_req = info.payment_request; // client backwards compatibility
 | 
					    info.pay_req = info.payment_request; // client backwards compatibility
 | 
				
			||||||
    console.log(info);
 | 
					 | 
				
			||||||
    await u.saveUserInvoice(info);
 | 
					    await u.saveUserInvoice(info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    res.send(info);
 | 
					    res.send(info);
 | 
				
			||||||
@ -118,7 +117,6 @@ router.post('/payinvoice', async function(req, res) {
 | 
				
			|||||||
    if (userBalance >= info.num_satoshis) {
 | 
					    if (userBalance >= info.num_satoshis) {
 | 
				
			||||||
      // got enough balance
 | 
					      // got enough balance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      console.log('infoinfoinfoinfoinfoinfoinfoinfoinfoinfo', info);
 | 
					 | 
				
			||||||
      if (identity_pubkey === info.destination) {
 | 
					      if (identity_pubkey === info.destination) {
 | 
				
			||||||
        // this is internal invoice
 | 
					        // this is internal invoice
 | 
				
			||||||
        // now, receiver add balance
 | 
					        // now, receiver add balance
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user