Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
likhita-809 committed Sep 20, 2023
1 parent 6c9c171 commit a384e45
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 38 deletions.
19 changes: 0 additions & 19 deletions x/distribution/keeper/fee_pool.go

This file was deleted.

41 changes: 23 additions & 18 deletions x/distribution/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ func (k msgServer) WithdrawValidatorCommission(ctx context.Context, msg *types.M
func (k msgServer) FundCommunityPool(ctx context.Context, msg *types.MsgFundCommunityPool) (*types.MsgFundCommunityPoolResponse, error) { //nolint:staticcheck // we're using a deprecated call for compatibility
sdkCtx := sdk.UnwrapSDKContext(ctx)

if err := validateAmount(msg.Amount); err != nil {
return nil, err
}

amount := make([]*basev1beta1.Coin, len(msg.Amount))
for i, coin := range msg.Amount {
amount[i] = &basev1beta1.Coin{
Expand Down Expand Up @@ -164,29 +160,38 @@ func (k msgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams)
}

func (k msgServer) CommunityPoolSpend(ctx context.Context, msg *types.MsgCommunityPoolSpend) (*types.MsgCommunityPoolSpendResponse, error) { //nolint:staticcheck // we're using a deprecated call for compatibility
if err := k.validateAuthority(msg.Authority); err != nil {
return nil, err
}
sdkCtx := sdk.UnwrapSDKContext(ctx)

if err := validateAmount(msg.Amount); err != nil {
return nil, err
amount := make([]*basev1beta1.Coin, len(msg.Amount))
for i, coin := range msg.Amount {
amount[i] = &basev1beta1.Coin{
Denom: coin.Denom,
Amount: coin.Amount.String(),
}
}

recipient, err := k.authKeeper.AddressCodec().StringToBytes(msg.Recipient)
if err != nil {
return nil, err
poolMsg := pooltypes.MsgCommunityPoolSpend{
Authority: msg.Authority,
Recipient: msg.Recipient,
Amount: amount,
}

if k.bankKeeper.BlockedAddr(recipient) {
return nil, errors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", msg.Recipient)
// Pass the msg to the MessageRouter
handler := k.router.Handler(&poolMsg)
if handler == nil {
return nil, fmt.Errorf("message not recognized by router: %s", sdk.MsgTypeURL(&poolMsg))
}

if err := k.DistributeFromFeePool(ctx, msg.Amount, recipient); err != nil {
msgResp, err := handler(sdkCtx, &poolMsg)
if err != nil {
return nil, err
}

logger := k.Logger(ctx)
logger.Info("transferred from the community pool to recipient", "amount", msg.Amount.String(), "recipient", msg.Recipient)
events := msgResp.Events
sdkEvents := make([]sdk.Event, 0, len(events))
for _, event := range events {
sdkEvents = append(sdkEvents, sdk.Event(event))
}
sdkCtx.EventManager().EmitEvents(sdkEvents)

return &types.MsgCommunityPoolSpendResponse{}, nil //nolint:staticcheck // we're using a deprecated call for compatibility
}
Expand Down
1 change: 1 addition & 0 deletions x/distribution/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var (
_ sdk.Msg = (*MsgWithdrawValidatorCommission)(nil)
_ sdk.Msg = (*MsgUpdateParams)(nil)
_ sdk.Msg = (*MsgCommunityPoolSpend)(nil)
_ sdk.Msg = (*MsgFundCommunityPool)(nil)
_ sdk.Msg = (*MsgDepositValidatorRewardsPool)(nil)
)

Expand Down
2 changes: 1 addition & 1 deletion x/pool/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (k MsgServer) CommunityPoolSpend(ctx context.Context, msg *types.MsgCommuni
return nil, err
}

if err := k.DistributeFromFeePool(ctx, msg.Amount, recipient); err != nil {
if err := k.Keeper.DistributeFromFeePool(ctx, msg.Amount, recipient); err != nil {
return nil, err
}

Expand Down
29 changes: 29 additions & 0 deletions x/pool/types/msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
_ sdk.Msg = (*MsgFundCommunityPool)(nil)
_ sdk.Msg = (*MsgCommunityPoolSpend)(nil)
)

// NewMsgFundCommunityPool returns a new MsgFundCommunityPool with a sender and
// a funding amount.
func NewMsgFundCommunityPool(amount sdk.Coins, depositor string) *MsgFundCommunityPool {
return &MsgFundCommunityPool{
Amount: amount,
Depositor: depositor,
}
}

// NewCommunityPoolSpend returns a new CommunityPoolSpend with authority, recipient and
// a spending amount.
func NewCommunityPoolSpend(amount sdk.Coins, authority, recipient string) *MsgCommunityPoolSpend {
return &MsgCommunityPoolSpend{
Authority: authority,
Recipient: recipient,
Amount: amount,
}
}

0 comments on commit a384e45

Please sign in to comment.