2023-06-05 01:52:55 +02:00
|
|
|
package freezer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2023-10-22 01:17:18 +02:00
|
|
|
"github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy"
|
2023-06-05 01:52:55 +02:00
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon-lib/types/ssz"
|
|
|
|
)
|
|
|
|
|
2023-06-06 03:24:59 +02:00
|
|
|
type marshalerHashable interface {
|
|
|
|
ssz.Marshaler
|
|
|
|
ssz.HashableSSZ
|
|
|
|
}
|
|
|
|
|
|
|
|
func PutObjectSSZIntoFreezer(objectName, freezerNamespace string, numericalId uint64, object marshalerHashable, record Freezer) error {
|
2023-06-05 01:52:55 +02:00
|
|
|
if record == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2023-07-27 17:55:14 -05:00
|
|
|
buffer := new(bytes.Buffer)
|
|
|
|
if err := ssz_snappy.EncodeAndWrite(buffer, object); err != nil {
|
2023-06-05 01:52:55 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
id := fmt.Sprintf("%d", numericalId)
|
2023-06-06 03:24:59 +02:00
|
|
|
// put the hash of the object as the sidecar.
|
|
|
|
h, err := object.HashSSZ()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-06-05 01:52:55 +02:00
|
|
|
|
2023-07-27 17:55:14 -05:00
|
|
|
return record.Put(buffer, h[:], freezerNamespace, objectName, id)
|
2023-06-05 01:52:55 +02:00
|
|
|
}
|