From 6956ecc82f3003fe8f69d3f11c590fad706f31ad Mon Sep 17 00:00:00 2001 From: Sri Kidambi <1702865+kidambisrinivas@users.noreply.github.com> Date: Fri, 1 Nov 2024 09:38:10 +0000 Subject: [PATCH] Minor refactor (#15052) --- .../capabilities/triggers/logevent/trigger.go | 3 +- .../test_server/test_server.go | 89 ------------------- 2 files changed, 2 insertions(+), 90 deletions(-) delete mode 100644 core/scripts/gateway/web_api_trigger/test_server/test_server.go diff --git a/core/capabilities/triggers/logevent/trigger.go b/core/capabilities/triggers/logevent/trigger.go index 517e4a94683..7ee76c6f44a 100644 --- a/core/capabilities/triggers/logevent/trigger.go +++ b/core/capabilities/triggers/logevent/trigger.go @@ -2,6 +2,7 @@ package logevent import ( "context" + "encoding/hex" "encoding/json" "fmt" "strconv" @@ -198,7 +199,7 @@ func createTriggerResponse(log types.Sequence, version string) capabilities.Trig Cursor: log.Cursor, Data: dataAsMap, Head: logeventcap.Head{ - Hash: fmt.Sprintf("0x%x", log.Hash), + Hash: "0x" + hex.EncodeToString(log.Hash), Height: log.Height, Timestamp: log.Timestamp, }, diff --git a/core/scripts/gateway/web_api_trigger/test_server/test_server.go b/core/scripts/gateway/web_api_trigger/test_server/test_server.go deleted file mode 100644 index 287d604e899..00000000000 --- a/core/scripts/gateway/web_api_trigger/test_server/test_server.go +++ /dev/null @@ -1,89 +0,0 @@ -package main - -import ( - "fmt" - "io" - "net/http" - "time" -) - -func handler(w http.ResponseWriter, r *http.Request) { - // Log request method and URL - fmt.Printf("Received %s request for %s\n", r.Method, r.URL.Path) - - // Handle GET requests - if r.Method == http.MethodGet { - fmt.Println("GET request received") - w.WriteHeader(http.StatusOK) - _, err := w.Write([]byte("GET request received")) - if err != nil { - http.Error(w, "could not write request body", http.StatusInternalServerError) - return - } - } - - // Handle POST requests - if r.Method == http.MethodPost { - body, err := io.ReadAll(r.Body) - if err != nil { - http.Error(w, "Could not read request body", http.StatusInternalServerError) - return - } - fmt.Printf("POST request body: %s\n", string(body)) - - w.WriteHeader(http.StatusOK) - } -} - -func lockHandler(w http.ResponseWriter, r *http.Request) { - // Log request method and URL - fmt.Printf("Received %s request for %s\n", r.Method, r.URL.Path) - - // Handle POST requests - if r.Method == http.MethodPost { - body, err := io.ReadAll(r.Body) - if err != nil { - http.Error(w, "Could not read request body", http.StatusInternalServerError) - return - } - fmt.Printf("Assets locked. E2E ID: %s\n", string(body)) - - w.WriteHeader(http.StatusOK) - } -} - -func unlockHandler(w http.ResponseWriter, r *http.Request) { - // Log request method and URL - fmt.Printf("Received %s request for %s\n", r.Method, r.URL.Path) - - // Handle POST requests - if r.Method == http.MethodPost { - body, err := io.ReadAll(r.Body) - if err != nil { - http.Error(w, "Could not read request body", http.StatusInternalServerError) - return - } - fmt.Printf("Assets unlocked. Settlement E2E ID: %s\n", string(body)) - - w.WriteHeader(http.StatusOK) - } -} - -func main() { - // Register the handler for all incoming requests - http.HandleFunc("/", handler) - http.HandleFunc("/lock", lockHandler) - http.HandleFunc("/unlock", unlockHandler) - - // Listen on port 1000 - port := ":1000" - fmt.Printf("Server listening on port %s\n", port) - server := &http.Server{ - Addr: port, - ReadHeaderTimeout: 30 * time.Second, - } - err := server.ListenAndServe() - if err != nil { - panic(err) - } -}