msats on lnaddr pay
This commit is contained in:
parent
25e46a525d
commit
8286095871
3
Procfile
3
Procfile
|
@ -1,2 +1,3 @@
|
|||
web: npm run start
|
||||
worker: node --trace-warnings worker/index.js
|
||||
worker: node --trace-warnings worker/index.js
|
||||
check: node checkInvoices.js
|
|
@ -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()
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue