forked from fiatjaf/noscl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nostr.go
43 lines (35 loc) · 817 Bytes
/
nostr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"log"
"github.com/nbd-wtf/go-nostr"
)
var pool *nostr.RelayPool
func initNostr() {
pool = nostr.NewRelayPool()
for relay, policy := range config.Relays {
cherr := pool.Add(relay, nostr.SimplePolicy{
Read: policy.Read,
Write: policy.Write,
})
err := <-cherr
if err != nil {
log.Printf("error adding relay '%s': %s", relay, err.Error())
}
}
hasRelays := false
pool.Relays.Range(func(_ string, _ *nostr.Relay) bool {
hasRelays = true
return false
})
if !hasRelays {
log.Printf("You have zero relays configured, everything will probably fail.")
}
go func() {
for notice := range pool.Notices {
log.Printf("%s has sent a notice: '%s'\n", notice.Relay, notice.Message)
}
}()
if config.PrivateKey != "" {
pool.SecretKey = &config.PrivateKey
}
}