start adding handling for lnurlp
This commit is contained in:
parent
79c6369c39
commit
e16fca179b
6 changed files with 107 additions and 8 deletions
75
main.go
75
main.go
|
|
@ -24,6 +24,68 @@ func write_error_message(w http.ResponseWriter, message string) {
|
|||
w.Write(jsonData)
|
||||
}
|
||||
|
||||
func lnurlp_response(w http.ResponseWriter, r *http.Request) {
|
||||
name := mux.Vars(r)["name"]
|
||||
|
||||
log.WithFields(
|
||||
log.Fields{
|
||||
"url_path": r.URL.Path,
|
||||
"name": name,
|
||||
"r.Host": r.Host,
|
||||
},).Info("lnurlp_response")
|
||||
|
||||
// look up domain in env vars (HOST_DOMAIN)
|
||||
env_host_domain := os.Getenv("HOST_DOMAIN")
|
||||
if r.Host != env_host_domain {
|
||||
log.Warn("wrong host domain")
|
||||
write_error(w)
|
||||
return
|
||||
}
|
||||
|
||||
// look up name in database (table cards, field card_name)
|
||||
|
||||
card_count, err := db_get_card_count_for_name(name)
|
||||
if err != nil {
|
||||
log.Warn("could not get card count for name")
|
||||
write_error(w)
|
||||
return
|
||||
}
|
||||
|
||||
if card_count != 1 {
|
||||
log.Info("not one card with that name")
|
||||
write_error(w)
|
||||
return
|
||||
}
|
||||
|
||||
jsonData := []byte(`{"status":"OK",` +
|
||||
`"callback":"https://` + env_host_domain + `/lnurlp/` + name + `",` +
|
||||
`"tag":"payRequest",` +
|
||||
`"maxSendable":1000000000,` +
|
||||
`"minSendable":1000,` +
|
||||
`"metadata":"[[\"text/plain\",\"` + name + `@` + env_host_domain + `\"]]",` +
|
||||
`"commentAllowed":0` +
|
||||
`}`)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(jsonData)
|
||||
}
|
||||
|
||||
func lnurlp_callback(w http.ResponseWriter, r *http.Request) {
|
||||
name := mux.Vars(r)["name"]
|
||||
amount := r.URL.Query().Get("amount");
|
||||
|
||||
log.WithFields(
|
||||
log.Fields{
|
||||
"url_path": r.URL.Path,
|
||||
"name": name,
|
||||
"amount": amount,
|
||||
"req.Host": r.Host,
|
||||
},).Info("lnurlp_callback")
|
||||
|
||||
|
||||
}
|
||||
|
||||
func main() {
|
||||
log_level := os.Getenv("LOG_LEVEL")
|
||||
|
||||
|
|
@ -39,19 +101,20 @@ func main() {
|
|||
})
|
||||
|
||||
// createboltcard
|
||||
router.Path("/new").HandlerFunc(new_card_request)
|
||||
router.Path("/new").Methods("GET").HandlerFunc(new_card_request)
|
||||
// lnurlw for pos
|
||||
router.Path("/ln").HandlerFunc(lnurlw_response)
|
||||
router.Path("/cb").HandlerFunc(lnurlw_callback)
|
||||
// lnurlp for lightning address
|
||||
// mux.HandleFunc("/.well-known/lnurlp/", lnurlp_response)
|
||||
router.Path("/ln").Methods("GET").HandlerFunc(lnurlw_response)
|
||||
router.Path("/cb").Methods("GET").HandlerFunc(lnurlw_callback)
|
||||
// lnurlp for lightning address lnurlp
|
||||
router.Path("/.well-known/lnurlp/{name}").Methods("GET").HandlerFunc(lnurlp_response)
|
||||
router.Path("/lnurlp/{name}").Methods("GET").HandlerFunc(lnurlp_callback)
|
||||
|
||||
port := os.Getenv("HOST_PORT")
|
||||
if len(port) == 0 {
|
||||
port = "9000"
|
||||
}
|
||||
|
||||
srv := &http.Server{
|
||||
srv := &http.Server {
|
||||
Handler: router,
|
||||
Addr: ":" + port, // consider adding host
|
||||
WriteTimeout: 30 * time.Second,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue