forked from ruqqq/blockchainparser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
39 lines (33 loc) · 779 Bytes
/
util.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
package blockchainparser
import (
"crypto/sha256"
"os"
"runtime"
)
func BitcoinDir() string {
if runtime.GOOS == "windows" {
home := os.Getenv("APPDATA")
return home + "/Bitcoin"
} else if runtime.GOOS == "osx" || runtime.GOOS == "darwin" {
return os.Getenv("HOME") + "/Library/Application Support/Bitcoin"
}
return os.Getenv("HOME") + "/.bitcoin"
}
// TODO: Maybe can optimize
func ReverseHex(b []byte) []byte {
newb := make([]byte, len(b))
copy(newb, b)
for i := len(newb)/2 - 1; i >= 0; i-- {
opp := len(newb) - 1 - i
newb[i], newb[opp] = newb[opp], newb[i]
}
return newb
}
func DoubleSha256(data []byte) Hash256 {
hash := sha256.New()
hash.Write(data)
firstSha256 := hash.Sum(nil)
hash.Reset()
hash.Write(firstSha256)
return hash.Sum(nil)
}