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 moniker = "__MONIKER__"
33 db_backend = "leveldb"
34 log_level = "state:info,*:info"
35 api_addr = "0.0.0.0:1999"
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/.test")
53 rootDir = filepath.Join(rootDir, testName)
54 if cmn.FileExists(rootDir + "_bak") {
55 err := os.RemoveAll(rootDir + "_bak")
57 cmn.PanicSanity(err.Error())
60 if cmn.FileExists(rootDir) {
61 err := os.Rename(rootDir, rootDir+"_bak")
63 cmn.PanicSanity(err.Error())
67 cmn.EnsureDir(rootDir, 0700)
68 cmn.EnsureDir(rootDir+"/data", 0700)
70 configFilePath := path.Join(rootDir, "config.toml")
71 genesisFilePath := path.Join(rootDir, "genesis.json")
72 privFilePath := path.Join(rootDir, "priv_validator.json")
74 // Write default config file if missing.
75 if !cmn.FileExists(configFilePath) {
76 // Ask user for moniker
77 cmn.MustWriteFile(configFilePath, []byte(testConfig("anonymous")), 0644)
79 if !cmn.FileExists(genesisFilePath) {
80 cmn.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
82 // we always overwrite the priv val
83 cmn.MustWriteFile(privFilePath, []byte(testPrivValidator), 0644)
85 config := TestConfig().SetRoot(rootDir)
89 var testConfigTmpl = `# This is a TOML config file.
90 # For more information, see https://github.com/toml-lang/toml
92 moniker = "__MONIKER__"
96 api_addr = "0.0.0.0:1999"
99 laddr = "tcp://0.0.0.0:36657"
102 laddr = "tcp://0.0.0.0:36656"
106 func testConfig(moniker string) (testConfig string) {
107 testConfig = strings.Replace(testConfigTmpl, "__MONIKER__", moniker, -1)
112 "genesis_time": "0001-01-01T00:00:00.000Z",
113 "chain_id": "tendermint_test",
118 "data":"3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8"
127 var testPrivValidator = `{
128 "address": "D028C9981F7A87F3093672BF0D5B0E2A1B3ED456",
131 "data": "3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8"
135 "data": "27F82582AEFAE7AB151CFB01C48BB6C1A0DA78F9BDDA979A9F70A84D074EB07D3B3069C422E19688B45CBFAE7BB009FC0FA1B1EA86593519318B7214853803C8"