From 1431887c0401dbe5e36cf638993de07c44851dbc Mon Sep 17 00:00:00 2001 From: Asara Date: Sat, 4 Feb 2023 22:39:01 -0500 Subject: [PATCH] Set up expiration --- lnd/lnd.go | 5 ++++- nostr/nostr.go | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lnd/lnd.go b/lnd/lnd.go index aaf73a7..6ff89e4 100644 --- a/lnd/lnd.go +++ b/lnd/lnd.go @@ -1,15 +1,18 @@ package lnd import ( + "time" + "github.com/davecgh/go-spew/spew" ) -func Request(rKey string, request []byte) (string, error) { +func Request(rKey string, request []byte, exp time.Duration) (string, error) { //redis, err := redis.New("localhost:6379", "", redis.LndDb) //if err != nil { // return "", 0, errors.New("Failed to connect to redis") //} spew.Dump(rKey) + spew.Dump(exp) spew.Dump(request) return "x", nil } diff --git a/nostr/nostr.go b/nostr/nostr.go index f32df2b..83e2e48 100644 --- a/nostr/nostr.go +++ b/nostr/nostr.go @@ -69,13 +69,14 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) { jsonUser, _ := json.Marshal(user) // generate the payment request - paymentReq, err := lnd.Request(rKey, jsonUser) + exp := time.Until(time.Now().Add(time.Minute * 15)) + paymentReq, err := lnd.Request(rKey, jsonUser, exp) if err != nil { w.WriteHeader(http.StatusServiceUnavailable) return } requestKey := getRkey("requested", r.FormValue("Name"), getHostname(r.Host)) - err = redisCli.Client.Set(ctx, requestKey, jsonUser, 15*time.Minute).Err() + err = redisCli.Client.Set(ctx, requestKey, jsonUser, exp).Err() if err != nil { fmt.Println("FAILED") } @@ -151,7 +152,7 @@ func convertNpubToHex(npub string) (string, error) { } _, hex, err := nip19.Decode(npub) if err != nil { - spew.Dump(hex) + return "", errors.New("Unable to decode npub") } return hex.(string), nil