-
Notifications
You must be signed in to change notification settings - Fork 18
/
msgs.go
159 lines (129 loc) · 4.68 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package types
import (
"encoding/json"
"cosmossdk.io/errors"
"github.com/KYVENetwork/chain/util"
sdk "github.com/cosmos/cosmos-sdk/types"
errorsTypes "github.com/cosmos/cosmos-sdk/types/errors"
)
var (
_ sdk.Msg = &MsgCreatePool{}
_ sdk.Msg = &MsgUpdatePool{}
_ sdk.Msg = &MsgDisablePool{}
_ sdk.Msg = &MsgEnablePool{}
_ sdk.Msg = &MsgScheduleRuntimeUpgrade{}
_ sdk.Msg = &MsgCancelRuntimeUpgrade{}
)
// GetSigners returns the expected signers for a MsgCreatePool message.
func (msg *MsgCreatePool) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{addr}
}
// ValidateBasic does a sanity check on the provided data.
func (msg *MsgCreatePool) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return errors.Wrap(err, "invalid authority address")
}
if err := util.ValidatePositiveNumber(msg.UploadInterval); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid upload interval")
}
if err := util.ValidatePositiveNumber(msg.OperatingCost); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid operating cost")
}
if err := util.ValidatePositiveNumber(msg.MinDelegation); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid minimum delegation")
}
return nil
}
// GetSigners returns the expected signers for a MsgUpdatePool message.
func (msg *MsgUpdatePool) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{addr}
}
// PoolUpdate ...
type PoolUpdate struct {
Name *string
Runtime *string
Logo *string
Config *string
UploadInterval *uint64
OperatingCost *uint64
MinDelegation *uint64
MaxBundleSize *uint64
StorageProviderId *uint32
CompressionId *uint32
}
// ValidateBasic does a sanity check on the provided data.
func (msg *MsgUpdatePool) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return errors.Wrap(err, "invalid authority address")
}
var payload PoolUpdate
if err := json.Unmarshal([]byte(msg.Payload), &payload); err != nil {
return err
}
if payload.UploadInterval != nil {
if err := util.ValidatePositiveNumber(*payload.UploadInterval); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid upload interval")
}
}
if payload.OperatingCost != nil {
if err := util.ValidatePositiveNumber(*payload.OperatingCost); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid operating cost")
}
}
if payload.MinDelegation != nil {
if err := util.ValidatePositiveNumber(*payload.MinDelegation); err != nil {
return errors.Wrapf(errorsTypes.ErrInvalidRequest, "invalid minimum delegation")
}
}
return nil
}
// GetSigners returns the expected signers for a MsgDisablePool message.
func (msg *MsgDisablePool) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{addr}
}
// ValidateBasic does a sanity check on the provided data.
func (msg *MsgDisablePool) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return errors.Wrap(err, "invalid authority address")
}
return nil
}
// GetSigners returns the expected signers for a MsgEnablePool message.
func (msg *MsgEnablePool) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{addr}
}
// ValidateBasic does a sanity check on the provided data.
func (msg *MsgEnablePool) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return errors.Wrap(err, "invalid authority address")
}
return nil
}
// GetSigners returns the expected signers for a MsgScheduleRuntimeUpgrade message.
func (msg *MsgScheduleRuntimeUpgrade) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{addr}
}
// ValidateBasic does a sanity check on the provided data.
func (msg *MsgScheduleRuntimeUpgrade) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return errors.Wrap(err, "invalid authority address")
}
return nil
}
// GetSigners returns the expected signers for a MsgCancelRuntimeUpgrade message.
func (msg *MsgCancelRuntimeUpgrade) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(msg.Authority)
return []sdk.AccAddress{addr}
}
// ValidateBasic does a sanity check on the provided data.
func (msg *MsgCancelRuntimeUpgrade) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil {
return errors.Wrap(err, "invalid authority address")
}
return nil
}