-
Notifications
You must be signed in to change notification settings - Fork 201
/
gov_reset_rate_limit.go
72 lines (56 loc) · 1.73 KB
/
gov_reset_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 (
ProposalTypeResetRateLimit = "ResetRateLimit"
)
func init() {
govtypes.RegisterProposalType(ProposalTypeResetRateLimit)
}
var (
_ govtypes.Content = &ResetRateLimitProposal{}
)
func NewResetRateLimitProposal(title, description, denom, channelId string) govtypes.Content {
return &ResetRateLimitProposal{
Title: title,
Description: description,
Denom: denom,
ChannelId: channelId,
}
}
func (p *ResetRateLimitProposal) GetTitle() string { return p.Title }
func (p *ResetRateLimitProposal) GetDescription() string { return p.Description }
func (p *ResetRateLimitProposal) ProposalRoute() string { return RouterKey }
func (p *ResetRateLimitProposal) ProposalType() string {
return ProposalTypeResetRateLimit
}
func (p *ResetRateLimitProposal) 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 ResetRateLimitProposal) String() string {
return fmt.Sprintf(`Reset Rate Limit Proposal:
Title: %s
Description: %s
Denom: %s
ChannelId: %s
`, p.Title, p.Description, p.Denom, p.ChannelId)
}