-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_init.go
57 lines (45 loc) · 1.35 KB
/
message_init.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
package types
import (
secp256k1 "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const TypeMsgInit = "init"
var _ sdk.Msg = &MsgInit{}
func NewMsgInit(operatorAddress string, enclaveReport []byte, oraclePubKey *secp256k1.PubKey) *MsgInit {
return &MsgInit{
OperatorAddress: operatorAddress,
EnclaveReport: enclaveReport,
OraclePubKey: oraclePubKey,
}
}
func (msg *MsgInit) Route() string {
return RouterKey
}
func (msg *MsgInit) Type() string {
return TypeMsgInit
}
func (msg *MsgInit) GetSigners() []sdk.AccAddress {
operatorAddress, err := sdk.AccAddressFromBech32(msg.OperatorAddress)
if err != nil {
panic(err)
}
return []sdk.AccAddress{operatorAddress}
}
func (msg *MsgInit) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}
func (msg *MsgInit) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.OperatorAddress)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid operatorAddress address (%s)", err)
}
if len(msg.EnclaveReport) == 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "enclaveReport is empty")
}
if len(msg.OraclePubKey.Key) == 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "oraclePubKey is empty")
}
return nil
}