OSDN Git Service

Mov (#518)
[bytom/vapor.git] / toolbar / precognitive / config / config.go
1 package config
2
3 import (
4         "encoding/json"
5         "os"
6
7         log "github.com/sirupsen/logrus"
8         "github.com/bytom/vapor/crypto/ed25519/chainkd"
9         "github.com/bytom/vapor/toolbar/common"
10 )
11
12 func NewConfig() *Config {
13         if len(os.Args) <= 1 {
14                 log.Fatal("Please setup the config file path")
15         }
16
17         return NewConfigWithPath(os.Args[1])
18 }
19
20 func NewConfigWithPath(path string) *Config {
21         configFile, err := os.Open(path)
22         if err != nil {
23                 log.WithFields(log.Fields{"err": err, "file_path": os.Args[1]}).Fatal("fail to open config file")
24         }
25         defer configFile.Close()
26
27         cfg := &Config{}
28         if err := json.NewDecoder(configFile).Decode(cfg); err != nil {
29                 log.WithField("err", err).Fatal("fail to decode config file")
30         }
31
32         return cfg
33 }
34
35 type Config struct {
36         NetworkID        uint64             `json:"network_id"`
37         MySQLConfig      common.MySQLConfig `json:"mysql"`
38         CheckFreqMinutes uint64             `json:"check_frequency_minutes"`
39         Policy           Policy             `json:"policy"`
40         Nodes            []Node             `json:"seeds"`
41         API              API                `json:"api"`
42 }
43
44 type Policy struct {
45         Confirmations uint64 `json:"confirmations"`
46         RequiredRttMS uint64 `json:"required_rtt_ms"`
47 }
48
49 type Node struct {
50         XPub      *chainkd.XPub `json:"xpub"`
51         PublicKey string        `json:"public_key"`
52         IP        string        `json:"ip"`
53         Port      uint16        `json:"port"`
54 }
55
56 type API struct {
57         ListeningPort uint64 `json:"listening_port"`
58         AccessToken   string `json:"access_token"`
59         IsReleaseMode bool   `json:"is_release_mode"`
60 }