From 95178ce036741ae6aa7af131fa9fccf3e13fff7a Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Sat, 3 Jun 2023 10:35:50 -0400 Subject: [PATCH] feat(genutil): Add module account at genesis. (#16046) Co-authored-by: marbar3778 --- CHANGELOG.md | 1 + x/auth/helpers/genaccounts.go | 4 ++++ x/genutil/client/cli/genaccount.go | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8dc5cf3fa9..0728b0450f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (cli) [#16209](https://github.com/cosmos/cosmos-sdk/pull/16209) Make `StartCmd` more customizable. * (types) [#16257](https://github.com/cosmos/cosmos-sdk/pull/16257) Allow setting the base denom in the denom registry. * (x/group) [#16191](https://github.com/cosmos/cosmos-sdk/pull/16191) Add EventProposalPruned event to group module whenever a proposal is pruned. +* (genutil) [#16046](https://github.com/cosmos/cosmos-sdk/pull/16046) Add "module-name" flag to genutil add-genesis-account to enable intializing module accounts at genesis. ### Improvements diff --git a/x/auth/helpers/genaccounts.go b/x/auth/helpers/genaccounts.go index 817d4f7109..9ff62f1715 100644 --- a/x/auth/helpers/genaccounts.go +++ b/x/auth/helpers/genaccounts.go @@ -19,6 +19,7 @@ import ( // `accAddr` is the address to be added to the genesis state, `amountStr` is the list of initial coins // to be added for the account, `appendAcct` updates the account if already exists. // `vestingStart, vestingEnd and vestingAmtStr` respectively are the schedule start time, end time (unix epoch) +// `moduleNameā€œ is the module name for which the account is being created // and coins to be appended to the account already in the genesis.json file. func AddGenesisAccount( cdc codec.Codec, @@ -26,6 +27,7 @@ func AddGenesisAccount( appendAcct bool, genesisFileURL, amountStr, vestingAmtStr string, vestingStart, vestingEnd int64, + moduleName string, ) error { coins, err := sdk.ParseCoinsNormalized(amountStr) if err != nil { @@ -61,6 +63,8 @@ func AddGenesisAccount( default: return errors.New("invalid vesting parameters; must supply start and end time or end time") } + } else if moduleName != "" { + genAccount = authtypes.NewEmptyModuleAccount(moduleName, authtypes.Burner, authtypes.Minter) } else { genAccount = baseAccount } diff --git a/x/genutil/client/cli/genaccount.go b/x/genutil/client/cli/genaccount.go index 043428daf5..d92fc2888d 100644 --- a/x/genutil/client/cli/genaccount.go +++ b/x/genutil/client/cli/genaccount.go @@ -19,6 +19,7 @@ const ( flagVestingEnd = "vesting-end-time" flagVestingAmt = "vesting-amount" flagAppendMode = "append" + flagModuleName = "module-name" ) // AddGenesisAccountCmd returns add-genesis-account cobra Command. @@ -71,8 +72,9 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa vestingStart, _ := cmd.Flags().GetInt64(flagVestingStart) vestingEnd, _ := cmd.Flags().GetInt64(flagVestingEnd) vestingAmtStr, _ := cmd.Flags().GetString(flagVestingAmt) + moduleNameStr, _ := cmd.Flags().GetString(flagModuleName) - return auth.AddGenesisAccount(clientCtx.Codec, addr, appendflag, config.GenesisFile(), args[1], vestingAmtStr, vestingStart, vestingEnd) + return auth.AddGenesisAccount(clientCtx.Codec, addr, appendflag, config.GenesisFile(), args[1], vestingAmtStr, vestingStart, vestingEnd, moduleNameStr) }, } @@ -82,6 +84,7 @@ contain valid denominations. Accounts may optionally be supplied with vesting pa cmd.Flags().Int64(flagVestingStart, 0, "schedule start time (unix epoch) for vesting accounts") cmd.Flags().Int64(flagVestingEnd, 0, "schedule end time (unix epoch) for vesting accounts") cmd.Flags().Bool(flagAppendMode, false, "append the coins to an account already in the genesis.json file") + cmd.Flags().String(flagModuleName, "", "module account name") flags.AddQueryFlagsToCmd(cmd) return cmd