package websocket import ( pb "northwest.io/muxstr/api/nostr/v1" "code.northwest.io/nostr" ) func NostrToPB(n *nostr.Event) *pb.Event { tags := make([]*pb.Tag, len(n.Tags)) for i, tag := range n.Tags { tags[i] = &pb.Tag{Values: tag} } return &pb.Event{ Id: n.ID, Pubkey: n.PubKey, CreatedAt: n.CreatedAt, Kind: int32(n.Kind), Tags: tags, Content: n.Content, Sig: n.Sig, } } func PBToNostr(e *pb.Event) *nostr.Event { tags := make(nostr.Tags, len(e.Tags)) for i, tag := range e.Tags { tags[i] = tag.Values } return &nostr.Event{ ID: e.Id, PubKey: e.Pubkey, CreatedAt: e.CreatedAt, Kind: int(e.Kind), Tags: tags, Content: e.Content, Sig: e.Sig, } } func NostrFilterToPB(f *nostr.Filter) *pb.Filter { pbFilter := &pb.Filter{ Ids: f.IDs, Authors: f.Authors, Kinds: make([]int32, len(f.Kinds)), } for i, kind := range f.Kinds { pbFilter.Kinds[i] = int32(kind) } if f.Since != nil { since := int64(*f.Since) pbFilter.Since = &since } if f.Until != nil { until := int64(*f.Until) pbFilter.Until = &until } if f.Limit > 0 { limit := int32(f.Limit) pbFilter.Limit = &limit } if len(f.Tags) > 0 { pbFilter.TagFilters = make(map[string]*pb.TagFilter) for tagName, values := range f.Tags { pbFilter.TagFilters[tagName] = &pb.TagFilter{Values: values} } } return pbFilter }