forked from blastshielddown/ln-addr-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (49 loc) · 1.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import process from 'node:process'
import express from 'express'
import { createInvoice, authenticatedLndGrpc, getWalletInfo } from 'ln-service'
import dotenv from 'dotenv'
dotenv.config()
const callbackHost = process.env.LN_ADDR_TEST_CALLBACK_HOST || 'localhost'
const port = process.env.LN_ADDR_TEST_PORT || 7777
const app = express()
const { lnd } = authenticatedLndGrpc({
cert: process.env.LN_ADDR_TEST_LND_CERT,
macaroon: process.env.LN_ADDR_TEST_LND_MACAROON,
socket: `${process.env.LN_ADDR_TEST_LND_HOST}:${process.env.LN_ADDR_TEST_LND_PORT || 10009}`,
})
const info = await getWalletInfo({ lnd })
console.log(`Connected to ${info.alias} (${info.public_key})`)
app.get('/', (request, response) => {
response.send('Hello World!')
})
app.get('/.well-known/lnurlp/:username', (request, response) => {
const host = request.ip === '127.0.0.1' ? '127.0.0.1' : callbackHost
response.json({
tag: 'payRequest',
callback: `http://${host}:${port}/payment-request/id-1234`,
maxSendable: 100_000_000_000,
minSendable: 1000,
metadata: '[["text/plain","Hello World!"]]',
})
})
app.get('/payment-request/id-1234', async (request, response, next) => {
try {
console.log(request.query)
const { request: pr } = await createInvoice({
mtokens: request.query.amount,
description: `test invoice`,
expiry: 180,
lnd,
})
response.json({ pr })
} catch (error) {
next(error)
}
})
app.use((error, request, response, next) => {
console.error(error)
response.status(500).json({ error })
})
app.listen(port, '0.0.0.0', () => {
console.log(`Lightning address test server listening on 0.0.0.0:${port}`)
})