github.com/Finschia/finschia-sdk@v0.48.1/x/distribution/keeper/fee_pool.go (about)

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