reverrted some changes that caused problems with nostrgram

This commit is contained in:
Dr. Tobias Baur
2023-03-11 00:35:18 +01:00
parent 94ba0ca85a
commit 77eb0fdabc
3 changed files with 30 additions and 37 deletions
+11 -13
View File
@@ -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
+17 -17
View File
@@ -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 == "" {
+2 -7
View File
@@ -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
}
}