Add nostr nip-05 registration with lnd invoices #1
3 changed files with 10 additions and 15 deletions
13
lnd/lnd.go
13
lnd/lnd.go
|
@ -37,21 +37,24 @@ func Request(rKey string) (string, error) {
|
||||||
return "", errors.New("internal server 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),
|
Memo: fmt.Sprintf("nostr addr %s", rKey),
|
||||||
Expiry: 1 * 60,
|
Expiry: expiryInMin * 60,
|
||||||
Value: addrFee,
|
Value: addrFee,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatal().Msg("unable to create lnd invoice")
|
l.Fatal().Msg("unable to create lnd invoice")
|
||||||
return "", errors.New("internal server error")
|
return "", errors.New("internal server error")
|
||||||
}
|
}
|
||||||
rHash := hex.EncodeToString(info.RHash)
|
paymentReq := invoice.PaymentRequest
|
||||||
paymentReq := info.PaymentRequest
|
rHash := hex.EncodeToString(invoice.RHash)
|
||||||
|
|
||||||
// write lnd request to redis
|
// write lnd request to redis
|
||||||
redisCli := redis.LndRedisConn.Client
|
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 {
|
if err != nil {
|
||||||
l.Error().Msg("unable to connect to redis when writing lnd request")
|
l.Error().Msg("unable to connect to redis when writing lnd request")
|
||||||
return "", errors.New("unable to make the request, please try again")
|
return "", errors.New("unable to make the request, please try again")
|
||||||
|
|
9
main.go
9
main.go
|
@ -22,14 +22,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Fatal().Msg("unable to connect to redis")
|
l.Fatal().Msg("unable to connect to redis")
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
nostrTest := nostr.NostrRequest{
|
|
||||||
Name: "asara",
|
|
||||||
Key: "npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6",
|
|
||||||
Hostname: "devvul.com",
|
|
||||||
}
|
|
||||||
nostr.AddNostrAddr(nostrTest)
|
|
||||||
*/
|
|
||||||
// matrix endpoints
|
// matrix endpoints
|
||||||
l.Debug().Msg("enabling matrix server endpoint")
|
l.Debug().Msg("enabling matrix server endpoint")
|
||||||
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
|
http.HandleFunc("/.well-known/matrix/server", matrix.MatrixServer)
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.minhas.io/asara/well-goknown/lnd"
|
"git.minhas.io/asara/well-goknown/lnd"
|
||||||
"git.minhas.io/asara/well-goknown/logger"
|
"git.minhas.io/asara/well-goknown/logger"
|
||||||
|
@ -108,7 +107,7 @@ func RequestNostrAddr(w http.ResponseWriter, r *http.Request) {
|
||||||
pngB64 := b64.StdEncoding.EncodeToString(png)
|
pngB64 := b64.StdEncoding.EncodeToString(png)
|
||||||
|
|
||||||
// write request to redis
|
// 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 {
|
if err != nil {
|
||||||
l.Error().Msg("unable to connect to redis")
|
l.Error().Msg("unable to connect to redis")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue