-
Notifications
You must be signed in to change notification settings - Fork 197
/
gov_remove_rate_limit.go
72 lines (56 loc) · 1.74 KB
/
gov_remove_rate_limit.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
package types
import (
"fmt"
"regexp"
errorsmod "cosmossdk.io/errors"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)
const (
ProposalTypeRemoveRateLimit = "RemoveRateLimit"
)
func init() {
govtypes.RegisterProposalType(ProposalTypeRemoveRateLimit)
}
var (
_ govtypes.Content = &RemoveRateLimitProposal{}
)
func NewRemoveRateLimitProposal(title, description, denom, channelId string) govtypes.Content {
return &RemoveRateLimitProposal{
Title: title,
Description: description,
Denom: denom,
ChannelId: channelId,
}
}
func (p *RemoveRateLimitProposal) GetTitle() string { return p.Title }
func (p *RemoveRateLimitProposal) GetDescription() string { return p.Description }
func (p *RemoveRateLimitProposal) ProposalRoute() string { return RouterKey }
func (p *RemoveRateLimitProposal) ProposalType() string {
return ProposalTypeRemoveRateLimit
}
func (p *RemoveRateLimitProposal) ValidateBasic() error {
err := govtypes.ValidateAbstract(p)
if err != nil {
return err
}
if p.Denom == "" {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid denom (%s)", p.Denom)
}
matched, err := regexp.MatchString(`^channel-\d+$`, p.ChannelId)
if err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "unable to verify channel-id (%s)", p.ChannelId)
}
if !matched {
return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "invalid channel-id (%s), must be of the format 'channel-{N}'", p.ChannelId)
}
return nil
}
func (p RemoveRateLimitProposal) String() string {
return fmt.Sprintf(`Remove Rate Limit Proposal:
Title: %s
Description: %s
Denom: %s
ChannelId: %s
`, p.Title, p.Description, p.Denom, p.ChannelId)
}