mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package db
|
|
|
|
import (
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/types"
|
|
)
|
|
|
|
// GetActiveState contains the current state of attestations and changes every block.
|
|
func (db *BeaconDB) GetActiveState() *types.ActiveState {
|
|
return db.state.aState
|
|
}
|
|
|
|
// GetCrystallizedState contains cycle dependent validator information, changes every cycle.
|
|
func (db *BeaconDB) GetCrystallizedState() *types.CrystallizedState {
|
|
return db.state.cState
|
|
}
|
|
|
|
// SaveActiveState is a convenience method which sets and persists the active state on the beacon chain.
|
|
func (db *BeaconDB) SaveActiveState(activeState *types.ActiveState) error {
|
|
db.state.aState = activeState
|
|
encodedState, err := db.GetCrystallizedState().Marshal()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return db.put(activeStateLookupKey, encodedState)
|
|
}
|
|
|
|
// SaveCrystallizedState is a convenience method which sets and persists the crystallized state on the beacon chain.
|
|
func (db *BeaconDB) SaveCrystallizedState(crystallizedState *types.CrystallizedState) error {
|
|
db.state.cState = crystallizedState
|
|
encodedState, err := db.GetActiveState().Marshal()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return db.put(crystallizedStateLookupKey, encodedState)
|
|
}
|
|
|
|
// HasStoredState checks if state has been stored to the database.
|
|
func (db *BeaconDB) HasStoredState() (bool, error) {
|
|
hasState, err := db.has(crystallizedStateLookupKey)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return hasState, nil
|
|
}
|