Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-api: stub for get state committees #2135

Draft
wants to merge 2 commits into
base: state-finality-checkpoints
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mod/node-api/engines/echo/vaildator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func ConstructValidator() *validator.Validate {
"slot": ValidateUint64,
"validator_status": ValidateValidatorStatus,
"parent_root": ValidateRoot,
"index": ValidateUint64,
}
validate := validator.New()
for tag, fn := range validators {
Expand Down
54 changes: 54 additions & 0 deletions mod/node-api/handlers/beacon/committees.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2024, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package beacon

import (
beacontypes "github.com/berachain/beacon-kit/mod/node-api/handlers/beacon/types"
"github.com/berachain/beacon-kit/mod/node-api/handlers/types"
"github.com/berachain/beacon-kit/mod/node-api/handlers/utils"
)

func (h *Handler[_, ContextT, _, _, _]) GetStateCommittees(
c ContextT,
) (any, error) {
req, err := utils.BindAndValidate[beacontypes.GetStateCommitteesRequest](
c, h.Logger(),
)
if err != nil {
return nil, err
}
slot, err := utils.SlotFromStateID(req.StateID, h.backend)
if err != nil {
return nil, err
}
// TODO : To be implemented
//committees, err := h.backend.CommitteesByStateID(slot)
//if err != nil {
// return nil, err
//}

// Stub the response
return types.Wrap(beacontypes.CommitteeResponseData{
Index: 0,
Slot: slot,
Validators: []uint64{0},
}), nil
}
2 changes: 1 addition & 1 deletion mod/node-api/handlers/beacon/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (h *Handler[_, ContextT, _, _, _]) RegisterRoutes(
{
Method: http.MethodGet,
Path: "/eth/v1/beacon/states/:state_id/committees",
Handler: h.NotImplemented,
Handler: h.GetStateCommittees,
},
{
Method: http.MethodGet,
Expand Down
2 changes: 1 addition & 1 deletion mod/node-api/handlers/beacon/types/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type EpochRequest struct {
}

type CommitteeIndexRequest struct {
CommitteeIndex string `query:"committee_index" validate:"committee_index"`
Index string `query:"index" validate:"index"`
}

type SlotRequest struct {
Expand Down
7 changes: 7 additions & 0 deletions mod/node-api/handlers/beacon/types/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/crypto"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)

type ValidatorResponse struct {
Expand Down Expand Up @@ -203,3 +204,9 @@ type FinalityCheckpointsData struct {
CurrentJustified common.Checkpoint `json:"current_justified"`
Finalized common.Checkpoint `json:"finalized"`
}

type CommitteeResponseData struct {
Index uint64 `json:"index,string"`
Slot math.Slot `json:"slot,string"`
Validators []uint64 `json:"validators"`
}
Loading