-
Notifications
You must be signed in to change notification settings - Fork 206
/
config.go
36 lines (31 loc) · 1.12 KB
/
config.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
package chaintracker
import "time"
const (
DefualtAssumedBlockMemory = 20
DefaultBlockCheckpointDistance = 100
)
type ChainTrackerConfig struct {
ForkCallback func(int64) // a function to be called when a fork is detected
NewLatestCallback func(int64) // a function to be called when a new block is detected
ServerAddress string // if not empty will open up a grpc server for that address
BlocksToSave uint64
AverageBlockTime time.Duration // how often to query latest block
ServerBlockMemory uint64
blocksCheckpointDistance uint64 // this causes the chainTracker to trigger it's checkpoint every X blocks
}
func (cnf *ChainTrackerConfig) validate() error {
if cnf.BlocksToSave == 0 {
return InvalidConfigErrorBlocksToSave
}
if cnf.AverageBlockTime == 0 {
return InvalidConfigBlockTime
}
if cnf.ServerBlockMemory == 0 {
cnf.ServerBlockMemory = DefualtAssumedBlockMemory
}
if cnf.blocksCheckpointDistance == 0 {
cnf.blocksCheckpointDistance = DefaultBlockCheckpointDistance
}
// TODO: validate address is in the right format if not empty
return nil
}