Skip to content

Commit

Permalink
updated supply
Browse files Browse the repository at this point in the history
  • Loading branch information
kaustubhkapatral committed Nov 29, 2024
1 parent b0d40c8 commit 04f5c7c
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions circulation_supply/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func main() {
r := mux.NewRouter().StrictSlash(true)

r.HandleFunc("/passage/supply/circulating", GetCircSupply)
r.HandleFunc("/passage/supply/total", GetPASGSupply)
fmt.Println("Listening on :8081")
log.Fatal(http.ListenAndServe(":8081", r))
}
Expand Down Expand Up @@ -100,8 +101,51 @@ func GetCircSupply(w http.ResponseWriter, r *http.Request) {
return
}

amt := originalAmount - int64(sum)
response.Amount.Amount = strconv.Itoa(int(amt))
//amt := originalAmount - int64(sum)
//response.Amount.Amount = strconv.Itoa(int(amt))
//json.NewEncoder(w).Encode(amt)

amt := (originalAmount - int64(sum)) / 1_000_000

// Set content type to plain text since we're returning a number
w.Header().Set("Content-Type", "text/plain")
// Write the integer directly
fmt.Fprintf(w, "%d", amt)

}


func GetPASGSupply(w http.ResponseWriter, r *http.Request) {
url := "https://api.passage.vitwit.com/cosmos/bank/v1beta1/supply/upasg"
resp, err := http.Get(url)
if err != nil {
http.Error(w, "Failed to make request:", http.StatusInternalServerError)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
http.Error(w, "Received non-200 response code:", http.StatusInternalServerError)
return
}

var response Response
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
http.Error(w, "Failed to parse response", http.StatusInternalServerError)
return
}

originalAmount, err := strconv.ParseInt(response.Amount.Amount, 10, 64)
if err != nil {
http.Error(w, "Failed to convert amount to int:", http.StatusInternalServerError)
return
}

amt := originalAmount / 1_000_000

// Set content type to plain text since we're returning a number
w.Header().Set("Content-Type", "text/plain")
// Write the integer directly
fmt.Fprintf(w, "%d", amt)

json.NewEncoder(w).Encode(amt)
}

0 comments on commit 04f5c7c

Please sign in to comment.