diff --git a/x/farming/client/proposal_handler.go b/x/farming/client/proposal_handler.go index b933d630..a8d00a97 100644 --- a/x/farming/client/proposal_handler.go +++ b/x/farming/client/proposal_handler.go @@ -4,9 +4,10 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/tendermint/farming/x/farming/client/cli" + "github.com/tendermint/farming/x/farming/client/rest" ) // ProposalHandler is the public plan creation handler. var ( - ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, nil) + ProposalHandler = govclient.NewProposalHandler(cli.GetCmdSubmitPublicPlanProposal, rest.ProposalRESTHandler) ) diff --git a/x/farming/client/rest/rest.go b/x/farming/client/rest/rest.go new file mode 100644 index 00000000..53a4b251 --- /dev/null +++ b/x/farming/client/rest/rest.go @@ -0,0 +1,24 @@ +package rest + +import ( + "net/http" + + "github.com/cosmos/cosmos-sdk/client" + govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest" +) + +// TODO: not implemented yet; although this legacy REST API may not be needed, +// it needs for ProposalHandler; otherwise it throws panic when starting the chain + +// ProposalRESTHandler returns a ProposalRESTHandler that exposes the community pool spend REST handler with a given sub-route. +func ProposalRESTHandler(clientCtx client.Context) govrest.ProposalRESTHandler { + return govrest.ProposalRESTHandler{ + SubRoute: "farming_plan", + Handler: postProposalHandlerFn(clientCtx), + } +} + +func postProposalHandlerFn(clientCtx client.Context) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + } +} diff --git a/x/farming/keeper/proposal_handler.go b/x/farming/keeper/proposal_handler.go index 86bfdb9e..65e6ccd0 100644 --- a/x/farming/keeper/proposal_handler.go +++ b/x/farming/keeper/proposal_handler.go @@ -37,10 +37,6 @@ func HandlePublicPlanProposal(ctx sdk.Context, k Keeper, proposal *types.PublicP // AddPublicPlanProposal adds a new public plan once the governance proposal is passed. func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddRequestProposal) error { for _, p := range proposals { - if err := p.Validate(); err != nil { - return err - } - farmingPoolAddrAcc, err := sdk.AccAddressFromBech32(p.GetFarmingPoolAddress()) if err != nil { return err @@ -90,10 +86,6 @@ func (k Keeper) AddPublicPlanProposal(ctx sdk.Context, proposals []*types.AddReq // UpdatePublicPlanProposal overwrites the plan with the new plan proposal once the governance proposal is passed. func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.UpdateRequestProposal) error { for _, proposal := range proposals { - if err := proposal.Validate(); err != nil { - return err - } - plan, found := k.GetPlan(ctx, proposal.GetPlanId()) if !found { return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", proposal.GetPlanId()) @@ -169,10 +161,6 @@ func (k Keeper) UpdatePublicPlanProposal(ctx sdk.Context, proposals []*types.Upd // DeletePublicPlanProposal delets public plan proposal once the governance proposal is passed. func (k Keeper) DeletePublicPlanProposal(ctx sdk.Context, proposals []*types.DeleteRequestProposal) error { for _, p := range proposals { - if err := p.Validate(); err != nil { - return err - } - plan, found := k.GetPlan(ctx, p.GetPlanId()) if !found { return sdkerrors.Wrapf(sdkerrors.ErrNotFound, "plan %d is not found", p.GetPlanId()) diff --git a/x/farming/types/proposal.go b/x/farming/types/proposal.go index 142818b2..48e1ebd1 100644 --- a/x/farming/types/proposal.go +++ b/x/farming/types/proposal.go @@ -43,6 +43,21 @@ func (p *PublicPlanProposal) ValidateBasic() error { if p.AddRequestProposals == nil && p.UpdateRequestProposals == nil && p.DeleteRequestProposals == nil { return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "proposal request must not be empty") } + for _, ap := range p.AddRequestProposals { + if err := ap.Validate(); err != nil { + return err + } + } + for _, up := range p.UpdateRequestProposals { + if err := up.Validate(); err != nil { + return err + } + } + for _, dp := range p.DeleteRequestProposals { + if err := dp.Validate(); err != nil { + return err + } + } return gov.ValidateAbstract(p) }