-
Notifications
You must be signed in to change notification settings - Fork 175
/
status.go
55 lines (46 loc) · 1.17 KB
/
status.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
// (c) 2019 Dapper Labs - ALL RIGHTS RESERVED
package chainsync
import (
"time"
"github.com/onflow/flow-go/model/flow"
)
// Status keeps track of a block download status.
type Status struct {
BlockHeight uint64 // always present even if we haven't received the header
Queued time.Time // when we originally queued this block request
Requested time.Time // the last time we requested this block
Attempts uint // how many times we've requested this block
Header *flow.Header // the requested header, if we've received it
Received time.Time // when we received a response
}
func (s *Status) WasQueued() bool {
return s != nil
}
func (s *Status) WasRequested() bool {
if s == nil {
return false
}
return !s.Requested.IsZero()
}
func (s *Status) WasReceived() bool {
if s == nil {
return false
}
return !s.Received.IsZero()
}
func (s *Status) StatusString() string {
if s.WasReceived() {
return "Received"
} else if s.WasRequested() {
return "Requested"
} else if s.WasQueued() {
return "Queued"
} else {
return "Unknown"
}
}
func NewQueuedStatus(height uint64) *Status {
return &Status{
Queued: time.Now(),
}
}