feat(genutil): Add module account at genesis. (#16046)

Co-authored-by: marbar3778 <marbar3778@yahoo.com>
This commit is contained in:
Devon Bear 2023-06-03 10:35:50 -04:00 committed by GitHub
parent 0246ee1713
commit 95178ce036
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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