* 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>
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/server"
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
)
|
|
|
|
// Validate genesis command takes
|
|
func ValidateGenesisCmd(mbm module.BasicManager, txEncCfg client.TxEncodingConfig) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "validate-genesis [file]",
|
|
Args: cobra.RangeArgs(0, 1),
|
|
Short: "validates the genesis file at the default location or at the location passed as an arg",
|
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
|
serverCtx := server.GetServerContextFromCmd(cmd)
|
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
|
|
|
cdc := clientCtx.JSONMarshaler
|
|
|
|
// Load default if passed no args, otherwise load passed file
|
|
var genesis string
|
|
if len(args) == 0 {
|
|
genesis = serverCtx.Config.GenesisFile()
|
|
} else {
|
|
genesis = args[0]
|
|
}
|
|
|
|
fmt.Fprintf(os.Stderr, "validating genesis file at %s\n", genesis)
|
|
|
|
var genDoc *tmtypes.GenesisDoc
|
|
if genDoc, err = tmtypes.GenesisDocFromFile(genesis); err != nil {
|
|
return fmt.Errorf("error loading genesis doc from %s: %s", genesis, err.Error())
|
|
}
|
|
|
|
var genState map[string]json.RawMessage
|
|
if err = json.Unmarshal(genDoc.AppState, &genState); err != nil {
|
|
return fmt.Errorf("error unmarshalling genesis doc %s: %s", genesis, err.Error())
|
|
}
|
|
|
|
if err = mbm.ValidateGenesis(cdc, txEncCfg, genState); err != nil {
|
|
return fmt.Errorf("error validating genesis file %s: %s", genesis, err.Error())
|
|
}
|
|
|
|
fmt.Printf("File at %s is a valid genesis file\n", genesis)
|
|
return nil
|
|
},
|
|
}
|
|
}
|