From 77eb0fdabced5b2a18c64ba3e6c10f505a97e912 Mon Sep 17 00:00:00 2001 From: "Dr. Tobias Baur" Date: Sat, 11 Mar 2023 00:35:18 +0100 Subject: [PATCH] reverrted some changes that caused problems with nostrgram --- invoice.go | 24 +++++++++++------------- makeinvoice.go | 34 +++++++++++++++++----------------- waitforinvoice.go | 9 ++------- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/invoice.go b/invoice.go index 32a0c43..1edaba5 100644 --- a/invoice.go +++ b/invoice.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "encoding/json" "fmt" "image" "image/jpeg" @@ -11,7 +10,6 @@ import ( "strconv" "time" - "github.com/nbd-wtf/go-nostr" "github.com/nfnt/resize" "github.com/fiatjaf/go-lnurl" @@ -129,23 +127,23 @@ func makeInvoice( //use zapEventSerializedStr if nip57, else build hash descriptionhash from params if zapEventSerializedStr != "" { //Ok here it gets a bit tricky (due to lack of standards, if we have a comment, we overwrite it) - if comment != "" { - mip.Memo = comment - var zapEvent nostr.Event - err = json.Unmarshal([]byte(zapEventSerializedStr), &zapEvent) - if zapEvent.Content == "" { - zapEvent.Content = comment - zapEventSerialized, _ := json.Marshal(zapEvent) - zapEventSerializedStr = fmt.Sprintf("%s", zapEventSerialized) - } - } + // if comment != "" { + // mip.Memo = comment + // // var zapEvent nostr.Event + // // err = json.Unmarshal([]byte(zapEventSerializedStr), &zapEvent) + // // if zapEvent.Content == "" { + // // zapEvent.Content = comment + // // zapEventSerialized, _ := json.Marshal(zapEvent) + // // zapEventSerializedStr = fmt.Sprintf("%s", zapEventSerialized) + // // } + // } mip.Description = zapEventSerializedStr } else { // make the lnurlpay description_hash mip.Description = metaData(params).Encode() - mip.Memo = comment + //mip.Memo = comment } mip.UseDescriptionHash = true diff --git a/makeinvoice.go b/makeinvoice.go index fdbd547..4bba0b0 100644 --- a/makeinvoice.go +++ b/makeinvoice.go @@ -21,7 +21,6 @@ import ( lightning "github.com/fiatjaf/lightningd-gjson-rpc" lnsocket "github.com/jb55/lnsocket/go" "github.com/lnpay/lnpay-go" - "github.com/nbd-wtf/go-nostr" "github.com/tidwall/gjson" "github.com/tidwall/sjson" // "github.com/fiatjaf/makeinvoice" @@ -226,23 +225,24 @@ func MakeInvoice(params MIParams) (bolt11 string, err error) { body, _ = sjson.Set(body, "out", false) if params.UseDescriptionHash { - var zapEvent nostr.Event - err = json.Unmarshal([]byte(params.Description), &zapEvent) - if err == nil && zapEvent.Content != "" { - //This works - log.Debug().Str("Zap Event Content", zapEvent.Content).Msg("Message") - body, _ = sjson.Set(body, "memo", zapEvent.Content) - } else { + //var zapEvent nostr.Event + //err = json.Unmarshal([]byte(params.Description), &zapEvent) + // if err == nil && zapEvent.Content != "" { + // //This works + // log.Debug().Str("Zap Event Content", zapEvent.Content).Msg("Message") + // body, _ = sjson.Set(body, "unhashed_description", hex.EncodeToString([]byte(zapEvent.Content))) + // //body, _ = sjson.Set(body, "memo", zapEvent.Content) + // } else { - //But this does not? - // if params.Memo != "" { - // log.Debug().Str("Empty/Non Zap Event Content", params.Memo).Msg("Message") - // body, _ = sjson.Set(body, "memo", params.Memo) - // } else { - log.Debug().Str("Empty/Non Zap Event Hash", hex.EncodeToString([]byte(params.Description))).Msg("Message") - body, _ = sjson.Set(body, "unhashed_description", hex.EncodeToString([]byte(params.Description))) - //} - } + //But this does not? + // if params.Memo != "" { + // log.Debug().Str("Empty/Non Zap Event Content", params.Memo).Msg("Message") + // body, _ = sjson.Set(body, "memo", params.Memo) + // } else { + //log.Debug().Str("Empty/Non Zap Event Hash", hex.EncodeToString([]byte(params.Description))).Msg("Message") + body, _ = sjson.Set(body, "unhashed_description", hex.EncodeToString([]byte(params.Description))) + //} + //} } else { if params.Description == "" { diff --git a/waitforinvoice.go b/waitforinvoice.go index 1c61562..b8eef7c 100644 --- a/waitforinvoice.go +++ b/waitforinvoice.go @@ -171,20 +171,15 @@ func WaitForInvoicePaid(payvalues LNURLPayValuesCustom, params *Params, comment //If invoice is paid and DescriptionHash matches Nip57 DescriptionHash, publish Zap Nostr Event. This is rather a sanity check. if isPaid { - if payvalues.nip57Receipt.Kind == 0 { - log.Debug().Str("Paid", "Paid non-Nostr Invoice").Msg("Paid") - close(quit) - return - } - log.Debug().Str("DescriptionHash", bolt11.DescriptionHash).Msg("zapped") log.Debug().Str("Description", bolt11.Description).Msg("zapped") var descriptionTag = *payvalues.nip57Receipt.Tags.GetFirst([]string{"description"}) - if (bolt11.DescriptionHash == Nip57DescriptionHash(descriptionTag.Value())) || (bolt11.Description == comment && descriptionTag.Value() != "") { + if bolt11.DescriptionHash == Nip57DescriptionHash(descriptionTag.Value()) { log.Debug().Str("ZAP", "Published on Nostr").Msg("zapped") publishNostrEvent(payvalues.nip57Receipt, payvalues.nip57ReceiptRelays) close(quit) return + } }