* Make JSONMarshaler require proto.Message * Use &msg with MarshalJSON * Use *LegacyAmino in queriers instead of JSONMarshaler * Revert ABCIMessageLogs String() and coins tests * Use LegacyAmino in client/debug and fix subspace tests * Use LegacyAmino in all legacy queriers and adapt simulation * Make AminoCodec implement Marshaler and some godoc fixes * Test fixes * Remove unrelevant comment * Use TxConfig.TxJSONEncoder * Use encoding/json in genutil cli migrate/validate genesis cmds * Address simulation related comments * Use JSONMarshaler in cli tests * Use proto.Message as respType in cli tests * Use tmjson for tm GenesisDoc * Update types/module/simulation.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Update types/module/module_test.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> * Add godoc comments * Remove unused InsertKeyJSON * Fix tests Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package rest
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
|
)
|
|
|
|
func registerQueryRoutes(clientCtx client.Context, r *mux.Router) {
|
|
r.HandleFunc(
|
|
"/upgrade/current", getCurrentPlanHandler(clientCtx),
|
|
).Methods("GET")
|
|
r.HandleFunc(
|
|
"/upgrade/applied/{name}", getDonePlanHandler(clientCtx),
|
|
).Methods("GET")
|
|
}
|
|
|
|
func getCurrentPlanHandler(clientCtx client.Context) func(http.ResponseWriter, *http.Request) {
|
|
return func(w http.ResponseWriter, request *http.Request) {
|
|
// ignore height for now
|
|
res, _, err := clientCtx.Query(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryCurrent))
|
|
if rest.CheckInternalServerError(w, err) {
|
|
return
|
|
}
|
|
if len(res) == 0 {
|
|
http.NotFound(w, request)
|
|
return
|
|
}
|
|
|
|
var plan types.Plan
|
|
err = clientCtx.LegacyAmino.UnmarshalBinaryBare(res, &plan)
|
|
if rest.CheckInternalServerError(w, err) {
|
|
return
|
|
}
|
|
|
|
rest.PostProcessResponse(w, clientCtx, plan)
|
|
}
|
|
}
|
|
|
|
func getDonePlanHandler(clientCtx client.Context) func(http.ResponseWriter, *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
name := mux.Vars(r)["name"]
|
|
|
|
params := types.QueryAppliedPlanRequest{Name: name}
|
|
bz, err := clientCtx.LegacyAmino.MarshalJSON(params)
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
|
|
res, _, err := clientCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierKey, types.QueryApplied), bz)
|
|
if rest.CheckBadRequestError(w, err) {
|
|
return
|
|
}
|
|
|
|
if len(res) == 0 {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
if len(res) != 8 {
|
|
rest.WriteErrorResponse(w, http.StatusInternalServerError, "unknown format for applied-upgrade")
|
|
}
|
|
|
|
applied := int64(binary.BigEndian.Uint64(res))
|
|
fmt.Println(applied)
|
|
rest.PostProcessResponse(w, clientCtx, applied)
|
|
}
|
|
}
|