mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
5a66807989
* First take at updating everything to v5 * Patch gRPC gateway to use prysm v5 Fix patch * Update go ssz --------- Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
35 lines
871 B
Go
35 lines
871 B
Go
package genesis
|
|
|
|
import (
|
|
_ "embed"
|
|
|
|
"github.com/golang/snappy"
|
|
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
|
|
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
var embeddedStates = map[string]*[]byte{}
|
|
|
|
// State returns a copy of the genesis state from a hardcoded value.
|
|
func State(name string) (state.BeaconState, error) {
|
|
sb, exists := embeddedStates[name]
|
|
if exists {
|
|
return load(*sb)
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
// load a compressed ssz state file into a beacon state struct.
|
|
func load(b []byte) (state.BeaconState, error) {
|
|
st := ðpb.BeaconState{}
|
|
b, err := snappy.Decode(nil /*dst*/, b)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := st.UnmarshalSSZ(b); err != nil {
|
|
return nil, err
|
|
}
|
|
return state_native.InitializeFromProtoUnsafePhase0(st)
|
|
}
|