github.com/cosmos/cosmos-sdk@v0.50.10/x/distribution/keeper/fee_pool.go (about)

     1  package keeper
     2  
     3  import (
     4  	"context"
     5  
     6  	sdk "github.com/cosmos/cosmos-sdk/types"
     7  	"github.com/cosmos/cosmos-sdk/x/distribution/types"
     8  )
     9  
    10  // DistributeFromFeePool distributes funds from the distribution module account to
    11  // a receiver address while updating the community pool
    12  func (k Keeper) DistributeFromFeePool(ctx context.Context, amount sdk.Coins, receiveAddr sdk.AccAddress) error {
    13  	feePool, err := k.FeePool.Get(ctx)
    14  	if err != nil {
    15  		return err
    16  	}
    17  
    18  	// NOTE the community pool isn't a module account, however its coins
    19  	// are held in the distribution module account. Thus the community pool
    20  	// must be reduced separately from the SendCoinsFromModuleToAccount call
    21  	newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoinsFromCoins(amount...))
    22  	if negative {
    23  		return types.ErrBadDistribution
    24  	}
    25  
    26  	feePool.CommunityPool = newPool
    27  
    28  	err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount)
    29  	if err != nil {
    30  		return err
    31  	}
    32  
    33  	return k.FeePool.Set(ctx, feePool)
    34  }