Skip to content
This repository has been archived by the owner on Sep 17, 2024. It is now read-only.

Commit

Permalink
Add /chain-tick endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
LINCKODE committed Apr 19, 2024
1 parent 9933c4f commit c7fd6c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,23 @@ func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) {

w.Write(b)
}

type tickResponse struct {
ChainTick int `json:"chain_tick"`
}

func (h *Handler) HandleTick(w http.ResponseWriter, r *http.Request) {
p := h.rp.Get()
res := tickResponse{
ChainTick: p.MaxTick,
}

b, err := json.Marshal(res)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}

w.Write(b)
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func run() error {

fmt.Println("Server started")
http.HandleFunc("/peers", h.Handle)
http.HandleFunc("/chain-tick", h.HandleTick)

log.Fatal(http.ListenAndServe(":8080", nil))

Expand Down

0 comments on commit c7fd6c6

Please sign in to comment.