forked from FactomProject/factomd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
60 lines (53 loc) · 1.24 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
package identity
import (
"encoding/binary"
"github.com/FactomProject/factomd/common/constants"
)
const (
TWELVE_HOURS_S uint64 = 12 * 60 * 60
)
// Makes sure the timestamp is within the designated window to be valid : 12 hours
// TimeEntered is in seconds
func CheckTimestamp(time []byte, timeEntered int64) bool {
if len(time) < 8 {
zero := []byte{00}
add := make([]byte, 0)
for i := len(time); i <= 8; i++ {
add = append(add, zero...)
}
time = append(add, time...)
}
// In Seconds
ts := binary.BigEndian.Uint64(time)
var res uint64
timeEnteredUint := uint64(timeEntered)
if timeEnteredUint > ts {
res = timeEnteredUint - ts
} else {
res = ts - timeEnteredUint
}
if res <= TWELVE_HOURS_S {
return true
} else {
return false
}
}
func BubbleSortUint32(arr []uint32) []uint32 {
for i := 1; i < len(arr); i++ {
for j := 0; j < len(arr)-i; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
return arr
}
func statusIsFedOrAudit(status uint8) bool {
if status == constants.IDENTITY_FEDERATED_SERVER ||
status == constants.IDENTITY_AUDIT_SERVER ||
status == constants.IDENTITY_PENDING_FEDERATED_SERVER ||
status == constants.IDENTITY_PENDING_AUDIT_SERVER {
return true
}
return false
}