10 // Top level options use an anonymous struct
11 BaseConfig `mapstructure:",squash"`
12 // Options for services
13 RPC *RPCConfig `mapstructure:"rpc"`
14 P2P *P2PConfig `mapstructure:"p2p"`
15 Wallet *WalletConfig `mapstructure:"wallet"`
18 func DefaultConfig() *Config {
20 BaseConfig: DefaultBaseConfig(),
21 RPC: DefaultRPCConfig(),
22 P2P: DefaultP2PConfig(),
23 Wallet: DefaultWalletConfig(),
27 func TestConfig() *Config {
29 BaseConfig: TestBaseConfig(),
32 Wallet: TestWalletConfig(),
36 // Set the RootDir for all Config structs
37 func (cfg *Config) SetRoot(root string) *Config {
38 cfg.BaseConfig.RootDir = root
39 cfg.RPC.RootDir = root
40 cfg.P2P.RootDir = root
44 //-----------------------------------------------------------------------------
47 type BaseConfig struct {
48 // The root directory for all data.
49 // This should be set in viper so it can unmarshal into this struct
50 RootDir string `mapstructure:"home"`
52 // A JSON file containing the initial validator set and other meta data
53 Genesis string `mapstructure:"genesis_file"`
55 //The ID of the network to json
56 ChainID string `mapstructure:"chain_id"`
58 // A JSON file containing the private key to use as a validator in the consensus protocol
59 PrivateKey string `mapstructure:"private_key"`
61 // A custom human readable name for this node
62 Moniker string `mapstructure:"moniker"`
64 // Output level for logging
65 LogLevel string `mapstructure:"log_level"`
67 // TCP or UNIX socket address for the profiling server to listen on
68 ProfListenAddress string `mapstructure:"prof_laddr"`
70 // If this node is many blocks behind the tip of the chain, FastSync
71 // allows them to catchup quickly by downloading blocks in parallel
72 // and verifying their commits
73 FastSync bool `mapstructure:"fast_sync"`
75 FilterPeers bool `mapstructure:"filter_peers"` // false
77 // What indexer to use for transactions
78 TxIndex string `mapstructure:"tx_index"`
80 // Database backend: leveldb | memdb
81 DBBackend string `mapstructure:"db_backend"`
84 DBPath string `mapstructure:"db_dir"`
87 KeysPath string `mapstructure:"keys_dir"`
90 HsmUrl string `mapstructure:"hsm_url"`
92 ApiAddress string `mapstructure:"api_addr"`
97 func DefaultBaseConfig() BaseConfig {
99 Genesis: "genesis.json",
100 Moniker: "anonymous",
101 LogLevel: DefaultPackageLogLevels(),
102 ProfListenAddress: "",
106 DBBackend: "leveldb",
108 KeysPath: "keystore",
113 func TestBaseConfig() BaseConfig {
114 conf := DefaultBaseConfig()
115 conf.ChainID = "bytom_test"
116 conf.FastSync = false
117 conf.DBBackend = "memdb"
121 func (b BaseConfig) GenesisFile() string {
122 return rootify(b.Genesis, b.RootDir)
125 func (b BaseConfig) DBDir() string {
126 return rootify(b.DBPath, b.RootDir)
129 func (b BaseConfig) KeysDir() string {
130 return rootify(b.KeysPath, b.RootDir)
133 func DefaultLogLevel() string {
137 func DefaultPackageLogLevels() string {
138 return fmt.Sprintf("state:info,*:%s", DefaultLogLevel())
143 type RPCConfig struct {
144 RootDir string `mapstructure:"home"`
146 // TCP or UNIX socket address for the RPC server to listen on
147 ListenAddress string `mapstructure:"laddr"`
149 // TCP or UNIX socket address for the gRPC server to listen on
150 // NOTE: This server only supports /broadcast_tx_commit
151 GRPCListenAddress string `mapstructure:"grpc_laddr"`
153 // Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool
154 Unsafe bool `mapstructure:"unsafe"`
157 func DefaultRPCConfig() *RPCConfig {
159 ListenAddress: "tcp://0.0.0.0:46657",
160 GRPCListenAddress: "",
165 func TestRPCConfig() *RPCConfig {
166 conf := DefaultRPCConfig()
167 conf.ListenAddress = "tcp://0.0.0.0:36657"
168 conf.GRPCListenAddress = "tcp://0.0.0.0:36658"
173 //-----------------------------------------------------------------------------
176 type P2PConfig struct {
177 RootDir string `mapstructure:"home"`
178 ListenAddress string `mapstructure:"laddr"`
179 Seeds string `mapstructure:"seeds"`
180 SkipUPNP bool `mapstructure:"skip_upnp"`
181 AddrBook string `mapstructure:"addr_book_file"`
182 AddrBookStrict bool `mapstructure:"addr_book_strict"`
183 PexReactor bool `mapstructure:"pex"`
184 MaxNumPeers int `mapstructure:"max_num_peers"`
187 func DefaultP2PConfig() *P2PConfig {
189 ListenAddress: "tcp://0.0.0.0:46656",
190 AddrBook: "addrbook.json",
191 AddrBookStrict: true,
197 func TestP2PConfig() *P2PConfig {
198 conf := DefaultP2PConfig()
199 conf.ListenAddress = "tcp://0.0.0.0:36656"
204 func (p *P2PConfig) AddrBookFile() string {
205 return rootify(p.AddrBook, p.RootDir)
208 //-----------------------------------------------------------------------------
211 type WalletConfig struct {
212 Enable bool `mapstructure:"enable"`
215 func DefaultWalletConfig() *WalletConfig {
216 return &WalletConfig{
221 func TestWalletConfig() *WalletConfig {
222 conf := DefaultWalletConfig()
226 //-----------------------------------------------------------------------------
229 // helper function to make config creation independent of root dir
230 func rootify(path, root string) string {
231 if filepath.IsAbs(path) {
234 return filepath.Join(root, path)