/
msgs.go
114 lines (98 loc) · 2.65 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package types
import (
fmt "fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ojo-network/ojo/util/checkers"
)
var _ sdk.Msg = &MsgSetParams{}
func NewMsgSetParams(
gmpAddress string,
gmpChannel string,
gmpTimeout int64,
feeRecipient string,
govAddress string,
) *MsgSetParams {
params := &Params{
GmpAddress: gmpAddress,
GmpChannel: gmpChannel,
GmpTimeout: gmpTimeout,
FeeRecipient: feeRecipient,
}
return &MsgSetParams{
Params: params,
Authority: govAddress,
}
}
// Type implements LegacyMsg interface
func (msg MsgSetParams) Type() string { return sdk.MsgTypeURL(&msg) }
// GetSignBytes implements sdk.Msg
func (msg MsgSetParams) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners implements sdk.Msg
func (msg MsgSetParams) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Authority)
}
// ValidateBasic Implements sdk.Msg
func (msg MsgSetParams) ValidateBasic() error {
// TODO validate params
return nil
}
func NewMsgRelay(
relayer string,
destinationChain string,
ojoContractAddress string,
clientContractAddress string,
token sdk.Coin,
denoms []string,
commandSelector []byte,
commandParams []byte,
timestamp int64,
) *MsgRelayPrice {
return &MsgRelayPrice{
Relayer: relayer,
DestinationChain: destinationChain,
ClientContractAddress: clientContractAddress,
OjoContractAddress: ojoContractAddress,
Token: token,
Denoms: denoms,
CommandSelector: commandSelector,
CommandParams: commandParams,
Timestamp: timestamp,
}
}
// Type implements LegacyMsg interface
func (msg MsgRelayPrice) Type() string { return sdk.MsgTypeURL(&msg) }
// GetSignBytes implements sdk.Msg
func (msg MsgRelayPrice) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
// GetSigners implements sdk.Msg
func (msg MsgRelayPrice) GetSigners() []sdk.AccAddress {
return checkers.Signers(msg.Relayer)
}
// ValidateBasic Implements sdk.Msg
func (msg MsgRelayPrice) ValidateBasic() error {
if len(msg.Denoms) == 0 {
return fmt.Errorf("denoms cannot be empty")
}
if msg.Timestamp == 0 {
return fmt.Errorf("timestamp cannot be empty")
}
if msg.OjoContractAddress == "" {
return fmt.Errorf("cjoContractAddress cannot be empty")
}
if msg.DestinationChain == "" {
return fmt.Errorf("destinationChain cannot be empty")
}
if msg.Relayer == "" {
return fmt.Errorf("relayer cannot be empty")
}
// Make sure no denoms are above 32 bytes
for _, denom := range msg.Denoms {
if len(denom) > 32 {
return fmt.Errorf("denom %s is too long", denom)
}
}
return nil
}