-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathccv.go
59 lines (47 loc) · 1.61 KB
/
ccv.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
package types
import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
abci "github.com/tendermint/tendermint/abci/types"
)
func ValidatorPacket(val []abci.ValidatorUpdate, valUpdateID unit64, SlashAcks []string) ValidatorSetChange {
return ValidatorSetChange{
ValidatorUpdates: val,
valUpdateID: valUpdateID.
SlashAcks: SlashAcks,
}
}
// ValidateBasic is used for validating the CCV packet data.
func (vsc ValidatorPacket) ValidateBasic() error {
if len(vsc.ValidatorUpdates) == 0 {
return sdkerrors.Wrap(ErrInvalidPacketData, "validator updates cannot be empty")
}
return nil
}
func (vsc ValidatorPacket) GetBytes() []byte {
valUpdateBytes := ModuleCdc.MustMarshalJSON(&vsc)
return valUpdateBytes
}
func NewSlashPacketData(validator abci.Validator, valUpdateId uint64, infractionType stakingtypes.InfractionType) SlashPacketData {
return SlashPacketData{
Validator: validator,
ValsetUpdateId: valUpdateId,
Infraction: infractionType,
}
}
func (vdt SlashPacketData) ValidateBasic() error {
if len(vdt.Validator.Address) == 0 || vdt.Validator.Power == 0 {
return sdkerrors.Wrap(ErrInvalidPacketData, "validator fields cannot be empty")
}
if vdt.ValsetUpdateId == 0 {
return sdkerrors.Wrap(ErrInvalidPacketData, "valset update id cannot be equal to zero")
}
if vdt.Infraction == stakingtypes.InfractionEmpty {
return sdkerrors.Wrap(ErrInvalidPacketData, "invalid infraction type")
}
return nil
}
func (vdt SlashPacketData) GetBytes() []byte {
valDowntimeBytes := ModuleCdc.MustMarshalJSON(&vdt)
return valDowntimeBytes
}