diff --git a/lnurl.go b/lnurl.go index 7f4d124..1be90d0 100644 --- a/lnurl.go +++ b/lnurl.go @@ -215,20 +215,9 @@ func handleLNURL(w http.ResponseWriter, r *http.Request) { //if we provided a nsec and the response contained zap information, we wait for the invoice to be paid //in order to submit the zap on nostr - if allowNostr && payvaluescustom.AwaitInvoicePaid { + //also check for invoice paid for regular ln payments for nostr notificaitons + if payvaluescustom.AwaitInvoicePaid { go WaitForInvoicePaid(payvaluescustom, params) - } else if params.Npub != "" && params.NotifyNonZap { - var amount = payvaluescustom.ParsedInvoice.MSatoshi / 1000 - var satsr = "Sats" - if amount == 1 { - satsr = "Sat" - } - if payvaluescustom.Comment != "" { - go sendMessage(params.Npub, "Received Non-Zap! Amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️. Comment: "+payvaluescustom.Comment) - - } else { - go sendMessage(params.Npub, "Received Non-Zap! Amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️.") - } } } } @@ -281,13 +270,12 @@ func serveLNURLpSecond(w http.ResponseWriter, params *Params, username string, a } //Check invoice paid only if we actually have a NIP57 event - var awaitPaid = false + var awaitPaid = true var sender = "" var note = "" // nip57 - we need to store the newly created invoice in the zap receipt if zapEvent.Sig != "" { nip57Receipt = CreateNostrReceipt(zapEvent, invoice) - awaitPaid = true sender = "@" + EncodeBench32Public(zapEvent.PubKey) if zapEvent.Tags.GetFirst([]string{"e"}) != nil { note = "@" + EncodeBench32Note(zapEvent.Tags.GetFirst([]string{"e"}).Value()) diff --git a/waitforinvoice.go b/waitforinvoice.go index 3f19132..338f71c 100644 --- a/waitforinvoice.go +++ b/waitforinvoice.go @@ -169,35 +169,53 @@ 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 payvalues.Paid { var amount = bolt11.MSatoshi / 1000 - var descriptionTag = *payvalues.Nip57Receipt.Tags.GetFirst([]string{"description"}) - if bolt11.DescriptionHash == Nip57DescriptionHash(descriptionTag.Value()) { - publishNostrEvent(payvalues.Nip57Receipt, payvalues.Nip57ReceiptRelays) + + if *&payvalues.Nip57Receipt.Tags != nil { + var descriptionTag = *payvalues.Nip57Receipt.Tags.GetFirst([]string{"description"}) + + if bolt11.DescriptionHash == Nip57DescriptionHash(descriptionTag.Value()) { + publishNostrEvent(payvalues.Nip57Receipt, payvalues.Nip57ReceiptRelays) + var satsr = "Sats" + if amount == 1 { + satsr = "Sat" + } + + if params.Npub != "" && params.NotifyZapComment && payvalues.Comment != "" { + if payvalues.Note != "" { + go sendMessage(params.Npub, "Received Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️ for note "+payvalues.Note+". Comment: "+payvalues.Comment) + + } else { + go sendMessage(params.Npub, "Received Profile Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️. Comment: "+payvalues.Comment) + } + } else if params.Npub != "" && params.NotifyZaps { + if payvalues.Note != "" { + go sendMessage(params.Npub, "Received Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️ for note "+payvalues.Note+".") + + } else { + go sendMessage(params.Npub, "Received Profile Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️.") + } + } + + } + } else if params.Npub != "" && params.NotifyNonZap { + var amount = payvalues.ParsedInvoice.MSatoshi / 1000 var satsr = "Sats" if amount == 1 { satsr = "Sat" } + if payvalues.Comment != "" { + go sendMessage(params.Npub, "Received Non-Zap! Amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️. Comment: "+payvalues.Comment) - if params.Npub != "" && params.NotifyZapComment && payvalues.Comment != "" { - if payvalues.Note != "" { - go sendMessage(params.Npub, "Received Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️ for note "+payvalues.Note+". Comment: "+payvalues.Comment) - - } else { - go sendMessage(params.Npub, "Received Profile Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️. Comment: "+payvalues.Comment) - } - } else if params.Npub != "" && params.NotifyZaps { - if payvalues.Note != "" { - go sendMessage(params.Npub, "Received Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️ for note "+payvalues.Note+".") - - } else { - go sendMessage(params.Npub, "Received Profile Zap from "+payvalues.Sender+" with amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️.") - } + } else { + go sendMessage(params.Npub, "Received Non-Zap! Amount: "+strconv.FormatInt(amount, 10)+" "+satsr+" ⚡️.") } - log.Debug().Str("ZAPPED ⚡️", "Published zap on Nostr").Msg("Nostr") - close(quit) - return } + log.Debug().Str("ZAPPED ⚡️", "Published zap on Nostr").Msg("Nostr") + close(quit) + return + maxiterations-- } case <-quit: