2023-06-08 07:43:27 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
2023-08-30 23:18:12 +00:00
|
|
|
"errors"
|
2023-06-08 07:43:27 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
2023-09-05 20:37:18 +00:00
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
2023-08-30 23:18:12 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
2023-06-08 07:43:27 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/fork"
|
|
|
|
)
|
|
|
|
|
|
|
|
type genesisReponse struct {
|
2023-09-05 20:37:18 +00:00
|
|
|
GenesisTime uint64 `json:"genesis_time,omitempty"`
|
|
|
|
GenesisValidatorRoot common.Hash `json:"genesis_validator_root,omitempty"`
|
|
|
|
GenesisForkVersion libcommon.Bytes4 `json:"genesis_fork_version,omitempty"`
|
2023-06-08 07:43:27 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 13:29:17 +00:00
|
|
|
func (a *ApiHandler) getGenesis(r *http.Request) (data any, finalized *bool, version *clparams.StateVersion, httpStatus int, err error) {
|
2023-06-08 07:43:27 +00:00
|
|
|
if a.genesisCfg == nil {
|
2023-08-30 23:18:12 +00:00
|
|
|
err = errors.New("Genesis Config is missing")
|
|
|
|
httpStatus = http.StatusNotFound
|
2023-06-08 07:43:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
digest, err := fork.ComputeForkDigest(a.beaconChainCfg, a.genesisCfg)
|
|
|
|
if err != nil {
|
2023-08-30 23:18:12 +00:00
|
|
|
err = errors.New("Failed to compute fork digest")
|
|
|
|
httpStatus = http.StatusInternalServerError
|
2023-06-08 07:43:27 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-08-30 23:18:12 +00:00
|
|
|
data = &genesisReponse{
|
2023-06-08 07:43:27 +00:00
|
|
|
GenesisTime: a.genesisCfg.GenesisTime,
|
|
|
|
GenesisValidatorRoot: a.genesisCfg.GenesisValidatorRoot,
|
2023-09-01 13:29:17 +00:00
|
|
|
GenesisForkVersion: digest,
|
2023-08-30 23:18:12 +00:00
|
|
|
}
|
|
|
|
httpStatus = http.StatusAccepted
|
|
|
|
return
|
2023-06-08 07:43:27 +00:00
|
|
|
}
|