-
Notifications
You must be signed in to change notification settings - Fork 176
/
msg.go
204 lines (171 loc) · 5.04 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package types
import (
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
hmCommon "github.com/maticnetwork/heimdall/common"
"github.com/maticnetwork/heimdall/types"
hmTypes "github.com/maticnetwork/heimdall/types"
)
// verify interface at compile time
var _ sdk.Msg = &MsgUnjail{}
// MsgUnjail - struct for unjailing jailed validator
type MsgUnjail struct {
From types.HeimdallAddress `json:"from"`
ID hmTypes.ValidatorID `json:"id"`
TxHash types.HeimdallHash `json:"tx_hash"`
LogIndex uint64 `json:"log_index"`
BlockNumber uint64 `json:"block_number"`
}
func NewMsgUnjail(from types.HeimdallAddress, id uint64, txHash types.HeimdallHash, logIndex uint64, blockNumber uint64) MsgUnjail {
return MsgUnjail{
From: from,
ID: hmTypes.NewValidatorID(id),
TxHash: txHash,
LogIndex: logIndex,
BlockNumber: blockNumber,
}
}
//nolint
func (msg MsgUnjail) Route() string { return RouterKey }
func (msg MsgUnjail) Type() string { return "unjail" }
func (msg MsgUnjail) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{hmTypes.HeimdallAddressToAccAddress(msg.From)}
}
// GetSignBytes gets the bytes for the message signer to sign on
func (msg MsgUnjail) GetSignBytes() []byte {
b, err := ModuleCdc.MarshalJSON(msg)
if err != nil {
panic(err)
}
return sdk.MustSortJSON(b)
}
// ValidateBasic validity check for the AnteHandler
func (msg MsgUnjail) ValidateBasic() sdk.Error {
if msg.ID <= 0 {
return hmCommon.ErrInvalidMsg(hmCommon.DefaultCodespace, "Invalid validator ID %v", msg.ID)
}
if msg.From.Empty() {
return hmCommon.ErrInvalidMsg(hmCommon.DefaultCodespace, "Invalid proposer %v", msg.From.String())
}
return nil
}
// Tick Msg
// TickMsg - struct for unjailing jailed validator
type MsgTick struct {
ID uint64 `json:"id"`
Proposer types.HeimdallAddress `json:"proposer"`
SlashingInfoBytes types.HexBytes `json:"slashinginfobytes"`
}
func NewMsgTick(id uint64, proposer types.HeimdallAddress, slashingInfoBytes types.HexBytes) MsgTick {
return MsgTick{
ID: id,
Proposer: proposer,
SlashingInfoBytes: slashingInfoBytes,
}
}
// Type returns message type
func (msg MsgTick) Type() string {
return "tick"
}
func (msg MsgTick) Route() string {
return RouterKey
}
// GetSigners returns address of the signer
func (msg MsgTick) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{types.HeimdallAddressToAccAddress(msg.Proposer)}
}
func (msg MsgTick) GetSignBytes() []byte {
b, err := ModuleCdc.MarshalJSON(msg)
if err != nil {
panic(err)
}
return sdk.MustSortJSON(b)
}
func (msg MsgTick) ValidateBasic() sdk.Error {
if msg.Proposer.Empty() {
return hmCommon.ErrInvalidMsg(hmCommon.DefaultCodespace, "Invalid proposer %v", msg.Proposer.String())
}
return nil
}
// GetSideSignBytes returns side sign bytes
func (msg MsgTick) GetSideSignBytes() []byte {
uintType, _ := abi.NewType("uint256", "", nil)
addressType, _ := abi.NewType("address", "", nil)
bytesType, _ := abi.NewType("bytes", "", nil)
arguments := abi.Arguments{
{
Type: uintType,
},
{
Type: addressType,
},
{
Type: bytesType,
},
}
bytes, _ := arguments.Pack(
new(big.Int).SetUint64(msg.ID),
msg.Proposer,
msg.SlashingInfoBytes,
)
return bytes
}
//
// Msg Tick Ack
//
var _ sdk.Msg = &MsgTickAck{}
type MsgTickAck struct {
From types.HeimdallAddress `json:"from"`
ID uint64 `json:"tick_id"`
SlashedAmount uint64 `json:"slashed_amount"`
TxHash types.HeimdallHash `json:"tx_hash"`
LogIndex uint64 `json:"log_index"`
BlockNumber uint64 `json:"block_number"`
}
func NewMsgTickAck(from types.HeimdallAddress, id uint64, slashedAmount uint64, txHash types.HeimdallHash, logIndex uint64, blockNumber uint64) MsgTickAck {
return MsgTickAck{
From: from,
ID: id,
SlashedAmount: slashedAmount,
TxHash: txHash,
BlockNumber: blockNumber,
LogIndex: logIndex,
}
}
// Type returns message type
func (msg MsgTickAck) Type() string {
return "tick-ack"
}
func (msg MsgTickAck) Route() string {
return RouterKey
}
// GetSigners returns address of the signer
func (msg MsgTickAck) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{types.HeimdallAddressToAccAddress(msg.From)}
}
func (msg MsgTickAck) GetSignBytes() []byte {
b, err := ModuleCdc.MarshalJSON(msg)
if err != nil {
panic(err)
}
return sdk.MustSortJSON(b)
}
func (msg MsgTickAck) ValidateBasic() sdk.Error {
if msg.From.Empty() {
return hmCommon.ErrInvalidMsg(hmCommon.DefaultCodespace, "Invalid from %v", msg.From.String())
}
return nil
}
// GetTxHash Returns tx hash
func (msg MsgTickAck) GetTxHash() types.HeimdallHash {
return msg.TxHash
}
// GetLogIndex Returns log index
func (msg MsgTickAck) GetLogIndex() uint64 {
return msg.LogIndex
}
// GetSideSignBytes returns side sign bytes
func (msg MsgTickAck) GetSideSignBytes() []byte {
return nil
}