-
Notifications
You must be signed in to change notification settings - Fork 339
/
proposal.go
120 lines (101 loc) · 3.73 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
package types
import (
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
const (
// ProposalTypeCommunityPoolMultiSpend defines the type for a CommunityPoolMultiSpendProposal
ProposalTypeCommunityPoolMultiSpend = "CommunityPoolMultiSpend"
)
// Assert CommunityPoolMultiSpendProposal implements govtypes.Content at compile-time
var _ govtypes.Content = CommunityPoolMultiSpendProposal{}
func init() {
govtypes.RegisterProposalType(ProposalTypeCommunityPoolMultiSpend)
govtypes.RegisterProposalTypeCodec(CommunityPoolMultiSpendProposal{}, "kava/CommunityPoolMultiSpendProposal")
}
// CommunityPoolMultiSpendProposal spends from the community pool by sending to one or more addresses
type CommunityPoolMultiSpendProposal struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
RecipientList MultiSpendRecipients `json:"recipient_list" yaml:"recipient_list"`
}
// NewCommunityPoolMultiSpendProposal creates a new community pool multi-spend proposal.
func NewCommunityPoolMultiSpendProposal(title, description string, recipientList MultiSpendRecipients) CommunityPoolMultiSpendProposal {
return CommunityPoolMultiSpendProposal{
Title: title,
Description: description,
RecipientList: recipientList}
}
// GetTitle returns the title of a community pool multi-spend proposal.
func (csp CommunityPoolMultiSpendProposal) GetTitle() string { return csp.Title }
// GetDescription returns the description of a community pool multi-spend proposal.
func (csp CommunityPoolMultiSpendProposal) GetDescription() string { return csp.Description }
// GetDescription returns the routing key of a community pool multi-spend proposal.
func (csp CommunityPoolMultiSpendProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of a community pool multi-spend proposal.
func (csp CommunityPoolMultiSpendProposal) ProposalType() string {
return ProposalTypeCommunityPoolMultiSpend
}
// ValidateBasic stateless validation of a community pool multi-spend proposal.
func (csp CommunityPoolMultiSpendProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(csp)
if err != nil {
return err
}
if err := csp.RecipientList.Validate(); err != nil {
return err
}
return nil
}
// String implements fmt.Stringer
func (csp CommunityPoolMultiSpendProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Community Pool Multi Spend Proposal:
Title: %s
Description: %s
Recipient List: %s
`, csp.Title, csp.Description, csp.RecipientList))
return b.String()
}
// MultiSpendRecipient defines a recipient and the amount of coins they are receiving
type MultiSpendRecipient struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Amount sdk.Coins `json:"amount" yaml:"amount"`
}
// Validate stateless validation of MultiSpendRecipient
func (msr MultiSpendRecipient) Validate() error {
if !msr.Amount.IsValid() {
return ErrInvalidProposalAmount
}
if msr.Address.Empty() {
return ErrEmptyProposalRecipient
}
return nil
}
// String implements fmt.Stringer
func (msr MultiSpendRecipient) String() string {
return fmt.Sprintf(`Receiver: %s
Amount: %s
`, msr.Address, msr.Amount)
}
// MultiSpendRecipients slice of MultiSpendRecipient
type MultiSpendRecipients []MultiSpendRecipient
// Validate stateless validation of MultiSpendRecipients
func (msrs MultiSpendRecipients) Validate() error {
for _, msr := range msrs {
if err := msr.Validate(); err != nil {
return err
}
}
return nil
}
// String implements fmt.Stringer
func (msrs MultiSpendRecipients) String() string {
out := ""
for _, msr := range msrs {
out += msr.String()
}
return out
}