mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-05 10:32:19 +00:00
47a6ac16da
adds a two indexes to the validators cache creates beaconhttp package with many utilities for beacon http endpoint (future support for ssz is baked in) started on some validator endpoints
48 lines
1.4 KiB
Go
48 lines
1.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"sort"
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
"github.com/ledgerwatch/erigon/cl/cltypes"
|
|
)
|
|
|
|
func (a *ApiHandler) getSpec(r *http.Request) (*beaconResponse, error) {
|
|
return newBeaconResponse(a.beaconChainCfg), nil
|
|
}
|
|
|
|
func (a *ApiHandler) getDepositContract(r *http.Request) (*beaconResponse, error) {
|
|
|
|
return newBeaconResponse(struct {
|
|
ChainId uint64 `json:"chain_id"`
|
|
DepositContract string `json:"address"`
|
|
}{ChainId: a.beaconChainCfg.DepositChainID, DepositContract: a.beaconChainCfg.DepositContractAddress}), nil
|
|
|
|
}
|
|
|
|
func (a *ApiHandler) getForkSchedule(r *http.Request) (*beaconResponse, error) {
|
|
response := []cltypes.Fork{}
|
|
// create first response (unordered and incomplete)
|
|
for currentVersion, epoch := range a.beaconChainCfg.ForkVersionSchedule {
|
|
response = append(response, cltypes.Fork{
|
|
CurrentVersion: currentVersion,
|
|
Epoch: epoch,
|
|
})
|
|
}
|
|
// Sort the respnses by epoch
|
|
sort.Slice(response, func(i, j int) bool {
|
|
if response[i].Epoch == response[j].Epoch {
|
|
return bytes.Compare(response[i].CurrentVersion[:], response[j].CurrentVersion[:]) < 0
|
|
}
|
|
return response[i].Epoch < response[j].Epoch
|
|
})
|
|
var previousVersion libcommon.Bytes4
|
|
for i := range response {
|
|
response[i].PreviousVersion = previousVersion
|
|
previousVersion = response[i].CurrentVersion
|
|
}
|
|
return newBeaconResponse(response), nil
|
|
}
|