-
Notifications
You must be signed in to change notification settings - Fork 337
/
proposal.go
122 lines (103 loc) · 4.53 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
110
111
112
113
114
115
116
117
118
119
120
121
122
package types
import (
fmt "fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
// ProposalTypeCommunityPoolLendDeposit defines the type for a CommunityPoolLendDepositProposal
ProposalTypeCommunityPoolLendDeposit = "CommunityPoolLendDeposit"
// ProposalTypeCommunityPoolLendWithdraw defines the type for a CommunityPoolLendDepositProposal
ProposalTypeCommunityPoolLendWithdraw = "CommunityPoolLendWithdraw"
)
// Assert CommunityPoolLendDepositProposal implements govtypes.Content at compile-time
var (
_ govtypes.Content = &CommunityPoolLendDepositProposal{}
_ govtypes.Content = &CommunityPoolLendWithdrawProposal{}
)
func init() {
govtypes.RegisterProposalType(ProposalTypeCommunityPoolLendDeposit)
govtypes.RegisterProposalTypeCodec(&CommunityPoolLendDepositProposal{}, "kava/CommunityPoolLendDepositProposal")
govtypes.RegisterProposalType(ProposalTypeCommunityPoolLendWithdraw)
govtypes.RegisterProposalTypeCodec(&CommunityPoolLendWithdrawProposal{}, "kava/CommunityPoolLendWithdrawProposal")
}
// NewCommunityPoolLendDepositProposal creates a new community pool deposit proposal.
func NewCommunityPoolLendDepositProposal(title, description string, amount sdk.Coins) *CommunityPoolLendDepositProposal {
return &CommunityPoolLendDepositProposal{
Title: title,
Description: description,
Amount: amount,
}
}
// GetTitle returns the title of a community pool lend deposit proposal.
func (p *CommunityPoolLendDepositProposal) GetTitle() string { return p.Title }
// GetDescription returns the description of a community pool lend deposit proposal.
func (p *CommunityPoolLendDepositProposal) GetDescription() string { return p.Description }
// GetDescription returns the routing key of a community pool lend deposit proposal.
func (p *CommunityPoolLendDepositProposal) ProposalRoute() string { return ModuleName }
// ProposalType returns the type of a community pool lend deposit proposal.
func (p *CommunityPoolLendDepositProposal) ProposalType() string {
return ProposalTypeCommunityPoolLendDeposit
}
// String implements fmt.Stringer
func (p *CommunityPoolLendDepositProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Community Pool Lend Deposit Proposal:
Title: %s
Description: %s
Amount: %s
`, p.Title, p.Description, p.Amount))
return b.String()
}
// ValidateBasic stateless validation of a community pool lend deposit proposal.
func (p *CommunityPoolLendDepositProposal) ValidateBasic() error {
if err := govtypes.ValidateAbstract(p); err != nil {
return err
}
// ensure the proposal has valid amount
if !p.Amount.IsValid() || p.Amount.IsZero() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "deposit amount %s", p.Amount)
}
return p.Amount.Validate()
}
// NewCommunityPoolLendWithdrawProposal creates a new community pool lend withdraw proposal.
func NewCommunityPoolLendWithdrawProposal(title, description string, amount sdk.Coins) *CommunityPoolLendWithdrawProposal {
return &CommunityPoolLendWithdrawProposal{
Title: title,
Description: description,
Amount: amount,
}
}
// GetTitle returns the title of a community pool withdraw proposal.
func (p *CommunityPoolLendWithdrawProposal) GetTitle() string { return p.Title }
// GetDescription returns the description of a community pool withdraw proposal.
func (p *CommunityPoolLendWithdrawProposal) GetDescription() string { return p.Description }
// GetDescription returns the routing key of a community pool withdraw proposal.
func (p *CommunityPoolLendWithdrawProposal) ProposalRoute() string { return ModuleName }
// ProposalType returns the type of a community pool withdraw proposal.
func (p *CommunityPoolLendWithdrawProposal) ProposalType() string {
return ProposalTypeCommunityPoolLendWithdraw
}
// String implements fmt.Stringer
func (p *CommunityPoolLendWithdrawProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Community Pool Lend Withdraw Proposal:
Title: %s
Description: %s
Amount: %s
`, p.Title, p.Description, p.Amount))
return b.String()
}
// ValidateBasic stateless validation of a community pool withdraw proposal.
func (p *CommunityPoolLendWithdrawProposal) ValidateBasic() error {
if err := govtypes.ValidateAbstract(p); err != nil {
return err
}
// ensure the proposal has valid amount
if !p.Amount.IsValid() || p.Amount.IsZero() {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidCoins, "withdraw amount %s", p.Amount)
}
return p.Amount.Validate()
}