ADD: process-unpaid-invoices; REF: stuck payments script; REF: website; REF: important channels script; DOC: some docs

This commit is contained in:
Overtorment
2020-05-04 14:09:37 +01:00
parent 9f45c31618
commit e390a06aae
10 changed files with 252 additions and 24 deletions

86
class/Invo.js Normal file
View File

@@ -0,0 +1,86 @@
var lightningPayReq = require('bolt11');
export class Invo {
constructor(redis, bitcoindrpc, lightning) {
this._redis = redis;
this._bitcoindrpc = bitcoindrpc;
this._lightning = lightning;
this._decoded = false;
this._bolt11 = false;
this._isPaid = null;
}
setInvoice(bolt11) {
this._bolt11 = bolt11;
}
async getIsMarkedAsPaidInDatabase() {
if (!this._bolt11) throw new Error('bolt11 is not provided');
const decoded = lightningPayReq.decode(this._bolt11);
let paymentHash = false;
for (const tag of decoded.tags) {
if (tag.tagName === 'payment_hash') {
paymentHash = tag.data;
}
}
if (!paymentHash) throw new Error('Could not find payment hash in invoice tags');
return await this._getIsPaymentHashMarkedPaidInDatabase(paymentHash);
}
async markAsPaidInDatabase() {
if (!this._bolt11) throw new Error('bolt11 is not provided');
const decoded = lightningPayReq.decode(this._bolt11);
let paymentHash = false;
for (const tag of decoded.tags) {
if (tag.tagName === 'payment_hash') {
paymentHash = tag.data;
}
}
if (!paymentHash) throw new Error('Could not find payment hash in invoice tags');
return await this._setIsPaymentHashPaidInDatabase(paymentHash, true);
}
async markAsUnpaidInDatabase() {
if (!this._bolt11) throw new Error('bolt11 is not provided');
const decoded = lightningPayReq.decode(this._bolt11);
let paymentHash = false;
for (const tag of decoded.tags) {
if (tag.tagName === 'payment_hash') {
paymentHash = tag.data;
}
}
if (!paymentHash) throw new Error('Could not find payment hash in invoice tags');
return await this._setIsPaymentHashPaidInDatabase(paymentHash, false);
}
async _setIsPaymentHashPaidInDatabase(paymentHash, isPaid) {
if (isPaid) {
return await this._redis.set('ispaid_' + paymentHash, 1);
} else {
return await this._redis.del('ispaid_' + paymentHash);
}
}
async _getIsPaymentHashMarkedPaidInDatabase(paymentHash) {
return await this._redis.get('ispaid_' + paymentHash);
}
/**
* Queries LND ofr all user invoices
*
* @return {Promise<array>}
*/
async listInvoices() {
return new Promise((resolve, reject) => {
this._lightning.listInvoices(
{
num_max_invoices: 9000111,
},
function(err, response) {
if (err) return reject(err);
resolve(response);
},
);
});
}
}

View File

@@ -38,7 +38,6 @@ export class Paym {
var request = {
pub_key: this._decoded.destination,
amt: this._decoded.num_satoshis,
num_routes: 1,
final_cltv_delta: 144,
fee_limit: { fixed: Math.floor(this._decoded.num_satoshis * 0.01) + 1 },
};
@@ -57,9 +56,11 @@ export class Paym {
let request = {
payment_hash_string: this._decoded.payment_hash,
routes: routes,
route: routes[0],
};
console.log('sendToRouteSync:', { request });
let that = this;
return new Promise(function(resolve, reject) {
that._lightning.sendToRouteSync(request, function(err, response) {

View File

@@ -212,6 +212,8 @@ export class User {
/**
* Doent belong here, FIXME
* @see Invo._setIsPaymentHashPaidInDatabase
* @see Invo.markAsPaidInDatabase
*/
async setPaymentHashPaid(payment_hash) {
return await this._redis.set('ispaid_' + payment_hash, 1);
@@ -229,6 +231,8 @@ export class User {
/**
* Doent belong here, FIXME
* @see Invo._getIsPaymentHashMarkedPaidInDatabase
* @see Invo.getIsMarkedAsPaidInDatabase
*/
async getPaymentHashPaid(payment_hash) {
return await this._redis.get('ispaid_' + payment_hash);
@@ -322,7 +326,10 @@ export class User {
invoice.value = +invoice.payment_route.total_fees + +invoice.payment_route.total_amt;
if (invoice.payment_route.total_amt_msat && invoice.payment_route.total_amt_msat / 1000 !== +invoice.payment_route.total_amt) {
// okay, we have to account for MSAT
invoice.value = +invoice.payment_route.total_fees + Math.max(parseInt(invoice.payment_route.total_amt_msat / 1000), +invoice.payment_route.total_amt) + 1; // extra sat to cover for msats, as external layer (clients) dont have that resolution
invoice.value =
+invoice.payment_route.total_fees +
Math.max(parseInt(invoice.payment_route.total_amt_msat / 1000), +invoice.payment_route.total_amt) +
1; // extra sat to cover for msats, as external layer (clients) dont have that resolution
}
} else {
invoice.fee = 0;

View File

@@ -1,3 +1,4 @@
export * from './User';
export * from './Lock';
export * from './Paym';
export * from './Invo';