-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (36 loc) · 1.04 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
const config = require('dotenv').config()
const express = require('express')
const app = express()
const host = "127.0.0.1"
const port = 3003
const lnd = require('./lnd')
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.get('/.well-known/lnurlp/:username', (req, res) => {
res.json({ tag: 'payRequest', callback: `http://${host}:${port}/payment-request/id-1234`})
})
app.get('/payment-request/id-1234', (req, res) => {
const amount = req.query.amount
const request = {
value_msat: amount,
memo: `test invoice`,
expiry: 180
};
console.log(request);
// Generate invoice
lnd.lnClient.addInvoice(request, function(err, response) {
if (err) {
res.json(err)
}
else {
// Update invoice with r_hash
const lndResponse = response;
const r_hash_str = Buffer.from(response.r_hash).toString('hex')
res.json({pr: lndResponse.payment_request});
}
})
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})