mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 18:51:19 +00:00
35 lines
707 B
Go
35 lines
707 B
Go
|
package db
|
||
|
|
||
|
import (
|
||
|
"github.com/boltdb/bolt"
|
||
|
)
|
||
|
|
||
|
// GetSimulatorSlot returns the last saved simulator slot
|
||
|
// from the disk.
|
||
|
func (db *BeaconDB) GetSimulatorSlot() (uint64, error) {
|
||
|
var slot uint64
|
||
|
err := db.view(func(tx *bolt.Tx) error {
|
||
|
b := tx.Bucket(simulatorBucket)
|
||
|
|
||
|
enc := b.Get(simSlotLookupKey)
|
||
|
if enc == nil {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
slot = decodeToSlotNumber(enc)
|
||
|
return nil
|
||
|
})
|
||
|
|
||
|
return slot, err
|
||
|
}
|
||
|
|
||
|
// SaveSimulatorSlot saves the current slot of the simulator to the disk.
|
||
|
func (db *BeaconDB) SaveSimulatorSlot(slot uint64) error {
|
||
|
return db.update(func(tx *bolt.Tx) error {
|
||
|
b := tx.Bucket(simulatorBucket)
|
||
|
enc := encodeSlotNumber(slot)
|
||
|
|
||
|
return b.Put(simSlotLookupKey, enc)
|
||
|
})
|
||
|
}
|