github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/farm/types/proposal.go (about) 1 package types 2 3 import ( 4 "fmt" 5 "strings" 6 7 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 8 govtypes "github.com/fibonacci-chain/fbc/x/gov/types" 9 ) 10 11 const ( 12 // proposalTypeManageWhiteList defines the type for a ManageWhiteListProposal 13 proposalTypeManageWhiteList = "ManageWhiteList" 14 ) 15 16 func init() { 17 govtypes.RegisterProposalType(proposalTypeManageWhiteList) 18 govtypes.RegisterProposalTypeCodec(ManageWhiteListProposal{}, "fbexchain/farm/ManageWhiteListProposal") 19 } 20 21 var _ govtypes.Content = (*ManageWhiteListProposal)(nil) 22 23 // ManageWhiteListProposal - structure for the proposal to add or delete a pool name from white list 24 type ManageWhiteListProposal struct { 25 Title string `json:"title" yaml:"title"` 26 Description string `json:"description" yaml:"description"` 27 PoolName string `json:"pool_name" yaml:"pool_name"` 28 IsAdded bool `json:"is_added" yaml:"is_added"` 29 } 30 31 // NewManageWhiteListProposal creates a new instance of ManageWhiteListProposal 32 func NewManageWhiteListProposal(title, description, poolName string, isAdded bool) ManageWhiteListProposal { 33 return ManageWhiteListProposal{ 34 Title: title, 35 Description: description, 36 PoolName: poolName, 37 IsAdded: isAdded, 38 } 39 } 40 41 // GetTitle returns title of a manage white list proposal object 42 func (mp ManageWhiteListProposal) GetTitle() string { 43 return mp.Title 44 } 45 46 // GetDescription returns description of a manage white list proposal object 47 func (mp ManageWhiteListProposal) GetDescription() string { 48 return mp.Description 49 } 50 51 // ProposalRoute returns route key of a manage white list proposal object 52 func (mp ManageWhiteListProposal) ProposalRoute() string { 53 return RouterKey 54 } 55 56 // ProposalType returns type of a manage white list proposal object 57 func (mp ManageWhiteListProposal) ProposalType() string { 58 return proposalTypeManageWhiteList 59 } 60 61 // ValidateBasic validates a manage white list proposal 62 func (mp ManageWhiteListProposal) ValidateBasic() sdk.Error { 63 if len(strings.TrimSpace(mp.Title)) == 0 { 64 return govtypes.ErrInvalidProposalContent("title is required") 65 } 66 if len(mp.Title) > govtypes.MaxTitleLength { 67 return govtypes.ErrInvalidProposalContent("title length is longer than the maximum title length") 68 } 69 70 if len(mp.Description) == 0 { 71 return govtypes.ErrInvalidProposalContent("description is required") 72 } 73 74 if len(mp.Description) > govtypes.MaxDescriptionLength { 75 return govtypes.ErrInvalidProposalContent("description length is longer than the maximum description length") 76 } 77 78 if mp.ProposalType() != proposalTypeManageWhiteList { 79 return govtypes.ErrInvalidProposalType(mp.ProposalType()) 80 } 81 82 if len(mp.PoolName) == 0 { 83 return govtypes.ErrInvalidProposalContent("pool name is required") 84 } 85 86 return nil 87 } 88 89 // String returns a human readable string representation of a ManageWhiteListProposal 90 func (mp ManageWhiteListProposal) String() string { 91 return fmt.Sprintf(`ManagerWhiteListProposal: 92 Title: %s 93 Description: %s 94 Type: %s 95 PoolName: %s 96 IsAdded: %t`, 97 mp.Title, mp.Description, mp.ProposalType(), mp.PoolName, mp.IsAdded) 98 }