Skip to content

Commit

Permalink
linter and generate
Browse files Browse the repository at this point in the history
Signed-off-by: nidhi-singh02 <[email protected]>
  • Loading branch information
nidhi-singh02 committed Sep 24, 2024
1 parent f6e5cdd commit 494d9d6
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 23 deletions.
2 changes: 0 additions & 2 deletions examples/berad/pkg/consensus-types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,3 @@ func (v *Validator) GetActivationEpoch() math.Epoch {
func (v *Validator) GetExitEpoch() math.Epoch {
return v.ExitEpoch
}

//
16 changes: 6 additions & 10 deletions mod/node-api/backend/mocks/validator.mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions mod/node-api/backend/mocks/withdrawal_credentials.mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions mod/node-api/backend/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
)

func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, ValidatorT, _, _, WithdrawalCredentialsT,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, ValidatorT, _, _,
WithdrawalCredentialsT,
]) ValidatorByID(
slot math.Slot, id string,
) (*beacontypes.ValidatorData[ValidatorT, WithdrawalCredentialsT], error) {
Expand Down Expand Up @@ -62,11 +63,14 @@ func (b Backend[

// TODO: filter by status
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, ValidatorT, _, _, WithdrawalCredentialsT,
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, ValidatorT, _, _,
WithdrawalCredentialsT,
]) ValidatorsByIDs(
slot math.Slot, ids []string, _ []string,
) ([]*beacontypes.ValidatorData[ValidatorT, WithdrawalCredentialsT], error) {
validatorsData := make([]*beacontypes.ValidatorData[ValidatorT, WithdrawalCredentialsT], 0)
validatorsData := make(
[]*beacontypes.ValidatorData[ValidatorT, WithdrawalCredentialsT],
0)
for _, id := range ids {
// TODO: we can probably optimize this via a getAllValidators
// query and then filtering but blocked by the fact that IDs
Expand Down
5 changes: 4 additions & 1 deletion mod/node-api/handlers/beacon/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ type StateBackend[ForkT any] interface {
StateForkAtSlot(slot math.Slot) (ForkT, error)
}

type ValidatorBackend[ValidatorT types.Validator[WithdrawalCredentialsT], WithdrawalCredentialsT types.WithdrawalCredentials] interface {
type ValidatorBackend[
ValidatorT types.Validator[WithdrawalCredentialsT],
WithdrawalCredentialsT types.WithdrawalCredentials,
] interface {
ValidatorByID(
slot math.Slot, id string,
) (*types.ValidatorData[ValidatorT, WithdrawalCredentialsT], error)
Expand Down
4 changes: 3 additions & 1 deletion mod/node-api/handlers/beacon/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"github.com/berachain/beacon-kit/mod/node-api/handlers/utils"
)

func (h *Handler[_, ContextT, _, _, _]) GetBlockRewards(c ContextT) (any, error) {
func (h *Handler[_, ContextT, _, _, _]) GetBlockRewards(c ContextT) (
any, error,
) {
req, err := utils.BindAndValidate[beacontypes.GetBlockRewardsRequest](
c, h.Logger(),
)
Expand Down
23 changes: 20 additions & 3 deletions mod/node-api/handlers/beacon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ type Handler[
WithdrawalCredentialsT types.WithdrawalCredentials,
] struct {
*handlers.BaseHandler[ContextT]
backend Backend[BeaconBlockHeaderT, ForkT, ValidatorT, WithdrawalCredentialsT]
backend Backend[
BeaconBlockHeaderT,
ForkT,
ValidatorT,
WithdrawalCredentialsT,
]
}

// NewHandler creates a new handler for the beacon API.
Expand All @@ -47,8 +52,20 @@ func NewHandler[
WithdrawalCredentialsT types.WithdrawalCredentials,
](
backend Backend[BeaconBlockHeaderT, ForkT, ValidatorT, WithdrawalCredentialsT],
) *Handler[BeaconBlockHeaderT, ContextT, ForkT, ValidatorT, WithdrawalCredentialsT] {
h := &Handler[BeaconBlockHeaderT, ContextT, ForkT, ValidatorT, WithdrawalCredentialsT]{
) *Handler[
BeaconBlockHeaderT,
ContextT,
ForkT,
ValidatorT,
WithdrawalCredentialsT,
] {
h := &Handler[
BeaconBlockHeaderT,
ContextT,
ForkT,
ValidatorT,
WithdrawalCredentialsT,
]{
BaseHandler: handlers.NewBaseHandler(
handlers.NewRouteSet[ContextT](""),
),
Expand Down
9 changes: 7 additions & 2 deletions mod/node-api/handlers/beacon/types/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func (vbd ValidatorBalanceData) MarshalJSON() ([]byte, error) {
})
}

type ValidatorData[ValidatorT Validator[WithdrawalCredentialsT], WithdrawalCredentialsT WithdrawalCredentials] struct {
type ValidatorData[
ValidatorT Validator[WithdrawalCredentialsT],
WithdrawalCredentialsT WithdrawalCredentials,
] struct {
ValidatorBalanceData
Status string `json:"status"`
Validator ValidatorT `json:"validator"`
Expand All @@ -95,7 +98,9 @@ type responseJSON struct {
Validator validatorJSON `json:"validator"`
}

func (vd ValidatorData[ValidatorT, WithdrawalCredentialsT]) MarshalJSON() ([]byte, error) {
func (vd ValidatorData[
ValidatorT, WithdrawalCredentialsT,
]) MarshalJSON() ([]byte, error) {
withdrawalCredentials := vd.Validator.GetWithdrawalCredentials()
withdrawalCredentialsBytes := withdrawalCredentials.Bytes()

Expand Down
5 changes: 4 additions & 1 deletion mod/node-core/pkg/components/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,10 @@ type (
StateFromSlotForProof(slot math.Slot) (BeaconStateT, math.Slot, error)
}

ValidatorBackend[ValidatorT types.Validator[WithdrawalCredentialsT], WithdrawalCredentialsT types.WithdrawalCredentials] interface {
ValidatorBackend[
ValidatorT types.Validator[WithdrawalCredentialsT],
WithdrawalCredentialsT types.WithdrawalCredentials,
] interface {
ValidatorByID(
slot math.Slot, id string,
) (*types.ValidatorData[ValidatorT, WithdrawalCredentialsT], error)
Expand Down

0 comments on commit 494d9d6

Please sign in to comment.