Skip to content

Commit

Permalink
Merge pull request #822 from iotaledger/feat/validators-api
Browse files Browse the repository at this point in the history
Fix validators API endpoint
  • Loading branch information
alexsporn authored Mar 8, 2024
2 parents 5ffb039 + 05c4b43 commit aa10bce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/restapi/core/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func validators(c echo.Context) (*api.ValidatorsResponse, error) {
}
slotRange := uint32(requestedSlot) / restapi.ParamsRestAPI.RequestsMemoryCacheGranularity

return deps.RequestHandler.Validators(slotRange, pageSize, cursorIndex)
return deps.RequestHandler.Validators(slotRange, cursorIndex, pageSize)
}

func validatorByAccountAddress(c echo.Context) (*api.ValidatorResponse, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,14 @@ func (o *SybilProtection) OrderedRegisteredCandidateValidatorsList(epoch iotago.
}); err != nil {
return nil, ierrors.Wrapf(err, "failed to iterate over eligible validator candidates")
}
// sort candidates by stake

// sort validators by pool stake, then by address
sort.Slice(validatorResp, func(i int, j int) bool {
return validatorResp[i].ValidatorStake > validatorResp[j].ValidatorStake
if validatorResp[i].PoolStake == validatorResp[j].PoolStake {
return validatorResp[i].AddressBech32 < validatorResp[j].AddressBech32
}

return validatorResp[i].PoolStake > validatorResp[j].PoolStake
})

return validatorResp, nil
Expand Down
10 changes: 10 additions & 0 deletions pkg/requesthandler/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package requesthandler

import (
"fmt"
"sort"

"github.com/labstack/echo/v4"

Expand Down Expand Up @@ -202,6 +203,15 @@ func (r *RequestHandler) SelectedCommittee(epoch iotago.EpochIndex) (*api.Commit
return true
})

// sort committee by pool stake, then by address
sort.Slice(committee, func(i, j int) bool {
if committee[i].PoolStake == committee[j].PoolStake {
return committee[i].AddressBech32 < committee[j].AddressBech32
}

return committee[i].PoolStake > committee[j].PoolStake
})

return &api.CommitteeResponse{
Epoch: epoch,
Committee: committee,
Expand Down

0 comments on commit aa10bce

Please sign in to comment.