/
system.go
62 lines (50 loc) · 1.28 KB
/
system.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
61
62
package storage
import "encoding/binary"
func (storage *Storage) LastHeight() (uint64, error) {
b, err := storage.getValue([]byte(LastHeightKey))
if err != nil {
return 0, err
}
return binary.BigEndian.Uint64(b), nil
}
func (storage *Storage) SetLastHeight(height uint64) error {
var b [8]byte
binary.BigEndian.PutUint64(b[:], height)
err := storage.setValue([]byte(LastHeightKey), b[:])
if err != nil {
return err
}
return err
}
func (storage *Storage) ConsulsCount() (int, error) {
b, err := storage.getValue([]byte(ConsulsCountKey))
if err != nil {
return 0, err
}
return int(binary.BigEndian.Uint64(b)), nil
}
func (storage *Storage) SetConsulsCount(consulsCount int) error {
var b [8]byte
binary.BigEndian.PutUint64(b[:], uint64(consulsCount))
err := storage.setValue([]byte(ConsulsCountKey), b[:])
if err != nil {
return err
}
return err
}
func (storage *Storage) SetLastRoundApproved(roundId uint64) error {
var b [8]byte
binary.BigEndian.PutUint64(b[:], roundId)
err := storage.setValue([]byte(LastRoundApproved), b[:])
if err != nil {
return err
}
return err
}
func (storage *Storage) LastRoundApproved() (uint64, error) {
b, err := storage.getValue([]byte(LastRoundApproved))
if err != nil {
return 0, err
}
return binary.BigEndian.Uint64(b), nil
}