-
Notifications
You must be signed in to change notification settings - Fork 113
/
msg_sign.go
53 lines (45 loc) · 1.85 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
42
43
44
45
46
47
48
49
50
51
52
53
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/axelarnetwork/axelar-core/utils"
"github.com/axelarnetwork/axelar-core/x/tss/tofnd"
)
// NewProcessSignTrafficRequest constructor for NewProcessSignTrafficRequest
func NewProcessSignTrafficRequest(sender sdk.AccAddress, session string, payload tofnd.TrafficOut) *ProcessSignTrafficRequest {
return &ProcessSignTrafficRequest{
Sender: sender,
SessionID: utils.NormalizeString(session),
Payload: payload,
}
}
// 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 err := utils.ValidateString(m.SessionID); err != nil {
return sdkerrors.Wrap(err, "invalid session ID")
}
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}
}