/
message_valset_confirm.go
58 lines (46 loc) · 1.44 KB
/
message_valset_confirm.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
package types
import (
"encoding/hex"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgValsetConfirm = "valset_confirm"
var _ sdk.Msg = &MsgValsetConfirm{}
func NewMsgValsetConfirm(orchestrator string, valsetNonce uint64, ethAddress string, signature string) *MsgValsetConfirm {
return &MsgValsetConfirm{
Orchestrator: orchestrator,
ValsetNonce: valsetNonce,
EthAddress: ethAddress,
Signature: signature,
}
}
func (msg *MsgValsetConfirm) Route() string {
return RouterKey
}
func (msg *MsgValsetConfirm) Type() string {
return TypeMsgValsetConfirm
}
func (msg *MsgValsetConfirm) GetSigners() []sdk.AccAddress {
orchestrator, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{orchestrator}
}
func (msg *MsgValsetConfirm) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgValsetConfirm) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Orchestrator)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid orchestrator address (%s)", err)
}
if err := ValidateEthAddress(msg.EthAddress); err != nil {
return sdkerrors.Wrap(err, "eth signer")
}
if _, err := hex.DecodeString(msg.Signature); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "Could not decode hex string %s", msg.Signature)
}
return nil
}