forked from JackalLabs/canine-chain
/
message_postkey.go
52 lines (41 loc) · 1.04 KB
/
message_postkey.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgPostkey = "postkey"
var _ sdk.Msg = &MsgPostkey{}
func NewMsgPostkey(creator string, key string) *MsgPostkey {
return &MsgPostkey{
Creator: creator,
Key: key,
}
}
func (msg *MsgPostkey) Route() string {
return RouterKey
}
func (msg *MsgPostkey) Type() string {
return TypeMsgPostkey
}
func (msg *MsgPostkey) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *MsgPostkey) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgPostkey) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err)
}
if msg.Key == "" {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest,
"invalid key: %s", msg.Key)
}
return nil
}