Skip to content

Commit

Permalink
server: add status endpoint from tendermint (#1175)
Browse files Browse the repository at this point in the history
* feat: expose status endpoint from rest-server

* call status directly

* remove public endpoint

* remove endpoint from checkpoint module

* server: add /status endpoint

* server: only return sync info

* server: rename fn to sync info

* server: fix milestone grpc endpoint

* server: rename sync_info to status
  • Loading branch information
manav2401 committed Jul 16, 2024
1 parent b0c4a07 commit b292451
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/gRPC/gRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
eventRecordList = "/clerk/event-record/list"
fetchCheckpointCount = "/checkpoints/count"
fetchCheckpoint = "/checkpoints/%s"
fetchMilestoneCount = "/checkpoints/count"
fetchMilestoneCount = "/milestone/count"
fetchMilestone = "/milestone/latest"
fetchMilestoneNoAck = "/milestone/noAck/%s"
fetchLastNoAckMilestone = "/milestone/lastNoAck"
Expand Down
17 changes: 17 additions & 0 deletions server/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/go-kit/log"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/maticnetwork/heimdall/app"
tx "github.com/maticnetwork/heimdall/client/tx"
"github.com/maticnetwork/heimdall/helper"
hmRest "github.com/maticnetwork/heimdall/types/rest"

// unnamed import of statik for swagger UI support
"github.com/maticnetwork/heimdall/server/gRPC"
Expand Down Expand Up @@ -264,6 +266,9 @@ func RegisterRoutes(ctx client.CLIContext, mux *mux.Router) {
rpc.RegisterRPCRoutes(ctx, mux)
tx.RegisterRoutes(ctx, mux)

// Register the status endpoint here (as it's generic)
mux.HandleFunc("/status", statusHandlerFn(ctx)).Methods("GET")

// auth.RegisterRoutes(rs.CliCtx, rs.Mux)
// bank.RegisterRoutes(rs.CliCtx, rs.Mux)

Expand All @@ -285,3 +290,15 @@ func registerSwaggerUI(mux *mux.Router) {
staticServer := http.FileServer(statikFS)
mux.PathPrefix("/swagger-ui/").Handler(http.StripPrefix("/swagger-ui/", staticServer))
}

func statusHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
status, err := cliCtx.Client.Status()
if err != nil {
hmRest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

rest.PostProcessResponse(w, cliCtx, status.SyncInfo)
}
}

0 comments on commit b292451

Please sign in to comment.