Skip to content

Commit

Permalink
Registration: allow empty relays, check event kind
Browse files Browse the repository at this point in the history
  • Loading branch information
boreq committed Nov 29, 2023
1 parent 75151de commit 3ee0956
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions service/domain/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package domain

import (
"encoding/json"
"fmt"

"github.com/boreq/errors"
"github.com/planetary-social/nos-event-service/internal"
Expand All @@ -13,6 +14,10 @@ type Registration struct {
}

func NewRegistrationFromEvent(event Event) (Registration, error) {
if event.Kind() != EventKindRegistration {
return Registration{}, fmt.Errorf("invalid event kind '%d'", event.Kind().Int())
}

var v registrationContent
if err := json.Unmarshal([]byte(event.Content()), &v); err != nil {
return Registration{}, errors.Wrap(err, "error unmarshaling content")
Expand Down Expand Up @@ -54,10 +59,5 @@ func newRelays(v registrationContent) ([]RelayAddress, error) {
}
relays = append(relays, address)
}

if len(relays) == 0 {
return nil, errors.New("missing relays")
}

return relays, nil
}

0 comments on commit 3ee0956

Please sign in to comment.