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"`
84 VaultMode bool `mapstructure:"vault_mode"`
89 LogName string `mapstructure:"log_name"`
92 // Default configurable base parameters.
93 func DefaultBaseConfig() BaseConfig {
96 ProfListenAddress: "",
101 DBBackend: "leveldb",
103 KeysPath: "keystore",
105 LogName: "bytom.log",
109 func (b BaseConfig) DBDir() string {
110 return rootify(b.DBPath, b.RootDir)
113 func (b BaseConfig) KeysDir() string {
114 return rootify(b.KeysPath, b.RootDir)
118 type P2PConfig struct {
119 RootDir string `mapstructure:"home"`
120 ListenAddress string `mapstructure:"laddr"`
121 Seeds string `mapstructure:"seeds"`
122 SkipUPNP bool `mapstructure:"skip_upnp"`
123 AddrBook string `mapstructure:"addr_book_file"`
124 AddrBookStrict bool `mapstructure:"addr_book_strict"`
125 PexReactor bool `mapstructure:"pex"`
126 MaxNumPeers int `mapstructure:"max_num_peers"`
127 HandshakeTimeout int `mapstructure:"handshake_timeout"`
128 DialTimeout int `mapstructure:"dial_timeout"`
131 // Default configurable p2p parameters.
132 func DefaultP2PConfig() *P2PConfig {
134 ListenAddress: "tcp://0.0.0.0:46656",
135 AddrBook: "addrbook.json",
136 AddrBookStrict: true,
139 HandshakeTimeout: 30,
145 func (p *P2PConfig) AddrBookFile() string {
146 return rootify(p.AddrBook, p.RootDir)
149 //-----------------------------------------------------------------------------
150 type WalletConfig struct {
151 Disable bool `mapstructure:"disable"`
152 Rescan bool `mapstructure:"rescan"`
155 type RPCAuthConfig struct {
156 Disable bool `mapstructure:"disable"`
159 type WebConfig struct {
160 Closed bool `mapstructure:"closed"`
163 // Default configurable rpc's auth parameters.
164 func DefaultRPCAuthConfig() *RPCAuthConfig {
165 return &RPCAuthConfig{
170 // Default configurable web parameters.
171 func DefaultWebConfig() *WebConfig {
177 // Default configurable wallet parameters.
178 func DefaultWalletConfig() *WalletConfig {
179 return &WalletConfig{
185 //-----------------------------------------------------------------------------
188 // helper function to make config creation independent of root dir
189 func rootify(path, root string) string {
190 if filepath.IsAbs(path) {
193 return filepath.Join(root, path)
196 // DefaultDataDir is the default data directory to use for the databases and other
197 // persistence requirements.
198 func DefaultDataDir() string {
199 // Try to place the data folder in the user's home dir
204 switch runtime.GOOS {
206 return filepath.Join(home, "Library", "Bytom")
208 return filepath.Join(home, "AppData", "Roaming", "Bytom")
210 return filepath.Join(home, ".bytom")
214 func homeDir() string {
215 if home := os.Getenv("HOME"); home != "" {
218 if usr, err := user.Current(); err == nil {