9 cmn "github.com/tendermint/tmlibs/common"
12 /****** these are for production settings ***********/
14 func EnsureRoot(rootDir string) {
15 cmn.EnsureDir(rootDir, 0700)
16 cmn.EnsureDir(rootDir+"/data", 0700)
18 configFilePath := path.Join(rootDir, "config.toml")
20 // Write default config file if missing.
21 if !cmn.FileExists(configFilePath) {
22 // Ask user for moniker
23 // moniker := cfg.Prompt("Type hostname: ", "anonymous")
24 cmn.MustWriteFile(configFilePath, []byte(defaultConfig("anonymous")), 0644)
28 var defaultConfigTmpl = `# This is a TOML config file.
29 # For more information, see https://github.com/toml-lang/toml
31 proxy_app = "tcp://127.0.0.1:46658"
32 moniker = "__MONIKER__"
34 db_backend = "leveldb"
35 log_level = "state:info,*:info"
38 laddr = "tcp://0.0.0.0:46657"
41 laddr = "tcp://0.0.0.0:46656"
45 func defaultConfig(moniker string) string {
46 return strings.Replace(defaultConfigTmpl, "__MONIKER__", moniker, -1)
49 /****** these are for test settings ***********/
51 func ResetTestRoot(testName string) *Config {
52 rootDir := os.ExpandEnv("$HOME/.tendermint_test")
53 rootDir = filepath.Join(rootDir, testName)
54 // Remove ~/.tendermint_test_bak
55 if cmn.FileExists(rootDir + "_bak") {
56 err := os.RemoveAll(rootDir + "_bak")
58 cmn.PanicSanity(err.Error())
61 // Move ~/.tendermint_test to ~/.tendermint_test_bak
62 if cmn.FileExists(rootDir) {
63 err := os.Rename(rootDir, rootDir+"_bak")
65 cmn.PanicSanity(err.Error())
69 cmn.EnsureDir(rootDir, 0700)
70 cmn.EnsureDir(rootDir+"/data", 0700)
72 configFilePath := path.Join(rootDir, "config.toml")
73 genesisFilePath := path.Join(rootDir, "genesis.json")
74 privFilePath := path.Join(rootDir, "priv_validator.json")
76 // Write default config file if missing.
77 if !cmn.FileExists(configFilePath) {
78 // Ask user for moniker
79 cmn.MustWriteFile(configFilePath, []byte(testConfig("anonymous")), 0644)
81 if !cmn.FileExists(genesisFilePath) {
82 cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
84 // we always overwrite the priv val
85 cmn.MustWriteFile(privFilePath, []byte(testPrivValidator), 0644)
87 config := TestConfig().SetRoot(rootDir)
91 var testConfigTmpl = `# This is a TOML config file.
92 # For more information, see https://github.com/toml-lang/toml
95 moniker = "__MONIKER__"
101 laddr = "tcp://0.0.0.0:36657"
104 laddr = "tcp://0.0.0.0:36656"
108 func testConfig(moniker string) (testConfig string) {
109 testConfig = strings.Replace(testConfigTmpl, "__MONIKER__", moniker, -1)
114 "genesis_time": "0001-01-01T00:00:00.000Z",
115 "chain_id": "tendermint_test",
120 "data":"3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8"
129 var testPrivValidator = `{
130 "address": "D028C9981F7A87F3093672BF0D5B0E2A1B3ED456",
133 "data": "3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8"
137 "data": "27F82582AEFAE7AB151CFB01C48BB6C1A0DA78F9BDDA979A9F70A84D074EB07D3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8"