-
Notifications
You must be signed in to change notification settings - Fork 11
/
msgs.go
56 lines (44 loc) · 1.76 KB
/
msgs.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const RouterKey = ModuleName // this was defined in your key.go file
type MsgRequestGuard struct {
SignedSimplexStateBytes []byte `json:"signed_simplex_state_bytes"`
SimplexReceiverSig []byte `json:"simplex_receiver_sig"`
Sender sdk.AccAddress `json:"sender"`
}
// NewMsgRequestGuard is a constructor function for MsgRequestGuard
func NewMsgRequestGuard(signedSimplexStateBytes, simplexReceiverSig []byte, sender sdk.AccAddress) MsgRequestGuard {
return MsgRequestGuard{
SignedSimplexStateBytes: signedSimplexStateBytes,
SimplexReceiverSig: simplexReceiverSig,
Sender: sender,
}
}
// Route should return the name of the module
func (msg MsgRequestGuard) Route() string { return RouterKey }
// Type should return the action
func (msg MsgRequestGuard) Type() string { return "request_guard" }
// ValidateBasic runs stateless checks on the message
func (msg MsgRequestGuard) ValidateBasic() error {
if len(msg.SignedSimplexStateBytes) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "SignedSimplexStateBytes cannot be empty")
}
if len(msg.SimplexReceiverSig) == 0 {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "SimplexReceiverSig cannot be empty")
}
if msg.Sender.Empty() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, msg.Sender.String())
}
return nil
}
// GetSignBytes encodes the message for signing
func (msg MsgRequestGuard) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg))
}
// GetSigners defines whose signature is required
func (msg MsgRequestGuard) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{msg.Sender}
}