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