Skip to content

Commit

Permalink
enchancements in fork
Browse files Browse the repository at this point in the history
Signed-off-by: nidhi-singh02 <trippin@berachain.com>
  • Loading branch information
nidhi-singh02 committed Sep 8, 2024
1 parent ca78d45 commit 318d0a7
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions mod/node-api/handlers/beacon/historical.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,15 @@ func (h *Handler[_, ContextT, _, _]) GetStateFork(c ContextT) (any, error) {
return nil, err
}

var epochString string
epochUint := uint64(fork.GetEpoch())
epochString = strconv.FormatUint(epochUint, 10)

// Create a custom struct for JSON marshaling
type CustomFork struct {
// Create a custom struct for JSON marshaling as per BeaconAPIs.
customFork := struct {
PreviousVersion common.Version `json:"previous_version"`
CurrentVersion common.Version `json:"current_version"`
Epoch string `json:"epoch"`
}

customFork := CustomFork{
}{
PreviousVersion: fork.GetPreviousVersion(),
CurrentVersion: fork.GetCurrentVersion(),
Epoch: epochString,
Epoch: strconv.FormatUint(uint64(fork.GetEpoch()), 10),
}

return beacontypes.ValidatorResponse{
Expand All @@ -103,7 +97,10 @@ func (h *Handler[_, ContextT, _, _]) GetStateFork(c ContextT) (any, error) {
func convertToFork[T any](forkGeneric T) (*consensustypes.Fork, error) {
fork, ok := any(forkGeneric).(*consensustypes.Fork)
if !ok {
return nil, errors.New("unexpected fork type")
return nil, errors.Wrapf(errors.New(
"type assertion failed",
), "unexpected fork type: %T", forkGeneric)

}
return fork, nil
}

0 comments on commit 318d0a7

Please sign in to comment.