-
Notifications
You must be signed in to change notification settings - Fork 2
/
msg.go
102 lines (84 loc) · 2.77 KB
/
msg.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
98
99
100
101
102
package types
import (
sdk "github.com/hdac-io/friday/types"
)
// RouterKey is not in sense yet
const RouterKey = ModuleName
////////////////////////////
/////// Add Account ////////
////////////////////////////
// MsgSetAccount defines a SetAccount message
type MsgSetNickname struct {
Nickname Name `json:"nickname"`
Address sdk.AccAddress `json:"address"`
}
// NewMsgSetNickname is a constructor function for MsgSetName
func NewMsgSetNickname(name Name, address sdk.AccAddress) MsgSetNickname {
return MsgSetNickname{
Nickname: name,
Address: address,
}
}
// Route should return the name of the module
func (msg MsgSetNickname) Route() string { return RouterKey }
// Type should return the action
func (msg MsgSetNickname) Type() string { return "newaccount" }
// ValidateBasic runs stateless checks on the message
func (msg MsgSetNickname) ValidateBasic() sdk.Error {
if msg.Address.String() == "" {
return sdk.ErrUnknownRequest("Address cannot be empty")
}
if msg.Nickname.Equal(NewName("")) {
return sdk.ErrUnknownRequest("ID cannot be empty")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgSetNickname) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgSetNickname) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Address}
}
///////////////////////////////////
////////// Change Key /////////////
///////////////////////////////////
// MsgChangeKey defines a ChangeKey message
type MsgChangeKey struct {
Nickname string `json:"nickname"`
OldAddress sdk.AccAddress `json:"old_address"`
NewAddress sdk.AccAddress `json:"new_address"`
}
// NewMsgChangeKey is a constructor function for MsgChangeKey
func NewMsgChangeKey(name string,
oldAddress, newAddress sdk.AccAddress,
) MsgChangeKey {
return MsgChangeKey{
Nickname: name,
OldAddress: oldAddress,
NewAddress: newAddress,
}
}
// Route should return the name of the module
func (msg MsgChangeKey) Route() string { return RouterKey }
// Type should return the action
func (msg MsgChangeKey) Type() string { return "changekey" }
// ValidateBasic runs stateless checks on the message
func (msg MsgChangeKey) ValidateBasic() sdk.Error {
if len(msg.OldAddress.Bytes()) == 0 || len(msg.NewAddress.Bytes()) == 0 {
return sdk.ErrUnknownRequest("Address cannot be empty")
}
if len(msg.Nickname) == 0 {
return sdk.ErrUnknownRequest("ID cannot be empty")
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgChangeKey) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgChangeKey) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.OldAddress}
}