forked from Fantom-foundation/Substate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
47 lines (36 loc) · 1.07 KB
/
metadata.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
package substate
import (
"encoding/binary"
)
const (
MetadataPrefix = "md"
UpdatesetPrefix = "us"
UpdatesetIntervalKey = MetadataPrefix + UpdatesetPrefix + "in"
UpdatesetSizeKey = MetadataPrefix + UpdatesetPrefix + "si"
)
// PutMetadata into db
func (db *UpdateDB) PutMetadata(interval, size uint64) error {
byteInterval := make([]byte, 8)
binary.BigEndian.PutUint64(byteInterval, interval)
if err := db.backend.Put([]byte(UpdatesetIntervalKey), byteInterval); err != nil {
return err
}
sizeInterval := make([]byte, 8)
binary.BigEndian.PutUint64(sizeInterval, size)
if err := db.backend.Put([]byte(UpdatesetSizeKey), sizeInterval); err != nil {
return err
}
return nil
}
// GetMetadata from db
func (db *UpdateDB) GetMetadata() (uint64, uint64, error) {
byteInterval, err := db.backend.Get([]byte(UpdatesetIntervalKey))
if err != nil {
return 0, 0, err
}
byteSize, err := db.backend.Get([]byte(UpdatesetSizeKey))
if err != nil {
return 0, 0, err
}
return binary.BigEndian.Uint64(byteInterval), binary.BigEndian.Uint64(byteSize), nil
}