/
code_authorization.go
97 lines (81 loc) · 2.35 KB
/
code_authorization.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
88
89
90
91
92
93
94
95
96
97
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
var (
_ sdk.Msg = &MsgSetCodeAuthorization{}
_ sdk.Msg = &MsgRemoveCodeAuthorization{}
)
// msg types
const (
TypeMsgSetCodeAuthorization = "set_code_authorization"
TypeMsgRemoveCodeAuthorization = "remove_code_authorization"
)
func NewMsgSetCodeAuthorization(sender string, codeID uint64, methods []string) *MsgSetCodeAuthorization {
return &MsgSetCodeAuthorization{
Sender: sender,
CodeAuthorization: &CodeAuthorization{
CodeID: codeID,
Methods: methods,
},
}
}
func (msg MsgSetCodeAuthorization) Route() string {
return RouterKey
}
func (msg MsgSetCodeAuthorization) Type() string {
return TypeMsgRemoveCodeAuthorization
}
func (msg MsgSetCodeAuthorization) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
func (msg MsgSetCodeAuthorization) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
func (msg MsgSetCodeAuthorization) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err)
}
return msg.CodeAuthorization.Validate()
}
func NewMsgRemoveCodeAuthorization(sender string, codeID uint64) *MsgRemoveCodeAuthorization {
return &MsgRemoveCodeAuthorization{
Sender: sender,
CodeID: codeID,
}
}
func (msg MsgRemoveCodeAuthorization) Route() string {
return RouterKey
}
func (msg MsgRemoveCodeAuthorization) Type() string {
return TypeMsgRemoveCodeAuthorization
}
func (msg MsgRemoveCodeAuthorization) GetSigners() []sdk.AccAddress {
sender, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
panic(err)
}
return []sdk.AccAddress{sender}
}
func (msg MsgRemoveCodeAuthorization) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}
func (msg MsgRemoveCodeAuthorization) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid sender address (%s)", err)
}
return nil
}
// Validate validates the values of code authorizations
func (ca CodeAuthorization) Validate() error {
return validateMethods(ca.Methods)
}