Skip to content

Commit

Permalink
fix: use height from response instead of ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
manav2401 committed Oct 5, 2023
1 parent 0e5a11e commit 37af7bd
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions checkpoint/client/rest/query_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ func milestoneLatestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

// Fetch latest milestone
result, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryLatestMilestone), nil)

// Return status code 503 (Service Unavailable) if HF hasn't been activated
if cliCtx.Height < helper.GetAalborgHardForkHeight() {
if height < helper.GetAalborgHardForkHeight() {
hmRest.WriteErrorResponse(w, http.StatusServiceUnavailable, "Aalborg hardfork not activated yet")

return
}

// Fetch latest milestone
result, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryLatestMilestone), nil)
if err != nil {
hmRest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())

Expand All @@ -63,14 +64,15 @@ func milestoneCountHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

countBytes, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCount), nil)

// Return status code 503 (Service Unavailable) if HF hasn't been activated
if cliCtx.Height < helper.GetAalborgHardForkHeight() {
if height < helper.GetAalborgHardForkHeight() {
hmRest.WriteErrorResponse(w, http.StatusServiceUnavailable, "Aalborg hardfork not activated yet")

return
}

countBytes, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCount), nil)
if err != nil {
hmRest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand Down Expand Up @@ -109,13 +111,6 @@ func milestoneByNumberHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

// Return status code 503 (Service Unavailable) if HF hasn't been activated
if cliCtx.Height < helper.GetAalborgHardForkHeight() {
hmRest.WriteErrorResponse(w, http.StatusServiceUnavailable, "Aalborg hardfork not activated yet")

return
}

// get milestone number
number, ok := rest.ParseUint64OrReturnBadRequest(w, vars["number"])
if !ok {
Expand All @@ -128,8 +123,16 @@ func milestoneByNumberHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

// query checkpoint
// query milestone
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryMilestoneByNumber), queryParams)

// Return status code 503 (Service Unavailable) if HF hasn't been activated
if height < helper.GetAalborgHardForkHeight() {
hmRest.WriteErrorResponse(w, http.StatusServiceUnavailable, "Aalborg hardfork not activated yet")

return
}

if err != nil {
hmRest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand All @@ -148,14 +151,15 @@ func latestNoAckMilestoneHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

result, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryLatestNoAckMilestone), nil)

// Return status code 503 (Service Unavailable) if HF hasn't been activated
if cliCtx.Height < helper.GetAalborgHardForkHeight() {
hmRest.WriteErrorResponse(w, http.StatusServiceUnavailable, "Aalborg hardfork not activated yet")

return
}

result, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryLatestNoAckMilestone), nil)
if err != nil {
hmRest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
Expand Down Expand Up @@ -194,13 +198,6 @@ func noAckMilestoneByIDHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}

// Return status code 503 (Service Unavailable) if HF hasn't been activated
if cliCtx.Height < helper.GetAalborgHardForkHeight() {
hmRest.WriteErrorResponse(w, http.StatusServiceUnavailable, "Aalborg hardfork not activated yet")

return
}

// get milestone number
id := vars["id"]

Expand All @@ -211,6 +208,14 @@ func noAckMilestoneByIDHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}

result, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNoAckMilestoneByID), queryID)

// Return status code 503 (Service Unavailable) if HF hasn't been activated
if height < helper.GetAalborgHardForkHeight() {
hmRest.WriteErrorResponse(w, http.StatusServiceUnavailable, "Aalborg hardfork not activated yet")

return
}

if err != nil {
hmRest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down Expand Up @@ -240,13 +245,6 @@ func milestoneByIDHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

// Return status code 503 (Service Unavailable) if HF hasn't been activated
if cliCtx.Height < helper.GetAalborgHardForkHeight() {
hmRest.WriteErrorResponse(w, http.StatusServiceUnavailable, "Aalborg hardfork not activated yet")

return
}

cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
Expand Down

0 comments on commit 37af7bd

Please sign in to comment.