-
Notifications
You must be signed in to change notification settings - Fork 115
/
msg_sign.go
41 lines (35 loc) · 1.4 KB
/
msg_sign.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// Route implements the sdk.Msg interface.
func (m ProcessSignTrafficRequest) Route() string { return RouterKey }
// Type implements the sdk.Msg interface.
// naming convention follows x/staking/types/msgs.go
func (m ProcessSignTrafficRequest) Type() string { return "SignTraffic" }
// ValidateBasic implements the sdk.Msg interface.
func (m ProcessSignTrafficRequest) ValidateBasic() error {
if err := sdk.VerifyAddressFormat(m.Sender); err != nil {
return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, sdkerrors.Wrap(err, "sender").Error())
}
if m.SessionID == "" {
return sdkerrors.Wrap(ErrTss, "session id must be set")
}
if !m.Payload.IsBroadcast && len(m.Payload.ToPartyUid) == 0 {
return sdkerrors.Wrap(ErrTss, "non-broadcast message must specify recipient")
}
if m.Payload.IsBroadcast && len(m.Payload.ToPartyUid) != 0 {
return sdkerrors.Wrap(ErrTss, "broadcast message must not specify recipient")
}
// TODO enforce a maximum length for m.SessionID?
return nil
}
// GetSignBytes implements the sdk.Msg interface
func (m ProcessSignTrafficRequest) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}
// GetSigners implements the sdk.Msg interface
func (m ProcessSignTrafficRequest) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{m.Sender}
}