WIP lightning addr
This commit is contained in:
parent
75a8ca2163
commit
eafe474746
|
@ -1,11 +1,11 @@
|
|||
const { withPlausibleProxy } = require('next-plausible')
|
||||
const { RuntimeSources } = require('/opt/elasticbeanstalk/deployment/app_version_manifest.json') // eslint-disable-line
|
||||
|
||||
module.exports = withPlausibleProxy()({
|
||||
compress: false,
|
||||
generateBuildId: async () => {
|
||||
// use the app version which eb doesn't otherwise give us
|
||||
// as the build id
|
||||
const { RuntimeSources } = require('/opt/elasticbeanstalk/deployment/app_version_manifest.json') // eslint-disable-line
|
||||
return Object.keys(RuntimeSources['stacker.news'])[0]
|
||||
},
|
||||
async rewrites () {
|
||||
|
@ -17,6 +17,10 @@ module.exports = withPlausibleProxy()({
|
|||
{
|
||||
source: '/story',
|
||||
destination: '/items/1620'
|
||||
},
|
||||
{
|
||||
source: '/.well-known/lnurlp/:username',
|
||||
destination: '/api/lnurlp/:username'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import models from '../../../../api/models'
|
||||
|
||||
export default async ({ query: { username } }, res) => {
|
||||
const user = await models.user.findUnique({ where: { name: username } })
|
||||
if (!user) {
|
||||
return res.status(400).json({ status: 'ERROR', reason: `user @${username} does not exist` })
|
||||
}
|
||||
|
||||
return res.status(200).json({
|
||||
callback: `/api/lnurlp/${username}/pay`, // The URL from LN SERVICE which will accept the pay request parameters
|
||||
minSendable: 1000, // Min amount LN SERVICE is willing to receive, can not be less than 1 or more than `maxSendable`
|
||||
metadata: [[
|
||||
'text/plain', // must always be present
|
||||
`Funding @${username} on stacker.news` // actual metadata content
|
||||
]], // Metadata json which must be presented as raw string here, this is required to pass signature verification at a later step
|
||||
tag: 'payRequest' // Type of LNURL
|
||||
})
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
import models from '../../../../api/models'
|
||||
import lnd from '../../../../api/lnd'
|
||||
import { createInvoice } from 'ln-service'
|
||||
|
||||
export default async ({ query: { username, amount } }, res) => {
|
||||
const user = await models.user.findUnique({ where: { name: username } })
|
||||
if (!user) {
|
||||
return res.status(400).json({ status: 'ERROR', reason: `user @${username} does not exist` })
|
||||
}
|
||||
|
||||
if (!amount || amount < 1000) {
|
||||
return res.status(400).json({ status: 'ERROR', reason: 'amount must be >=1000 msats' })
|
||||
}
|
||||
|
||||
// generate invoice
|
||||
const expiresAt = new Date(new Date().setHours(new Date().getHours() + 3))
|
||||
const description = `${amount} msats for @${user.name} on stacker.news`
|
||||
try {
|
||||
const invoice = await createInvoice({
|
||||
description,
|
||||
lnd,
|
||||
mtokens: amount,
|
||||
expires_at: expiresAt
|
||||
})
|
||||
|
||||
const data = {
|
||||
hash: invoice.id,
|
||||
bolt11: invoice.request,
|
||||
expiresAt: expiresAt,
|
||||
msatsRequested: Number(amount),
|
||||
user: {
|
||||
connect: {
|
||||
id: user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await models.invoice.create({ data })
|
||||
|
||||
return res.status(200).json({
|
||||
pr: invoice.request
|
||||
})
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
res.status(400).json({ status: 'ERROR', reason: 'failed to create invoice' })
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue