-
Notifications
You must be signed in to change notification settings - Fork 244
/
events_node.go
71 lines (57 loc) · 1.85 KB
/
events_node.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
package signal
const (
// EventNodeStarted is triggered when underlying node is started
EventNodeStarted = "node.started"
// EventNodeReady is triggered when underlying node is fully ready
// (consider backend to be fully registered)
EventNodeReady = "node.ready"
// EventNodeStopped is triggered when underlying node is fully stopped
EventNodeStopped = "node.stopped"
// EventNodeCrashed is triggered when node crashes
EventNodeCrashed = "node.crashed"
// EventChainDataRemoved is triggered when node's chain data is removed
EventChainDataRemoved = "chaindata.removed"
// EventLoggedIn is once node was injected with user account and ready to be used.
EventLoggedIn = "node.login"
)
// NodeCrashEvent is special kind of error, used to report node crashes
type NodeCrashEvent struct {
Error string `json:"error"`
}
// NodeLoginEvent returns the result of the login event
type NodeLoginEvent struct {
Error string `json:"error,omitempty"`
}
// SendNodeCrashed emits a signal when status node has crashed, and
// provides error description.
func SendNodeCrashed(err error) {
send(EventNodeCrashed,
NodeCrashEvent{
Error: err.Error(),
})
}
// SendNodeStarted emits a signal when status node has just started (but not
// finished startup yet).
func SendNodeStarted() {
send(EventNodeStarted, nil)
}
// SendNodeReady emits a signal when status node has started and successfully
// completed startup.
func SendNodeReady() {
send(EventNodeReady, nil)
}
// SendNodeStopped emits a signal when underlying node has stopped.
func SendNodeStopped() {
send(EventNodeStopped, nil)
}
// SendChainDataRemoved emits a signal when node's chain data has been removed.
func SendChainDataRemoved() {
send(EventChainDataRemoved, nil)
}
func SendLoggedIn(err error) {
event := NodeLoginEvent{}
if err != nil {
event.Error = err.Error()
}
send(EventLoggedIn, event)
}