35 lines
1015 B
Go
35 lines
1015 B
Go
package keeper
|
|
|
|
import (
|
|
"context"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
|
)
|
|
|
|
// DistributeFromFeePool distributes funds from the distribution module account to
|
|
// a receiver address while updating the community pool
|
|
func (k Keeper) DistributeFromFeePool(ctx context.Context, amount sdk.Coins, receiveAddr sdk.AccAddress) error {
|
|
feePool, err := k.FeePool.Get(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 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
|
|
newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoinsFromCoins(amount...))
|
|
if negative {
|
|
return types.ErrBadDistribution
|
|
}
|
|
|
|
feePool.CommunityPool = newPool
|
|
|
|
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return k.FeePool.Set(ctx, feePool)
|
|
}
|