-
Notifications
You must be signed in to change notification settings - Fork 182
/
proposal.go
85 lines (70 loc) · 2.69 KB
/
proposal.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package keeper
import (
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/okex/exchain/x/farm/types"
sdkGov "github.com/okex/exchain/x/gov"
govKeeper "github.com/okex/exchain/x/gov/keeper"
govTypes "github.com/okex/exchain/x/gov/types"
)
var _ govKeeper.ProposalHandler = (*Keeper)(nil)
// GetMinDeposit returns min deposit
func (k Keeper) GetMinDeposit(ctx sdk.Context, content sdkGov.Content) (minDeposit sdk.SysCoins) {
if _, ok := content.(types.ManageWhiteListProposal); ok {
minDeposit = k.govKeeper.GetDepositParams(ctx).MinDeposit
}
return
}
// GetMaxDepositPeriod returns max deposit period
func (k Keeper) GetMaxDepositPeriod(ctx sdk.Context, content sdkGov.Content) (maxDepositPeriod time.Duration) {
if _, ok := content.(types.ManageWhiteListProposal); ok {
maxDepositPeriod = k.govKeeper.GetDepositParams(ctx).MaxDepositPeriod
}
return
}
// GetVotingPeriod returns voting period
func (k Keeper) GetVotingPeriod(ctx sdk.Context, content sdkGov.Content) (votingPeriod time.Duration) {
if _, ok := content.(types.ManageWhiteListProposal); ok {
votingPeriod = k.govKeeper.GetVotingParams(ctx).VotingPeriod
}
return
}
// CheckMsgSubmitProposal validates MsgSubmitProposal
func (k Keeper) CheckMsgSubmitProposal(ctx sdk.Context, msg govTypes.MsgSubmitProposal) sdk.Error {
switch content := msg.Content.(type) {
case types.ManageWhiteListProposal:
return k.CheckMsgManageWhiteListProposal(ctx, content)
default:
return sdk.ErrUnknownRequest(fmt.Sprintf("unrecognized dex proposal content type: %T", content))
}
}
// nolint
func (k Keeper) AfterSubmitProposalHandler(_ sdk.Context, _ govTypes.Proposal) {}
func (k Keeper) AfterDepositPeriodPassed(_ sdk.Context, _ govTypes.Proposal) {}
func (k Keeper) RejectedHandler(_ sdk.Context, _ govTypes.Content) {}
func (k Keeper) VoteHandler(_ sdk.Context, _ govTypes.Proposal, _ govTypes.Vote) (string, sdk.Error) {
return "", nil
}
// CheckMsgManageWhiteListProposal checks msg manage white list proposal
func (k Keeper) CheckMsgManageWhiteListProposal(ctx sdk.Context, proposal types.ManageWhiteListProposal) sdk.Error {
if proposal.IsAdded {
// add pool name into white list
// 1. check the existence
pool, found := k.GetFarmPool(ctx, proposal.PoolName)
if !found {
return types.ErrNoFarmPoolFound(proposal.PoolName)
}
// 2. check the swap token pair
if sdkErr := k.satisfyWhiteListAdmittance(ctx, pool); sdkErr != nil {
return sdkErr
}
return nil
}
// delete the pool name from the white list
// 1. check the existence of the pool name in whitelist
if !k.isPoolNameExistedInWhiteList(ctx, proposal.PoolName) {
return types.ErrPoolNameNotExistedInWhiteList(proposal.PoolName)
}
return nil
}