From 232b1b8d277713841df2935a155e0e3e9ac22e6a Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Fri, 30 Aug 2024 16:00:41 -0400 Subject: [PATCH] handlekind refactored to only handle storing events in database --- server/handlers/event.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/server/handlers/event.go b/server/handlers/event.go index e85f2bf..7518d43 100644 --- a/server/handlers/event.go +++ b/server/handlers/event.go @@ -44,6 +44,12 @@ func HandleEvent(ws *websocket.Conn, message []interface{}) { return } + // Signature check moved here + if !utils.CheckSignature(evt) { + response.SendOK(ws, evt.ID, false, "invalid: signature verification failed") + return + } + eventSize := len(eventBytes) // Calculate event size if !handleBlacklistAndWhitelist(ws, evt) { @@ -54,7 +60,7 @@ func HandleEvent(ws *websocket.Conn, message []interface{}) { return } - HandleKind(context.TODO(), evt, ws, eventSize) + storeEvent(context.TODO(), evt, ws) fmt.Println("Event processed:", evt.ID) }) @@ -110,12 +116,7 @@ func handleRateAndSizeLimits(ws *websocket.Conn, evt relay.Event, eventSize int) return true } -func HandleKind(ctx context.Context, evt relay.Event, ws *websocket.Conn, eventSize int) { - if !utils.CheckSignature(evt) { - response.SendOK(ws, evt.ID, false, "invalid: signature verification failed") - return - } - +func storeEvent(ctx context.Context, evt relay.Event, ws *websocket.Conn) { collection := db.GetCollection(evt.Kind) var err error