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"`
49 // A JSON file containing the private key to use as a validator in the consensus protocol
50 PrivateKey string `mapstructure:"private_key"`
52 // A custom human readable name for this node
53 Moniker string `mapstructure:"moniker"`
55 // TCP or UNIX socket address for the profiling server to listen on
56 ProfListenAddress string `mapstructure:"prof_laddr"`
58 // If this node is many blocks behind the tip of the chain, FastSync
59 // allows them to catchup quickly by downloading blocks in parallel
60 // and verifying their commits
61 FastSync bool `mapstructure:"fast_sync"`
63 Mining bool `mapstructure:"mining"`
65 FilterPeers bool `mapstructure:"filter_peers"` // false
67 // What indexer to use for transactions
68 TxIndex string `mapstructure:"tx_index"`
70 // Database backend: leveldb | memdb
71 DBBackend string `mapstructure:"db_backend"`
74 DBPath string `mapstructure:"db_dir"`
77 KeysPath string `mapstructure:"keys_dir"`
80 HsmUrl string `mapstructure:"hsm_url"`
82 ApiAddress string `mapstructure:"api_addr"`
87 // Default configurable base parameters.
88 func DefaultBaseConfig() BaseConfig {
91 ProfListenAddress: "",
103 func (b BaseConfig) DBDir() string {
104 return rootify(b.DBPath, b.RootDir)
107 func (b BaseConfig) KeysDir() string {
108 return rootify(b.KeysPath, b.RootDir)
112 type P2PConfig struct {
113 RootDir string `mapstructure:"home"`
114 ListenAddress string `mapstructure:"laddr"`
115 Seeds string `mapstructure:"seeds"`
116 SkipUPNP bool `mapstructure:"skip_upnp"`
117 AddrBook string `mapstructure:"addr_book_file"`
118 AddrBookStrict bool `mapstructure:"addr_book_strict"`
119 PexReactor bool `mapstructure:"pex"`
120 MaxNumPeers int `mapstructure:"max_num_peers"`
121 HandshakeTimeout int `mapstructure:"handshake_timeout"`
122 DialTimeout int `mapstructure:"dial_timeout"`
125 // Default configurable p2p parameters.
126 func DefaultP2PConfig() *P2PConfig {
128 ListenAddress: "tcp://0.0.0.0:46656",
129 AddrBook: "addrbook.json",
130 AddrBookStrict: true,
133 HandshakeTimeout: 30,
139 func (p *P2PConfig) AddrBookFile() string {
140 return rootify(p.AddrBook, p.RootDir)
143 //-----------------------------------------------------------------------------
144 type WalletConfig struct {
145 Disable bool `mapstructure:"disable"`
148 type RPCAuthConfig struct {
149 Disable bool `mapstructure:"disable"`
152 type WebConfig struct {
153 Closed bool `mapstructure:"closed"`
156 // Default configurable rpc's auth parameters.
157 func DefaultRPCAuthConfig() *RPCAuthConfig {
158 return &RPCAuthConfig{
163 // Default configurable web parameters.
164 func DefaultWebConfig() *WebConfig {
170 // Default configurable wallet parameters.
171 func DefaultWalletConfig() *WalletConfig {
172 return &WalletConfig{
177 //-----------------------------------------------------------------------------
180 // helper function to make config creation independent of root dir
181 func rootify(path, root string) string {
182 if filepath.IsAbs(path) {
185 return filepath.Join(root, path)
188 // DefaultDataDir is the default data directory to use for the databases and other
189 // persistence requirements.
190 func DefaultDataDir() string {
191 // Try to place the data folder in the user's home dir
193 dataDir := "./.Bytom"
195 switch runtime.GOOS {
197 dataDir = filepath.Join(home, "Library", "Bytom")
199 dataDir = filepath.Join(home, "AppData", "Roaming", "Bytom")
201 dataDir = filepath.Join(home, ".Bytom")
207 func homeDir() string {
208 if home := os.Getenv("HOME"); home != "" {
211 if usr, err := user.Current(); err == nil {