erigon-pulse/cl/clparams/initial_state/initial_state.go
a cda14447ad
[caplin] pkg refactor (#7507)
Co-authored-by: Giulio <giulio.rebuffo@gmail.com>
2023-05-13 23:44:07 +02:00

43 lines
1.1 KiB
Go

package initial_state
import (
_ "embed"
"fmt"
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
"github.com/ledgerwatch/erigon/cl/clparams"
)
//go:embed mainnet.state.ssz
var mainnetStateSSZ []byte
//go:embed sepolia.state.ssz
var sepoliaStateSSZ []byte
//go:embed goerli.state.ssz
var goerliStateSSZ []byte
// Return genesis state
func GetGenesisState(network clparams.NetworkType) (*state.BeaconState, error) {
_, _, config := clparams.GetConfigsByNetwork(network)
returnState := state.New(config)
switch network {
case clparams.MainnetNetwork:
if err := returnState.DecodeSSZ(mainnetStateSSZ, int(clparams.Phase0Version)); err != nil {
return nil, err
}
case clparams.GoerliNetwork:
if err := returnState.DecodeSSZ(goerliStateSSZ, int(clparams.Phase0Version)); err != nil {
return nil, err
}
case clparams.SepoliaNetwork:
if err := returnState.DecodeSSZ(sepoliaStateSSZ, int(clparams.Phase0Version)); err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unsupported network for genesis fetching")
}
return returnState, nil
}