From 6b15da4c536be080cd7011274da69e40b07aa5be Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Sat, 20 Jul 2024 20:13:40 -0600 Subject: [PATCH] Update server.go --- wap/pkg/server/server.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/wap/pkg/server/server.go b/wap/pkg/server/server.go index 8fdabf8..cb75a16 100644 --- a/wap/pkg/server/server.go +++ b/wap/pkg/server/server.go @@ -675,6 +675,34 @@ func accountIdHandler(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(account) } +func accountSeedHandler(w http.ResponseWriter, r *http.Request) { + // Check if the account file exists + filePath := "/internal/.secrets/secret_seed.txt" + if _, err := os.Stat(filePath); os.IsNotExist(err) { + http.Error(w, "Account Seed file not found", http.StatusNotFound) + return + } + + // Read the account seed file + data, err := os.ReadFile(filePath) + if err != nil { + http.Error(w, "Failed to read account seed file", http.StatusInternalServerError) + return + } + + // Convert byte slice to string and trim any whitespace + accountSeed := strings.TrimSpace(string(data)) + + // Create the account map + account := map[string]interface{}{ + "accountSeed": accountSeed, + } + + // Return the account seed as JSON + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(account) +} + // This function accepts an ip and port that it runs the webserver on. Default is 10.42.0.1:3500 and if it fails reverts to 0.0.0.0:3500 // - /wifi/list endpoint: shows the list of available wifis func Serve(peerFn func(clientPeerId string, bloxSeed string) (string, error), ip string, port string, connectedCh chan bool) io.Closer { @@ -701,6 +729,7 @@ func Serve(peerFn func(clientPeerId string, bloxSeed string) (string, error), ip mux.HandleFunc("/chain/status", chainStatusHandler) mux.HandleFunc("/account/id", accountIdHandler) + mux.HandleFunc("/account/seed", accountSeedHandler) listenAddr := ""