OSDN Git Service

rename (#465)
[bytom/vapor.git] / toolbar / vote_reward / config / config.go
1 package config
2
3 import (
4         "bytes"
5         "encoding/json"
6         "io/ioutil"
7         "os"
8         "path"
9
10         "github.com/bytom/vapor/toolbar/common"
11 )
12
13 type Config struct {
14         NodeIP      string             `json:"node_ip"`
15         ChainID     string             `json:"chain_id"`
16         MySQLConfig common.MySQLConfig `json:"mysql"`
17         RewardConf  *RewardConfig      `json:"reward_config"`
18 }
19
20 func ConfigFile() string {
21         return path.Join("./", "reward.json")
22 }
23
24 type RewardConfig struct {
25         XPub          string `json:"xpub"`
26         AccountID     string `json:"account_id"`
27         Password      string `json:"password"`
28         MiningAddress string `json:"mining_address"`
29         RewardRatio   uint64 `json:"reward_ratio"`
30 }
31
32 func ExportConfigFile(configFile string, config *Config) error {
33         buf := new(bytes.Buffer)
34
35         encoder := json.NewEncoder(buf)
36         encoder.SetIndent("", "  ")
37         if err := encoder.Encode(config); err != nil {
38                 return err
39         }
40
41         return ioutil.WriteFile(configFile, buf.Bytes(), 0644)
42 }
43
44 func LoadConfigFile(configFile string, config *Config) error {
45         file, err := os.Open(configFile)
46         if err != nil {
47                 return err
48         }
49         defer file.Close()
50
51         return json.NewDecoder(file).Decode(config)
52 }