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