cosmos-sdk/x/genutil/client/rest/query.go
Marie 7f59723d88
Make JSONMarshaler methods require proto.Message (#7054)
* 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>
2020-08-26 09:39:38 +00:00

49 lines
1.3 KiB
Go

package rest
import (
"fmt"
"net/http"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)
// QueryGenesisTxs writes the genesis transactions to the response if no error
// occurs.
func QueryGenesisTxs(clientCtx client.Context, w http.ResponseWriter) {
resultGenesis, err := clientCtx.Client.Genesis()
if err != nil {
rest.WriteErrorResponse(
w, http.StatusInternalServerError,
fmt.Sprintf("failed to retrieve genesis from client: %s", err),
)
return
}
appState, err := types.GenesisStateFromGenDoc(*resultGenesis.Genesis)
if err != nil {
rest.WriteErrorResponse(
w, http.StatusInternalServerError,
fmt.Sprintf("failed to decode genesis doc: %s", err),
)
return
}
genState := types.GetGenesisStateFromAppState(clientCtx.JSONMarshaler, appState)
genTxs := make([]sdk.Tx, len(genState.GenTxs))
for i, tx := range genState.GenTxs {
err := clientCtx.LegacyAmino.UnmarshalJSON(tx, &genTxs[i])
if err != nil {
rest.WriteErrorResponse(
w, http.StatusInternalServerError,
fmt.Sprintf("failed to decode genesis transaction: %s", err),
)
return
}
}
rest.PostProcessResponseBare(w, clientCtx, genTxs)
}