9 // Top level options use an anonymous struct
10 BaseConfig `mapstructure:",squash"`
11 // Options for services
12 RPC *RPCConfig `mapstructure:"rpc"`
13 P2P *P2PConfig `mapstructure:"p2p"`
14 Wallet *WalletConfig `mapstructure:"wallet"`
17 func DefaultConfig() *Config {
19 BaseConfig: DefaultBaseConfig(),
20 RPC: DefaultRPCConfig(),
21 P2P: DefaultP2PConfig(),
22 Wallet: DefaultWalletConfig(),
26 func TestConfig() *Config {
28 BaseConfig: TestBaseConfig(),
31 Wallet: TestWalletConfig(),
35 // Set the RootDir for all Config structs
36 func (cfg *Config) SetRoot(root string) *Config {
37 cfg.BaseConfig.RootDir = root
38 cfg.RPC.RootDir = root
39 cfg.P2P.RootDir = root
43 //-----------------------------------------------------------------------------
46 type BaseConfig struct {
47 // The root directory for all data.
48 // This should be set in viper so it can unmarshal into this struct
49 RootDir string `mapstructure:"home"`
51 // A JSON file containing the initial validator set and other meta data
52 Genesis string `mapstructure:"genesis_file"`
54 //The ID of the network to json
55 ChainID string `mapstructure:"chain_id"`
57 // A JSON file containing the private key to use as a validator in the consensus protocol
58 PrivateKey string `mapstructure:"private_key"`
60 // A custom human readable name for this node
61 Moniker string `mapstructure:"moniker"`
63 // TCP or UNIX socket address for the profiling server to listen on
64 ProfListenAddress string `mapstructure:"prof_laddr"`
66 // If this node is many blocks behind the tip of the chain, FastSync
67 // allows them to catchup quickly by downloading blocks in parallel
68 // and verifying their commits
69 FastSync bool `mapstructure:"fast_sync"`
71 FilterPeers bool `mapstructure:"filter_peers"` // false
73 // What indexer to use for transactions
74 TxIndex string `mapstructure:"tx_index"`
76 // Database backend: leveldb | memdb
77 DBBackend string `mapstructure:"db_backend"`
80 DBPath string `mapstructure:"db_dir"`
83 KeysPath string `mapstructure:"keys_dir"`
86 HsmUrl string `mapstructure:"hsm_url"`
88 ApiAddress string `mapstructure:"api_addr"`
93 func DefaultBaseConfig() BaseConfig {
95 Genesis: "genesis.json",
97 ProfListenAddress: "",
101 DBBackend: "leveldb",
103 KeysPath: "keystore",
108 func TestBaseConfig() BaseConfig {
109 conf := DefaultBaseConfig()
110 conf.ChainID = "bytom_test"
111 conf.FastSync = false
112 conf.DBBackend = "memdb"
116 func (b BaseConfig) GenesisFile() string {
117 return rootify(b.Genesis, b.RootDir)
120 func (b BaseConfig) DBDir() string {
121 return rootify(b.DBPath, b.RootDir)
124 func (b BaseConfig) KeysDir() string {
125 return rootify(b.KeysPath, b.RootDir)
128 func DefaultLogLevel() string {
134 type RPCConfig struct {
135 RootDir string `mapstructure:"home"`
137 // TCP or UNIX socket address for the RPC server to listen on
138 ListenAddress string `mapstructure:"laddr"`
140 // TCP or UNIX socket address for the gRPC server to listen on
141 // NOTE: This server only supports /broadcast_tx_commit
142 GRPCListenAddress string `mapstructure:"grpc_laddr"`
144 // Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool
145 Unsafe bool `mapstructure:"unsafe"`
148 func DefaultRPCConfig() *RPCConfig {
150 ListenAddress: "tcp://0.0.0.0:46657",
151 GRPCListenAddress: "",
156 func TestRPCConfig() *RPCConfig {
157 conf := DefaultRPCConfig()
158 conf.ListenAddress = "tcp://0.0.0.0:36657"
159 conf.GRPCListenAddress = "tcp://0.0.0.0:36658"
164 //-----------------------------------------------------------------------------
167 type P2PConfig struct {
168 RootDir string `mapstructure:"home"`
169 ListenAddress string `mapstructure:"laddr"`
170 Seeds string `mapstructure:"seeds"`
171 SkipUPNP bool `mapstructure:"skip_upnp"`
172 AddrBook string `mapstructure:"addr_book_file"`
173 AddrBookStrict bool `mapstructure:"addr_book_strict"`
174 PexReactor bool `mapstructure:"pex"`
175 MaxNumPeers int `mapstructure:"max_num_peers"`
176 HandshakeTimeout int `mapstructure:"handshake_timeout"`
177 DialTimeout int `mapstructure:"dial_timeout"`
180 func DefaultP2PConfig() *P2PConfig {
182 ListenAddress: "tcp://0.0.0.0:46656",
183 AddrBook: "addrbook.json",
184 AddrBookStrict: true,
187 HandshakeTimeout: 30,
192 func TestP2PConfig() *P2PConfig {
193 conf := DefaultP2PConfig()
194 conf.ListenAddress = "tcp://0.0.0.0:36656"
199 func (p *P2PConfig) AddrBookFile() string {
200 return rootify(p.AddrBook, p.RootDir)
203 //-----------------------------------------------------------------------------
206 type WalletConfig struct {
207 Enable bool `mapstructure:"enable"`
210 func DefaultWalletConfig() *WalletConfig {
211 return &WalletConfig{
216 func TestWalletConfig() *WalletConfig {
217 conf := DefaultWalletConfig()
221 //-----------------------------------------------------------------------------
224 // helper function to make config creation independent of root dir
225 func rootify(path, root string) string {
226 if filepath.IsAbs(path) {
229 return filepath.Join(root, path)