-
Notifications
You must be signed in to change notification settings - Fork 202
/
delproposal.go
67 lines (51 loc) · 1.69 KB
/
delproposal.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
package types
import (
fmt "fmt"
"strings"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
sdkerrors "cosmossdk.io/errors"
commontypes "github.com/lavanet/lava/common/types"
)
const (
ProposalPlansDel = "PlansDel"
)
func init() {
v1beta1.RegisterProposalType(ProposalPlansDel)
}
func NewPlansDelProposal(title, description string, indices []string) *PlansDelProposal {
return &PlansDelProposal{title, description, indices}
}
// GetTitle returns the title of a proposal.
func (pcp *PlansDelProposal) GetTitle() string { return pcp.Title }
// GetDescription returns the description of a proposal.
func (pcp *PlansDelProposal) GetDescription() string { return pcp.Description }
// ProposalRoute returns the routing key of a proposal.
func (pcp *PlansDelProposal) ProposalRoute() string { return ProposalsRouterKey }
// ProposalType returns the type of a proposal.
func (pcp *PlansDelProposal) ProposalType() string { return ProposalPlansDel }
// ValidateBasic validates the proposal
func (pcp *PlansDelProposal) ValidateBasic() error {
err := v1beta1.ValidateAbstract(pcp)
if err != nil {
return err
}
if len(pcp.Plans) == 0 {
return sdkerrors.Wrap(ErrEmptyPlans, "proposal plans delete cannot be empty")
}
for _, index := range pcp.Plans {
if !commontypes.ValidateString(index, commontypes.NAME_RESTRICTIONS, nil) {
return fmt.Errorf("invalid plan name: %s", index)
}
}
return nil
}
// String implements the Stringer interface.
func (pcp PlansDelProposal) String() string {
var b strings.Builder
b.WriteString(fmt.Sprintf(`Plan Del Proposal:
Title: %s
Description: %s
Deleted: %s
`, pcp.Title, pcp.Description, strings.Join(pcp.Plans, ", ")))
return b.String()
}