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"`
19 Simd *SimdConfig `mapstructure:"simd"`
22 // Default configurable parameters.
23 func DefaultConfig() *Config {
25 BaseConfig: DefaultBaseConfig(),
26 P2P: DefaultP2PConfig(),
27 Wallet: DefaultWalletConfig(),
28 Auth: DefaultRPCAuthConfig(),
29 Web: DefaultWebConfig(),
30 Simd: DefaultSimdConfig(),
34 // Set the RootDir for all Config structs
35 func (cfg *Config) SetRoot(root string) *Config {
36 cfg.BaseConfig.RootDir = root
37 cfg.P2P.RootDir = root
41 //-----------------------------------------------------------------------------
43 type BaseConfig struct {
44 // The root directory for all data.
45 // This should be set in viper so it can unmarshal into this struct
46 RootDir string `mapstructure:"home"`
48 //The ID of the network to json
49 ChainID string `mapstructure:"chain_id"`
52 LogLevel string `mapstructure:"log_level"`
54 // A JSON file containing the private key to use as a validator in the consensus protocol
55 PrivateKey string `mapstructure:"private_key"`
57 // A custom human readable name for this node
58 Moniker string `mapstructure:"moniker"`
60 // TCP or UNIX socket address for the profiling server to listen on
61 ProfListenAddress string `mapstructure:"prof_laddr"`
63 // If this node is many blocks behind the tip of the chain, FastSync
64 // allows them to catchup quickly by downloading blocks in parallel
65 // and verifying their commits
66 FastSync bool `mapstructure:"fast_sync"`
68 Mining bool `mapstructure:"mining"`
70 FilterPeers bool `mapstructure:"filter_peers"` // false
72 // What indexer to use for transactions
73 TxIndex string `mapstructure:"tx_index"`
75 // Database backend: leveldb | memdb
76 DBBackend string `mapstructure:"db_backend"`
79 DBPath string `mapstructure:"db_dir"`
82 KeysPath string `mapstructure:"keys_dir"`
85 HsmUrl string `mapstructure:"hsm_url"`
87 ApiAddress string `mapstructure:"api_addr"`
89 VaultMode bool `mapstructure:"vault_mode"`
94 LogFile string `mapstructure:"log_file"`
97 // Default configurable base parameters.
98 func DefaultBaseConfig() BaseConfig {
100 Moniker: "anonymous",
101 ProfListenAddress: "",
106 DBBackend: "leveldb",
108 KeysPath: "keystore",
113 func (b BaseConfig) DBDir() string {
114 return rootify(b.DBPath, b.RootDir)
117 func (b BaseConfig) KeysDir() string {
118 return rootify(b.KeysPath, b.RootDir)
122 type P2PConfig struct {
123 RootDir string `mapstructure:"home"`
124 ListenAddress string `mapstructure:"laddr"`
125 Seeds string `mapstructure:"seeds"`
126 SkipUPNP bool `mapstructure:"skip_upnp"`
127 AddrBook string `mapstructure:"addr_book_file"`
128 AddrBookStrict bool `mapstructure:"addr_book_strict"`
129 PexReactor bool `mapstructure:"pex"`
130 MaxNumPeers int `mapstructure:"max_num_peers"`
131 HandshakeTimeout int `mapstructure:"handshake_timeout"`
132 DialTimeout int `mapstructure:"dial_timeout"`
135 // Default configurable p2p parameters.
136 func DefaultP2PConfig() *P2PConfig {
138 ListenAddress: "tcp://0.0.0.0:46656",
139 AddrBook: "addrbook.json",
140 AddrBookStrict: true,
143 HandshakeTimeout: 30,
149 func (p *P2PConfig) AddrBookFile() string {
150 return rootify(p.AddrBook, p.RootDir)
153 //-----------------------------------------------------------------------------
154 type WalletConfig struct {
155 Disable bool `mapstructure:"disable"`
156 Rescan bool `mapstructure:"rescan"`
159 type RPCAuthConfig struct {
160 Disable bool `mapstructure:"disable"`
163 type WebConfig struct {
164 Closed bool `mapstructure:"closed"`
167 type SimdConfig struct {
168 Enable bool `mapstructure:"enable"`
171 // Default configurable rpc's auth parameters.
172 func DefaultRPCAuthConfig() *RPCAuthConfig {
173 return &RPCAuthConfig{
178 // Default configurable web parameters.
179 func DefaultWebConfig() *WebConfig {
185 // Default configurable wallet parameters.
186 func DefaultWalletConfig() *WalletConfig {
187 return &WalletConfig{
193 // Default configurable web parameters.
194 func DefaultSimdConfig() *SimdConfig {
200 //-----------------------------------------------------------------------------
203 // helper function to make config creation independent of root dir
204 func rootify(path, root string) string {
205 if filepath.IsAbs(path) {
208 return filepath.Join(root, path)
211 // DefaultDataDir is the default data directory to use for the databases and other
212 // persistence requirements.
213 func DefaultDataDir() string {
214 // Try to place the data folder in the user's home dir
219 switch runtime.GOOS {
221 return filepath.Join(home, "Library", "Bytom")
223 return filepath.Join(home, "AppData", "Roaming", "Bytom")
225 return filepath.Join(home, ".bytom")
229 func homeDir() string {
230 if home := os.Getenv("HOME"); home != "" {
233 if usr, err := user.Current(); err == nil {