-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathevents.go
69 lines (53 loc) · 1.11 KB
/
events.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
package sbac
type EventKind uint8
const (
EventKindSBACMessage EventKind = iota
EventKindConsensus
)
func (e EventKind) String() string {
if e == EventKindSBACMessage {
return "EventKindSBACMessage"
} else if e == EventKindConsensus {
return "EventKindConsensus"
}
return "error"
}
type Event interface {
Kind() EventKind
TxID() []byte
PeerID() uint64
}
// sbac event
type SBACEvent struct {
kind EventKind
msg *SBACMessage
}
func (e *SBACEvent) Kind() EventKind {
return e.kind
}
func (e *SBACEvent) TxID() []byte {
return e.msg.TxID
}
func (e *SBACEvent) PeerID() uint64 {
return e.msg.PeerID
}
func NewSBACEvent(data *SBACMessage) Event {
return &SBACEvent{EventKindSBACMessage, data}
}
// consensus event
type ConsensusEvent struct {
kind EventKind
data *ConsensusTransaction
}
func (e *ConsensusEvent) Kind() EventKind {
return e.kind
}
func (e *ConsensusEvent) TxID() []byte {
return e.data.TxID
}
func (e *ConsensusEvent) PeerID() uint64 {
return e.data.Initiator
}
func NewConsensusEvent(data *ConsensusTransaction) *ConsensusEvent {
return &ConsensusEvent{EventKindConsensus, data}
}