status-go/signal/events_node.go

79 lines
2.2 KiB
Go
Raw Normal View History

2018-05-03 07:35:58 +00:00
package signal
2023-07-05 15:56:34 +00:00
import (
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/settings"
)
2018-05-03 07:35:58 +00:00
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"
2018-05-03 07:35:58 +00:00
)
// 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 {
2023-07-05 15:56:34 +00:00
Error string `json:"error,omitempty"`
Settings *settings.Settings `json:"settings,omitempty"`
Account *multiaccounts.Account `json:"account,omitempty"`
}
2018-05-03 07:35:58 +00:00
// 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)
}
2023-07-05 15:56:34 +00:00
func SendLoggedIn(account *multiaccounts.Account, settings *settings.Settings, err error) {
event := NodeLoginEvent{Settings: settings, Account: account}
if err != nil {
event.Error = err.Error()
}
send(EventLoggedIn, event)
}