-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.go
61 lines (47 loc) · 1.74 KB
/
app.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
package backend
import (
"errors"
"fmt"
"code.vegaprotocol.io/vegawallet-desktop/app"
"go.uber.org/zap"
)
var ErrAppIsNotInitialised = errors.New("the application has not been initialised")
func (h *Handler) IsAppInitialised() (bool, error) {
isConfigInit, err := h.isAppInitialised()
if err != nil {
h.log.Error("Could not verify the application configuration existence", zap.Error(err))
return false, fmt.Errorf("could not verify the application configuration existence: %w", err)
}
return isConfigInit, nil
}
// isAppInitialised abstract the application initialization state verification,
// so we don't have to rely on the backend API to start the program.
func (h *Handler) isAppInitialised() (bool, error) {
return h.configLoader.IsConfigInitialised()
}
type InitialiseAppRequest struct {
VegaHome string `json:"vegaHome"`
}
func (h *Handler) InitialiseApp(req *InitialiseAppRequest) error {
h.log.Debug("Entering InitialiseApp")
defer h.log.Debug("Leaving InitialiseApp")
cfg := app.DefaultConfig()
cfg.VegaHome = req.VegaHome
if err := h.configLoader.SaveConfig(cfg); err != nil {
h.log.Error("Could not save the application configuration", zap.Error(err))
return fmt.Errorf("could not save the application configuration: %w", err)
}
h.appInitialised = true
if err := h.reloadBackendComponentsFromConfig(); err != nil {
h.log.Error("Could not reload the backend components during the application initialisation", zap.Error(err))
return fmt.Errorf("could not reload the backend components during the application initialisation: %w", err)
}
return nil
}
func (h *Handler) ensureAppIsInitialised() error {
if !h.appInitialised {
h.log.Error("The application is not initialised")
return ErrAppIsNotInitialised
}
return nil
}