2020-11-20 18:06:12 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
bolt "go.etcd.io/bbolt"
|
|
|
|
)
|
|
|
|
|
2022-02-14 13:34:38 +00:00
|
|
|
// SaveGenesisValidatorsRoot saves the genesis validators root to db.
|
2020-11-20 18:06:12 +00:00
|
|
|
func (s *Store) SaveGenesisValidatorsRoot(ctx context.Context, genValRoot []byte) error {
|
|
|
|
err := s.db.Update(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(genesisInfoBucket)
|
|
|
|
enc := bkt.Get(genesisValidatorsRootKey)
|
|
|
|
if len(enc) != 0 {
|
|
|
|
return fmt.Errorf("cannot overwite existing genesis validators root: %#x", enc)
|
|
|
|
}
|
|
|
|
return bkt.Put(genesisValidatorsRootKey, genValRoot)
|
|
|
|
})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-02-14 13:34:38 +00:00
|
|
|
// GenesisValidatorsRoot retrieves the genesis validators root from db.
|
2020-11-20 18:06:12 +00:00
|
|
|
func (s *Store) GenesisValidatorsRoot(ctx context.Context) ([]byte, error) {
|
|
|
|
var genValRoot []byte
|
|
|
|
err := s.db.View(func(tx *bolt.Tx) error {
|
|
|
|
bkt := tx.Bucket(genesisInfoBucket)
|
|
|
|
enc := bkt.Get(genesisValidatorsRootKey)
|
|
|
|
if len(enc) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
genValRoot = enc
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return genValRoot, err
|
|
|
|
}
|