-
Notifications
You must be signed in to change notification settings - Fork 57
/
proposal_handler.go
34 lines (27 loc) · 1.26 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
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/peggyjv/gravity-bridge/module/v3/x/gravity/types"
)
func (k Keeper) HandleCommunityPoolEthereumSpendProposal(ctx sdk.Context, p *types.CommunityPoolEthereumSpendProposal) error {
feePool := k.DistributionKeeper.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 createSendToEthereum calls
totalToSpend := p.Amount.Add(p.BridgeFee)
newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoinsFromCoins(totalToSpend))
if negative {
return distributiontypes.ErrBadDistribution
}
feePool.CommunityPool = newPool
sender := authtypes.NewModuleAddress(distributiontypes.ModuleName)
txID, err := k.createSendToEthereum(ctx, sender, p.Recipient, p.Amount, p.BridgeFee)
if err != nil {
return err
}
k.DistributionKeeper.SetFeePool(ctx, feePool)
k.Logger(ctx).Info("transfer from the community pool created as unbatched send to Ethereum", "tx ID", txID, "amount", p.Amount.String(), "recipient", p.Recipient)
return nil
}