Skip to content

Commit

Permalink
fix api /cosmos/base/tendermint/v1beta1/blocks/latest and /cosmos/bas…
Browse files Browse the repository at this point in the history
…e/tendermint/v1beta1/validatorsets/latest
  • Loading branch information
baabeetaa committed Nov 20, 2023
1 parent c25c073 commit 6b8cd30
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions server/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ func (m *ApiServer) StartApiServer() {
height, err := strconv.ParseInt(xCosmosBlockHeight, 10, 64)
if err != nil {
_ = utils.SendError(w)
return
}

node, err := state.SelectMatchedBackend(height, config.ProtocolTypeApi)
if err != nil {
_ = utils.SendError(w)
return
}

selectedHost = node.Backend.Api
Expand All @@ -61,17 +63,24 @@ func (m *ApiServer) StartApiServer() {
strings.HasPrefix(urlPath, "/cosmos/base/tendermint/v1beta1/validatorsets/") {
pHeight := path.Base(r.URL.Path)
fmt.Printf("pHeight=%s\n", pHeight)
height, err := strconv.ParseInt(pHeight, 10, 64)
if err != nil {
_ = utils.SendError(w)
}

node, err := state.SelectMatchedBackend(height, config.ProtocolTypeApi)
if err != nil {
_ = utils.SendError(w)
if pHeight == "latest" {
selectedHost = prunedNode.Backend.Api
} else {
height, err := strconv.ParseInt(pHeight, 10, 64)
if err != nil {
_ = utils.SendError(w)
return
}

node, err := state.SelectMatchedBackend(height, config.ProtocolTypeApi)
if err != nil {
_ = utils.SendError(w)
return
}

selectedHost = node.Backend.Api
}

selectedHost = node.Backend.Api
}
}
}
Expand Down

0 comments on commit 6b8cd30

Please sign in to comment.