From 5b2902529617e591d97790beffac905f5655a2f2 Mon Sep 17 00:00:00 2001 From: Asara Date: Sat, 6 May 2023 19:50:10 -0400 Subject: [PATCH] Clean up main, unset expiry on redis, add expiry to redis values --- lnd/lnd.go | 13 ++++++++----- main.go | 9 +-------- nostr/nostr.go | 3 +-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lnd/lnd.go b/lnd/lnd.go index dfe6180..2d5e77e 100644 --- a/lnd/lnd.go +++ b/lnd/lnd.go @@ -37,21 +37,24 @@ func Request(rKey string) (string, error) { return "", errors.New("internal server error") } - info, err := lndCli.AddInvoice(ctx, &lnrpc.Invoice{ + 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: 1 * 60, + Expiry: expiryInMin * 60, Value: addrFee, }) if err != nil { l.Fatal().Msg("unable to create lnd invoice") return "", errors.New("internal server error") } - rHash := hex.EncodeToString(info.RHash) - paymentReq := info.PaymentRequest + paymentReq := invoice.PaymentRequest + rHash := hex.EncodeToString(invoice.RHash) // write lnd request to redis redisCli := redis.LndRedisConn.Client - err = redisCli.Set(ctx, rKey, fmt.Sprintf("%s:%s", rHash, paymentReq), 15*time.Minute).Err() + err = redisCli.Set(ctx, rKey, fmt.Sprintf("%d:%s:%s", expiryTime, rHash, paymentReq), 0).Err() if err != nil { l.Error().Msg("unable to connect to redis when writing lnd request") return "", errors.New("unable to make the request, please try again") diff --git a/main.go b/main.go index 09b1831..783ebca 100644 --- a/main.go +++ b/main.go @@ -22,14 +22,7 @@ func main() { if err != nil { l.Fatal().Msg("unable to connect to redis") } - /* - nostrTest := nostr.NostrRequest{ - Name: "asara", - Key: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6", - Hostname: "devvul.com", - } - nostr.AddNostrAddr(nostrTest) - */ + // matrix endpoints l.Debug().Msg("enabling matrix server endpoint") http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer) diff --git a/nostr/nostr.go b/nostr/nostr.go index 773319e..1bdcdaf 100644 --- a/nostr/nostr.go +++ b/nostr/nostr.go @@ -9,7 +9,6 @@ import ( "html/template" "net/http" "strings" - "time" "git.minhas.io/asara/well-goknown/lnd" "git.minhas.io/asara/well-goknown/logger" @@ -108,7 +107,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) { pngB64 := b64.StdEncoding.EncodeToString(png) // write request to redis - err = redisCli.Set(ctx, rKey, enc, 15*time.Minute).Err() + err = redisCli.Set(ctx, rKey, enc, 0).Err() if err != nil { l.Error().Msg("unable to connect to redis") }