forked from FactomProject/factom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
60 lines (50 loc) · 1.2 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package factom
import (
"bytes"
"crypto/sha256"
"crypto/sha512"
"encoding/binary"
"time"
)
const (
ZeroHash = "0000000000000000000000000000000000000000000000000000000000000000"
)
var (
server = "localhost:8088"
serverFct = "localhost:8089"
)
// SetServer sets the gloabal target for the factomd server
func SetServer(s string) {
server = s
}
// SetWallet sets the global target for the fctwallet server
func SetWallet(s string) {
serverFct = s
}
// Server() returns the global server string for debugging
func Server() string {
return server
}
// milliTime returns a 6 byte slice representing the unix time in milliseconds
func milliTime() (r []byte) {
buf := new(bytes.Buffer)
t := time.Now().UnixNano()
m := t / 1e6
binary.Write(buf, binary.BigEndian, m)
return buf.Bytes()[2:]
}
// shad Double Sha256 Hash; sha256(sha256(data))
func shad(data []byte) []byte {
h1 := sha256.Sum256(data)
h2 := sha256.Sum256(h1[:])
return h2[:]
}
// sha52
func sha52(data []byte) []byte {
h1 := sha512.Sum512(data)
h2 := sha256.Sum256(append(h1[:], data...))
return h2[:]
}