From 1143c1a68d0ebb772b3efadc109de040bf6027a5 Mon Sep 17 00:00:00 2001 From: Yun Date: Thu, 30 Jun 2022 16:33:31 +0900 Subject: [PATCH 1/2] add vesting token donation feature --- docs/core/proto-docs.md | 34 +- proto/cosmos/vesting/v1beta1/tx.proto | 19 +- simapp/app.go | 2 +- x/auth/vesting/client/cli/tx.go | 29 ++ x/auth/vesting/handler.go | 8 +- x/auth/vesting/handler_test.go | 79 ++++- x/auth/vesting/module.go | 9 +- x/auth/vesting/msg_server.go | 60 +++- x/auth/vesting/types/codec.go | 7 + x/auth/vesting/types/expected_keepers.go | 5 + x/auth/vesting/types/msgs.go | 48 ++- x/auth/vesting/types/tx.pb.go | 406 +++++++++++++++++++++-- 12 files changed, 657 insertions(+), 49 deletions(-) diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index b9d5fc76d6d5..885332670ed0 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -594,6 +594,8 @@ - [MsgCreatePeriodicVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse) - [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount) - [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse) + - [MsgDonateAllVestingTokens](#cosmos.vesting.v1beta1.MsgDonateAllVestingTokens) + - [MsgDonateAllVestingTokensResponse](#cosmos.vesting.v1beta1.MsgDonateAllVestingTokensResponse) - [Msg](#cosmos.vesting.v1beta1.Msg) @@ -8458,7 +8460,7 @@ Since: cosmos-sdk 0.43 ### MsgCreatePeriodicVestingAccount -MsgCreateVestingAccount defines a message that enables creating a vesting +MsgCreatePeriodicVestingAccount defines a message that enables creating a vesting account. @@ -8477,7 +8479,7 @@ account. ### MsgCreatePeriodicVestingAccountResponse -MsgCreateVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount +MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount response type. @@ -8514,6 +8516,33 @@ MsgCreateVestingAccountResponse defines the Msg/CreateVestingAccount response ty + + + +### MsgDonateAllVestingTokens +MsgDonateAllVestingTokens defines a message that enables donating all vesting +token to community pool. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `from_address` | [string](#string) | | | + + + + + + + + +### MsgDonateAllVestingTokensResponse +MsgDonateAllVestingTokensResponse defines the Msg/MsgDonateAllVestingTokens +response type. + + + + + @@ -8530,6 +8559,7 @@ Msg defines the bank Msg service. | ----------- | ------------ | ------------- | ------------| ------- | -------- | | `CreateVestingAccount` | [MsgCreateVestingAccount](#cosmos.vesting.v1beta1.MsgCreateVestingAccount) | [MsgCreateVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreateVestingAccountResponse) | CreateVestingAccount defines a method that enables creating a vesting account. | | | `CreatePeriodicVestingAccount` | [MsgCreatePeriodicVestingAccount](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount) | [MsgCreatePeriodicVestingAccountResponse](#cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccountResponse) | CreatePeriodicVestingAccount defines a method that enables creating a periodic vesting account. | | +| `DonateAllVestingTokens` | [MsgDonateAllVestingTokens](#cosmos.vesting.v1beta1.MsgDonateAllVestingTokens) | [MsgDonateAllVestingTokensResponse](#cosmos.vesting.v1beta1.MsgDonateAllVestingTokensResponse) | DonateAllVestingTokens defines a method that enables donating all vesting tokens to community pool | | diff --git a/proto/cosmos/vesting/v1beta1/tx.proto b/proto/cosmos/vesting/v1beta1/tx.proto index 9432f0c3f389..a3bff8cb6183 100644 --- a/proto/cosmos/vesting/v1beta1/tx.proto +++ b/proto/cosmos/vesting/v1beta1/tx.proto @@ -15,6 +15,9 @@ service Msg { // CreatePeriodicVestingAccount defines a method that enables creating a // periodic vesting account. 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 @@ -35,7 +38,7 @@ message MsgCreateVestingAccount { message MsgCreateVestingAccountResponse {} -// MsgCreateVestingAccount defines a message that enables creating a vesting +// MsgCreatePeriodicVestingAccount defines a message that enables creating a vesting // account. message MsgCreatePeriodicVestingAccount { option (gogoproto.equal) = false; @@ -46,6 +49,18 @@ message MsgCreatePeriodicVestingAccount { repeated Period vesting_periods = 4 [(gogoproto.nullable) = false]; } -// MsgCreateVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount +// MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount // response type. 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/simapp/app.go b/simapp/app.go index 783774aa04c5..8133838b3c30 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -308,7 +308,7 @@ func NewSimApp( encodingConfig.TxConfig, ), auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts), - vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), + vesting.NewAppModule(app.AccountKeeper, app.BankKeeper, app.DistrKeeper), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper), crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), diff --git a/x/auth/vesting/client/cli/tx.go b/x/auth/vesting/client/cli/tx.go index 97922051fd84..3ff971fed286 100644 --- a/x/auth/vesting/client/cli/tx.go +++ b/x/auth/vesting/client/cli/tx.go @@ -33,6 +33,7 @@ func GetTxCmd() *cobra.Command { txCmd.AddCommand( NewMsgCreateVestingAccountCmd(), NewMsgCreatePeriodicVestingAccountCmd(), + NewMsgDonateAllVestingTokensCmd(), ) return txCmd @@ -171,3 +172,31 @@ 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 index c8aa791975bd..53764e718d52 100644 --- a/x/auth/vesting/handler.go +++ b/x/auth/vesting/handler.go @@ -8,8 +8,8 @@ import ( ) // NewHandler returns a handler for x/auth message types. -func NewHandler(ak keeper.AccountKeeper, bk types.BankKeeper) sdk.Handler { - msgServer := NewMsgServerImpl(ak, bk) +func NewHandler(ak keeper.AccountKeeper, bk types.BankKeeper, dk types.DistrKeeper) sdk.Handler { + msgServer := NewMsgServerImpl(ak, bk, dk) return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { ctx = ctx.WithEventManager(sdk.NewEventManager()) @@ -23,6 +23,10 @@ func NewHandler(ak keeper.AccountKeeper, bk types.BankKeeper) sdk.Handler { 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/handler_test.go b/x/auth/vesting/handler_test.go index f78a337044db..6f0db79276b5 100644 --- a/x/auth/vesting/handler_test.go +++ b/x/auth/vesting/handler_test.go @@ -8,6 +8,8 @@ import ( "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) @@ -23,7 +25,7 @@ func (suite *HandlerTestSuite) SetupTest() { checkTx := false app := simapp.Setup(checkTx) - suite.handler = vesting.NewHandler(app.AccountKeeper, app.BankKeeper) + suite.handler = vesting.NewHandler(app.AccountKeeper, app.BankKeeper, app.DistrKeeper) suite.app = app } @@ -91,6 +93,81 @@ func (suite *HandlerTestSuite) TestMsgCreateVestingAccount() { } } +func (suite *HandlerTestSuite) TestMsgDonateVestingToken() { + ctx := suite.app.BaseApp.NewContext(false, tmproto.Header{Height: suite.app.LastBlockHeight() + 1}) + + balances := sdk.NewCoins(sdk.NewInt64Coin("test", 1000)) + addr1 := sdk.AccAddress([]byte("addr1_______________")) + addr2 := sdk.AccAddress([]byte("addr2_______________")) + addr3 := sdk.AccAddress([]byte("addr3_______________")) + + acc1 := suite.app.AccountKeeper.NewAccountWithAddress(ctx, addr1) + suite.app.AccountKeeper.SetAccount(ctx, acc1) + suite.Require().NoError(simapp.FundAccount(suite.app.BankKeeper, ctx, addr1, balances)) + + acc2 := types.NewPermanentLockedAccount( + suite.app.AccountKeeper.NewAccountWithAddress(ctx, addr2).(*authtypes.BaseAccount), balances, + ) + acc2.DelegatedVesting = balances + suite.app.AccountKeeper.SetAccount(ctx, acc2) + suite.Require().NoError(simapp.FundAccount(suite.app.BankKeeper, ctx, addr2, balances)) + + acc3 := types.NewPermanentLockedAccount( + suite.app.AccountKeeper.NewAccountWithAddress(ctx, addr3).(*authtypes.BaseAccount), balances, + ) + suite.app.AccountKeeper.SetAccount(ctx, acc3) + suite.Require().NoError(simapp.FundAccount(suite.app.BankKeeper, ctx, addr3, balances)) + + testCases := []struct { + name string + msg *types.MsgDonateAllVestingTokens + expectErr bool + }{ + { + name: "donate from normal account", + msg: types.NewMsgDonateAllVestingTokens(addr1), + expectErr: true, + }, + { + name: "donate from vesting account with delegated vesting", + msg: types.NewMsgDonateAllVestingTokens(addr2), + expectErr: true, + }, + { + name: "donate form vesting account", + msg: types.NewMsgDonateAllVestingTokens(addr3), + expectErr: false, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + res, err := suite.handler(ctx, tc.msg) + if tc.expectErr { + suite.Require().Error(err) + } else { + suite.Require().NoError(err) + suite.Require().NotNil(res) + + feePool := suite.app.DistrKeeper.GetFeePool(ctx).CommunityPool + communityFund, _ := feePool.TruncateDecimal() + suite.Require().Equal(balances, communityFund) + + fromAddr, err := sdk.AccAddressFromBech32(tc.msg.FromAddress) + suite.Require().NoError(err) + accI := suite.app.AccountKeeper.GetAccount(ctx, fromAddr) + suite.Require().NotNil(accI) + _, ok := accI.(*authtypes.BaseAccount) + suite.Require().True(ok) + balance := suite.app.BankKeeper.GetAllBalances(ctx, fromAddr) + suite.Require().Empty(balance) + } + }) + } +} + func TestHandlerTestSuite(t *testing.T) { suite.Run(t, new(HandlerTestSuite)) } diff --git a/x/auth/vesting/module.go b/x/auth/vesting/module.go index 25820b11bf66..6138738a13b7 100644 --- a/x/auth/vesting/module.go +++ b/x/auth/vesting/module.go @@ -14,6 +14,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "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" ) @@ -78,13 +79,15 @@ type AppModule struct { accountKeeper keeper.AccountKeeper bankKeeper types.BankKeeper + distrKeeper types.DistrKeeper } -func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule { +func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper, dk types.DistrKeeper) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, accountKeeper: ak, bankKeeper: bk, + distrKeeper: dk, } } @@ -93,7 +96,7 @@ func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // Route returns the module's message router and handler. func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(types.RouterKey, NewHandler(am.accountKeeper, am.bankKeeper)) + return sdk.NewRoute(types.RouterKey, NewHandler(am.accountKeeper, am.bankKeeper, am.distrKeeper)) } // QuerierRoute returns an empty string as the module contains no query @@ -102,7 +105,7 @@ func (AppModule) QuerierRoute() string { return "" } // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer(cfg.MsgServer(), NewMsgServerImpl(am.accountKeeper, am.bankKeeper)) + types.RegisterMsgServer(cfg.MsgServer(), NewMsgServerImpl(am.accountKeeper, am.bankKeeper, am.distrKeeper)) } // LegacyQuerierHandler performs a no-op. diff --git a/x/auth/vesting/msg_server.go b/x/auth/vesting/msg_server.go index 5557b96ba4a3..bd61f7d359f4 100644 --- a/x/auth/vesting/msg_server.go +++ b/x/auth/vesting/msg_server.go @@ -11,18 +11,20 @@ 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/exported" "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" ) type msgServer struct { keeper.AccountKeeper types.BankKeeper + types.DistrKeeper } // 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 { - return &msgServer{AccountKeeper: k, BankKeeper: bk} +func NewMsgServerImpl(k keeper.AccountKeeper, bk types.BankKeeper, dk types.DistrKeeper) types.MsgServer { + return &msgServer{AccountKeeper: k, BankKeeper: bk, DistrKeeper: dk} } var _ types.MsgServer = msgServer{} @@ -158,3 +160,57 @@ 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 + + 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) + } + + vestingAcc, ok := acc.(exported.VestingAccount) + if !ok { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s not vesting account", msg.FromAddress) + } + + if !vestingAcc.GetDelegatedVesting().IsZero() { + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s has delegated vesting tokens", 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 + } + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory), + ), + ) + + return &types.MsgDonateAllVestingTokensResponse{}, nil +} diff --git a/x/auth/vesting/types/codec.go b/x/auth/vesting/types/codec.go index 6a4b795107d8..7ca4c357f2bb 100644 --- a/x/auth/vesting/types/codec.go +++ b/x/auth/vesting/types/codec.go @@ -18,6 +18,11 @@ 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) + + // msg registration + cdc.RegisterConcrete(&MsgCreateVestingAccount{}, "cosmos-sdk/MsgCreateVestingAccount", nil) + cdc.RegisterConcrete(&MsgCreatePeriodicVestingAccount{}, "cosmos-sdk/MsgCreatePeriodicVestingAccount", nil) + cdc.RegisterConcrete(&MsgDonateAllVestingTokens{}, "cosmos-sdk/MsgDonateAllVestingTokens", nil) } // RegisterInterface associates protoName with AccountI and VestingAccount @@ -53,6 +58,8 @@ func RegisterInterfaces(registry types.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgCreateVestingAccount{}, + &MsgCreatePeriodicVestingAccount{}, + &MsgDonateAllVestingTokens{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/auth/vesting/types/expected_keepers.go b/x/auth/vesting/types/expected_keepers.go index 5705eea30baf..2b179712eef4 100644 --- a/x/auth/vesting/types/expected_keepers.go +++ b/x/auth/vesting/types/expected_keepers.go @@ -11,3 +11,8 @@ 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 { + FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error +} diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index 37f38b42454b..3419ccef1137 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -13,12 +13,16 @@ const TypeMsgCreateVestingAccount = "msg_create_vesting_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" + var _ sdk.Msg = &MsgCreateVestingAccount{} 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(), @@ -145,3 +149,45 @@ 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 824e20b4beb0..d46b530d1715 100644 --- a/x/auth/vesting/types/tx.pb.go +++ b/x/auth/vesting/types/tx.pb.go @@ -145,7 +145,7 @@ func (m *MsgCreateVestingAccountResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgCreateVestingAccountResponse proto.InternalMessageInfo -// MsgCreateVestingAccount defines a message that enables creating a vesting +// MsgCreatePeriodicVestingAccount defines a message that enables creating a vesting // account. type MsgCreatePeriodicVestingAccount struct { FromAddress string `protobuf:"bytes,1,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty" yaml:"from_address"` @@ -215,7 +215,7 @@ func (m *MsgCreatePeriodicVestingAccount) GetVestingPeriods() []Period { return nil } -// MsgCreateVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount +// MsgCreatePeriodicVestingAccountResponse defines the Msg/CreatePeriodicVestingAccount // response type. type MsgCreatePeriodicVestingAccountResponse struct { } @@ -255,50 +255,139 @@ 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{4} +} +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{5} +} +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") 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) } var fileDescriptor_5338ca97811f9792 = []byte{ - // 519 bytes of a gzipped FileDescriptorProto + // 569 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x54, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xf6, 0xc5, 0xa1, 0x6d, 0xae, 0x88, 0x0a, 0xb7, 0x50, 0x13, 0x21, 0x3b, 0x9c, 0x90, 0x30, - 0x03, 0x67, 0x52, 0x2a, 0x21, 0x65, 0x41, 0x75, 0x47, 0x14, 0x09, 0x59, 0x88, 0x81, 0x25, 0xba, - 0xd8, 0x87, 0x6b, 0x51, 0xfb, 0x22, 0xdf, 0xa5, 0x6a, 0x36, 0x7e, 0x02, 0x23, 0x13, 0x42, 0x62, - 0xe3, 0x57, 0x30, 0x76, 0xec, 0xc8, 0x14, 0x50, 0xb2, 0x30, 0xe7, 0x17, 0x20, 0xdf, 0x9d, 0xd3, - 0x0c, 0x49, 0x23, 0x58, 0x98, 0x92, 0xe7, 0xef, 0xfb, 0xde, 0xbd, 0xf7, 0xbd, 0x77, 0x07, 0xdd, - 0x88, 0xf1, 0x8c, 0x71, 0xff, 0x8c, 0x72, 0x91, 0xe6, 0x89, 0x7f, 0xd6, 0xee, 0x53, 0x41, 0xda, - 0xbe, 0x38, 0xc7, 0x83, 0x82, 0x09, 0x66, 0xdd, 0x55, 0x04, 0xac, 0x09, 0x58, 0x13, 0x9a, 0x7b, - 0x09, 0x4b, 0x98, 0xa4, 0xf8, 0xe5, 0x3f, 0xc5, 0x6e, 0x3a, 0x3a, 0x5d, 0x9f, 0x70, 0x3a, 0xcf, - 0x15, 0xb1, 0x34, 0xd7, 0xf8, 0xc3, 0x15, 0xc7, 0x55, 0xd9, 0x25, 0x0b, 0x7d, 0xaf, 0xc1, 0xfd, - 0x2e, 0x4f, 0x8e, 0x0b, 0x4a, 0x04, 0x7d, 0xa3, 0xa0, 0xa3, 0x28, 0x62, 0xc3, 0x5c, 0x58, 0x1d, - 0x78, 0xf3, 0x5d, 0xc1, 0xb2, 0x1e, 0x89, 0xe3, 0x82, 0x72, 0x6e, 0x83, 0x16, 0xf0, 0x1a, 0xc1, - 0xfe, 0x6c, 0xec, 0xee, 0x8e, 0x48, 0x76, 0xda, 0x41, 0x8b, 0x28, 0x0a, 0xb7, 0xcb, 0xf0, 0x48, - 0x45, 0xd6, 0x21, 0x84, 0x82, 0xcd, 0x95, 0x35, 0xa9, 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, 0x77, 0x67, + 0x37, 0x43, 0x9c, 0xaa, 0x30, 0x30, 0xd9, 0xcf, 0xef, 0xfb, 0xbe, 0x7b, 0xef, 0xbb, 0xe7, 0x07, + 0x0d, 0x8f, 0xd0, 0x88, 0x50, 0xfb, 0x14, 0x53, 0x16, 0xc6, 0x81, 0x7d, 0xda, 0xec, 0x61, 0x86, + 0x9a, 0x36, 0x3b, 0xb3, 0x06, 0x09, 0x61, 0x44, 0xdd, 0x16, 0x00, 0x4b, 0x02, 0x2c, 0x09, 0xa8, + 0x6d, 0x05, 0x24, 0x20, 0x1c, 0x62, 0xa7, 0x6f, 0x02, 0x5d, 0xd3, 0xa5, 0x5c, 0x0f, 0x51, 0x9c, + 0x6b, 0x79, 0x24, 0x8c, 0x65, 0xfe, 0x7e, 0xc1, 0x71, 0x99, 0x3a, 0x47, 0x99, 0xdf, 0xcb, 0x70, + 0xa7, 0x43, 0x83, 0xc3, 0x04, 0x23, 0x86, 0x5f, 0x8b, 0x54, 0xdb, 0xf3, 0xc8, 0x30, 0x66, 0x6a, + 0x0b, 0xde, 0x7c, 0x97, 0x90, 0xa8, 0x8b, 0x7c, 0x3f, 0xc1, 0x94, 0x6a, 0xa0, 0x0e, 0x1a, 0x55, + 0x67, 0x67, 0x36, 0x36, 0x36, 0x47, 0x28, 0xea, 0xb7, 0xcc, 0xf9, 0xac, 0xe9, 0xae, 0xa7, 0x61, + 0x5b, 0x44, 0xea, 0x01, 0x84, 0x8c, 0xe4, 0xcc, 0x32, 0x67, 0xde, 0x99, 0x8d, 0x8d, 0xdb, 0x82, + 0x79, 0x99, 0x33, 0xdd, 0x2a, 0x23, 0x19, 0xcb, 0x83, 0x2b, 0x28, 0x4a, 0xcf, 0xd6, 0x94, 0xba, + 0xd2, 0x58, 0xdf, 0xdf, 0xb5, 0xa4, 0x25, 0x69, 0x93, 0x99, 0x1f, 0xd6, 0x21, 0x09, 0x63, 0xe7, + 0xf1, 0xf9, 0xd8, 0x28, 0x7d, 0xfd,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 0xca, 0x4a, 0xee, 0xc1, + 0xbd, 0x42, 0xf9, 0xac, 0x86, 0xfd, 0x6f, 0x0a, 0x54, 0x3a, 0x34, 0x50, 0xdf, 0x03, 0xb8, 0xb5, + 0xf0, 0xd7, 0xb1, 0x8b, 0xbc, 0x28, 0x98, 0x94, 0xda, 0xd3, 0x6b, 0x12, 0xb2, 0x52, 0xd4, 0x4f, + 0x00, 0xde, 0x5d, 0x3a, 0x57, 0x57, 0x2b, 0x2f, 0x26, 0xd6, 0x9e, 0xff, 0x25, 0x31, 0x2f, 0xed, + 0x03, 0x80, 0xdb, 0x05, 0xf7, 0xd4, 0x5c, 0xa2, 0xbd, 0x98, 0x52, 0x7b, 0x76, 0x6d, 0x4a, 0x56, + 0x88, 0xf3, 0xf2, 0x7c, 0xa2, 0x83, 0x8b, 0x89, 0x0e, 0x7e, 0x4d, 0x74, 0xf0, 0x71, 0xaa, 0x97, + 0x2e, 0xa6, 0x7a, 0xe9, 0xc7, 0x54, 0x2f, 0xbd, 0x69, 0x2e, 0xdd, 0x1e, 0x67, 0x36, 0x1a, 0xb2, + 0xe3, 0x7c, 0x83, 0xf2, 0x65, 0xd2, 0x5b, 0xe1, 0x8b, 0xf3, 0xc9, 0x9f, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xb0, 0xfb, 0x1a, 0x04, 0xcf, 0x05, 0x00, 0x00, } func (this *MsgCreateVestingAccount) Equal(that interface{}) bool { @@ -361,6 +450,9 @@ type MsgClient interface { // CreatePeriodicVestingAccount defines a method that enables creating a // periodic vesting account. 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 { @@ -389,6 +481,15 @@ 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 @@ -397,6 +498,9 @@ type MsgServer interface { // CreatePeriodicVestingAccount defines a method that enables creating a // periodic vesting account. 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. @@ -409,6 +513,9 @@ func (*UnimplementedMsgServer) CreateVestingAccount(ctx context.Context, req *Ms 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) @@ -450,6 +557,24 @@ 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), @@ -462,6 +587,10 @@ 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", @@ -635,6 +764,59 @@ 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 @@ -719,6 +901,28 @@ 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 } @@ -1179,6 +1383,138 @@ 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 From 78e0a1968c0883588bc470dbefd361877b09caf1 Mon Sep 17 00:00:00 2001 From: Yun Date: Fri, 1 Jul 2022 13:06:27 +0900 Subject: [PATCH 2/2] fix comment --- x/auth/vesting/msg_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/auth/vesting/msg_server.go b/x/auth/vesting/msg_server.go index bd61f7d359f4..90a38b5c5746 100644 --- a/x/auth/vesting/msg_server.go +++ b/x/auth/vesting/msg_server.go @@ -179,7 +179,7 @@ func (s msgServer) DonateAllVestingTokens(goCtx context.Context, msg *types.MsgD vestingAcc, ok := acc.(exported.VestingAccount) if !ok { - return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s not vesting account", msg.FromAddress) + return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "account %s is not vesting account", msg.FromAddress) } if !vestingAcc.GetDelegatedVesting().IsZero() {