-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
77 lines (69 loc) · 2.17 KB
/
config.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
package main
import (
"encoding/json"
"os"
"time"
)
// HubPeer struct holds the remoteKey and the address of the peer
type HubPeer struct {
RemoteKey string `json:"remoteKey"`
Address string `json:"address"`
}
// LNDConfig struct holds mandatory information how to connect to the lncli
type LNDConfig struct {
Directory string `json:"lndDir"`
CertPath string `json:"certPath"`
Host string `json:"host"`
Port int `json:"port"`
HubPeers []HubPeer `json:"hubPeers"`
}
// LSSDConfig struct holds mandatory information how connect to the LSSD which is a bridge to the Stakenet swaps and Stakenet orderbook
type LSSDConfig struct {
Host string `json:"host"`
Port int `json:"port"`
TimeoutStr string `json:"timeout"`
Timeout time.Duration
}
// BotConfig struct holds mandatory data of the how the bot is configured
// Also, it contains the path to the lncli to fetch useful information for the respective LND
type BotConfig struct {
JobIntervalStr string `json:"jobInterval"`
JobInterval time.Duration
Host string `json:"host"`
Port int `json:"port"`
LNCLIPath string `json:"lnCLIPath"`
LogLevel string `json:"logLevel"`
OrderLimit int `json:"orderLimit"`
}
// Config struct keeps all the individual configs together
type Config struct {
Bot BotConfig `json:"botCfg"`
LSSDConfig LSSDConfig `json:"lssdConfig"`
XSN LNDConfig `json:"xsnLNDConfig"`
LTC LNDConfig `json:"ltcLNDConfig"`
BTC LNDConfig `json:"btcLNDConfig"`
}
// Reads the entire config, "cfg.json" is hardcoded and must be placed on same level as the application binary
func readConfig() error {
file, err := os.Open("cfg.json")
if err != nil {
logger.Fatalf("can't open config file: %v", err)
return err
}
defer file.Close()
decoder := json.NewDecoder(file)
err = decoder.Decode(&cfg)
if err != nil {
logger.Fatalf("can't decode config JSON: %v", err)
return err
}
cfg.LSSDConfig.Timeout, err = time.ParseDuration(cfg.LSSDConfig.TimeoutStr)
if err != nil {
return err
}
cfg.Bot.JobInterval, err = time.ParseDuration(cfg.Bot.JobIntervalStr)
if err != nil {
return err
}
return nil
}