diff options
| author | bndw <ben@bdw.to> | 2026-02-13 17:48:36 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-13 17:48:36 -0800 |
| commit | 62d31434ddbadff18580826576e1169f539e23f0 (patch) | |
| tree | a3e56da30e33ddf0dbfdea407df6724c9640a7b1 /internal/handler/grpc/convert.go | |
| parent | 5fcf5bd1fa5b2e707cea82c4652ea65c3c113c1a (diff) | |
feat: add gRPC handler with event validation and publishing
Handler implementation:
- EventStore interface (consumer-side)
- Server with PublishEvent, QueryEvents, CountEvents, PublishBatch
- pb.Event <-> nostr.Event conversion helpers
- Signature and ID validation using existing nostr package
- Canonical JSON generation for storage
9 tests passing
Diffstat (limited to 'internal/handler/grpc/convert.go')
| -rw-r--r-- | internal/handler/grpc/convert.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/internal/handler/grpc/convert.go b/internal/handler/grpc/convert.go new file mode 100644 index 0000000..19505cd --- /dev/null +++ b/internal/handler/grpc/convert.go | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | package grpc | ||
| 2 | |||
| 3 | import ( | ||
| 4 | pb "northwest.io/nostr-grpc/api/nostr/v1" | ||
| 5 | "northwest.io/nostr-grpc/internal/nostr" | ||
| 6 | ) | ||
| 7 | |||
| 8 | func NostrToPB(n *nostr.Event) *pb.Event { | ||
| 9 | tags := make([]*pb.Tag, len(n.Tags)) | ||
| 10 | for i, tag := range n.Tags { | ||
| 11 | tags[i] = &pb.Tag{Values: tag} | ||
| 12 | } | ||
| 13 | |||
| 14 | return &pb.Event{ | ||
| 15 | Id: n.ID, | ||
| 16 | Pubkey: n.PubKey, | ||
| 17 | CreatedAt: n.CreatedAt, | ||
| 18 | Kind: int32(n.Kind), | ||
| 19 | Tags: tags, | ||
| 20 | Content: n.Content, | ||
| 21 | Sig: n.Sig, | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | func PBToNostr(e *pb.Event) *nostr.Event { | ||
| 26 | tags := make(nostr.Tags, len(e.Tags)) | ||
| 27 | for i, tag := range e.Tags { | ||
| 28 | tags[i] = tag.Values | ||
| 29 | } | ||
| 30 | |||
| 31 | return &nostr.Event{ | ||
| 32 | ID: e.Id, | ||
| 33 | PubKey: e.Pubkey, | ||
| 34 | CreatedAt: e.CreatedAt, | ||
| 35 | Kind: int(e.Kind), | ||
| 36 | Tags: tags, | ||
| 37 | Content: e.Content, | ||
| 38 | Sig: e.Sig, | ||
| 39 | } | ||
| 40 | } | ||
