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

@@ -24,8 +24,8 @@ type EventMessage struct {
Relay string
}
// Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01
// Unsub() also closes the channel sub.Events
// Unsub closes the subscription, sending "CLOSE" to relay as in NIP-01.
// Unsub() also closes the channel sub.Events.
func (sub *Subscription) Unsub() {
sub.mutex.Lock()
defer sub.mutex.Unlock()
@@ -37,14 +37,14 @@ func (sub *Subscription) Unsub() {
sub.stopped = true
}
// Sub sets sub.Filters and then calls sub.Fire(ctx)
// Sub sets sub.Filters and then calls sub.Fire(ctx).
func (sub *Subscription) Sub(ctx context.Context, filters Filters) {
sub.Filters = filters
sub.Fire(ctx)
}
// Fire sends the "REQ" command to the relay
// when ctx is cancelled, sub.Unsub() is called, closing the subscription
// Fire sends the "REQ" command to the relay.
// When ctx is cancelled, sub.Unsub() is called, closing the subscription.
func (sub *Subscription) Fire(ctx context.Context) {
message := []interface{}{"REQ", sub.id}
for _, filter := range sub.Filters {