github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/consensus/ipbft/utils.go (about) 1 package ipbft 2 3 import ( 4 "gopkg.in/urfave/cli.v1" 5 "os" 6 "os/user" 7 "path/filepath" 8 "runtime" 9 10 tmcfg "github.com/intfoundation/intchain/consensus/ipbft/config/tendermint" 11 cfg "github.com/intfoundation/go-config" 12 ) 13 14 func GetTendermintConfig(chainId string, ctx *cli.Context) cfg.Config { 15 datadir := ctx.GlobalString(DataDirFlag.Name) 16 config := tmcfg.GetConfig(datadir, chainId) 17 18 return config 19 } 20 21 func HomeDir() string { 22 if home := os.Getenv("HOME"); home != "" { 23 return home 24 } 25 if usr, err := user.Current(); err == nil { 26 return usr.HomeDir 27 } 28 return "" 29 } 30 31 func DefaultDataDir() string { 32 // Try to place the data folder in the user's home dir 33 home := HomeDir() 34 if home != "" { 35 if runtime.GOOS == "windows" { 36 return filepath.Join(home, "AppData", "Roaming", "intchain") 37 } else { 38 return filepath.Join(home, ".intchain") 39 } 40 } 41 // As we cannot guess a stable location, return empty and handle later 42 return "" 43 } 44 45 func ConcatCopyPreAllocate(slices [][]byte) []byte { 46 var totalLen int 47 for _, s := range slices { 48 totalLen += len(s) 49 } 50 tmp := make([]byte, totalLen) 51 var i int 52 for _, s := range slices { 53 i += copy(tmp[i:], s) 54 } 55 return tmp 56 }