msats on lnaddr pay

This commit is contained in:
keyan 2022-01-09 11:13:57 -06:00
parent 25e46a525d
commit 8286095871
3 changed files with 61 additions and 2 deletions

View File

@ -1,2 +1,3 @@
web: npm run start
worker: node --trace-warnings worker/index.js
check: node checkInvoices.js

58
checkInvoices.js Normal file
View File

@ -0,0 +1,58 @@
const { PrismaClient } = require('@prisma/client')
const { authenticatedLndGrpc, getInvoice } = require('ln-service')
const dotenv = require('dotenv')
const serialize = require('./api/resolvers/serial')
dotenv.config({ path: '.' })
const { lnd } = authenticatedLndGrpc({
cert: process.env.LND_CERT,
macaroon: process.env.LND_MACAROON,
socket: process.env.LND_SOCKET
})
const models = new PrismaClient()
async function recordInvoiceStatus (inv) {
console.log(inv)
if (inv.is_confirmed) {
await serialize(models,
models.$executeRaw`SELECT confirm_invoice(${inv.id}, ${Number(inv.received_mtokens)})`)
} else if (inv.is_canceled) {
// mark as cancelled
await serialize(models,
models.invoice.update({
where: {
hash: inv.id
},
data: {
cancelled: true
}
}))
}
}
// 2. check all pending invoices from db in lnd
async function checkPendingInvoices () {
// invoices
const active = await models.invoice.findMany({
where: {
cancelled: false,
confirmedAt: {
equals: null
}
}
})
active.forEach(async invoice => {
try {
const inv = await getInvoice({ id: invoice.hash, lnd })
await recordInvoiceStatus(inv)
} catch (error) {
console.log(invoice, error)
process.exit(1)
}
})
}
checkPendingInvoices()

View File

@ -29,7 +29,7 @@ export default async ({ query: { username, amount } }, res) => {
await serialize(models,
models.$queryRaw`SELECT * FROM create_invoice(${invoice.id}, ${invoice.request},
${expiresAt}, ${amount * 1000}, ${user.id})`)
${expiresAt}, ${amount}, ${user.id})`)
return res.status(200).json({
pr: invoice.request