From dce0ce9df85b339cc8ad3252674b43848186421e Mon Sep 17 00:00:00 2001 From: Marc Font Date: Tue, 14 May 2024 19:14:48 +0200 Subject: [PATCH] deleting outdated legacy endpoints --- .../api/handlers/postSignaturesByValidator.go | 38 -------- .../handlers/postSignaturesByValidatorAggr.go | 88 ------------------- listener/internal/api/routes/routes.go | 6 -- 3 files changed, 132 deletions(-) delete mode 100644 listener/internal/api/handlers/postSignaturesByValidator.go delete mode 100644 listener/internal/api/handlers/postSignaturesByValidatorAggr.go diff --git a/listener/internal/api/handlers/postSignaturesByValidator.go b/listener/internal/api/handlers/postSignaturesByValidator.go deleted file mode 100644 index 2283ed5..0000000 --- a/listener/internal/api/handlers/postSignaturesByValidator.go +++ /dev/null @@ -1,38 +0,0 @@ -package handlers - -import ( - "encoding/json" - "net/http" - - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" -) - -type signaturesRequest struct { - Pubkey string `json:"pubkey"` - Network string `json:"network"` -} - -func PostSignaturesByValidator(w http.ResponseWriter, r *http.Request, dbCollection *mongo.Collection) { - var req signaturesRequest - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - respondError(w, http.StatusBadRequest, "Invalid request body") - return - } - - filter := bson.M{"pubkey": req.Pubkey, "network": req.Network} - cursor, err := dbCollection.Find(r.Context(), filter) - if err != nil { - respondError(w, http.StatusInternalServerError, "Error fetching signatures from MongoDB") - return - } - defer cursor.Close(r.Context()) - - var signatures []bson.M - if err = cursor.All(r.Context(), &signatures); err != nil { - respondError(w, http.StatusInternalServerError, "Error reading signatures from cursor") - return - } - - respondOK(w, signatures) -} diff --git a/listener/internal/api/handlers/postSignaturesByValidatorAggr.go b/listener/internal/api/handlers/postSignaturesByValidatorAggr.go deleted file mode 100644 index 01045f1..0000000 --- a/listener/internal/api/handlers/postSignaturesByValidatorAggr.go +++ /dev/null @@ -1,88 +0,0 @@ -package handlers - -import ( - "encoding/json" - "net/http" - - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" -) - -// Endpoint that returns an aggregation of all signatures for a given pubkey and network in this format: -// [ -// -// { -// "label": "example_label", -// "network": "stader", -// "pubkey": "0xb48c495c19082d892f38227bced89f7199f4e9b642bf94c7f2f1ccf29c0e6a6f54d653002513aa7cdb56c88368797ec", -// "signatures": [ -// { -// "platform": "dappnode", -// "signature": "0xa8b00e7746a523346c5165dfa80ffafe52317c6fe6cdcfabd41886f9c8209b829266c5000597142b58dddbcc9c23cfd81315180acf18bb000db50d08293bc539e06a7c751d3d9dec89fb441b3ba6aefdeeff9cfed72fb41171173f22e2993e74", -// "timestamp": "185921877" -// }, -// { -// "platform": "dappnode", -// "signature": "0xa8b00e7746a523346c5165dfa80ffafe52317c6fe6cdcfabd41886f9c8209b829266c5000597142b58dddbcc9c23cfd81315180acf18bb000db50d08293bc539e06a7c751d3d9dec89fb441b3ba6aefdeeff9cfed72fb41171173f22e2993e74", -// "timestamp": "185921877" -// } -// ] -// } -// -// ] -func PostSignaturesByValidatorAggr(w http.ResponseWriter, r *http.Request, dbCollection *mongo.Collection) { - var req signaturesRequest - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - respondError(w, http.StatusBadRequest, "Invalid request body") - return - } - - // Define the aggregation pipeline - // We should probably add pubkey to each signatures array element, so a 3rd party can easily verify the signature? - pipeline := []bson.M{ - { - "$match": bson.M{ - "pubkey": req.Pubkey, - "network": req.Network, - }, - }, - { - "$group": bson.M{ - "_id": bson.M{"pubkey": "$pubkey", "network": "$network", "tag": "$tag"}, - "signatures": bson.M{ - "$push": bson.M{ - "signature": "$signature", - "timestamp": "$timestamp", - "platform": "$platform", - }, - }, - }, - }, - { - "$project": bson.M{ - "_id": 0, - "pubkey": "$_id.pubkey", - "network": "$_id.network", - "tag": "$_id.tag", - "signatures": 1, - }, - }, - } - - cursor, err := dbCollection.Aggregate(r.Context(), pipeline, options.Aggregate()) - if err != nil { - respondError(w, http.StatusInternalServerError, "Error aggregating signatures from MongoDB") - return - } - defer cursor.Close(r.Context()) - - var results []bson.M - if err := cursor.All(r.Context(), &results); err != nil { - respondError(w, http.StatusInternalServerError, "Error reading aggregation results") - return - } - - // Respond with the aggregation results - respondOK(w, results) -} diff --git a/listener/internal/api/routes/routes.go b/listener/internal/api/routes/routes.go index 5735c3e..c651c35 100644 --- a/listener/internal/api/routes/routes.go +++ b/listener/internal/api/routes/routes.go @@ -17,12 +17,6 @@ func SetupRouter(dbCollection *mongo.Collection, beaconNodeUrls map[string]strin r.HandleFunc("/newSignature", func(w http.ResponseWriter, r *http.Request) { handlers.PostNewSignature(w, r, dbCollection, beaconNodeUrls, bypassValidatorFiltering) }).Methods(http.MethodPost) - r.HandleFunc("/signaturesByValidator", func(w http.ResponseWriter, r *http.Request) { - handlers.PostSignaturesByValidator(w, r, dbCollection) - }).Methods(http.MethodPost) - r.HandleFunc("/signaturesByValidatorAggr", func(w http.ResponseWriter, r *http.Request) { - handlers.PostSignaturesByValidatorAggr(w, r, dbCollection) - }).Methods(http.MethodPost) // Middlewares // r.Use(corsmiddleware()))