2020-03-04 19:16:27 +00:00
|
|
|
package committee
|
2020-03-04 16:55:12 +00:00
|
|
|
|
2020-03-21 18:06:58 +00:00
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-27 18:19:05 +00:00
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
2023-04-04 00:08:45 +00:00
|
|
|
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/kava-labs/kava/x/committee/keeper"
|
2021-06-07 16:08:03 +00:00
|
|
|
"github.com/kava-labs/kava/x/committee/types"
|
2020-03-21 18:06:58 +00:00
|
|
|
)
|
|
|
|
|
2023-04-04 00:08:45 +00:00
|
|
|
func NewProposalHandler(k keeper.Keeper) govv1beta1.Handler {
|
|
|
|
return func(ctx sdk.Context, content govv1beta1.Content) error {
|
2020-03-21 18:06:58 +00:00
|
|
|
switch c := content.(type) {
|
2022-01-08 00:39:27 +00:00
|
|
|
case *types.CommitteeChangeProposal:
|
2020-03-21 18:06:58 +00:00
|
|
|
return handleCommitteeChangeProposal(ctx, k, c)
|
2022-01-08 00:39:27 +00:00
|
|
|
case *types.CommitteeDeleteProposal:
|
2020-03-21 18:06:58 +00:00
|
|
|
return handleCommitteeDeleteProposal(ctx, k, c)
|
|
|
|
|
|
|
|
default:
|
2022-01-08 00:39:27 +00:00
|
|
|
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c)
|
2020-03-21 18:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func handleCommitteeChangeProposal(ctx sdk.Context, k keeper.Keeper, committeeProposal *types.CommitteeChangeProposal) error {
|
2020-03-21 18:06:58 +00:00
|
|
|
if err := committeeProposal.ValidateBasic(); err != nil {
|
2022-01-08 00:39:27 +00:00
|
|
|
return sdkerrors.Wrap(types.ErrInvalidPubProposal, err.Error())
|
2020-03-21 18:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all committee's ongoing proposals
|
2022-01-08 00:39:27 +00:00
|
|
|
proposals := k.GetProposalsByCommittee(ctx, committeeProposal.GetNewCommittee().GetID())
|
2020-05-15 19:25:49 +00:00
|
|
|
for _, p := range proposals {
|
2021-06-07 16:08:03 +00:00
|
|
|
k.CloseProposal(ctx, p, types.Failed)
|
2020-05-15 19:25:49 +00:00
|
|
|
}
|
2020-03-21 18:06:58 +00:00
|
|
|
|
|
|
|
// update/create the committee
|
2022-01-08 00:39:27 +00:00
|
|
|
k.SetCommittee(ctx, committeeProposal.GetNewCommittee())
|
2020-03-21 18:06:58 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func handleCommitteeDeleteProposal(ctx sdk.Context, k keeper.Keeper, committeeProposal *types.CommitteeDeleteProposal) error {
|
2020-03-21 18:06:58 +00:00
|
|
|
if err := committeeProposal.ValidateBasic(); err != nil {
|
2022-01-08 00:39:27 +00:00
|
|
|
return sdkerrors.Wrap(types.ErrInvalidPubProposal, err.Error())
|
2020-03-21 18:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all committee's ongoing proposals
|
2020-05-15 19:25:49 +00:00
|
|
|
proposals := k.GetProposalsByCommittee(ctx, committeeProposal.CommitteeID)
|
|
|
|
for _, p := range proposals {
|
2021-06-07 16:08:03 +00:00
|
|
|
k.CloseProposal(ctx, p, types.Failed)
|
2020-05-15 19:25:49 +00:00
|
|
|
}
|
2020-03-21 18:06:58 +00:00
|
|
|
|
|
|
|
k.DeleteCommittee(ctx, committeeProposal.CommitteeID)
|
|
|
|
return nil
|
|
|
|
}
|