-
Notifications
You must be signed in to change notification settings - Fork 182
/
proposal_handler.go
49 lines (39 loc) · 1.58 KB
/
proposal_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/okex/okexchain/x/distribution/types"
)
// HandleCommunityPoolSpendProposal is a handler for executing a passed community spend proposal
func HandleCommunityPoolSpendProposal(ctx sdk.Context, k Keeper, p types.CommunityPoolSpendProposal) error {
if k.blacklistedAddrs[p.Recipient.String()] {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is blacklisted from receiving external funds", p.Recipient)
}
err := k.distributeFromFeePool(ctx, p.Amount, p.Recipient)
if err != nil {
return err
}
logger := k.Logger(ctx)
logger.Info(fmt.Sprintf("transferred %s from the community pool to recipient %s", p.Amount, p.Recipient))
return nil
}
// distributeFromFeePool distributes funds from the distribution module account to
// a receiver address while updating the community pool
func (k Keeper) distributeFromFeePool(ctx sdk.Context, amount sdk.Coins, receiveAddr sdk.AccAddress) error {
feePool := k.GetFeePool(ctx)
// 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(amount)
if negative {
return types.ErrBadDistribution()
}
feePool.CommunityPool = newPool
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, receiveAddr, amount)
if err != nil {
return err
}
k.SetFeePool(ctx, feePool)
return nil
}