cosmos-sdk/x/distribution/keeper/proposal_handler.go
Christopher Goes dd89c32951 Community pool spend proposal (#4329)
Implement the "CommunityPoolSpendProposal" as described in Cosmos Hub proposal 7.

Also a useful test of Git flow for merging features passed in governance proposals.
2019-05-21 11:02:10 +01:00

26 lines
719 B
Go

package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)
func HandleCommunityPoolSpendProposal(ctx sdk.Context, k Keeper, p types.CommunityPoolSpendProposal) sdk.Error {
feePool := k.GetFeePool(ctx)
newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoins(p.Amount))
if negative {
return types.ErrBadDistribution(k.codespace)
}
feePool.CommunityPool = newPool
k.SetFeePool(ctx, feePool)
_, err := k.bankKeeper.AddCoins(ctx, p.Recipient, p.Amount)
if err != nil {
return err
}
logger := k.Logger(ctx)
logger.Info(fmt.Sprintf("Spent %s coins from the community pool to recipient %s", p.Amount, p.Recipient))
return nil
}