From a724ad6cf1ae439fcd88ddf67edd891a67d5ccb1 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Wed, 8 Jun 2022 10:08:00 -0400 Subject: [PATCH 1/4] updates --- x/auth/vesting/msg_server.go | 42 ++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/x/auth/vesting/msg_server.go b/x/auth/vesting/msg_server.go index e3fd521a62f6..0660d73ef8e4 100644 --- a/x/auth/vesting/msg_server.go +++ b/x/auth/vesting/msg_server.go @@ -70,15 +70,14 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre baseVestingAccount := types.NewBaseVestingAccount(baseAccount, msg.Amount.Sort(), msg.EndTime) - var acc authtypes.AccountI - + var vestingAccount authtypes.AccountI if msg.Delayed { - acc = types.NewDelayedVestingAccountRaw(baseVestingAccount) + vestingAccount = types.NewDelayedVestingAccountRaw(baseVestingAccount) } else { - acc = types.NewContinuousVestingAccountRaw(baseVestingAccount, ctx.BlockTime().Unix()) + vestingAccount = types.NewContinuousVestingAccountRaw(baseVestingAccount, ctx.BlockTime().Unix()) } - ak.SetAccount(ctx, acc) + ak.SetAccount(ctx, vestingAccount) defer func() { telemetry.IncrCounter(1, "new", "account") @@ -135,16 +134,19 @@ func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *type return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress) } - baseAccountI := ak.NewAccountWithAddress(ctx, to) - - baseAcc, ok := baseAccountI.(*authtypes.BaseAccount) + account := ak.NewAccountWithAddress(ctx, to) + baseAccount, ok := account.(*authtypes.BaseAccount) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccountI) + if getter, ok := account.(baseAccountGetter); ok { + baseAccount = getter.GetBaseAccount() + } + } + if baseAccount == nil { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount) } - var acc authtypes.AccountI = types.NewPermanentLockedAccount(baseAcc, msg.Amount) - - ak.SetAccount(ctx, acc) + vestingAccount := types.NewPermanentLockedAccount(baseAccount, msg.Amount) + ak.SetAccount(ctx, vestingAccount) defer func() { telemetry.IncrCounter(1, "new", "account") @@ -200,11 +202,19 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type totalCoins = totalCoins.Add(period.Amount...) } - baseAccount := ak.NewAccountWithAddress(ctx, to) - - acc := types.NewPeriodicVestingAccount(baseAccount.(*authtypes.BaseAccount), totalCoins.Sort(), msg.StartTime, msg.VestingPeriods) + account := ak.NewAccountWithAddress(ctx, to) + baseAccount, ok := account.(*authtypes.BaseAccount) + if !ok { + if getter, ok := account.(baseAccountGetter); ok { + baseAccount = getter.GetBaseAccount() + } + } + if baseAccount == nil { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount) + } - ak.SetAccount(ctx, acc) + vestingAccount := types.NewPeriodicVestingAccount(baseAccount, totalCoins.Sort(), msg.StartTime, msg.VestingPeriods) + ak.SetAccount(ctx, vestingAccount) defer func() { telemetry.IncrCounter(1, "new", "account") From 4cde1d11503d012522bbf83ca78e372b72c1dd31 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Wed, 8 Jun 2022 10:11:13 -0400 Subject: [PATCH 2/4] cl++ --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67e790c45463..72e7567f0704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (vesting) [#12190](https://github.com/cosmos/cosmos-sdk/pull/12190) Extend https://github.com/cosmos/cosmos-sdk/pull/12190 to apply to all vesting message handlers. * (linting) [#12135](https://github.com/cosmos/cosmos-sdk/pull/12135/) Fix variable naming issues per enabled linters. Run gofumpt to ensure easy reviews of ongoing linting work. * (linting) [#12132](https://github.com/cosmos/cosmos-sdk/pull/12132) Change sdk.Int to math.Int, run `gofumpt -w -l .`, and `golangci-lint run ./... --fix` * (cli) [#12127](https://github.com/cosmos/cosmos-sdk/pull/12127) Fix the CLI not always taking into account `--fee-payer` and `--fee-granter` flags. From 3960c63b7698446697c17e79a53d554b29cdce2f Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Thu, 9 Jun 2022 15:20:36 -0400 Subject: [PATCH 3/4] updates --- x/auth/vesting/msg_server.go | 48 +++++++----------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/x/auth/vesting/msg_server.go b/x/auth/vesting/msg_server.go index 0660d73ef8e4..afcd2681e1bb 100644 --- a/x/auth/vesting/msg_server.go +++ b/x/auth/vesting/msg_server.go @@ -3,14 +3,13 @@ package vesting import ( "context" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/armon/go-metrics" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" 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/types" ) @@ -19,10 +18,6 @@ type msgServer struct { types.BankKeeper } -type baseAccountGetter interface { - GetBaseAccount() *authtypes.BaseAccount -} - // NewMsgServerImpl returns an implementation of the vesting MsgServer interface, // wrapping the corresponding AccountKeeper and BankKeeper. func NewMsgServerImpl(k keeper.AccountKeeper, bk types.BankKeeper) types.MsgServer { @@ -57,17 +52,8 @@ func (s msgServer) CreateVestingAccount(goCtx context.Context, msg *types.MsgCre return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress) } - account := ak.NewAccountWithAddress(ctx, to) - baseAccount, ok := account.(*authtypes.BaseAccount) - if !ok { - if getter, ok := account.(baseAccountGetter); ok { - baseAccount = getter.GetBaseAccount() - } - } - if baseAccount == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount) - } - + baseAccount := authtypes.NewBaseAccountWithAddress(to) + baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount) baseVestingAccount := types.NewBaseVestingAccount(baseAccount, msg.Amount.Sort(), msg.EndTime) var vestingAccount authtypes.AccountI @@ -134,18 +120,10 @@ func (s msgServer) CreatePermanentLockedAccount(goCtx context.Context, msg *type return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s already exists", msg.ToAddress) } - account := ak.NewAccountWithAddress(ctx, to) - baseAccount, ok := account.(*authtypes.BaseAccount) - if !ok { - if getter, ok := account.(baseAccountGetter); ok { - baseAccount = getter.GetBaseAccount() - } - } - if baseAccount == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount) - } - + baseAccount := authtypes.NewBaseAccountWithAddress(to) + baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount) vestingAccount := types.NewPermanentLockedAccount(baseAccount, msg.Amount) + ak.SetAccount(ctx, vestingAccount) defer func() { @@ -202,18 +180,10 @@ func (s msgServer) CreatePeriodicVestingAccount(goCtx context.Context, msg *type totalCoins = totalCoins.Add(period.Amount...) } - account := ak.NewAccountWithAddress(ctx, to) - baseAccount, ok := account.(*authtypes.BaseAccount) - if !ok { - if getter, ok := account.(baseAccountGetter); ok { - baseAccount = getter.GetBaseAccount() - } - } - if baseAccount == nil { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid account type; expected: BaseAccount, got: %T", baseAccount) - } - + baseAccount := authtypes.NewBaseAccountWithAddress(to) + baseAccount = ak.NewAccount(ctx, baseAccount).(*authtypes.BaseAccount) vestingAccount := types.NewPeriodicVestingAccount(baseAccount, totalCoins.Sort(), msg.StartTime, msg.VestingPeriods) + ak.SetAccount(ctx, vestingAccount) defer func() { From 0717c5bebc93dc22c892953878912fd9541e41f9 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Thu, 9 Jun 2022 15:22:24 -0400 Subject: [PATCH 4/4] cl++ --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f26089a37ab8..58e62e91b746 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,7 +52,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -* (vesting) [#12190](https://github.com/cosmos/cosmos-sdk/pull/12190) Extend https://github.com/cosmos/cosmos-sdk/pull/12190 to apply to all vesting message handlers. +* (vesting) [#12190](https://github.com/cosmos/cosmos-sdk/pull/12190) Replace https://github.com/cosmos/cosmos-sdk/pull/12190 to use `NewBaseAccountWithAddress` in all vesting account message handlers. * (linting) [#12135](https://github.com/cosmos/cosmos-sdk/pull/12135/) Fix variable naming issues per enabled linters. Run gofumpt to ensure easy reviews of ongoing linting work. * (linting) [#12132](https://github.com/cosmos/cosmos-sdk/pull/12132) Change sdk.Int to math.Int, run `gofumpt -w -l .`, and `golangci-lint run ./... --fix` * (cli) [#12127](https://github.com/cosmos/cosmos-sdk/pull/12127) Fix the CLI not always taking into account `--fee-payer` and `--fee-granter` flags.