use easyjson and envelopes.

This commit is contained in:
fiatjaf 2023-11-28 15:18:43 -03:00
parent f2f9dda33a
commit d9d36e7619
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 5 additions and 4 deletions

View File

@ -142,7 +142,7 @@ example:
kindWasSupplied := false kindWasSupplied := false
mustRehashAndResign := false mustRehashAndResign := false
if stdinEvent != "" { if stdinEvent != "" {
if err := json.Unmarshal([]byte(stdinEvent), &evt); err != nil { if err := easyjson.Unmarshal([]byte(stdinEvent), &evt); err != nil {
lineProcessingError(c, "invalid event received from stdin: %s", err) lineProcessingError(c, "invalid event received from stdin: %s", err)
continue continue
} }
@ -235,7 +235,7 @@ example:
} else { } else {
var result string var result string
if c.Bool("envelope") { if c.Bool("envelope") {
j, _ := json.Marshal([]any{"EVENT", evt}) j, _ := json.Marshal(nostr.EventEnvelope{Event: evt})
result = string(j) result = string(j)
} else if c.Bool("nson") { } else if c.Bool("nson") {
result, _ = nson.Marshal(&evt) result, _ = nson.Marshal(&evt)

5
req.go
View File

@ -6,6 +6,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/mailru/easyjson"
"github.com/nbd-wtf/go-nostr" "github.com/nbd-wtf/go-nostr"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -113,7 +114,7 @@ example:
for stdinFilter := range getStdinLinesOrBlank() { for stdinFilter := range getStdinLinesOrBlank() {
filter := nostr.Filter{} filter := nostr.Filter{}
if stdinFilter != "" { if stdinFilter != "" {
if err := json.Unmarshal([]byte(stdinFilter), &filter); err != nil { if err := easyjson.Unmarshal([]byte(stdinFilter), &filter); err != nil {
lineProcessingError(c, "invalid filter '%s' received from stdin: %s", stdinFilter, err) lineProcessingError(c, "invalid filter '%s' received from stdin: %s", stdinFilter, err)
continue continue
} }
@ -184,7 +185,7 @@ example:
if c.Bool("bare") { if c.Bool("bare") {
result = filter.String() result = filter.String()
} else { } else {
j, _ := json.Marshal([]any{"REQ", "nak", filter}) j, _ := json.Marshal(nostr.ReqEnvelope{SubscriptionID: "nak", Filters: nostr.Filters{filter}})
result = string(j) result = string(j)
} }