2019-05-21 03:02:10 -07:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-12-27 09:57:54 -08:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2019-05-21 03:02:10 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/distribution/types"
|
|
|
|
)
|
|
|
|
|
2019-06-28 13:11:27 -07:00
|
|
|
// HandleCommunityPoolSpendProposal is a handler for executing a passed community spend proposal
|
2020-04-14 12:05:14 -07:00
|
|
|
func HandleCommunityPoolSpendProposal(ctx sdk.Context, k Keeper, p *types.CommunityPoolSpendProposal) error {
|
2020-09-25 03:25:37 -07:00
|
|
|
if k.blockedAddrs[p.Recipient] {
|
2020-06-17 06:32:49 -07:00
|
|
|
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive external funds", p.Recipient)
|
2019-08-02 05:29:00 -07:00
|
|
|
}
|
2020-09-25 03:25:37 -07:00
|
|
|
recipient, addrErr := sdk.AccAddressFromBech32(p.Recipient)
|
|
|
|
if addrErr != nil {
|
|
|
|
return addrErr
|
|
|
|
}
|
|
|
|
err := k.DistributeFromFeePool(ctx, p.Amount, recipient)
|
2019-05-21 03:02:10 -07:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-06-28 13:11:27 -07:00
|
|
|
|
2019-05-21 03:02:10 -07:00
|
|
|
logger := k.Logger(ctx)
|
2019-06-28 13:11:27 -07:00
|
|
|
logger.Info(fmt.Sprintf("transferred %s from the community pool to recipient %s", p.Amount, p.Recipient))
|
2019-05-21 03:02:10 -07:00
|
|
|
return nil
|
|
|
|
}
|