--nevent flag on nak event to print an nevent at the end.

This commit is contained in:
fiatjaf 2024-01-24 22:43:23 -03:00
parent 14b69f36cf
commit 3dfcec69b7
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -11,6 +11,7 @@ import (
"github.com/mailru/easyjson"
"github.com/nbd-wtf/go-nostr"
"github.com/nbd-wtf/go-nostr/nip19"
"github.com/nbd-wtf/go-nostr/nson"
"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
@ -51,6 +52,10 @@ example:
Name: "auth",
Usage: "always perform NIP-42 \"AUTH\" when facing an \"auth-required: \" rejection and try again",
},
&cli.BoolFlag{
Name: "nevent",
Usage: "print the nevent code (to stderr) after the event is published",
},
&cli.BoolFlag{
Name: "nson",
Usage: "encode the event using NSON",
@ -229,6 +234,7 @@ example:
stdout(result)
// publish to relays
successRelays := make([]string, 0, len(relays))
if len(relays) > 0 {
os.Stdout.Sync()
for _, relay := range relays {
@ -241,6 +247,7 @@ example:
if err == nil {
// published fine
log("success.\n")
successRelays = append(successRelays, relay.URL)
continue // continue to next relay
}
@ -259,6 +266,10 @@ example:
}
log("failed: %s\n", err)
}
if len(successRelays) > 0 && c.Bool("nevent") {
nevent, _ := nip19.EncodeEvent(evt.ID, successRelays, evt.PubKey)
log(nevent + "\n")
}
}
}