forked from solarlabsteam/missed-blocks-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
85 lines (71 loc) · 1.73 KB
/
types.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
package main
import (
"time"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
type Direction int
const (
INCREASING = iota
DECREASING
JAILED
UNJAILED
TOMBSTONED
)
const (
TombstonedEmoji = "💀"
JailedEmoju = "❌"
UnjailedEmoji = "👌"
)
const (
TombstonedDesc = "was tombstoned"
JailedDesc = "was jailed"
UnjailedDesc = "was unjailed"
)
type ValidatorState struct {
Address string
Moniker string
ConsensusAddress string
MissedBlocks int64
Jailed bool
Active bool
Tombstoned bool
}
func NewValidatorState(
validator stakingtypes.Validator,
info slashingtypes.ValidatorSigningInfo,
) ValidatorState {
return ValidatorState{
Address: validator.OperatorAddress,
Moniker: validator.Description.Moniker,
ConsensusAddress: info.Address,
MissedBlocks: info.MissedBlocksCounter,
Jailed: validator.Jailed,
Active: validator.Status == 3, // BOND_STATUS_BONDED
Tombstoned: info.Tombstoned,
}
}
type ValidatorsState map[string]ValidatorState
type ReportEntry struct {
ValidatorAddress string
ValidatorMoniker string
Emoji string
Description string
MissingBlocks int64
Direction Direction
}
func (r ReportEntry) GetTimeToJail(params *Params) time.Duration {
blocksLeftToJail := params.MissedBlocksToJail - r.MissingBlocks
secondsLeftToJail := params.AvgBlockTime * float64(blocksLeftToJail)
return time.Duration(secondsLeftToJail) * time.Second
}
type Report struct {
Entries []ReportEntry
}
type Reporter interface {
Serialize(Report) string
Init()
Enabled() bool
SendReport(Report) error
Name() string
}