mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-27 21:57:16 +00:00
78a865eb0b
* Replaced. Debugging missing strict dependencies... * Merge branch 'master' into bbolt-import * Update import path * Merge branch 'bbolt-import' of github.com:prysmaticlabs/prysm into bbolt-import * use forked prombbolt * Merge branch 'bbolt-import' of github.com:prysmaticlabs/prysm into bbolt-import * fix * remove old boltdb reference * Use correct bolt for pk manager * Merge branch 'bbolt-import' of github.com:prysmaticlabs/prysm into bbolt-import * fix for docker build * gaz, oops
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
"github.com/prysmaticlabs/prysm/proto/beacon/db"
|
|
bolt "go.etcd.io/bbolt"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
// SavePowchainData saves the pow chain data.
|
|
func (k *Store) SavePowchainData(ctx context.Context, data *db.ETH1ChainData) error {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.SavePowchainData")
|
|
defer span.End()
|
|
|
|
return k.db.Update(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(powchainBucket)
|
|
enc, err := proto.Marshal(data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return bkt.Put(powchainDataKey, enc)
|
|
})
|
|
}
|
|
|
|
// PowchainData retrieves the powchain data.
|
|
func (k *Store) PowchainData(ctx context.Context) (*db.ETH1ChainData, error) {
|
|
ctx, span := trace.StartSpan(ctx, "BeaconDB.PowchainData")
|
|
defer span.End()
|
|
|
|
var data *db.ETH1ChainData
|
|
err := k.db.View(func(tx *bolt.Tx) error {
|
|
bkt := tx.Bucket(powchainBucket)
|
|
enc := bkt.Get(powchainDataKey)
|
|
if len(enc) == 0 {
|
|
return nil
|
|
}
|
|
data = &db.ETH1ChainData{}
|
|
return proto.Unmarshal(enc, data)
|
|
})
|
|
return data, err
|
|
}
|