github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/distribution/keeper/proposal_handler.go (about) 1 package keeper 2 3 import ( 4 "fmt" 5 6 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 7 sdkerrors "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/errors" 8 9 "github.com/fibonacci-chain/fbc/x/distribution/types" 10 ) 11 12 // HandleCommunityPoolSpendProposal is a handler for executing a passed community spend proposal 13 func HandleCommunityPoolSpendProposal(ctx sdk.Context, k Keeper, p types.CommunityPoolSpendProposal) error { 14 if k.blacklistedAddrs[p.Recipient.String()] { 15 return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is blacklisted from receiving external funds", p.Recipient) 16 } 17 18 err := k.distributeFromFeePool(ctx, p.Amount, p.Recipient) 19 if err != nil { 20 return err 21 } 22 23 logger := k.Logger(ctx) 24 logger.Info(fmt.Sprintf("transferred %s from the community pool to recipient %s", p.Amount, p.Recipient)) 25 return nil 26 } 27 28 // distributeFromFeePool distributes funds from the distribution module account to 29 // a receiver address while updating the community pool 30 func (k Keeper) distributeFromFeePool(ctx sdk.Context, amount sdk.Coins, receiveAddr sdk.AccAddress) error { 31 feePool := k.GetFeePool(ctx) 32 33 // NOTE the community pool isn't a module account, however its coins 34 // are held in the distribution module account. Thus the community pool 35 // must be reduced separately from the SendCoinsFromModuleToAccount call 36 newPool, negative := feePool.CommunityPool.SafeSub(amount) 37 if negative { 38 return types.ErrBadDistribution() 39 } 40 feePool.CommunityPool = newPool 41 42 err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount) 43 if err != nil { 44 return err 45 } 46 47 k.SetFeePool(ctx, feePool) 48 return nil 49 }