/
proposal_handler.go
41 lines (36 loc) · 1.29 KB
/
proposal_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package farm
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/omexapp/omexchain/x/common"
"github.com/omexapp/omexchain/x/farm/types"
govTypes "github.com/omexapp/omexchain/x/gov/types"
)
// NewManageWhiteListProposalHandler handles "gov" type message in "farm"
func NewManageWhiteListProposalHandler(k *Keeper) govTypes.Handler {
return func(ctx sdk.Context, proposal *govTypes.Proposal) (err sdk.Error) {
switch content := proposal.Content.(type) {
case types.ManageWhiteListProposal:
return handleManageWhiteListProposal(ctx, k, proposal)
default:
return common.ErrUnknownProposalType(DefaultCodespace, content.ProposalType())
}
}
}
func handleManageWhiteListProposal(ctx sdk.Context, k *Keeper, proposal *govTypes.Proposal) sdk.Error {
// check
manageWhiteListProposal, ok := proposal.Content.(types.ManageWhiteListProposal)
if !ok {
return types.ErrUnexpectedProposalType(proposal.Content.ProposalType())
}
if sdkErr := k.CheckMsgManageWhiteListProposal(ctx, manageWhiteListProposal); sdkErr != nil {
return sdkErr
}
if manageWhiteListProposal.IsAdded {
// add pool name into whitelist
k.SetWhitelist(ctx, manageWhiteListProposal.PoolName)
return nil
}
// remove pool name from whitelist
k.DeleteWhiteList(ctx, manageWhiteListProposal.PoolName)
return nil
}