/
proposal.go
68 lines (53 loc) · 2.06 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
package types
import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
const (
// UpdateSymbolRequest defines the type for a UpdateSymbolRequestProposal
UpdateSymbolRequest = "UpdateSymbolRequest"
)
// Assert UpdateSymbolRequestProposal implements govtypes.Content at compile-time
var _ govtypes.Content = &UpdateSymbolRequestProposal{}
func init() {
govtypes.RegisterProposalType(UpdateSymbolRequest)
}
func NewUpdateSymbolRequestProposal(
title, description string, symbolRequests []SymbolRequest,
) *UpdateSymbolRequestProposal {
return &UpdateSymbolRequestProposal{title, description, symbolRequests}
}
// GetTitle returns the title of a update symbol request proposal.
func (p *UpdateSymbolRequestProposal) GetTitle() string { return p.Title }
// GetDescription returns the description of a update symbol request proposal.
func (p *UpdateSymbolRequestProposal) GetDescription() string { return p.Description }
// ProposalRoute returns the routing key of a update symbol request proposal.
func (*UpdateSymbolRequestProposal) ProposalRoute() string { return RouterKey }
// ProposalType returns the type of a update symbol request proposal.
func (*UpdateSymbolRequestProposal) ProposalType() string { return UpdateSymbolRequest }
// ValidateBasic validates the update symbol request proposal.
func (p *UpdateSymbolRequestProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
return ValidateSymbolRequests(p.SymbolRequests)
}
func NewSymbolRequest(symbol string, oracleScriptID, interval uint64) SymbolRequest {
return SymbolRequest{symbol, oracleScriptID, interval}
}
// ValidateSymbolRequests performs basic validation checks over a set of SymbolRequest. It
// returns an error if any SymbolRequest is invalid.
func ValidateSymbolRequests(symbols []SymbolRequest) error {
if len(symbols) == 0 {
return ErrEmptySymbolRequests
}
for _, s := range symbols {
if len(s.Symbol) == 0 {
return ErrEmptySymbol
}
if s.BlockInterval != 0 && s.OracleScriptID == 0 {
return ErrInvalidOracleScriptID
}
}
return nil
}