aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/common.go
diff options
context:
space:
mode:
authorEthan Buchman <ethan@coinculture.info>2015-02-27 06:54:57 +0800
committerEthan Buchman <ethan@coinculture.info>2015-02-27 06:54:57 +0800
commit5a827417d9cef0d2a765df11e747b1755bf04898 (patch)
treecd3764686dcb59f5b1b9faf16c9f29dcc5efd593 /ethutil/common.go
parent9446489cf3f2eb4b5237b9355b3975fde2886508 (diff)
parentcc5c8a444dbc23501ba1a131eb2334f4b5e1ce9f (diff)
downloadgo-tangerine-5a827417d9cef0d2a765df11e747b1755bf04898.tar.gz
go-tangerine-5a827417d9cef0d2a765df11e747b1755bf04898.tar.zst
go-tangerine-5a827417d9cef0d2a765df11e747b1755bf04898.zip
Merge branch 'develop' of https://github.com/ethereum/go-ethereum into develop
Diffstat (limited to 'ethutil/common.go')
-rw-r--r--ethutil/common.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/ethutil/common.go b/ethutil/common.go
index 271c56fd5..c4e7415dc 100644
--- a/ethutil/common.go
+++ b/ethutil/common.go
@@ -3,9 +3,51 @@ package ethutil
import (
"fmt"
"math/big"
+ "os"
+ "os/user"
+ "path"
+ "path/filepath"
"runtime"
+ "time"
+
+ "github.com/kardianos/osext"
)
+func DefaultAssetPath() string {
+ var assetPath string
+ // If the current working directory is the go-ethereum dir
+ // assume a debug build and use the source directory as
+ // asset directory.
+ pwd, _ := os.Getwd()
+ if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist") {
+ assetPath = path.Join(pwd, "assets")
+ } else {
+ switch runtime.GOOS {
+ case "darwin":
+ // Get Binary Directory
+ exedir, _ := osext.ExecutableFolder()
+ assetPath = filepath.Join(exedir, "../Resources")
+ case "linux":
+ assetPath = "/usr/share/mist"
+ case "windows":
+ assetPath = "./assets"
+ default:
+ assetPath = "."
+ }
+ }
+ return assetPath
+}
+
+func DefaultDataDir() string {
+ usr, _ := user.Current()
+ if runtime.GOOS == "darwin" {
+ return path.Join(usr.HomeDir, "Library/Ethereum")
+ } else if runtime.GOOS == "windows" {
+ return path.Join(usr.HomeDir, "AppData/Roaming/Ethereum")
+ } else {
+ return path.Join(usr.HomeDir, ".ethereum")
+ }
+}
func IsWindows() bool {
return runtime.GOOS == "windows"
}
@@ -86,3 +128,9 @@ var (
Big256 = big.NewInt(0xff)
Big257 = big.NewInt(257)
)
+
+func Bench(pre string, cb func()) {
+ start := time.Now()
+ cb()
+ fmt.Println(pre, ": took:", time.Since(start))
+}