X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=toolbar%2Freward%2Fconfig%2Fconfig.go;h=95ed77adef59042bdb62f0bb63375016e1f93d8c;hp=d912156bec00a9f00850ab2ec3a3baf1016c2141;hb=259fee232ebced1fa0d60b04b6a69a4bf38ca50e;hpb=32605ab49e746065f4b5a68301ce080d1576c6ef diff --git a/toolbar/reward/config/config.go b/toolbar/reward/config/config.go index d912156b..95ed77ad 100644 --- a/toolbar/reward/config/config.go +++ b/toolbar/reward/config/config.go @@ -1 +1,46 @@ package config + +import ( + "encoding/json" + "os" + + log "github.com/sirupsen/logrus" + + "github.com/vapor/crypto/ed25519/chainkd" + "github.com/vapor/toolbar/common" +) + +func NewConfig() *Config { + if len(os.Args) <= 1 { + log.Fatal("Please setup the config file path") + } + + return NewConfigWithPath(os.Args[1]) +} + +func NewConfigWithPath(path string) *Config { + configFile, err := os.Open(path) + if err != nil { + log.WithFields(log.Fields{"err": err, "file_path": os.Args[1]}).Fatal("fail to open config file") + } + defer configFile.Close() + + cfg := &Config{} + if err := json.NewDecoder(configFile).Decode(cfg); err != nil { + log.WithField("err", err).Fatal("fail to decode config file") + } + + return cfg +} + +type Config struct { + MySQLConfig common.MySQLConfig `json:"mysql"` + Chain Chain `json:"chain"` + XPubs []chainkd.XPub `json:"xpubs"` +} + +type Chain struct { + Name string `json:"name"` + Upstream string `json:"upstream"` + SyncSeconds uint64 `json:"sync_seconds"` +}