From df3702c9a675895e716ffab8e2a7ec26b6f84718 Mon Sep 17 00:00:00 2001 From: emidev98 <49301655+emidev98@users.noreply.github.com> Date: Fri, 18 Aug 2023 15:51:09 +0300 Subject: [PATCH] Revert "feat: upgrade terra to v0.47.x" --- ...ew.yml.disable => dependencies-review.yml} | 0 proto/cosmos/vesting/v1beta1/tx.proto | 19 +- scripts/protocgen.sh | 4 + simapp/app.go | 2 +- x/auth/migrations/v2/store_test.go | 8 +- x/auth/vesting/client/cli/tx.go | 56 +-- x/auth/vesting/handler.go | 39 -- x/auth/vesting/module.go | 26 +- x/auth/vesting/msg_server.go | 89 +---- x/auth/vesting/msg_server_test.go | 6 +- .../testutil/expected_keepers_mocks.go | 241 +------------ x/auth/vesting/types/codec.go | 13 +- x/auth/vesting/types/expected_keepers.go | 24 -- x/auth/vesting/types/msgs.go | 49 +-- x/auth/vesting/types/tx.pb.go | 337 +----------------- x/auth/vesting/types/vesting_account.go | 5 - x/auth/vesting/types/vesting_account_test.go | 12 +- 17 files changed, 48 insertions(+), 882 deletions(-) rename .github/workflows/{dependencies-review.yml.disable => dependencies-review.yml} (100%) delete mode 100644 x/auth/vesting/handler.go diff --git a/.github/workflows/dependencies-review.yml.disable b/.github/workflows/dependencies-review.yml similarity index 100% rename from .github/workflows/dependencies-review.yml.disable rename to .github/workflows/dependencies-review.yml diff --git a/proto/cosmos/vesting/v1beta1/tx.proto b/proto/cosmos/vesting/v1beta1/tx.proto index e8a5e6f6c2f1..42d3213f7b26 100644 --- a/proto/cosmos/vesting/v1beta1/tx.proto +++ b/proto/cosmos/vesting/v1beta1/tx.proto @@ -27,9 +27,6 @@ service Msg { // // Since: cosmos-sdk 0.46 rpc CreatePeriodicVestingAccount(MsgCreatePeriodicVestingAccount) returns (MsgCreatePeriodicVestingAccountResponse); - // DonateAllVestingTokens defines a method that enables donating all vesting - // tokens to community pool - rpc DonateAllVestingTokens(MsgDonateAllVestingTokens) returns (MsgDonateAllVestingTokensResponse); } // MsgCreateVestingAccount defines a message that enables creating a vesting @@ -79,7 +76,7 @@ message MsgCreatePermanentLockedAccount { // Since: cosmos-sdk 0.46 message MsgCreatePermanentLockedAccountResponse {} -// MsgCreatePeriodicVestingAccount defines a message that enables creating a vesting +// MsgCreateVestingAccount defines a message that enables creating a vesting // account. // // Since: cosmos-sdk 0.46 @@ -96,20 +93,8 @@ message MsgCreatePeriodicVestingAccount { repeated Period vesting_periods = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; } -// MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount +// MsgCreateVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount // response type. // // Since: cosmos-sdk 0.46 message MsgCreatePeriodicVestingAccountResponse {} - -// MsgDonateAllVestingTokens defines a message that enables donating all vesting -// token to community pool. -message MsgDonateAllVestingTokens { - option (gogoproto.equal) = false; - - string from_address = 1 [(gogoproto.moretags) = "yaml:\"from_address\""]; -} - -// MsgDonateAllVestingTokensResponse defines the Msg/MsgDonateAllVestingTokens -// response type. -message MsgDonateAllVestingTokensResponse {} diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index be064af94797..ca667a44a04e 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -31,3 +31,7 @@ cd .. # move proto files to the right places cp -r github.com/cosmos/cosmos-sdk/* ./ rm -rf github.com + +go mod tidy + +./scripts/protocgen-pulsar.sh diff --git a/simapp/app.go b/simapp/app.go index 60e1e90ee32d..078bda019336 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -400,7 +400,7 @@ func NewSimApp( encodingConfig.TxConfig, ), auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), - vesting.NewAppModule(app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.StakingKeeper), + vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), diff --git a/x/auth/migrations/v2/store_test.go b/x/auth/migrations/v2/store_test.go index 9924bdb37ea2..fd6e80b37108 100644 --- a/x/auth/migrations/v2/store_test.go +++ b/x/auth/migrations/v2/store_test.go @@ -384,7 +384,7 @@ func TestMigrateVestingAccounts(t *testing.T) { 3666666670000, 3666666670000, 0, - 1601042400, + 1601042400 + 1, }, { "periodic vesting account, all has vested", @@ -430,7 +430,7 @@ func TestMigrateVestingAccounts(t *testing.T) { 3666666670000, 0, 3666666670000, - 1601042400 + 31536000 + 15897600 + 15897600, + 1601042400 + 31536000 + 15897600 + 15897600 + 1, }, { "periodic vesting account, first period has vested", @@ -476,7 +476,7 @@ func TestMigrateVestingAccounts(t *testing.T) { 3666666670000, 3666666670000 - 1833333335000, 1833333335000, - 1601042400 + 31536000, + 1601042400 + 31536000 + 1, }, { "periodic vesting account, first 2 period has vested", @@ -522,7 +522,7 @@ func TestMigrateVestingAccounts(t *testing.T) { 3666666670000, 3666666670000 - 1833333335000 - 916666667500, 1833333335000 + 916666667500, - 1601042400 + 31536000 + 15638400, + 1601042400 + 31536000 + 15638400 + 1, }, { "vesting account has unbonding delegations in place", diff --git a/x/auth/vesting/client/cli/tx.go b/x/auth/vesting/client/cli/tx.go index 03586792f714..f2ef3ba67fe7 100644 --- a/x/auth/vesting/client/cli/tx.go +++ b/x/auth/vesting/client/cli/tx.go @@ -34,7 +34,6 @@ func GetTxCmd() *cobra.Command { NewMsgCreateVestingAccountCmd(), NewMsgCreatePermanentLockedAccountCmd(), NewMsgCreatePeriodicVestingAccountCmd(), - NewMsgDonateAllVestingTokensCmd(), ) return txCmd @@ -142,20 +141,19 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command { Where periods.json contains: An array of coin strings and unix epoch times for coins to vest -{ - "start_time": 1625204910, - "periods":[ - { - "coins": "10test", - "length_seconds":2592000 - }, - { - "coins": "10test", - "length_seconds":2592000 //30 days - } - ] -} -`, +{ "start_time": 1625204910, +"periods":[ + { + "coins": "10test", + "length_seconds":2592000 //30 days + }, + { + "coins": "10test", + "length_seconds":2592000 //30 days + }, +] + } + `, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -209,31 +207,3 @@ func NewMsgCreatePeriodicVestingAccountCmd() *cobra.Command { return cmd } - -// NewMsgDonateAllVestingTokensCmd returns a CLI command handler for creating a -// MsgDonateAllVestingTokens transaction. -func NewMsgDonateAllVestingTokensCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "donate-all-vesting-tokens", - Short: "Donate all vesting tokens of a vesting account to community pool.", - Long: `Donate all vesting tokens of a vesting account to community pool. - The account must not have any delegated vesting tokens to prevent complex - vesting logic changes. After donation, the account will be changed to normal - "BaseAccount".`, - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientTxContext(cmd) - if err != nil { - return err - } - - msg := types.NewMsgDonateAllVestingTokens(clientCtx.GetFromAddress()) - - return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) - }, - } - - flags.AddTxFlagsToCmd(cmd) - - return cmd -} diff --git a/x/auth/vesting/handler.go b/x/auth/vesting/handler.go deleted file mode 100644 index cd48e43c9d9d..000000000000 --- a/x/auth/vesting/handler.go +++ /dev/null @@ -1,39 +0,0 @@ -package vesting - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/keeper" - "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" -) - -// NewHandler returns a handler for x/auth message types. -func NewHandler( - ak keeper.AccountKeeper, - bk types.BankKeeper, - dk types.DistrKeeper, - sk types.StakingKeeper, -) sdk.Handler { - msgServer := NewMsgServerImpl(ak, bk, dk, sk) - - return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - ctx = ctx.WithEventManager(sdk.NewEventManager()) - - switch msg := msg.(type) { - case *types.MsgCreateVestingAccount: - res, err := msgServer.CreateVestingAccount(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - - case *types.MsgCreatePeriodicVestingAccount: - res, err := msgServer.CreatePeriodicVestingAccount(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - - case *types.MsgDonateAllVestingTokens: - res, err := msgServer.DonateAllVestingTokens(sdk.WrapSDKContext(ctx), msg) - return sdk.WrapServiceResult(ctx, res, err) - - default: - return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg) - } - } -} diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index a795698b2281..985b51bb6251 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -19,7 +19,6 @@ import ( "cosmossdk.io/core/appmodule" "github.com/cosmos/cosmos-sdk/x/auth/keeper" - "github.com/cosmos/cosmos-sdk/x/auth/vesting/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) @@ -81,22 +80,13 @@ type AppModule struct { accountKeeper keeper.AccountKeeper bankKeeper types.BankKeeper - distrKeeper types.DistrKeeper - stakingKeeper types.StakingKeeper } -func NewAppModule( - ak keeper.AccountKeeper, - bk types.BankKeeper, - dk types.DistrKeeper, - sk types.StakingKeeper, -) AppModule { +func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, accountKeeper: ak, bankKeeper: bk, - distrKeeper: dk, - stakingKeeper: sk, } } @@ -113,15 +103,7 @@ func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer( - cfg.MsgServer(), - NewMsgServerImpl( - am.accountKeeper, - am.bankKeeper, - am.distrKeeper, - am.stakingKeeper, - ), - ) + types.RegisterMsgServer(cfg.MsgServer(), NewMsgServerImpl(am.accountKeeper, am.bankKeeper)) } // InitGenesis performs a no-op. @@ -152,8 +134,6 @@ type VestingInputs struct { AccountKeeper keeper.AccountKeeper BankKeeper types.BankKeeper - // DistrKeeper types.DistrKeeper - StakingKeeper types.StakingKeeper } type VestingOutputs struct { @@ -163,7 +143,7 @@ type VestingOutputs struct { } func ProvideModule(in VestingInputs) VestingOutputs { - m := NewAppModule(in.AccountKeeper, in.BankKeeper, nil, in.StakingKeeper) + m := NewAppModule(in.AccountKeeper, in.BankKeeper) return VestingOutputs{Module: m} } diff --git a/x/auth/vesting/msg_server.go b/x/auth/vesting/msg_server.go index 79307c16ac2a..33dd56861cb1 100644 --- a/x/auth/vesting/msg_server.go +++ b/x/auth/vesting/msg_server.go @@ -2,8 +2,6 @@ package vesting import ( "context" - "fmt" - "math" "github.com/armon/go-metrics" @@ -12,26 +10,18 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) type msgServer struct { keeper.AccountKeeper types.BankKeeper - types.DistrKeeper - types.StakingKeeper } // NewMsgServerImpl returns an implementation of the vesting MsgServer interface, // wrapping the corresponding AccountKeeper and BankKeeper. -func NewMsgServerImpl( - k keeper.AccountKeeper, - bk types.BankKeeper, - dk types.DistrKeeper, - sk types.StakingKeeper, -) types.MsgServer { - return &msgServer{AccountKeeper: k, BankKeeper: bk, DistrKeeper: dk, StakingKeeper: sk} +func NewMsgServerImpl(k keeper.AccountKeeper, bk types.BankKeeper) types.MsgServer { + return &msgServer{AccountKeeper: k, BankKeeper: bk} } var _ types.MsgServer = msgServer{} @@ -203,78 +193,3 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type return &types.MsgCreatePeriodicVestingAccountResponse{}, nil } - -func (s msgServer) DonateAllVestingTokens(goCtx context.Context, msg *types.MsgDonateAllVestingTokens) (*types.MsgDonateAllVestingTokensResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - ak := s.AccountKeeper - dk := s.DistrKeeper - sk := s.StakingKeeper - - from, err := sdk.AccAddressFromBech32(msg.FromAddress) - if err != nil { - return nil, err - } - - acc := ak.GetAccount(ctx, from) - if acc == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s not exists", msg.FromAddress) - } - - // get all delegations of an account and undust those that have less than 1 uluna - delegations := sk.GetDelegatorDelegations(ctx, acc.GetAddress(), math.MaxUint16) - for _, delegation := range delegations { - validatorAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) - if err != nil { - return nil, err - } - validator, found := sk.GetValidator(ctx, validatorAddr) - if !found { - return nil, fmt.Errorf("validator not found") - } - // Try to delete the dust delegation - _, removedTokens := sk.RemoveValidatorTokensAndShares(ctx, validator, delegation.Shares) - // If the delegation is not dust, return an error and stop the donation flow - if !removedTokens.IsZero() { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s has a non-zero staking entry", msg.FromAddress) - } - - // Remove the dust delegation shares from the validator - err = sk.RemoveDelegation(ctx, delegation) - if err != nil { - return nil, err - } - } - - // check whether an account has any other type of staking entries - if len(sk.GetUnbondingDelegations(ctx, acc.GetAddress(), 1)) != 0 || - len(sk.GetRedelegations(ctx, acc.GetAddress(), 1)) != 0 { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s has staking entry", msg.FromAddress) - } - - vestingAcc, ok := acc.(exported.VestingAccount) - if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s is not a vesting account", msg.FromAddress) - } - - vestingCoins := vestingAcc.GetVestingCoins(ctx.BlockTime()) - if vestingCoins.IsZero() { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s has no vesting tokens", msg.FromAddress) - } - - // Change the account as normal account - ak.SetAccount(ctx, - authtypes.NewBaseAccount( - acc.GetAddress(), - acc.GetPubKey(), - acc.GetAccountNumber(), - acc.GetSequence(), - ), - ) - - if err := dk.FundCommunityPool(ctx, vestingCoins, from); err != nil { - return nil, err - } - - return &types.MsgDonateAllVestingTokensResponse{}, nil -} diff --git a/x/auth/vesting/msg_server_test.go b/x/auth/vesting/msg_server_test.go index c55df14e03dc..18205f705b2a 100644 --- a/x/auth/vesting/msg_server_test.go +++ b/x/auth/vesting/msg_server_test.go @@ -34,8 +34,6 @@ type VestingTestSuite struct { ctx sdk.Context accountKeeper authkeeper.AccountKeeper bankKeeper *vestingtestutil.MockBankKeeper - distrKeeper *vestingtestutil.MockDistrKeeper - stakingKeeper *vestingtestutil.MockStakingKeeper msgServer vestingtypes.MsgServer } @@ -49,8 +47,6 @@ func (s *VestingTestSuite) SetupTest() { ctrl := gomock.NewController(s.T()) s.bankKeeper = vestingtestutil.NewMockBankKeeper(ctrl) - s.distrKeeper = vestingtestutil.NewMockDistrKeeper(ctrl) - s.stakingKeeper = vestingtestutil.NewMockStakingKeeper(ctrl) s.accountKeeper = authkeeper.NewAccountKeeper( encCfg.Codec, key, @@ -62,7 +58,7 @@ func (s *VestingTestSuite) SetupTest() { vestingtypes.RegisterInterfaces(encCfg.InterfaceRegistry) authtypes.RegisterInterfaces(encCfg.InterfaceRegistry) - s.msgServer = vesting.NewMsgServerImpl(s.accountKeeper, s.bankKeeper, s.distrKeeper, s.stakingKeeper) + s.msgServer = vesting.NewMsgServerImpl(s.accountKeeper, s.bankKeeper) } func (s *VestingTestSuite) TestCreateVestingAccount() { diff --git a/x/auth/vesting/testutil/expected_keepers_mocks.go b/x/auth/vesting/testutil/expected_keepers_mocks.go index 582d9104f9b2..fd1fe6140d9c 100644 --- a/x/auth/vesting/testutil/expected_keepers_mocks.go +++ b/x/auth/vesting/testutil/expected_keepers_mocks.go @@ -1,17 +1,14 @@ // Code generated by MockGen. DO NOT EDIT. // Source: x/auth/vesting/types/expected_keepers.go -// Package mock_types is a generated GoMock package. -package mock_types +// Package testutil is a generated GoMock package. +package testutil import ( reflect "reflect" - math "cosmossdk.io/math" - log "github.com/cometbft/cometbft/libs/log" types "github.com/cosmos/cosmos-sdk/types" - types0 "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/golang/mock/gomock" + gomock "github.com/golang/mock/gomock" ) // MockBankKeeper is a mock of BankKeeper interface. @@ -83,235 +80,3 @@ func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt inter mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoins", reflect.TypeOf((*MockBankKeeper)(nil).SendCoins), ctx, fromAddr, toAddr, amt) } - -// MockDistrKeeper is a mock of DistrKeeper interface. -type MockDistrKeeper struct { - ctrl *gomock.Controller - recorder *MockDistrKeeperMockRecorder -} - -// MockDistrKeeperMockRecorder is the mock recorder for MockDistrKeeper. -type MockDistrKeeperMockRecorder struct { - mock *MockDistrKeeper -} - -// NewMockDistrKeeper creates a new mock instance. -func NewMockDistrKeeper(ctrl *gomock.Controller) *MockDistrKeeper { - mock := &MockDistrKeeper{ctrl: ctrl} - mock.recorder = &MockDistrKeeperMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockDistrKeeper) EXPECT() *MockDistrKeeperMockRecorder { - return m.recorder -} - -// FundCommunityPool mocks base method. -func (m *MockDistrKeeper) FundCommunityPool(ctx types.Context, amount types.Coins, sender types.AccAddress) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FundCommunityPool", ctx, amount, sender) - ret0, _ := ret[0].(error) - return ret0 -} - -// FundCommunityPool indicates an expected call of FundCommunityPool. -func (mr *MockDistrKeeperMockRecorder) FundCommunityPool(ctx, amount, sender interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FundCommunityPool", reflect.TypeOf((*MockDistrKeeper)(nil).FundCommunityPool), ctx, amount, sender) -} - -// GetAuthority mocks base method. -func (m *MockDistrKeeper) GetAuthority() string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAuthority") - ret0, _ := ret[0].(string) - return ret0 -} - -// GetAuthority indicates an expected call of GetAuthority. -func (mr *MockDistrKeeperMockRecorder) GetAuthority() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAuthority", reflect.TypeOf((*MockDistrKeeper)(nil).GetAuthority)) -} - -// GetTotalRewards mocks base method. -func (m *MockDistrKeeper) GetTotalRewards(ctx types.Context) types.DecCoins { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTotalRewards", ctx) - ret0, _ := ret[0].(types.DecCoins) - return ret0 -} - -// GetTotalRewards indicates an expected call of GetTotalRewards. -func (mr *MockDistrKeeperMockRecorder) GetTotalRewards(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTotalRewards", reflect.TypeOf((*MockDistrKeeper)(nil).GetTotalRewards), ctx) -} - -// Logger mocks base method. -func (m *MockDistrKeeper) Logger(ctx types.Context) log.Logger { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Logger", ctx) - ret0, _ := ret[0].(log.Logger) - return ret0 -} - -// Logger indicates an expected call of Logger. -func (mr *MockDistrKeeperMockRecorder) Logger(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Logger", reflect.TypeOf((*MockDistrKeeper)(nil).Logger), ctx) -} - -// SetWithdrawAddr mocks base method. -func (m *MockDistrKeeper) SetWithdrawAddr(ctx types.Context, delegatorAddr, withdrawAddr types.AccAddress) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SetWithdrawAddr", ctx, delegatorAddr, withdrawAddr) - ret0, _ := ret[0].(error) - return ret0 -} - -// SetWithdrawAddr indicates an expected call of SetWithdrawAddr. -func (mr *MockDistrKeeperMockRecorder) SetWithdrawAddr(ctx, delegatorAddr, withdrawAddr interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetWithdrawAddr", reflect.TypeOf((*MockDistrKeeper)(nil).SetWithdrawAddr), ctx, delegatorAddr, withdrawAddr) -} - -// WithdrawDelegationRewards mocks base method. -func (m *MockDistrKeeper) WithdrawDelegationRewards(ctx types.Context, delAddr types.AccAddress, valAddr types.ValAddress) (types.Coins, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WithdrawDelegationRewards", ctx, delAddr, valAddr) - ret0, _ := ret[0].(types.Coins) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WithdrawDelegationRewards indicates an expected call of WithdrawDelegationRewards. -func (mr *MockDistrKeeperMockRecorder) WithdrawDelegationRewards(ctx, delAddr, valAddr interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithdrawDelegationRewards", reflect.TypeOf((*MockDistrKeeper)(nil).WithdrawDelegationRewards), ctx, delAddr, valAddr) -} - -// WithdrawValidatorCommission mocks base method. -func (m *MockDistrKeeper) WithdrawValidatorCommission(ctx types.Context, valAddr types.ValAddress) (types.Coins, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "WithdrawValidatorCommission", ctx, valAddr) - ret0, _ := ret[0].(types.Coins) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// WithdrawValidatorCommission indicates an expected call of WithdrawValidatorCommission. -func (mr *MockDistrKeeperMockRecorder) WithdrawValidatorCommission(ctx, valAddr interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WithdrawValidatorCommission", reflect.TypeOf((*MockDistrKeeper)(nil).WithdrawValidatorCommission), ctx, valAddr) -} - -// MockStakingKeeper is a mock of StakingKeeper interface. -type MockStakingKeeper struct { - ctrl *gomock.Controller - recorder *MockStakingKeeperMockRecorder -} - -// MockStakingKeeperMockRecorder is the mock recorder for MockStakingKeeper. -type MockStakingKeeperMockRecorder struct { - mock *MockStakingKeeper -} - -// NewMockStakingKeeper creates a new mock instance. -func NewMockStakingKeeper(ctrl *gomock.Controller) *MockStakingKeeper { - mock := &MockStakingKeeper{ctrl: ctrl} - mock.recorder = &MockStakingKeeperMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockStakingKeeper) EXPECT() *MockStakingKeeperMockRecorder { - return m.recorder -} - -// GetDelegatorDelegations mocks base method. -func (m *MockStakingKeeper) GetDelegatorDelegations(ctx types.Context, delegator types.AccAddress, maxRetrieve uint16) []types0.Delegation { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetDelegatorDelegations", ctx, delegator, maxRetrieve) - ret0, _ := ret[0].([]types0.Delegation) - return ret0 -} - -// GetDelegatorDelegations indicates an expected call of GetDelegatorDelegations. -func (mr *MockStakingKeeperMockRecorder) GetDelegatorDelegations(ctx, delegator, maxRetrieve interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDelegatorDelegations", reflect.TypeOf((*MockStakingKeeper)(nil).GetDelegatorDelegations), ctx, delegator, maxRetrieve) -} - -// GetRedelegations mocks base method. -func (m *MockStakingKeeper) GetRedelegations(ctx types.Context, delegator types.AccAddress, maxRetrieve uint16) []types0.Redelegation { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetRedelegations", ctx, delegator, maxRetrieve) - ret0, _ := ret[0].([]types0.Redelegation) - return ret0 -} - -// GetRedelegations indicates an expected call of GetRedelegations. -func (mr *MockStakingKeeperMockRecorder) GetRedelegations(ctx, delegator, maxRetrieve interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRedelegations", reflect.TypeOf((*MockStakingKeeper)(nil).GetRedelegations), ctx, delegator, maxRetrieve) -} - -// GetUnbondingDelegations mocks base method. -func (m *MockStakingKeeper) GetUnbondingDelegations(ctx types.Context, delegator types.AccAddress, maxRetrieve uint16) []types0.UnbondingDelegation { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetUnbondingDelegations", ctx, delegator, maxRetrieve) - ret0, _ := ret[0].([]types0.UnbondingDelegation) - return ret0 -} - -// GetUnbondingDelegations indicates an expected call of GetUnbondingDelegations. -func (mr *MockStakingKeeperMockRecorder) GetUnbondingDelegations(ctx, delegator, maxRetrieve interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUnbondingDelegations", reflect.TypeOf((*MockStakingKeeper)(nil).GetUnbondingDelegations), ctx, delegator, maxRetrieve) -} - -// GetValidator mocks base method. -func (m *MockStakingKeeper) GetValidator(ctx types.Context, addr types.ValAddress) (types0.Validator, bool) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetValidator", ctx, addr) - ret0, _ := ret[0].(types0.Validator) - ret1, _ := ret[1].(bool) - return ret0, ret1 -} - -// GetValidator indicates an expected call of GetValidator. -func (mr *MockStakingKeeperMockRecorder) GetValidator(ctx, addr interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidator", reflect.TypeOf((*MockStakingKeeper)(nil).GetValidator), ctx, addr) -} - -// RemoveDelegation mocks base method. -func (m *MockStakingKeeper) RemoveDelegation(ctx types.Context, delegation types0.Delegation) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RemoveDelegation", ctx, delegation) - ret0, _ := ret[0].(error) - return ret0 -} - -// RemoveDelegation indicates an expected call of RemoveDelegation. -func (mr *MockStakingKeeperMockRecorder) RemoveDelegation(ctx, delegation interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveDelegation", reflect.TypeOf((*MockStakingKeeper)(nil).RemoveDelegation), ctx, delegation) -} - -// RemoveValidatorTokensAndShares mocks base method. -func (m *MockStakingKeeper) RemoveValidatorTokensAndShares(ctx types.Context, validator types0.Validator, sharesToRemove types.Dec) (types0.Validator, math.Int) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "RemoveValidatorTokensAndShares", ctx, validator, sharesToRemove) - ret0, _ := ret[0].(types0.Validator) - ret1, _ := ret[1].(math.Int) - return ret0, ret1 -} - -// RemoveValidatorTokensAndShares indicates an expected call of RemoveValidatorTokensAndShares. -func (mr *MockStakingKeeperMockRecorder) RemoveValidatorTokensAndShares(ctx, validator, sharesToRemove interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoveValidatorTokensAndShares", reflect.TypeOf((*MockStakingKeeper)(nil).RemoveValidatorTokensAndShares), ctx, validator, sharesToRemove) -} diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 8701e629d677..2dd2c5a8196f 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -2,6 +2,7 @@ package types import ( "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -22,12 +23,9 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&DelayedVestingAccount{}, "cosmos-sdk/DelayedVestingAccount", nil) cdc.RegisterConcrete(&PeriodicVestingAccount{}, "cosmos-sdk/PeriodicVestingAccount", nil) cdc.RegisterConcrete(&PermanentLockedAccount{}, "cosmos-sdk/PermanentLockedAccount", nil) - cdc.RegisterConcrete(&MsgCreatePermanentLockedAccount{}, "cosmos-sdk/MsgCreatePermLockedAccount", nil) - - // msg registration - cdc.RegisterConcrete(&MsgCreateVestingAccount{}, "cosmos-sdk/MsgCreateVestingAccount", nil) - cdc.RegisterConcrete(&MsgCreatePeriodicVestingAccount{}, "cosmos-sdk/MsgCreatePeriodicVestingAccount", nil) - cdc.RegisterConcrete(&MsgDonateAllVestingTokens{}, "cosmos-sdk/MsgDonateAllVestingTokens", nil) + legacy.RegisterAminoMsg(cdc, &MsgCreateVestingAccount{}, "cosmos-sdk/MsgCreateVestingAccount") + legacy.RegisterAminoMsg(cdc, &MsgCreatePermanentLockedAccount{}, "cosmos-sdk/MsgCreatePermLockedAccount") + legacy.RegisterAminoMsg(cdc, &MsgCreatePeriodicVestingAccount{}, "cosmos-sdk/MsgCreatePeriodVestAccount") } // RegisterInterface associates protoName with AccountI and VestingAccount @@ -63,8 +61,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgCreateVestingAccount{}, - &MsgCreatePeriodicVestingAccount{}, - &MsgDonateAllVestingTokens{}, + &MsgCreatePermanentLockedAccount{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/auth/vesting/types/expected_keepers.go b/x/auth/vesting/types/expected_keepers.go index 1a1bd981fe09..5705eea30baf 100644 --- a/x/auth/vesting/types/expected_keepers.go +++ b/x/auth/vesting/types/expected_keepers.go @@ -1,10 +1,7 @@ package types import ( - "cosmossdk.io/math" - "github.com/cometbft/cometbft/libs/log" sdk "github.com/cosmos/cosmos-sdk/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // BankKeeper defines the expected interface contract the vesting module requires @@ -14,24 +11,3 @@ type BankKeeper interface { SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error BlockedAddr(addr sdk.AccAddress) bool } - -// DistrKeeper defines the expected interface for distribution keeper -type DistrKeeper interface { - GetAuthority() string - Logger(ctx sdk.Context) log.Logger - SetWithdrawAddr(ctx sdk.Context, delegatorAddr sdk.AccAddress, withdrawAddr sdk.AccAddress) error - WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error) - WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddress) (sdk.Coins, error) - GetTotalRewards(ctx sdk.Context) (totalRewards sdk.DecCoins) - FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error -} - -// StakingKeeper defines the exported interface for staking keeper -type StakingKeeper interface { - GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) (delegations []stakingtypes.Delegation) - GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) (unbondingDelegations []stakingtypes.UnbondingDelegation) - GetRedelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) (redelegations []stakingtypes.Redelegation) - RemoveValidatorTokensAndShares(ctx sdk.Context, validator stakingtypes.Validator, sharesToRemove sdk.Dec) (valOut stakingtypes.Validator, removedTokens math.Int) - GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator stakingtypes.Validator, found bool) - RemoveDelegation(ctx sdk.Context, delegation stakingtypes.Delegation) error -} diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index 9441a809557c..f2194af5690b 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -16,18 +16,15 @@ const TypeMsgCreatePermanentLockedAccount = "msg_create_permanent_locked_account // TypeMsgCreatePeriodicVestingAccount defines the type value for a MsgCreateVestingAccount. const TypeMsgCreatePeriodicVestingAccount = "msg_create_periodic_vesting_account" -// TypeMsgDonateAllVestingTokens defines the type value for a MsgDonateAllVestingTokens. -const TypeMsgDonateAllVestingTokens = "msg_donate_all_vesting_tokens" //nolint: gosec - var _ sdk.Msg = &MsgCreateVestingAccount{} var _ sdk.Msg = &MsgCreatePermanentLockedAccount{} var _ sdk.Msg = &MsgCreatePeriodicVestingAccount{} -var _ sdk.Msg = &MsgDonateAllVestingTokens{} - // NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount. +// +//nolint:interfacer func NewMsgCreateVestingAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins, endTime int64, delayed bool) *MsgCreateVestingAccount { return &MsgCreateVestingAccount{ FromAddress: fromAddr.String(), @@ -200,45 +197,3 @@ func (msg MsgCreatePeriodicVestingAccount) ValidateBasic() error { return nil } - -// NewMsgDonateAllVestingTokens returns a reference to a new MsgDonateAllVestingTokens. -func NewMsgDonateAllVestingTokens(fromAddr sdk.AccAddress) *MsgDonateAllVestingTokens { - return &MsgDonateAllVestingTokens{ - FromAddress: fromAddr.String(), - } -} - -// Route returns the message route for a MsgDonateAllVestingTokens. -func (msg MsgDonateAllVestingTokens) Route() string { return RouterKey } - -// Type returns the message type for a MsgDonateAllVestingTokens. -func (msg MsgDonateAllVestingTokens) Type() string { return TypeMsgDonateAllVestingTokens } - -// ValidateBasic Implements Msg. -func (msg MsgDonateAllVestingTokens) ValidateBasic() error { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) - if err != nil { - return err - } - - if err := sdk.VerifyAddressFormat(from); err != nil { - return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address: %s", err) - } - - return nil -} - -// GetSignBytes returns the bytes all expected signers must sign over for a -// MsgDonateAllVestingTokens. -func (msg MsgDonateAllVestingTokens) GetSignBytes() []byte { - return sdk.MustSortJSON(amino.MustMarshalJSON(&msg)) -} - -// GetSigners returns the expected signers for a MsgDonateAllVestingTokens. -func (msg MsgDonateAllVestingTokens) GetSigners() []sdk.AccAddress { - from, err := sdk.AccAddressFromBech32(msg.FromAddress) - if err != nil { - panic(err) - } - return []sdk.AccAddress{from} -} diff --git a/x/auth/vesting/types/tx.pb.go b/x/auth/vesting/types/tx.pb.go index a89deed95273..463804f25cfd 100644 --- a/x/auth/vesting/types/tx.pb.go +++ b/x/auth/vesting/types/tx.pb.go @@ -254,7 +254,7 @@ func (m *MsgCreatePermanentLockedAccountResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgCreatePermanentLockedAccountResponse proto.InternalMessageInfo -// MsgCreatePeriodicVestingAccount defines a message that enables creating a vesting +// MsgCreateVestingAccount defines a message that enables creating a vesting // account. // // Since: cosmos-sdk 0.46 @@ -327,7 +327,7 @@ func (m *MsgCreatePeriodicVestingAccount) GetVestingPeriods() []Period { return nil } -// MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount +// MsgCreateVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount // response type. // // Since: cosmos-sdk 0.46 @@ -369,90 +369,6 @@ func (m *MsgCreatePeriodicVestingAccountResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgCreatePeriodicVestingAccountResponse proto.InternalMessageInfo -// MsgDonateAllVestingTokens defines a message that enables donating all vesting -// token to community pool. -type MsgDonateAllVestingTokens struct { - FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"` -} - -func (m *MsgDonateAllVestingTokens) Reset() { *m = MsgDonateAllVestingTokens{} } -func (m *MsgDonateAllVestingTokens) String() string { return proto.CompactTextString(m) } -func (*MsgDonateAllVestingTokens) ProtoMessage() {} -func (*MsgDonateAllVestingTokens) Descriptor() ([]byte, []int) { - return fileDescriptor_5338ca97811f9792, []int{6} -} -func (m *MsgDonateAllVestingTokens) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgDonateAllVestingTokens) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgDonateAllVestingTokens.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgDonateAllVestingTokens) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgDonateAllVestingTokens.Merge(m, src) -} -func (m *MsgDonateAllVestingTokens) XXX_Size() int { - return m.Size() -} -func (m *MsgDonateAllVestingTokens) XXX_DiscardUnknown() { - xxx_messageInfo_MsgDonateAllVestingTokens.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgDonateAllVestingTokens proto.InternalMessageInfo - -func (m *MsgDonateAllVestingTokens) GetFromAddress() string { - if m != nil { - return m.FromAddress - } - return "" -} - -// MsgDonateAllVestingTokensResponse defines the Msg/MsgDonateAllVestingTokens -// response type. -type MsgDonateAllVestingTokensResponse struct { -} - -func (m *MsgDonateAllVestingTokensResponse) Reset() { *m = MsgDonateAllVestingTokensResponse{} } -func (m *MsgDonateAllVestingTokensResponse) String() string { return proto.CompactTextString(m) } -func (*MsgDonateAllVestingTokensResponse) ProtoMessage() {} -func (*MsgDonateAllVestingTokensResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_5338ca97811f9792, []int{7} -} -func (m *MsgDonateAllVestingTokensResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgDonateAllVestingTokensResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgDonateAllVestingTokensResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgDonateAllVestingTokensResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgDonateAllVestingTokensResponse.Merge(m, src) -} -func (m *MsgDonateAllVestingTokensResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgDonateAllVestingTokensResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgDonateAllVestingTokensResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgDonateAllVestingTokensResponse proto.InternalMessageInfo - func init() { proto.RegisterType((*MsgCreateVestingAccount)(nil), "cosmos.vesting.v1beta1.MsgCreateVestingAccount") proto.RegisterType((*MsgCreateVestingAccountResponse)(nil), "cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse") @@ -460,8 +376,6 @@ func init() { proto.RegisterType((*MsgCreatePermanentLockedAccountResponse)(nil), "cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccountResponse") proto.RegisterType((*MsgCreatePeriodicVestingAccount)(nil), "cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount") proto.RegisterType((*MsgCreatePeriodicVestingAccountResponse)(nil), "cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse") - proto.RegisterType((*MsgDonateAllVestingTokens)(nil), "cosmos.vesting.v1beta1.MsgDonateAllVestingTokens") - proto.RegisterType((*MsgDonateAllVestingTokensResponse)(nil), "cosmos.vesting.v1beta1.MsgDonateAllVestingTokensResponse") } func init() { proto.RegisterFile("cosmos/vesting/v1beta1/tx.proto", fileDescriptor_5338ca97811f9792) } @@ -614,9 +528,6 @@ type MsgClient interface { // // Since: cosmos-sdk 0.46 CreatePeriodicVestingAccount(ctx context.Context, in *MsgCreatePeriodicVestingAccount, opts ...grpc.CallOption) (*MsgCreatePeriodicVestingAccountResponse, error) - // DonateAllVestingTokens defines a method that enables donating all vesting - // tokens to community pool - DonateAllVestingTokens(ctx context.Context, in *MsgDonateAllVestingTokens, opts ...grpc.CallOption) (*MsgDonateAllVestingTokensResponse, error) } type msgClient struct { @@ -654,15 +565,6 @@ func (c *msgClient) CreatePeriodicVestingAccount(ctx context.Context, in *MsgCre return out, nil } -func (c *msgClient) DonateAllVestingTokens(ctx context.Context, in *MsgDonateAllVestingTokens, opts ...grpc.CallOption) (*MsgDonateAllVestingTokensResponse, error) { - out := new(MsgDonateAllVestingTokensResponse) - err := c.cc.Invoke(ctx, "/cosmos.vesting.v1beta1.Msg/DonateAllVestingTokens", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - // MsgServer is the server API for Msg service. type MsgServer interface { // CreateVestingAccount defines a method that enables creating a vesting @@ -678,9 +580,6 @@ type MsgServer interface { // // Since: cosmos-sdk 0.46 CreatePeriodicVestingAccount(context.Context, *MsgCreatePeriodicVestingAccount) (*MsgCreatePeriodicVestingAccountResponse, error) - // DonateAllVestingTokens defines a method that enables donating all vesting - // tokens to community pool - DonateAllVestingTokens(context.Context, *MsgDonateAllVestingTokens) (*MsgDonateAllVestingTokensResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -696,9 +595,6 @@ func (*UnimplementedMsgServer) CreatePermanentLockedAccount(ctx context.Context, func (*UnimplementedMsgServer) CreatePeriodicVestingAccount(ctx context.Context, req *MsgCreatePeriodicVestingAccount) (*MsgCreatePeriodicVestingAccountResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CreatePeriodicVestingAccount not implemented") } -func (*UnimplementedMsgServer) DonateAllVestingTokens(ctx context.Context, req *MsgDonateAllVestingTokens) (*MsgDonateAllVestingTokensResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method DonateAllVestingTokens not implemented") -} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -758,24 +654,6 @@ func _Msg_CreatePeriodicVestingAccount_Handler(srv interface{}, ctx context.Cont return interceptor(ctx, in, info, handler) } -func _Msg_DonateAllVestingTokens_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgDonateAllVestingTokens) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).DonateAllVestingTokens(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cosmos.vesting.v1beta1.Msg/DonateAllVestingTokens", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).DonateAllVestingTokens(ctx, req.(*MsgDonateAllVestingTokens)) - } - return interceptor(ctx, in, info, handler) -} - var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "cosmos.vesting.v1beta1.Msg", HandlerType: (*MsgServer)(nil), @@ -792,10 +670,6 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "CreatePeriodicVestingAccount", Handler: _Msg_CreatePeriodicVestingAccount_Handler, }, - { - MethodName: "DonateAllVestingTokens", - Handler: _Msg_DonateAllVestingTokens_Handler, - }, }, Streams: []grpc.StreamDesc{}, Metadata: "cosmos/vesting/v1beta1/tx.proto", @@ -1043,59 +917,6 @@ func (m *MsgCreatePeriodicVestingAccountResponse) MarshalToSizedBuffer(dAtA []by return len(dAtA) - i, nil } -func (m *MsgDonateAllVestingTokens) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgDonateAllVestingTokens) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgDonateAllVestingTokens) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.FromAddress) > 0 { - i -= len(m.FromAddress) - copy(dAtA[i:], m.FromAddress) - i = encodeVarintTx(dAtA, i, uint64(len(m.FromAddress))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgDonateAllVestingTokensResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgDonateAllVestingTokensResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgDonateAllVestingTokensResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -1212,28 +1033,6 @@ func (m *MsgCreatePeriodicVestingAccountResponse) Size() (n int) { return n } -func (m *MsgDonateAllVestingTokens) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.FromAddress) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - return n -} - -func (m *MsgDonateAllVestingTokensResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1892,138 +1691,6 @@ func (m *MsgCreatePeriodicVestingAccountResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *MsgDonateAllVestingTokens) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgDonateAllVestingTokens: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgDonateAllVestingTokens: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.FromAddress = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgDonateAllVestingTokensResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgDonateAllVestingTokensResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgDonateAllVestingTokensResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index 59d84cd7c94e..892794f669cc 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -364,11 +364,6 @@ func (pva PeriodicVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins for _, period := range pva.VestingPeriods { x := blockTime.Unix() - currentPeriodStartTime if x < period.Length { - coins, _ := sdk.NewDecCoinsFromCoins(period.Amount...). - MulDec(sdk.NewDec(x).QuoInt64(period.Length)). - TruncateDecimal() - vestedCoins = vestedCoins.Add(coins...) - break } diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index c7e225f32816..8d8a2f6a3d33 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -369,17 +369,17 @@ func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { vestedCoins = pva.GetVestedCoins(endTime) require.Equal(t, origCoins, vestedCoins) - // require 50% of first period coins vested during first vesting period + // require no coins vested during first vesting period vestedCoins = pva.GetVestedCoins(now.Add(6 * time.Hour)) - require.Equal(t, vestedCoins, sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}) + require.Nil(t, vestedCoins) // require 50% of coins vested after period 1 vestedCoins = pva.GetVestedCoins(now.Add(12 * time.Hour)) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, vestedCoins) - // require 50% of period 2 coins vested until 15 hours + // require period 2 coins don't vest until period is over vestedCoins = pva.GetVestedCoins(now.Add(15 * time.Hour)) - require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 625), sdk.NewInt64Coin(stakeDenom, 62)}, vestedCoins) + require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, vestedCoins) // require 75% of coins vested after period 2 vestedCoins = pva.GetVestedCoins(now.Add(18 * time.Hour)) @@ -417,9 +417,9 @@ func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) { vestingCoins = pva.GetVestingCoins(now.Add(12 * time.Hour)) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, vestingCoins) - // require 37.5% of coins vesting after period 1, but before period 2 completes. + // require 50% of coins vesting after period 1, but before period 2 completes. vestingCoins = pva.GetVestingCoins(now.Add(15 * time.Hour)) - require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 375), sdk.NewInt64Coin(stakeDenom, 38)}, vestingCoins) + require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}, vestingCoins) // require 25% of coins vesting after period 2 vestingCoins = pva.GetVestingCoins(now.Add(18 * time.Hour))