-
Notifications
You must be signed in to change notification settings - Fork 45
/
msgs_profile.go
88 lines (70 loc) · 2.56 KB
/
msgs_profile.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
package types
import (
"fmt"
"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// ----------------------
// --- MsgSaveProfile
// ----------------------
// NewMsgSaveProfile returns a new MsgSaveProfile instance
func NewMsgSaveProfile(dTag string, nickname, bio, profilePic, coverPic string, creator string) *MsgSaveProfile {
return &MsgSaveProfile{
DTag: dTag,
Nickname: nickname,
Bio: bio,
ProfilePicture: profilePic,
CoverPicture: coverPic,
Creator: creator,
}
}
// Route should return the name of the module
func (msg *MsgSaveProfile) Route() string { return RouterKey }
// Type should return the action
func (msg *MsgSaveProfile) Type() string { return ActionSaveProfile }
// ValidateBasic runs stateless checks on the message
func (msg *MsgSaveProfile) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return errors.Wrap(sdkerrors.ErrInvalidAddress, fmt.Sprintf("invalid creator: %s", msg.Creator))
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg *MsgSaveProfile) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg *MsgSaveProfile) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Creator)
return []sdk.AccAddress{addr}
}
// ___________________________________________________________________________________________________________________
// NewMsgDeleteProfile is a constructor function for MsgDeleteProfile
func NewMsgDeleteProfile(creator string) *MsgDeleteProfile {
return &MsgDeleteProfile{
Creator: creator,
}
}
// Route should return the name of the module
func (msg *MsgDeleteProfile) Route() string { return RouterKey }
// Type should return the action
func (msg *MsgDeleteProfile) Type() string { return ActionDeleteProfile }
// ValidateBasic runs stateless checks on the message
func (msg *MsgDeleteProfile) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
return errors.Wrap(sdkerrors.ErrInvalidAddress, fmt.Sprintf("invalid creator: %s", msg.Creator))
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg *MsgDeleteProfile) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg *MsgDeleteProfile) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Creator)
return []sdk.AccAddress{addr}
}