forked from ledgerwatch/erigon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
32 lines (27 loc) · 736 Bytes
/
utils.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
package freezer
import (
"bytes"
"fmt"
"github.com/nebojsa94/erigon/cl/sentinel/communication/ssz_snappy"
"github.com/nebojsa94/erigon/erigon-lib/types/ssz"
)
type marshalerHashable interface {
ssz.Marshaler
ssz.HashableSSZ
}
func PutObjectSSZIntoFreezer(objectName, freezerNamespace string, numericalId uint64, object marshalerHashable, record Freezer) error {
if record == nil {
return nil
}
buffer := new(bytes.Buffer)
if err := ssz_snappy.EncodeAndWrite(buffer, object); err != nil {
return err
}
id := fmt.Sprintf("%d", numericalId)
// put the hash of the object as the sidecar.
h, err := object.HashSSZ()
if err != nil {
return err
}
return record.Put(buffer, h[:], freezerNamespace, objectName, id)
}