mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 19:50:36 +00:00
47 lines
1.5 KiB
Go
47 lines
1.5 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(w http.ResponseWriter, r *http.Request) (*beaconResponse, error) {
|
|
return newBeaconResponse(a.beaconChainCfg), nil
|
|
}
|
|
|
|
func (a *ApiHandler) getDepositContract(w http.ResponseWriter, r *http.Request) (*beaconResponse, error) {
|
|
return newBeaconResponse(struct {
|
|
ChainId uint64 `json:"chain_id,string"`
|
|
DepositContract string `json:"address"`
|
|
}{ChainId: a.beaconChainCfg.DepositChainID, DepositContract: a.beaconChainCfg.DepositContractAddress}), nil
|
|
|
|
}
|
|
|
|
func (a *ApiHandler) getForkSchedule(w http.ResponseWriter, 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
|
|
}
|