OSDN Git Service

Merge branch 'dev' into dev-verify
[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:9888"
27 `
28
29 var mainNetConfigTmpl = `chain_id = "mainnet"
30 [p2p]
31 laddr = "tcp://0.0.0.0:46657"
32 seeds = "45.79.213.28:46657,198.74.61.131:46657,212.111.41.245:46657,47.100.214.154:46657,47.100.109.199:46657,47.100.105.165:46657"
33 `
34
35 var testNetConfigTmpl = `chain_id = "testnet"
36 [p2p]
37 laddr = "tcp://0.0.0.0:46656"
38 seeds = "47.96.42.1:46656,172.104.224.219:46656,45.118.132.164:46656"
39 `
40
41 var soloNetConfigTmpl = `chain_id = "solonet"
42 [p2p]
43 laddr = "tcp://0.0.0.0:46658"
44 seeds = ""
45 `
46
47 // Select network seeds to merge a new string.
48 func selectNetwork(network string) string {
49         if network == "testnet" {
50                 return defaultConfigTmpl + testNetConfigTmpl
51         } else if network == "mainnet" {
52                 return defaultConfigTmpl + mainNetConfigTmpl
53         } else {
54                 return defaultConfigTmpl + soloNetConfigTmpl
55         }
56 }