OSDN Git Service

Bvm (#138)
[bytom/bytom.git] / config / toml.go
1 package config
2
3 import (
4         "path"
5
6         cmn "github.com/tendermint/tmlibs/common"
7 )
8
9 /****** these are for production settings ***********/
10 func EnsureRoot(rootDir string, network string) {
11         cmn.EnsureDir(rootDir, 0700)
12         cmn.EnsureDir(rootDir+"/data", 0700)
13
14         configFilePath := path.Join(rootDir, "config.toml")
15
16         // Write default config file if missing.
17         if !cmn.FileExists(configFilePath) {
18                 cmn.MustWriteFile(configFilePath, []byte(selectNetwork(network)), 0644)
19         }
20 }
21
22 var defaultConfigTmpl = `# This is a TOML config file.
23 # For more information, see https://github.com/toml-lang/toml
24 fast_sync = true
25 db_backend = "leveldb"
26 api_addr = "0.0.0.0:1999"
27
28 [p2p]
29 laddr = "tcp://0.0.0.0:46656"
30 `
31
32 var testnetSeeds = `
33 seeds = "139.162.105.40:46656,139.162.88.74:46656,139.162.96.53:46656,139.162.104.59:46656"
34 `
35 var mainnetSeeds = `seeds = ""`
36
37 // Select network seeds to merge a new string.
38 func selectNetwork(network string) string {
39         if network == "testnet" {
40                 return defaultConfigTmpl + testnetSeeds
41         } else {
42                 return defaultConfigTmpl + mainnetSeeds
43         }
44 }