refactor(genutil/cli): remove txConfig from genesis command (#20976)
This commit is contained in:
parent
f9f0ca442d
commit
2370a50d86
@ -120,6 +120,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
|
||||
|
||||
### API Breaking Changes
|
||||
|
||||
* (client) [#20976](https://github.com/cosmos/cosmos-sdk/pull/20976) Simplified command initialization by removing unnecessary parameters such as `txConfig` and `addressCodec`.
|
||||
* Remove parameter `txConfig` from `genutilcli.Commands`,`genutilcli.CommandsWithCustomMigrationMap`,`genutilcli.GenTxCmd`.
|
||||
* Remove parameter `addressCodec` from `genutilcli.GenTxCmd`,`genutilcli.AddGenesisAccountCmd`,`stakingcli.BuildCreateValidatorMsg`.
|
||||
* (x/genutil) [#20740](https://github.com/cosmos/cosmos-sdk/pull/20740) Update `genutilcli.Commands` and `genutilcli.CommandsWithCustomMigrationMap` to take the genesis module and abstract the module manager.
|
||||
* (server) [#20422](https://github.com/cosmos/cosmos-sdk/pull/20422) Deprecated `ServerContext`. To get `cmtcfg.Config` from cmd, use `client.GetCometConfigFromCmd(cmd)` instead of `server.GetServerContextFromCmd(cmd).Config`
|
||||
* (types)[#20369](https://github.com/cosmos/cosmos-sdk/pull/20369) The signature of `HasAminoCodec` has changed to accept a `core/legacy.Amino` interface instead of `codec.LegacyAmino`.
|
||||
|
||||
@ -31,7 +31,6 @@ import (
|
||||
|
||||
func initRootCmd(
|
||||
rootCmd *cobra.Command,
|
||||
txConfig client.TxConfig,
|
||||
moduleManager *module.Manager,
|
||||
) {
|
||||
cfg := sdk.GetConfig()
|
||||
@ -51,7 +50,7 @@ func initRootCmd(
|
||||
// add keybase, auxiliary RPC, query, genesis, and tx child commands
|
||||
rootCmd.AddCommand(
|
||||
server.StatusCommand(),
|
||||
genesisCommand(txConfig, moduleManager, appExport),
|
||||
genesisCommand(moduleManager, appExport),
|
||||
queryCommand(),
|
||||
txCommand(),
|
||||
keys.Commands(),
|
||||
@ -60,8 +59,8 @@ func initRootCmd(
|
||||
}
|
||||
|
||||
// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter
|
||||
func genesisCommand(txConfig client.TxConfig, moduleManager *module.Manager, appExport servertypes.AppExporter, cmds ...*cobra.Command) *cobra.Command {
|
||||
cmd := genutilcli.Commands(txConfig, moduleManager.Modules[genutiltypes.ModuleName].(genutil.AppModule), moduleManager, appExport)
|
||||
func genesisCommand(moduleManager *module.Manager, appExport servertypes.AppExporter, cmds ...*cobra.Command) *cobra.Command {
|
||||
cmd := genutilcli.Commands(moduleManager.Modules[genutiltypes.ModuleName].(genutil.AppModule), moduleManager, appExport)
|
||||
for _, subCmd := range cmds {
|
||||
cmd.AddCommand(subCmd)
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ func NewRootCmd() *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
initRootCmd(rootCmd, encodingConfig.TxConfig, tempApp.ModuleManager)
|
||||
initRootCmd(rootCmd, tempApp.ModuleManager)
|
||||
|
||||
// autocli opts
|
||||
customClientTemplate, customClientConfig := initClientConfig()
|
||||
|
||||
@ -81,7 +81,7 @@ func NewRootCmd() *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
initRootCmd(rootCmd, clientCtx.TxConfig, moduleManager)
|
||||
initRootCmd(rootCmd, moduleManager)
|
||||
|
||||
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
|
||||
panic(err)
|
||||
|
||||
@ -102,7 +102,7 @@ func initRootCmd[T transaction.Tx](
|
||||
|
||||
// add keybase, auxiliary RPC, query, genesis, and tx child commands
|
||||
rootCmd.AddCommand(
|
||||
genesisCommand[T](txConfig, moduleManager, appExport[T]),
|
||||
genesisCommand[T](moduleManager, appExport[T]),
|
||||
queryCommand(),
|
||||
txCommand(),
|
||||
keys.Commands(),
|
||||
@ -123,7 +123,6 @@ func initRootCmd[T transaction.Tx](
|
||||
|
||||
// genesisCommand builds genesis-related `simd genesis` command. Users may provide application specific commands as a parameter
|
||||
func genesisCommand[T transaction.Tx](
|
||||
txConfig client.TxConfig,
|
||||
moduleManager *runtimev2.MM[T],
|
||||
appExport func(logger log.Logger,
|
||||
height int64,
|
||||
@ -143,7 +142,7 @@ func genesisCommand[T transaction.Tx](
|
||||
return appExport(logger, height, forZeroHeight, jailAllowedAddrs, viperAppOpts, modulesToExport)
|
||||
}
|
||||
|
||||
cmd := genutilcli.Commands(txConfig, moduleManager.Modules()[genutiltypes.ModuleName].(genutil.AppModule), moduleManager, compatAppExporter)
|
||||
cmd := genutilcli.Commands(moduleManager.Modules()[genutiltypes.ModuleName].(genutil.AppModule), moduleManager, compatAppExporter)
|
||||
for _, subCmd := range cmds {
|
||||
cmd.AddCommand(subCmd)
|
||||
}
|
||||
|
||||
@ -21,13 +21,13 @@ type genesisMM interface {
|
||||
}
|
||||
|
||||
// Commands adds core sdk's sub-commands into genesis command.
|
||||
func Commands(txConfig client.TxConfig, genutilModule genutil.AppModule, genMM genesisMM, appExport servertypes.AppExporter) *cobra.Command {
|
||||
return CommandsWithCustomMigrationMap(txConfig, genutilModule, genMM, appExport, MigrationMap)
|
||||
func Commands(genutilModule genutil.AppModule, genMM genesisMM, appExport servertypes.AppExporter) *cobra.Command {
|
||||
return CommandsWithCustomMigrationMap(genutilModule, genMM, appExport, MigrationMap)
|
||||
}
|
||||
|
||||
// CommandsWithCustomMigrationMap adds core sdk's sub-commands into genesis command with custom migration map.
|
||||
// This custom migration map can be used by the application to add its own migration map.
|
||||
func CommandsWithCustomMigrationMap(txConfig client.TxConfig, genutilModule genutil.AppModule, genMM genesisMM, appExport servertypes.AppExporter, migrationMap genutiltypes.MigrationMap) *cobra.Command {
|
||||
func CommandsWithCustomMigrationMap(genutilModule genutil.AppModule, genMM genesisMM, appExport servertypes.AppExporter, migrationMap genutiltypes.MigrationMap) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "genesis",
|
||||
Short: "Application's genesis-related subcommands",
|
||||
@ -36,11 +36,11 @@ func CommandsWithCustomMigrationMap(txConfig client.TxConfig, genutilModule genu
|
||||
RunE: client.ValidateCmd,
|
||||
}
|
||||
cmd.AddCommand(
|
||||
GenTxCmd(genMM, txConfig, banktypes.GenesisBalancesIterator{}, txConfig.SigningContext().ValidatorAddressCodec()),
|
||||
GenTxCmd(genMM, banktypes.GenesisBalancesIterator{}),
|
||||
MigrateGenesisCmd(migrationMap),
|
||||
CollectGenTxsCmd(genutilModule.GenTxValidator()),
|
||||
ValidateGenesisCmd(genMM),
|
||||
AddGenesisAccountCmd(txConfig.SigningContext().AddressCodec()),
|
||||
AddGenesisAccountCmd(),
|
||||
ExportCmd(appExport),
|
||||
)
|
||||
|
||||
|
||||
@ -6,8 +6,6 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
@ -25,7 +23,7 @@ const (
|
||||
|
||||
// AddGenesisAccountCmd returns add-genesis-account cobra Command.
|
||||
// This command is provided as a default, applications are expected to provide their own command if custom genesis accounts are needed.
|
||||
func AddGenesisAccountCmd(addressCodec address.Codec) *cobra.Command {
|
||||
func AddGenesisAccountCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]",
|
||||
Short: "Add a genesis account to genesis.json",
|
||||
@ -39,6 +37,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
config := client.GetConfigFromCmd(cmd)
|
||||
|
||||
addressCodec := clientCtx.TxConfig.SigningContext().AddressCodec()
|
||||
var kr keyring.Keyring
|
||||
addr, err := addressCodec.StringToBytes(args[0])
|
||||
if err != nil {
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
"cosmossdk.io/x/auth"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
@ -71,15 +70,18 @@ func TestAddGenesisAccountCmd(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
logger := log.NewNopLogger()
|
||||
viper := viper.New()
|
||||
v := viper.New()
|
||||
|
||||
appCodec := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}).Codec
|
||||
encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{})
|
||||
appCodec := encodingConfig.Codec
|
||||
txConfig := encodingConfig.TxConfig
|
||||
err = genutiltest.ExecInitCmd(testMbm, home, appCodec)
|
||||
require.NoError(t, err)
|
||||
|
||||
err := writeAndTrackDefaultConfig(viper, home)
|
||||
err := writeAndTrackDefaultConfig(v, home)
|
||||
require.NoError(t, err)
|
||||
clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(home).WithAddressCodec(ac)
|
||||
clientCtx := client.Context{}.WithCodec(appCodec).WithHomeDir(home).
|
||||
WithAddressCodec(ac).WithTxConfig(txConfig)
|
||||
|
||||
if tc.withKeyring {
|
||||
path := hd.CreateHDPath(118, 0, 0).String()
|
||||
@ -92,10 +94,10 @@ func TestAddGenesisAccountCmd(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
|
||||
ctx = context.WithValue(ctx, corectx.ViperContextKey, viper)
|
||||
ctx = context.WithValue(ctx, corectx.ViperContextKey, v)
|
||||
ctx = context.WithValue(ctx, corectx.LoggerContextKey, logger)
|
||||
|
||||
cmd := genutilcli.AddGenesisAccountCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
cmd := genutilcli.AddGenesisAccountCmd()
|
||||
cmd.SetArgs([]string{
|
||||
tc.addr,
|
||||
tc.denom,
|
||||
|
||||
@ -11,7 +11,6 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/errors"
|
||||
authclient "cosmossdk.io/x/auth/client"
|
||||
"cosmossdk.io/x/staking/client/cli"
|
||||
@ -28,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
// GenTxCmd builds the application's gentx command.
|
||||
func GenTxCmd(genMM genesisMM, txEncCfg client.TxEncodingConfig, genBalIterator types.GenesisBalancesIterator, valAdddressCodec address.Codec) *cobra.Command {
|
||||
func GenTxCmd(genMM genesisMM, genBalIterator types.GenesisBalancesIterator) *cobra.Command {
|
||||
ipDefault, _ := server.ExternalIP()
|
||||
fsCreateValidator, defaultsDesc := cli.CreateValidatorMsgFlagSet(ipDefault)
|
||||
|
||||
@ -139,11 +138,7 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o
|
||||
return err
|
||||
}
|
||||
|
||||
pub, err := key.GetAddress()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
clientCtx = clientCtx.WithInput(inBuf).WithFromAddress(pub)
|
||||
clientCtx = clientCtx.WithInput(inBuf).WithFromAddress(addr)
|
||||
|
||||
// The following line comes from a discrepancy between the `gentx`
|
||||
// and `create-validator` commands:
|
||||
@ -159,7 +154,7 @@ $ %s gentx my-key-name 1000000stake --home=/path/to/home/dir --keyring-backend=o
|
||||
createValCfg.Amount = amount
|
||||
|
||||
// create a 'create-validator' message
|
||||
txBldr, msg, err := cli.BuildCreateValidatorMsg(clientCtx, createValCfg, txFactory, true, valAdddressCodec)
|
||||
txBldr, msg, err := cli.BuildCreateValidatorMsg(clientCtx, createValCfg, txFactory, true)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to build create-validator message")
|
||||
}
|
||||
|
||||
@ -17,7 +17,6 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
@ -124,7 +123,7 @@ func (s *CLITestSuite) TestGenTxCmd() {
|
||||
clientCtx := s.clientCtx
|
||||
ctx := svrcmd.CreateExecuteContext(context.Background())
|
||||
|
||||
cmd := cli.GenTxCmd(module.NewManager(), clientCtx.TxConfig, banktypes.GenesisBalancesIterator{}, address.NewBech32Codec("cosmosvaloper"))
|
||||
cmd := cli.GenTxCmd(module.NewManager(), banktypes.GenesisBalancesIterator{})
|
||||
cmd.SetContext(ctx)
|
||||
cmd.SetArgs(tc.args)
|
||||
|
||||
|
||||
@ -89,6 +89,9 @@ func InitCmd(mm genesisMM) *cobra.Command {
|
||||
default:
|
||||
chainID = fmt.Sprintf("test-chain-%v", unsafe.Str(6))
|
||||
}
|
||||
if config.RootDir == "" {
|
||||
config.RootDir = clientCtx.HomeDir
|
||||
}
|
||||
|
||||
// Get bip39 mnemonic
|
||||
var mnemonic string
|
||||
|
||||
@ -365,7 +365,7 @@ func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, c
|
||||
}
|
||||
|
||||
// BuildCreateValidatorMsg makes a new MsgCreateValidator.
|
||||
func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorConfig, txBldr tx.Factory, generateOnly bool, valCodec address.Codec) (tx.Factory, sdk.Msg, error) {
|
||||
func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorConfig, txBldr tx.Factory, generateOnly bool) (tx.Factory, sdk.Msg, error) {
|
||||
amounstStr := config.Amount
|
||||
amount, err := sdk.ParseCoinNormalized(amounstStr)
|
||||
if err != nil {
|
||||
@ -398,7 +398,8 @@ func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorC
|
||||
return txBldr, nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "minimum self delegation must be a positive integer")
|
||||
}
|
||||
|
||||
valStr, err := valCodec.BytesToString(sdk.ValAddress(valAddr))
|
||||
valCodec := clientCtx.TxConfig.SigningContext().ValidatorAddressCodec()
|
||||
valStr, err := valCodec.BytesToString(valAddr)
|
||||
if err != nil {
|
||||
return txBldr, nil, err
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user