-
Notifications
You must be signed in to change notification settings - Fork 1
/
notification.go
105 lines (85 loc) · 3.12 KB
/
notification.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
package blockntfns
import (
"fmt"
"github.com/classzz/classzz/wire"
)
// BlockNtfn is an interface that coalesces all the different types of block
// notifications.
type BlockNtfn interface {
// Header returns the header of the block for which this notification is
// for.
Header() wire.BlockHeader
// Height returns the height of the block for which this notification is
// for.
Height() uint32
// ChainTip returns the header of the new tip of the chain after
// processing the block being connected/disconnected.
ChainTip() wire.BlockHeader
}
// Connected is a block notification that gets dispatched to clients when the
// filter header of a new block has been found that extends the current chain.
type Connected struct {
header wire.BlockHeader
height uint32
}
// A compile-time check to ensure Connected satisfies the BlockNtfn interface.
var _ BlockNtfn = (*Connected)(nil)
// NewBlockConnected creates a new Connected notification for the given block.
func NewBlockConnected(header wire.BlockHeader, height uint32) *Connected {
return &Connected{header: header, height: height}
}
// Header returns the header of the block extending the chain.
func (n *Connected) Header() wire.BlockHeader {
return n.header
}
// Height returns the height of the block extending the chain.
func (n *Connected) Height() uint32 {
return n.height
}
// ChainTip returns the header of the new tip of the chain after processing the
// block being connected.
func (n *Connected) ChainTip() wire.BlockHeader {
return n.header
}
// String returns the string representation of a Connected notification.
func (n *Connected) String() string {
return fmt.Sprintf("block connected (height=%d, hash=%v)", n.height,
n.header.BlockHash())
}
// Disconnected if a notification that gets dispatched to clients when a reorg
// has been detected at the tip of the chain.
type Disconnected struct {
headerDisconnected wire.BlockHeader
heightDisconnected uint32
chainTip wire.BlockHeader
}
// A compile-time check to ensure Disconnected satisfies the BlockNtfn
// interface.
var _ BlockNtfn = (*Disconnected)(nil)
// NewBlockDisconnected creates a Disconnected notification for the given block.
func NewBlockDisconnected(headerDisconnected wire.BlockHeader,
heightDisconnected uint32, chainTip wire.BlockHeader) *Disconnected {
return &Disconnected{
headerDisconnected: headerDisconnected,
heightDisconnected: heightDisconnected,
chainTip: chainTip,
}
}
// Header returns the header of the block being disconnected.
func (n *Disconnected) Header() wire.BlockHeader {
return n.headerDisconnected
}
// Height returns the height of the block being disconnected.
func (n *Disconnected) Height() uint32 {
return n.heightDisconnected
}
// ChainTip returns the header of the new tip of the chain after processing the
// block being disconnected.
func (n *Disconnected) ChainTip() wire.BlockHeader {
return n.chainTip
}
// String returns the string representation of a Disconnected notification.
func (n *Disconnected) String() string {
return fmt.Sprintf("block disconnected (height=%d, hash=%v)",
n.heightDisconnected, n.headerDisconnected.BlockHash())
}