-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: process-unpaid-invoices; REF: stuck payments script; REF: websit…
…e; REF: important channels script; DOC: some docs
- Loading branch information
1 parent
9f45c31
commit e390a06
Showing
10 changed files
with
252 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}, | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './User'; | ||
export * from './Lock'; | ||
export * from './Paym'; | ||
export * from './Invo'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
recover user's wallet | ||
===================== | ||
|
||
* find user's id | ||
f0db84e6fd5dee530314fbb90cec24839f4620914e7cd0c7 | ||
* issue new credentials via tests/integration/LightningCustodianWallet.test.js | ||
lndhub://3d7c028419356d017199:66666666666666666666 | ||
(this is user:password) | ||
* lookup redis record `user_{login}_{password_hash} = {userid}` : | ||
``` | ||
> keys user_3d7c028419356d017199* | ||
1) "user_3d7c028419356d017199_505018e35414147406fcacdae63babbfca9b1abfcb6d091a4cca9a7611183284" | ||
``` | ||
|
||
* save to this record old user's id: | ||
`> set user_3d7c028419356d017199_505018e35414147406fcacdae63babbfca9b1abfcb6d091a4cca9a7611183284 f0db84e6fd5dee530314fbb90cec24839f4620914e7cd0c7` | ||
done! issued credentials should point to old user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* This script goes through all user invoices in LND and if it is settled - marks it | ||
* so in our database. Does this only for invoices younger than week. * | ||
*/ | ||
import { Invo } from '../class/'; | ||
const config = require('../config'); | ||
|
||
const fs = require('fs'); | ||
const Redis = require('ioredis'); | ||
const redis = new Redis(config.redis); | ||
|
||
let bitcoinclient = require('../bitcoin'); | ||
let lightning = require('../lightning'); | ||
|
||
(async () => { | ||
console.log('fetching listinvoices...'); | ||
let tempInv = new Invo(redis, bitcoinclient, lightning); | ||
|
||
let listinvoices = await tempInv.listInvoices(); | ||
console.log('done', 'got', listinvoices['invoices'].length, 'invoices'); | ||
fs.writeFileSync('listInvoices.json', JSON.stringify(listinvoices['invoices'], null, 2)); | ||
|
||
let markedInvoices = 0; | ||
for (const invoice of listinvoices['invoices']) { | ||
if (invoice.state === 'SETTLED' && +invoice.creation_date >= +new Date() / 1000 - 3600 * 24 * 7) { | ||
tempInv.setInvoice(invoice.payment_request); | ||
await tempInv.markAsPaidInDatabase(); | ||
markedInvoices++; | ||
process.stdout.write(markedInvoices + '\r'); | ||
} | ||
} | ||
|
||
console.log('done, marked', markedInvoices, 'invoices'); | ||
process.exit(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters