diff --git a/mod/node-api/engines/echo/vaildator.go b/mod/node-api/engines/echo/vaildator.go index bffe2838f1..2847e709de 100644 --- a/mod/node-api/engines/echo/vaildator.go +++ b/mod/node-api/engines/echo/vaildator.go @@ -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 { diff --git a/mod/node-api/handlers/beacon/committees.go b/mod/node-api/handlers/beacon/committees.go new file mode 100644 index 0000000000..da5d2746ba --- /dev/null +++ b/mod/node-api/handlers/beacon/committees.go @@ -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 +} diff --git a/mod/node-api/handlers/beacon/routes.go b/mod/node-api/handlers/beacon/routes.go index 1534ae0973..2cdfaa6caf 100644 --- a/mod/node-api/handlers/beacon/routes.go +++ b/mod/node-api/handlers/beacon/routes.go @@ -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, diff --git a/mod/node-api/handlers/beacon/types/request.go b/mod/node-api/handlers/beacon/types/request.go index eba1fd6fe6..0238b39ef3 100644 --- a/mod/node-api/handlers/beacon/types/request.go +++ b/mod/node-api/handlers/beacon/types/request.go @@ -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 { diff --git a/mod/node-api/handlers/beacon/types/response.go b/mod/node-api/handlers/beacon/types/response.go index 5389e2d744..bab69c1d9c 100644 --- a/mod/node-api/handlers/beacon/types/response.go +++ b/mod/node-api/handlers/beacon/types/response.go @@ -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 { @@ -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"` +}