-
Notifications
You must be signed in to change notification settings - Fork 368
/
proposal.go
105 lines (89 loc) · 3.14 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
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")
}
// NewCommunityPoolMultiSpendProposal creates a new community pool multi-spend proposal.
func NewCommunityPoolMultiSpendProposal(title, description string, recipientList []MultiSpendRecipient) *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
}
for _, msr := range csp.RecipientList {
if err := msr.Validate(); err != nil {
return err
}
}
return nil
}
// String implements fmt.Stringer
func (csp CommunityPoolMultiSpendProposal) String() string {
receiptList := ""
for _, msr := range csp.RecipientList {
receiptList += msr.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, receiptList))
return b.String()
}
// Validate stateless validation of MultiSpendRecipient
func (msr MultiSpendRecipient) Validate() error {
if !msr.Amount.IsValid() {
return ErrInvalidProposalAmount
}
if msr.Address == "" {
return ErrEmptyProposalRecipient
}
if _, err := sdk.AccAddressFromBech32(msr.Address); err != nil {
return err
}
return nil
}
// String implements fmt.Stringer
func (msr MultiSpendRecipient) String() string {
return fmt.Sprintf(`Receiver: %s
Amount: %s
`, msr.Address, msr.Amount)
}
// Gets recipient address in sdk.AccAddress
func (msr MultiSpendRecipient) GetAddress() sdk.AccAddress {
addr, err := sdk.AccAddressFromBech32(msr.Address)
if err != nil {
panic(fmt.Errorf("couldn't convert %q to account address: %v", msr.Address, err))
}
return addr
}