github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/config/toml.go (about)

     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  node_alias = ""
    28  `
    29  
    30  var mainNetConfigTmpl = `chain_id = "mainnet"
    31  [p2p]
    32  laddr = "tcp://0.0.0.0:46657"
    33  seeds = "139.196.106.51:46657,139.224.235.249:46657,139.224.234.206:46657,106.15.207.204:46657,8.212.14.144:46657"
    34  `
    35  
    36  var testNetConfigTmpl = `chain_id = "wisdom"
    37  [p2p]
    38  laddr = "tcp://0.0.0.0:46656"
    39  seeds = "47.101.140.15:46656,47.100.241.64:46656,47.101.139.241:46656,47.100.231.59:46656,139.224.105.227:46656,139.196.235.27:46656,139.224.60.72:46656,139.224.222.59:46656,139.196.233.101:46656,47.100.242.217:46656"
    40  `
    41  
    42  var soloNetConfigTmpl = `chain_id = "solonet"
    43  [p2p]
    44  laddr = "tcp://0.0.0.0:46658"
    45  seeds = ""
    46  `
    47  
    48  // Select network seeds to merge a new string.
    49  func selectNetwork(network string) string {
    50  	switch network {
    51  	case "mainnet":
    52  		return defaultConfigTmpl + mainNetConfigTmpl
    53  	case "testnet":
    54  		return defaultConfigTmpl + testNetConfigTmpl
    55  	default:
    56  		return defaultConfigTmpl + soloNetConfigTmpl
    57  	}
    58  }