More code cleanup.

This commit is contained in:
Believethehype
2023-03-12 03:11:27 +01:00
parent fabb8553b4
commit 760ebae76e
2 changed files with 16 additions and 9 deletions
+8 -2
View File
@@ -166,8 +166,10 @@ func handleLNURL(w http.ResponseWriter, r *http.Request) {
return
}
}
comment = zapEvent.Content
log.Debug().Str("NIP57 Comment received", comment).Msg("Comment")
if len(zapEvent.Content) > 0 {
comment = zapEvent.Content
log.Debug().Str("NIP57 Comment received", comment).Msg("Comment")
}
}
@@ -269,12 +271,16 @@ func serveLNURLpSecond(w http.ResponseWriter, params *Params, username string, a
awaitPaid = true
}
decoded_invoice, _ := decodepay.Decodepay(invoice)
return LNURLPayValuesCustom{
LNURLResponse: lnurl.LNURLResponse{Status: "OK"},
PR: invoice,
Routes: make([]struct{}, 0),
SuccessAction: &lnurl.SuccessAction{Message: "Payment Received!", Tag: "message"},
Comment: comment,
Paid: false,
CreatedAt: time.Now(),
ParsedInvoice: decoded_invoice,
Nip57Receipt: nip57Receipt,
Nip57ReceiptRelays: nip57ReceiptRelays,
AwaitInvoicePaid: awaitPaid,
+8 -7
View File
@@ -181,9 +181,8 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) {
case <-ticker.C:
bolt11, _ := decodepay.Decodepay(payvalues.PR)
var isPaid bool = false
switch backend := mip.Backend.(type) {
case LNDParams:
req, err := http.NewRequest("GET",
backend.Host+"/v1/invoice/"+bolt11.PaymentHash,
@@ -210,7 +209,8 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) {
}
if gjson.ParseBytes(b).Get("settled").String() == "true" {
isPaid = true
payvalues.PaidAt = time.Now()
payvalues.Paid = true
}
case LNBitsParams:
@@ -229,15 +229,16 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) {
json.Unmarshal([]byte(string(responseData)), &jsonMap)
if jsonMap["paid"].(bool) {
isPaid = true
payvalues.PaidAt = time.Now()
payvalues.Paid = true
}
case SparkoParams:
//TODO
case LNPayParams:
//TODO
case EclairParams:
//TODO
case SparkoParams:
//TODO
case CommandoParams:
//TODO
@@ -249,7 +250,7 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params) {
}
//If invoice is paid and DescriptionHash matches Nip57 DescriptionHash, publish Zap Nostr Event. This is rather a sanity check.
if isPaid {
if payvalues.Paid {
var descriptionTag = *payvalues.Nip57Receipt.Tags.GetFirst([]string{"description"})
if bolt11.DescriptionHash == Nip57DescriptionHash(descriptionTag.Value()) {
publishNostrEvent(payvalues.Nip57Receipt, payvalues.Nip57ReceiptRelays)