-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
68 lines (56 loc) · 1.66 KB
/
types.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
package types
import (
"fmt"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov"
)
// Tokens is a struct that contains all the token issued as vote right
type Issuers struct {
Owner sdk.AccAddress
Tokens sdk.Coins
}
// Returns a new Issuers with the minprice as the price
func NewIssuers() Issuers {
return Issuers{}
}
// implement fmt.Stringer
func (i Issuers) String() string {
return strings.TrimSpace(fmt.Sprintf(`Owner: %s
Tokens: %s`, i.Owner, i.Tokens))
}
// Proposal types
const (
ProposalTypeText string = "Text"
)
// Text Proposal
type TextProposal struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description" yaml:"description"`
}
func NewTextProposal(title, description string) Content {
return TextProposal{title, description}
}
// Implements Proposal Interface
var _ Content = TextProposal{}
// nolint
func (tp TextProposal) GetTitle() string { return tp.Title }
func (tp TextProposal) GetDescription() string { return tp.Description }
func (tp TextProposal) ProposalRoute() string { return RouterKey }
func (tp TextProposal) ProposalType() string { return ProposalTypeText }
func (tp TextProposal) ValidateBasic() sdk.Error { return gov.ValidateAbstract(DefaultCodespace, tp) }
func (tp TextProposal) String() string {
return fmt.Sprintf(`Text Proposal:
Title: %s
Description: %s
`, tp.Title, tp.Description)
}
// ContentFromProposalType returns a Content object based on the proposal type.
func ContentFromProposalType(title, desc, ty string) Content {
switch ty {
case ProposalTypeText:
return NewTextProposal(title, desc)
default:
return nil
}
}