Skip to content

Commit

Permalink
fix api /cosmos/base/tendermint/v1beta1/blocks/ and /cosmos/base/tend…
Browse files Browse the repository at this point in the history
…ermint/v1beta1/validatorsets/
  • Loading branch information
baabeetaa committed Nov 19, 2023
1 parent 232ee6b commit c25c073
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions server/api_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"github.com/notional-labs/subnode/utils"
"log"
"net/http"
"path"
"strconv"
"strings"
)

type ApiServer struct {
Expand Down Expand Up @@ -48,9 +50,34 @@ func (m *ApiServer) StartApiServer() {
}

selectedHost = node.Backend.Api
} else {
// /cosmos/base/tendermint/v1beta1/blocks/{height}
// /cosmos/base/tendermint/v1beta1/validatorsets/{height}

urlPath := r.URL.Path
//fmt.Printf("urlPath=%s\n", urlPath)

if strings.HasPrefix(urlPath, "/cosmos/base/tendermint/v1beta1/blocks/") ||
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)
}

selectedHost = node.Backend.Api
}
}
}

//fmt.Printf("selectedHost=%s\n", selectedHost)

r.Host = r.URL.Host
state.ProxyMapApi[selectedHost].ServeHTTP(w, r)
}
Expand Down

0 comments on commit c25c073

Please sign in to comment.