2019-03-28 16:27:47 -07:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
|
|
|
)
|
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
// DistributeFromFeePool distributes funds from the distribution module account to
|
|
|
|
// a receiver address while updating the community pool
|
2019-12-27 09:57:54 -08:00
|
|
|
func (k Keeper) DistributeFromFeePool(ctx sdk.Context, amount sdk.Coins, receiveAddr sdk.AccAddress) error {
|
2019-03-28 16:27:47 -07:00
|
|
|
feePool := k.GetFeePool(ctx)
|
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
// NOTE the community pool isn't a module account, however its coins
|
|
|
|
// are held in the distribution module account. Thus the community pool
|
|
|
|
// must be reduced separately from the SendCoinsFromModuleToAccount call
|
2020-01-03 12:44:53 -08:00
|
|
|
newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoinsFromCoins(amount...))
|
2019-06-28 13:11:27 -07:00
|
|
|
if negative {
|
2019-12-27 09:57:54 -08:00
|
|
|
return types.ErrBadDistribution
|
2019-03-28 16:27:47 -07:00
|
|
|
}
|
2019-12-27 09:57:54 -08:00
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
feePool.CommunityPool = newPool
|
2019-03-28 16:27:47 -07:00
|
|
|
|
2020-04-20 08:22:12 -07:00
|
|
|
err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount)
|
2019-03-28 16:27:47 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
k.SetFeePool(ctx, feePool)
|
|
|
|
return nil
|
|
|
|
}
|