-
Notifications
You must be signed in to change notification settings - Fork 182
/
proposal.go
109 lines (89 loc) · 3.01 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package types
import (
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/okex/okexchain/x/gov/types"
)
const (
proposalTypeDelist = "Delist"
)
func init() {
govtypes.RegisterProposalType(proposalTypeDelist)
govtypes.RegisterProposalTypeCodec(DelistProposal{}, "okexchain/dex/DelistProposal")
}
// Assert DelistProposal implements govtypes.Content at compile-time
var _ govtypes.Content = (*DelistProposal)(nil)
// DelistProposal represents delist proposal object
type DelistProposal struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
Proposer sdk.AccAddress `json:"proposer" yaml:"proposer"`
BaseAsset string `json:"base_asset" yaml:"base_asset"`
QuoteAsset string `json:"quote_asset" yaml:"quote_asset"`
}
// NewDelistProposal create a new delist proposal object
func NewDelistProposal(title, description string, proposer sdk.AccAddress, baseAsset, quoteAsset string) DelistProposal {
return DelistProposal{
Title: title,
Description: description,
Proposer: proposer,
BaseAsset: baseAsset,
QuoteAsset: quoteAsset,
}
}
// GetTitle returns title of delist proposal object
func (drp DelistProposal) GetTitle() string {
return drp.Title
}
// GetDescription returns description of delist proposal object
func (drp DelistProposal) GetDescription() string {
return drp.Description
}
// ProposalRoute returns route key of delist proposal object
func (DelistProposal) ProposalRoute() string {
return RouterKey
}
// ProposalType returns type of delist proposal object
func (DelistProposal) ProposalType() string {
return proposalTypeDelist
}
// ValidateBasic validates delist proposal
func (drp DelistProposal) ValidateBasic() sdk.Error {
if len(strings.TrimSpace(drp.Title)) == 0 {
return govtypes.ErrInvalidProposalContent("title is required")
}
if len(drp.Title) > govtypes.MaxTitleLength {
return govtypes.ErrInvalidProposalContent("title length is longer than the max")
}
if len(drp.Description) == 0 {
return govtypes.ErrInvalidProposalContent("description is required")
}
if len(drp.Description) > govtypes.MaxDescriptionLength {
return govtypes.ErrInvalidProposalContent("description length is longer than the max")
}
if drp.ProposalType() != proposalTypeDelist {
return govtypes.ErrInvalidProposalType(drp.ProposalType())
}
if drp.Proposer.Empty() {
return sdk.ErrInvalidAddress(drp.Proposer.String())
}
if drp.BaseAsset == drp.QuoteAsset {
return sdk.ErrInvalidCoins(fmt.Sprintf("failed to submit delist proposal because baseasset is same as quoteasset"))
}
return nil
}
// String converts delist proposal object to string
func (drp DelistProposal) String() string {
return fmt.Sprintf(`DelistProposal:
Title: %s
Description: %s
Type: %s
Proposer: %s
ListAsset %s
QuoteAsset %s
`, drp.Title, drp.Description,
drp.ProposalType(), drp.Proposer,
drp.BaseAsset, drp.QuoteAsset,
)
}