Some error messages and fix up lnd logic

This commit is contained in:
Amarpreet Minhas 2023-05-06 20:16:00 -04:00
parent 5b29025296
commit ed1a74bb60
2 changed files with 20 additions and 4 deletions

View file

@ -38,8 +38,6 @@ func Request(rKey string) (string, error) {
}
expiryInMin := int64(5)
expiryTime := time.Now().Local().Add(time.Minute * time.Duration(expiryInMin)).Unix()
invoice, err := lndCli.AddInvoice(ctx, &lnrpc.Invoice{
Memo: fmt.Sprintf("nostr addr %s", rKey),
Expiry: expiryInMin * 60,
@ -49,6 +47,10 @@ func Request(rKey string) (string, error) {
l.Fatal().Msg("unable to create lnd invoice")
return "", errors.New("internal server error")
}
// add a minute to the expiry time to ensure entries aren't removed from redis before they are expired
expiryTime := time.Now().Local().Add(time.Minute * time.Duration(expiryInMin+1)).Unix()
paymentReq := invoice.PaymentRequest
rHash := hex.EncodeToString(invoice.RHash)

View file

@ -43,6 +43,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
l := logger.Get()
switch r.Method {
case "GET":
w.WriteHeader(http.StatusOK)
http.ServeFile(w, r, "html/nostr_form.html")
case "POST":
r.ParseForm()
@ -110,6 +111,11 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
err = redisCli.Set(ctx, rKey, enc, 0).Err()
if err != nil {
l.Error().Msg("unable to connect to redis")
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(&jsonErrorMessage{
Error: "service unavailable",
})
return
}
// return qr code
@ -121,12 +127,20 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
tmplt, err := template.ParseFiles("html/nostr_qr_response.html")
if err != nil {
l.Error().Msg("unable to parse template")
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(&jsonErrorMessage{
Error: "service unavailable",
})
return
}
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
err = tmplt.Execute(w, response)
if err != nil {
l.Error().Msg("unable to connect to render template")
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(&jsonErrorMessage{
Error: "service unavailable",
})
return
}
return
}