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"`
15 Auth *RPCAuthConfig `mapstructure:"auth"`
16 Web *WebConfig `mapstructure:"web"`
19 // Default configurable parameters.
20 func DefaultConfig() *Config {
22 BaseConfig: DefaultBaseConfig(),
23 RPC: DefaultRPCConfig(),
24 P2P: DefaultP2PConfig(),
25 Wallet: DefaultWalletConfig(),
26 Auth: DefaultRPCAuthConfig(),
27 Web: DefaultWebConfig(),
31 func TestConfig() *Config {
33 BaseConfig: TestBaseConfig(),
36 Wallet: TestWalletConfig(),
40 // Set the RootDir for all Config structs
41 func (cfg *Config) SetRoot(root string) *Config {
42 cfg.BaseConfig.RootDir = root
43 cfg.RPC.RootDir = root
44 cfg.P2P.RootDir = root
48 //-----------------------------------------------------------------------------
50 type BaseConfig struct {
51 // The root directory for all data.
52 // This should be set in viper so it can unmarshal into this struct
53 RootDir string `mapstructure:"home"`
55 // A JSON file containing the initial validator set and other meta data
56 Genesis string `mapstructure:"genesis_file"`
58 //The ID of the network to json
59 ChainID string `mapstructure:"chain_id"`
61 // A JSON file containing the private key to use as a validator in the consensus protocol
62 PrivateKey string `mapstructure:"private_key"`
64 // A custom human readable name for this node
65 Moniker string `mapstructure:"moniker"`
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 Mining bool `mapstructure:"mining"`
77 FilterPeers bool `mapstructure:"filter_peers"` // false
79 // What indexer to use for transactions
80 TxIndex string `mapstructure:"tx_index"`
82 // Database backend: leveldb | memdb
83 DBBackend string `mapstructure:"db_backend"`
86 DBPath string `mapstructure:"db_dir"`
89 KeysPath string `mapstructure:"keys_dir"`
92 HsmUrl string `mapstructure:"hsm_url"`
94 ApiAddress string `mapstructure:"api_addr"`
99 // Default configurable base parameters.
100 func DefaultBaseConfig() BaseConfig {
102 Genesis: "genesis.json",
103 Moniker: "anonymous",
104 ProfListenAddress: "",
109 DBBackend: "leveldb",
111 KeysPath: "keystore",
116 func TestBaseConfig() BaseConfig {
117 conf := DefaultBaseConfig()
118 conf.ChainID = "bytom_test"
119 conf.FastSync = false
120 conf.DBBackend = "memdb"
124 func (b BaseConfig) GenesisFile() string {
125 return rootify(b.Genesis, b.RootDir)
128 func (b BaseConfig) DBDir() string {
129 return rootify(b.DBPath, b.RootDir)
132 func (b BaseConfig) KeysDir() string {
133 return rootify(b.KeysPath, b.RootDir)
136 type RPCConfig struct {
137 RootDir string `mapstructure:"home"`
139 // TCP or UNIX socket address for the RPC server to listen on
140 ListenAddress string `mapstructure:"laddr"`
142 // TCP or UNIX socket address for the gRPC server to listen on
143 // NOTE: This server only supports /broadcast_tx_commit
144 GRPCListenAddress string `mapstructure:"grpc_laddr"`
146 // Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool
147 Unsafe bool `mapstructure:"unsafe"`
150 // Default configurable rpc parameters.
151 func DefaultRPCConfig() *RPCConfig {
153 ListenAddress: "tcp://0.0.0.0:9888",
154 GRPCListenAddress: "",
159 func TestRPCConfig() *RPCConfig {
160 conf := DefaultRPCConfig()
161 conf.ListenAddress = "tcp://0.0.0.0:36657"
162 conf.GRPCListenAddress = "tcp://0.0.0.0:36658"
167 //-----------------------------------------------------------------------------
169 type P2PConfig struct {
170 RootDir string `mapstructure:"home"`
171 ListenAddress string `mapstructure:"laddr"`
172 Seeds string `mapstructure:"seeds"`
173 SkipUPNP bool `mapstructure:"skip_upnp"`
174 AddrBook string `mapstructure:"addr_book_file"`
175 AddrBookStrict bool `mapstructure:"addr_book_strict"`
176 PexReactor bool `mapstructure:"pex"`
177 MaxNumPeers int `mapstructure:"max_num_peers"`
178 HandshakeTimeout int `mapstructure:"handshake_timeout"`
179 DialTimeout int `mapstructure:"dial_timeout"`
182 // Default configurable p2p parameters.
183 func DefaultP2PConfig() *P2PConfig {
185 ListenAddress: "tcp://0.0.0.0:46656",
186 AddrBook: "addrbook.json",
187 AddrBookStrict: true,
190 HandshakeTimeout: 30,
195 func TestP2PConfig() *P2PConfig {
196 conf := DefaultP2PConfig()
197 conf.ListenAddress = "tcp://0.0.0.0:36656"
202 func (p *P2PConfig) AddrBookFile() string {
203 return rootify(p.AddrBook, p.RootDir)
206 //-----------------------------------------------------------------------------
207 type WalletConfig struct {
208 Disable bool `mapstructure:"disable"`
211 type RPCAuthConfig struct {
212 Disable bool `mapstructure:"disable"`
215 type WebConfig struct {
216 Closed bool `mapstructure:"closed"`
219 // Default configurable rpc's auth parameters.
220 func DefaultRPCAuthConfig() *RPCAuthConfig {
221 return &RPCAuthConfig{
226 // Default configurable web parameters.
227 func DefaultWebConfig() *WebConfig {
233 // Default configurable wallet parameters.
234 func DefaultWalletConfig() *WalletConfig {
235 return &WalletConfig{
240 func TestWalletConfig() *WalletConfig {
241 conf := DefaultWalletConfig()
245 //-----------------------------------------------------------------------------
248 // helper function to make config creation independent of root dir
249 func rootify(path, root string) string {
250 if filepath.IsAbs(path) {
253 return filepath.Join(root, path)