Added some NIP-42 functionality to the client (relay.go) (#38)

This commit is contained in:
barkyq
2023-01-16 06:27:11 -05:00
committed by GitHub
parent 9775016bf1
commit 87b6280299
5 changed files with 139 additions and 24 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"strings"
"time"
@@ -13,7 +14,7 @@ import (
)
func main() {
ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
// connect to relay
url := "wss://nostr.zebedee.cloud"
@@ -58,7 +59,7 @@ func main() {
go func() {
<-sub.EndOfStoredEvents
sub.Unsub()
cancel()
}()
for ev := range sub.Events {
evs = append(evs, ev)
@@ -106,19 +107,14 @@ func main() {
fmt.Fprintln(os.Stderr, "enter content of note, ending with an empty newline:")
for {
if n, err := reader.Read(b[:]); err == nil {
new_line := strings.TrimSpace(fmt.Sprintf("%s", b[:n]))
if new_line == "" {
break
} else if content == "" {
content = new_line
} else {
content = fmt.Sprintf("%s\n%s", content, new_line)
}
content = fmt.Sprintf("%s%s", content, fmt.Sprintf("%s", b[:n]))
} else if err == io.EOF {
break
} else {
panic(err)
}
}
ev.Content = content
ev.Content = strings.TrimSpace(content)
ev.Sign(sk)
for _, url := range []string{"wss://nostr.zebedee.cloud"} {
ctx := context.WithValue(context.Background(), "url", url)