12 // Top level options use an anonymous struct
13 BaseConfig `mapstructure:",squash"`
14 // Options for services
15 P2P *P2PConfig `mapstructure:"p2p"`
16 Wallet *WalletConfig `mapstructure:"wallet"`
17 Auth *RPCAuthConfig `mapstructure:"auth"`
18 Web *WebConfig `mapstructure:"web"`
21 // Default configurable parameters.
22 func DefaultConfig() *Config {
24 BaseConfig: DefaultBaseConfig(),
25 P2P: DefaultP2PConfig(),
26 Wallet: DefaultWalletConfig(),
27 Auth: DefaultRPCAuthConfig(),
28 Web: DefaultWebConfig(),
32 // Set the RootDir for all Config structs
33 func (cfg *Config) SetRoot(root string) *Config {
34 cfg.BaseConfig.RootDir = root
35 cfg.P2P.RootDir = root
39 //-----------------------------------------------------------------------------
41 type BaseConfig struct {
42 // The root directory for all data.
43 // This should be set in viper so it can unmarshal into this struct
44 RootDir string `mapstructure:"home"`
46 //The ID of the network to json
47 ChainID string `mapstructure:"chain_id"`
50 LogLevel string `mapstructure:"log_level"`
52 // A JSON file containing the private key to use as a validator in the consensus protocol
53 PrivateKey string `mapstructure:"private_key"`
55 // A custom human readable name for this node
56 Moniker string `mapstructure:"moniker"`
58 // TCP or UNIX socket address for the profiling server to listen on
59 ProfListenAddress string `mapstructure:"prof_laddr"`
61 // If this node is many blocks behind the tip of the chain, FastSync
62 // allows them to catchup quickly by downloading blocks in parallel
63 // and verifying their commits
64 FastSync bool `mapstructure:"fast_sync"`
66 Mining bool `mapstructure:"mining"`
68 FilterPeers bool `mapstructure:"filter_peers"` // false
70 // What indexer to use for transactions
71 TxIndex string `mapstructure:"tx_index"`
73 // Database backend: leveldb | memdb
74 DBBackend string `mapstructure:"db_backend"`
77 DBPath string `mapstructure:"db_dir"`
80 KeysPath string `mapstructure:"keys_dir"`
83 HsmUrl string `mapstructure:"hsm_url"`
85 ApiAddress string `mapstructure:"api_addr"`
87 VaultMode bool `mapstructure:"vault_mode"`
92 LogFile string `mapstructure:"log_file"`
95 // Default configurable base parameters.
96 func DefaultBaseConfig() BaseConfig {
99 ProfListenAddress: "",
104 DBBackend: "leveldb",
106 KeysPath: "keystore",
111 func (b BaseConfig) DBDir() string {
112 return rootify(b.DBPath, b.RootDir)
115 func (b BaseConfig) KeysDir() string {
116 return rootify(b.KeysPath, b.RootDir)
120 type P2PConfig struct {
121 RootDir string `mapstructure:"home"`
122 ListenAddress string `mapstructure:"laddr"`
123 Seeds string `mapstructure:"seeds"`
124 SkipUPNP bool `mapstructure:"skip_upnp"`
125 AddrBook string `mapstructure:"addr_book_file"`
126 AddrBookStrict bool `mapstructure:"addr_book_strict"`
127 PexReactor bool `mapstructure:"pex"`
128 MaxNumPeers int `mapstructure:"max_num_peers"`
129 HandshakeTimeout int `mapstructure:"handshake_timeout"`
130 DialTimeout int `mapstructure:"dial_timeout"`
133 // Default configurable p2p parameters.
134 func DefaultP2PConfig() *P2PConfig {
136 ListenAddress: "tcp://0.0.0.0:46656",
137 AddrBook: "addrbook.json",
138 AddrBookStrict: true,
141 HandshakeTimeout: 30,
147 func (p *P2PConfig) AddrBookFile() string {
148 return rootify(p.AddrBook, p.RootDir)
151 //-----------------------------------------------------------------------------
152 type WalletConfig struct {
153 Disable bool `mapstructure:"disable"`
154 Rescan bool `mapstructure:"rescan"`
157 type RPCAuthConfig struct {
158 Disable bool `mapstructure:"disable"`
161 type WebConfig struct {
162 Closed bool `mapstructure:"closed"`
165 // Default configurable rpc's auth parameters.
166 func DefaultRPCAuthConfig() *RPCAuthConfig {
167 return &RPCAuthConfig{
172 // Default configurable web parameters.
173 func DefaultWebConfig() *WebConfig {
179 // Default configurable wallet parameters.
180 func DefaultWalletConfig() *WalletConfig {
181 return &WalletConfig{
187 //-----------------------------------------------------------------------------
190 // helper function to make config creation independent of root dir
191 func rootify(path, root string) string {
192 if filepath.IsAbs(path) {
195 return filepath.Join(root, path)
198 // DefaultDataDir is the default data directory to use for the databases and other
199 // persistence requirements.
200 func DefaultDataDir() string {
201 // Try to place the data folder in the user's home dir
206 switch runtime.GOOS {
208 return filepath.Join(home, "Library", "Bytom")
210 return filepath.Join(home, "AppData", "Roaming", "Bytom")
212 return filepath.Join(home, ".bytom")
216 func homeDir() string {
217 if home := os.Getenv("HOME"); home != "" {
220 if usr, err := user.Current(); err == nil {