/
msgs.go
87 lines (71 loc) · 2.2 KB
/
msgs.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package types
import (
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/umee-network/umee/v5/util/checkers"
"gopkg.in/yaml.v3"
)
var _ sdk.Msg = &MsgGovUpdateRegistry{}
// NewMsgUpdateRegistry will create a new MsgUpdateRegistry instance
func NewMsgUpdateRegistry(authority, title, description string, updateTokens, addTokens []Token) *MsgGovUpdateRegistry {
return &MsgGovUpdateRegistry{
Title: title,
Description: description,
UpdateTokens: updateTokens,
AddTokens: addTokens,
Authority: authority,
}
}
// Type implements Msg interface
func (msg MsgGovUpdateRegistry) Type() string { return sdk.MsgTypeURL(&msg) }
// String implements the Stringer interface.
func (msg MsgGovUpdateRegistry) String() string {
out, _ := yaml.Marshal(msg)
return string(out)
}
// ValidateBasic implements Msg
func (msg MsgGovUpdateRegistry) ValidateBasic() error {
if err := checkers.ValidateProposal(msg.Title, msg.Description, msg.Authority); err != nil {
return err
}
if len(msg.AddTokens) == 0 && len(msg.UpdateTokens) == 0 {
return ErrEmptyAddAndUpdateTokens
}
if err := validateRegistryTokenDenoms(msg.AddTokens); err != nil {
return err
}
for _, token := range msg.AddTokens {
if err := token.Validate(); err != nil {
return errors.Wrap(err, "token")
}
}
if err := validateRegistryTokenDenoms(msg.UpdateTokens); err != nil {
return err
}
for _, token := range msg.UpdateTokens {
if err := token.Validate(); err != nil {
return errors.Wrap(err, "token")
}
}
return nil
}
// GetSignBytes implements Msg
func (msg MsgGovUpdateRegistry) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
// GetSigners implements Msg
func (msg MsgGovUpdateRegistry) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Authority)
}
// validateRegistryTokenDenoms returns error if duplicate baseDenom exists.
func validateRegistryTokenDenoms(tokens []Token) error {
tokenDenoms := map[string]bool{}
for _, token := range tokens {
if _, ok := tokenDenoms[token.BaseDenom]; ok {
return ErrDuplicateToken.Wrapf("duplicate token with baseDenom %s", token.BaseDenom)
}
tokenDenoms[token.BaseDenom] = true
}
return nil
}