Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update index.js to support zap note requests #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function create_server(opts={})
return server
}

async function make_invoice(opts, amount)
async function make_invoice(opts, amount, nostr)
{
let bolt11 = null
const ln = await LNSocket()
Expand All @@ -31,7 +31,9 @@ async function make_invoice(opts, amount)
method: "invoice",
params: {
msatoshi: amount || "any",
description: opts.description,
expiry: 3600,
description: nostr,
deschashonly: true,
label: crypto.randomUUID().toString(),
}
});
Expand Down Expand Up @@ -77,17 +79,18 @@ function handle_static_payreq(opts, req, res)
minSendable: 1,
maxSendable: 10000000000,
callback: opts.callback,
metadata: JSON.stringify(metadata)
metadata: JSON.stringify(metadata),
allowsNostr: true
}
res.statusCode = 200
res.write(JSON.stringify(resp))
res.end()
}

async function handle_payreq(amount, opts, req, res)
async function handle_payreq(amount, opts, req, res, nostr)
{
try {
const pr = await make_invoice(opts, amount)
const pr = await make_invoice(opts, amount, nostr)
const routes = []
const resp = JSON.stringify({pr, routes})
res.statusCode = 200
Expand All @@ -108,8 +111,8 @@ function handle_request(opts, req, res)
const parsed = url.parse(req.url)
const qs = querystring.parse(parsed.query)

if (qs && qs.amount) {
handle_payreq(qs.amount, opts, req, res)
if (qs && qs.amount && qs.nostr) {
handle_payreq(qs.amount, opts, req, res, qs.nostr)
return
}

Expand Down