diff --git a/app/app.go b/app/app.go index 14ca2a9..1ce6d68 100644 --- a/app/app.go +++ b/app/app.go @@ -23,10 +23,12 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" "github.com/cosmos/cosmos-sdk/x/authz" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" @@ -157,6 +159,7 @@ var ( evidence.AppModuleBasic{}, transfer.AppModuleBasic{}, authzmodule.AppModuleBasic{}, + vesting.AppModuleBasic{}, wasm.AppModuleBasic{}, ssimodule.AppModuleBasic{}, ibcfee.AppModuleBasic{}, @@ -578,6 +581,7 @@ func NewHidnodeApp( encodingConfig.TxConfig, ), auth.NewAppModule(appCodec, app.AccountKeeper, nil), + vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper), @@ -604,6 +608,7 @@ func NewHidnodeApp( // NOTE: staking module is required if HistoricalEntries param > 0 app.mm.SetOrderBeginBlockers( authtypes.ModuleName, + vestingtypes.ModuleName, banktypes.ModuleName, govtypes.ModuleName, upgradetypes.ModuleName, @@ -627,6 +632,7 @@ func NewHidnodeApp( app.mm.SetOrderEndBlockers( authtypes.ModuleName, + vestingtypes.ModuleName, banktypes.ModuleName, crisistypes.ModuleName, govtypes.ModuleName, @@ -656,6 +662,7 @@ func NewHidnodeApp( app.mm.SetOrderInitGenesis( capabilitytypes.ModuleName, authtypes.ModuleName, + vestingtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, diff --git a/cmd/hid-noded/cmd/genaccounts.go b/cmd/hid-noded/cmd/genaccounts.go index 0788727..e212813 100644 --- a/cmd/hid-noded/cmd/genaccounts.go +++ b/cmd/hid-noded/cmd/genaccounts.go @@ -3,6 +3,7 @@ package cmd import ( "bufio" "encoding/json" + "errors" "fmt" "github.com/spf13/cobra" @@ -13,11 +14,18 @@ import ( "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" ) +const ( + flagVestingStart = "vesting-start-time" + flagVestingEnd = "vesting-end-time" + flagVestingAmt = "vesting-amount" +) + // AddGenesisAccountCmd returns add-genesis-account cobra Command. func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ @@ -26,7 +34,7 @@ func AddGenesisAccountCmd(defaultNodeHome string) *cobra.Command { Long: `Add a genesis account to genesis.json. The provided account must specify the account address or key name and a list of initial coins. If a key name is given, the address will be looked up in the local Keybase. The list of initial tokens must -contain valid denominations. +contain valid denominations. Accounts may optionally be supplied with vesting parameters. `, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { @@ -65,12 +73,51 @@ contain valid denominations. addr = info.GetAddress() } + vestingStart, err := cmd.Flags().GetInt64(flagVestingStart) + if err != nil { + return err + } + vestingEnd, err := cmd.Flags().GetInt64(flagVestingEnd) + if err != nil { + return err + } + vestingAmtStr, err := cmd.Flags().GetString(flagVestingAmt) + if err != nil { + return err + } + + vestingAmt, err := sdk.ParseCoinsNormalized(vestingAmtStr) + if err != nil { + return fmt.Errorf("failed to parse vesting amount: %w", err) + } + // create concrete account type based on input parameters var genAccount authtypes.GenesisAccount balances := banktypes.Balance{Address: addr.String(), Coins: coins.Sort()} baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0) - genAccount = baseAccount + + if !vestingAmt.IsZero() { + baseVestingAccount := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd) + + if (balances.Coins.IsZero() && !baseVestingAccount.OriginalVesting.IsZero()) || + baseVestingAccount.OriginalVesting.IsAnyGT(balances.Coins) { + return errors.New("vesting amount cannot be greater than total amount") + } + + switch { + case vestingStart != 0 && vestingEnd != 0: + genAccount = authvesting.NewContinuousVestingAccountRaw(baseVestingAccount, vestingStart) + + case vestingEnd != 0: + genAccount = authvesting.NewDelayedVestingAccountRaw(baseVestingAccount) + + default: + return errors.New("invalid vesting parameters; must supply start and end time or end time") + } + } else { + genAccount = baseAccount + } if err := genAccount.Validate(); err != nil { return fmt.Errorf("failed to validate new genesis account: %w", err) @@ -134,6 +181,9 @@ contain valid denominations. cmd.Flags().String(flags.FlagKeyringBackend, flags.DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)") cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") + cmd.Flags().String(flagVestingAmt, "", "amount of coins for vesting accounts") + 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") flags.AddQueryFlagsToCmd(cmd) return cmd diff --git a/cmd/hid-noded/cmd/root.go b/cmd/hid-noded/cmd/root.go index ef7b5d1..bc8156e 100644 --- a/cmd/hid-noded/cmd/root.go +++ b/cmd/hid-noded/cmd/root.go @@ -25,6 +25,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" + vestingcli "github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli" "github.com/prometheus/client_golang/prometheus" "github.com/spf13/cast" @@ -169,6 +170,7 @@ func txCommand() *cobra.Command { authcmd.GetEncodeCommand(), authcmd.GetDecodeCommand(), flags.LineBreak, + vestingcli.GetTxCmd(), ) hidnode.ModuleBasics.AddTxCommands(cmd)