mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 03:55:19 +00:00
ffef832d45
- Upgrade cosmos-sdk to v0.44.5 from v0.39.2 - Add Legacy Tx Endpoint for backwards compatibility - Add IBC v1.2.3 Support Co-authored-by: DracoLi <draco@dracoli.com> Co-authored-by: drklee3 <derrick@dlee.dev> Co-authored-by: denalimarsh <denalimarsh@gmail.com> Co-authored-by: Draco Li <draco@kava.io> Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> Co-authored-by: Denali Marsh <denali@kava.io>
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package committee
|
|
|
|
import (
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
"github.com/kava-labs/kava/x/committee/keeper"
|
|
"github.com/kava-labs/kava/x/committee/types"
|
|
)
|
|
|
|
func NewProposalHandler(k keeper.Keeper) govtypes.Handler {
|
|
return func(ctx sdk.Context, content govtypes.Content) error {
|
|
switch c := content.(type) {
|
|
case *types.CommitteeChangeProposal:
|
|
return handleCommitteeChangeProposal(ctx, k, c)
|
|
case *types.CommitteeDeleteProposal:
|
|
return handleCommitteeDeleteProposal(ctx, k, c)
|
|
|
|
default:
|
|
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s proposal content type: %T", types.ModuleName, c)
|
|
}
|
|
}
|
|
}
|
|
|
|
func handleCommitteeChangeProposal(ctx sdk.Context, k keeper.Keeper, committeeProposal *types.CommitteeChangeProposal) error {
|
|
if err := committeeProposal.ValidateBasic(); err != nil {
|
|
return sdkerrors.Wrap(types.ErrInvalidPubProposal, err.Error())
|
|
}
|
|
|
|
// Remove all committee's ongoing proposals
|
|
proposals := k.GetProposalsByCommittee(ctx, committeeProposal.GetNewCommittee().GetID())
|
|
for _, p := range proposals {
|
|
k.CloseProposal(ctx, p, types.Failed)
|
|
}
|
|
|
|
// update/create the committee
|
|
k.SetCommittee(ctx, committeeProposal.GetNewCommittee())
|
|
return nil
|
|
}
|
|
|
|
func handleCommitteeDeleteProposal(ctx sdk.Context, k keeper.Keeper, committeeProposal *types.CommitteeDeleteProposal) error {
|
|
if err := committeeProposal.ValidateBasic(); err != nil {
|
|
return sdkerrors.Wrap(types.ErrInvalidPubProposal, err.Error())
|
|
}
|
|
|
|
// Remove all committee's ongoing proposals
|
|
proposals := k.GetProposalsByCommittee(ctx, committeeProposal.CommitteeID)
|
|
for _, p := range proposals {
|
|
k.CloseProposal(ctx, p, types.Failed)
|
|
}
|
|
|
|
k.DeleteCommittee(ctx, committeeProposal.CommitteeID)
|
|
return nil
|
|
}
|