diff --git a/backend/pkg/api/data_access/dummy.go b/backend/pkg/api/data_access/dummy.go index 7f8168461..bf1c57407 100644 --- a/backend/pkg/api/data_access/dummy.go +++ b/backend/pkg/api/data_access/dummy.go @@ -139,7 +139,31 @@ func (d *DummyService) GetValidatorDashboardGroupExists(dashboardId t.VDBIdPrima return true, nil } -func (d *DummyService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId int64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) { +func (d *DummyService) GetValidatorDashboardExistingValidatorCount(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) (uint64, error) { + r := uint64(0) + err := commonFakeData(&r) + return r, err +} + +func (d *DummyService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) { + r := []t.VDBPostValidatorsData{} + err := commonFakeData(&r) + return r, err +} + +func (d *DummyService) AddValidatorDashboardValidatorsByDepositAddress(dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) { + r := []t.VDBPostValidatorsData{} + err := commonFakeData(&r) + return r, err +} + +func (d *DummyService) AddValidatorDashboardValidatorsByWithdrawalAddress(dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) { + r := []t.VDBPostValidatorsData{} + err := commonFakeData(&r) + return r, err +} + +func (d *DummyService) AddValidatorDashboardValidatorsByGraffiti(dashboardId t.VDBIdPrimary, groupId uint64, graffiti string, limit uint64) ([]t.VDBPostValidatorsData, error) { r := []t.VDBPostValidatorsData{} err := commonFakeData(&r) return r, err diff --git a/backend/pkg/api/data_access/networks.go b/backend/pkg/api/data_access/networks.go index 78a2039db..df95fb008 100644 --- a/backend/pkg/api/data_access/networks.go +++ b/backend/pkg/api/data_access/networks.go @@ -19,5 +19,9 @@ func (d *DataAccessService) GetAllNetworks() ([]types.NetworkInfo, error) { ChainId: 100, Name: "gnosis", }, + { + ChainId: 17000, + Name: "holesky", + }, }, nil } diff --git a/backend/pkg/api/data_access/search.go b/backend/pkg/api/data_access/search.go index 95b711fb6..d033ff696 100644 --- a/backend/pkg/api/data_access/search.go +++ b/backend/pkg/api/data_access/search.go @@ -58,14 +58,13 @@ func (d *DataAccessService) GetSearchValidatorByPublicKey(ctx context.Context, c func (d *DataAccessService) GetSearchValidatorsByDepositAddress(ctx context.Context, chainId uint64, address []byte) (*t.SearchValidatorsByDepositAddress, error) { // TODO: implement handling of chainid ret := &t.SearchValidatorsByDepositAddress{ - Address: address, - Validators: make([]uint64, 0), + Address: address, } - err := db.ReaderDb.Select(&ret.Validators, "select validatorindex from validators where pubkey in (select publickey from eth1_deposits where from_address = $1) order by validatorindex LIMIT 10;", address) + err := db.ReaderDb.Get(&ret.Count, "select count(validatorindex) from validators where pubkey in (select publickey from eth1_deposits where from_address = $1);", address) if err != nil { return nil, err } - if len(ret.Validators) == 0 { + if ret.Count == 0 { return nil, ErrNotFound } return ret, nil @@ -81,13 +80,12 @@ func (d *DataAccessService) GetSearchValidatorsByWithdrawalCredential(ctx contex // TODO: implement handling of chainid ret := &t.SearchValidatorsByWithdrwalCredential{ WithdrawalCredential: credential, - Validators: make([]uint64, 0), } - err := db.ReaderDb.Select(&ret.Validators, "select validatorindex from validators where withdrawalcredentials = $1 order by validatorindex LIMIT 10;", credential) + err := db.ReaderDb.Get(&ret.Count, "select count(validatorindex) from validators where withdrawalcredentials = $1;", credential) if err != nil { return nil, err } - if len(ret.Validators) == 0 { + if ret.Count == 0 { return nil, ErrNotFound } return ret, nil @@ -102,14 +100,13 @@ func (d *DataAccessService) GetSearchValidatorsByWithdrawalEnsName(ctx context.C func (d *DataAccessService) GetSearchValidatorsByGraffiti(ctx context.Context, chainId uint64, graffiti string) (*t.SearchValidatorsByGraffiti, error) { // TODO: implement handling of chainid ret := &t.SearchValidatorsByGraffiti{ - Graffiti: graffiti, - Validators: make([]uint64, 0), + Graffiti: graffiti, } - err := db.ReaderDb.Select(&ret.Validators, "select distinct proposer from blocks where graffiti_text = $1 limit 10;", graffiti) // added a limit here to keep the query fast + err := db.ReaderDb.Get(&ret.Count, "select count(distinct proposer) from blocks where graffiti_text = $1;", graffiti) if err != nil { return nil, err } - if len(ret.Validators) == 0 { + if ret.Count == 0 { return nil, ErrNotFound } return ret, nil diff --git a/backend/pkg/api/data_access/vdb_helpers.go b/backend/pkg/api/data_access/vdb_helpers.go index 7eba40601..ff346ade7 100644 --- a/backend/pkg/api/data_access/vdb_helpers.go +++ b/backend/pkg/api/data_access/vdb_helpers.go @@ -25,7 +25,12 @@ type ValidatorDashboardRepository interface { RemoveValidatorDashboardGroup(dashboardId t.VDBIdPrimary, groupId uint64) error GetValidatorDashboardGroupExists(dashboardId t.VDBIdPrimary, groupId uint64) (bool, error) - AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId int64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) + GetValidatorDashboardExistingValidatorCount(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) (uint64, error) + AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) + AddValidatorDashboardValidatorsByDepositAddress(dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) + AddValidatorDashboardValidatorsByWithdrawalAddress(dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) + AddValidatorDashboardValidatorsByGraffiti(dashboardId t.VDBIdPrimary, groupId uint64, graffiti string, limit uint64) ([]t.VDBPostValidatorsData, error) + RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error GetValidatorDashboardValidators(dashboardId t.VDBId, groupId int64, cursor string, colSort t.Sort[enums.VDBManageValidatorsColumn], search string, limit uint64) ([]t.VDBManageValidatorsTableRow, *t.Paging, error) diff --git a/backend/pkg/api/data_access/vdb_management.go b/backend/pkg/api/data_access/vdb_management.go index f37fd4bc6..3615458b7 100644 --- a/backend/pkg/api/data_access/vdb_management.go +++ b/backend/pkg/api/data_access/vdb_management.go @@ -736,7 +736,22 @@ func (d *DataAccessService) GetValidatorDashboardGroupExists(dashboardId t.VDBId return groupExists, err } -func (d *DataAccessService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId int64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) { +// return how many of the passed validators are already in the dashboard +func (d *DataAccessService) GetValidatorDashboardExistingValidatorCount(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) (uint64, error) { + if len(validators) == 0 { + return 0, nil + } + + var count uint64 + err := d.alloyReader.Get(&count, ` + SELECT COUNT(*) + FROM users_val_dashboards_validators + WHERE dashboard_id = $1 AND validator_index = ANY($2) + `, dashboardId, pq.Array(validators)) + return count, err +} + +func (d *DataAccessService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) { if len(validators) == 0 { // No validators to add return nil, nil @@ -820,6 +835,27 @@ func (d *DataAccessService) AddValidatorDashboardValidators(dashboardId t.VDBIdP return result, nil } +func (d *DataAccessService) AddValidatorDashboardValidatorsByDepositAddress(dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) { + // TODO + // for all validators already in the dashboard that are associated with the deposit address, update the group + // then add no more than `limit` validators associated with the deposit address to the dashboard + return d.dummy.AddValidatorDashboardValidatorsByDepositAddress(dashboardId, groupId, address, limit) +} + +func (d *DataAccessService) AddValidatorDashboardValidatorsByWithdrawalAddress(dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) { + // TODO + // for all validators already in the dashboard that are associated with the withdrawal address, update the group + // then add no more than `limit` validators associated with the withdrawal address to the dashboard + return d.dummy.AddValidatorDashboardValidatorsByWithdrawalAddress(dashboardId, groupId, address, limit) +} + +func (d *DataAccessService) AddValidatorDashboardValidatorsByGraffiti(dashboardId t.VDBIdPrimary, groupId uint64, graffiti string, limit uint64) ([]t.VDBPostValidatorsData, error) { + // TODO + // for all validators already in the dashboard that are associated with the graffiti (by produced block), update the group + // then add no more than `limit` validators associated with the graffiti to the dashboard + return d.dummy.AddValidatorDashboardValidatorsByGraffiti(dashboardId, groupId, graffiti, limit) +} + func (d *DataAccessService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error { if len(validators) == 0 { // Remove all validators for the dashboard diff --git a/backend/pkg/api/handlers/common.go b/backend/pkg/api/handlers/common.go index d0df9539f..fea7d6a52 100644 --- a/backend/pkg/api/handlers/common.go +++ b/backend/pkg/api/handlers/common.go @@ -509,9 +509,9 @@ func returnNotFound(w http.ResponseWriter, err error) { returnError(w, http.StatusNotFound, err) } -/* func returnConflict(w http.ResponseWriter, err error) { +func returnConflict(w http.ResponseWriter, err error) { returnError(w, http.StatusConflict, err) -} */ +} func returnInternalServerError(w http.ResponseWriter, err error) { log.Error(err, "internal server error", 2, nil) diff --git a/backend/pkg/api/handlers/internal.go b/backend/pkg/api/handlers/internal.go index 5d9987750..b9cb595fc 100644 --- a/backend/pkg/api/handlers/internal.go +++ b/backend/pkg/api/handlers/internal.go @@ -2,7 +2,9 @@ package handlers import ( "errors" + "fmt" "net/http" + "reflect" "github.com/gobitfly/beaconchain/pkg/api/enums" types "github.com/gobitfly/beaconchain/pkg/api/types" @@ -388,24 +390,34 @@ func (h *HandlerService) InternalPostValidatorDashboardValidators(w http.Respons var v validationError dashboardId := v.checkPrimaryDashboardId(mux.Vars(r)["dashboard_id"]) req := struct { - Validators []string `json:"validators"` - GroupId string `json:"group_id,omitempty"` + GroupId uint64 `json:"group_id,omitempty"` + Validators []string `json:"validators,omitempty"` + DepositAddress string `json:"deposit_address,omitempty"` + WithdrawalAddress string `json:"withdrawal_address,omitempty"` + Graffiti string `json:"graffiti,omitempty"` }{} if err := v.checkBody(&req, r); err != nil { handleErr(w, err) return } - indices, pubkeys := v.checkValidatorArray(req.Validators, forbidEmpty) - groupId := v.checkGroupId(req.GroupId, allowEmpty) + // check if exactly one of validators, deposit_address, withdrawal_address, graffiti is set + fields := []interface{}{req.Validators, req.DepositAddress, req.WithdrawalAddress, req.Graffiti} + var count int + for _, set := range fields { + if !reflect.ValueOf(set).IsZero() { + count++ + } + } + if count != 1 { + v.add("request body", "exactly one of `validators`, `deposit_address`, `withdrawal_address`, `graffiti` must be set. please check the API documentation for more information") + } if v.hasErrors() { handleErr(w, v) return } - // empty group id becomes default group - if groupId == types.AllGroups { - groupId = types.DefaultGroupId - } - groupExists, err := h.dai.GetValidatorDashboardGroupExists(dashboardId, uint64(groupId)) + + groupId := req.GroupId + groupExists, err := h.dai.GetValidatorDashboardGroupExists(dashboardId, groupId) if err != nil { handleErr(w, err) return @@ -414,18 +426,63 @@ func (h *HandlerService) InternalPostValidatorDashboardValidators(w http.Respons returnNotFound(w, errors.New("group not found")) return } - validators, err := h.dai.GetValidatorsFromSlices(indices, pubkeys) - if err != nil { - handleErr(w, err) - return + // TODO get real limit once stripe is implemented + limit := ^uint64(0) // user mustn't add more validators than the limit + var data []types.VDBPostValidatorsData + var dataErr error + switch { + case req.Validators != nil: + indices, pubkeys := v.checkValidatorArray(req.Validators, forbidEmpty) + if v.hasErrors() { + handleErr(w, v) + return + } + validators, err := h.dai.GetValidatorsFromSlices(indices, pubkeys) + if err != nil { + handleErr(w, err) + return + } + // check if adding more validators than allowed + existingValidatorCount, err := h.dai.GetValidatorDashboardExistingValidatorCount(dashboardId, validators) + if err != nil { + handleErr(w, err) + return + } + if uint64(len(validators)) > existingValidatorCount+limit { + returnConflict(w, fmt.Errorf("adding more validators than allowed, limit is %v new validators", limit)) + return + } + data, dataErr = h.dai.AddValidatorDashboardValidators(dashboardId, groupId, validators) + + case req.DepositAddress != "": + depositAddress := v.checkRegex(reEthereumAddress, req.DepositAddress, "deposit_address") + if v.hasErrors() { + handleErr(w, v) + return + } + data, dataErr = h.dai.AddValidatorDashboardValidatorsByDepositAddress(dashboardId, groupId, depositAddress, limit) + + case req.WithdrawalAddress != "": + withdrawalAddress := v.checkRegex(reEthereumAddress, req.WithdrawalAddress, "withdrawal_address") + if v.hasErrors() { + handleErr(w, v) + return + } + data, dataErr = h.dai.AddValidatorDashboardValidatorsByWithdrawalAddress(dashboardId, groupId, withdrawalAddress, limit) + + case req.Graffiti != "": + graffiti := v.checkRegex(reNonEmpty, req.Graffiti, "graffiti") + if v.hasErrors() { + handleErr(w, v) + return + } + data, dataErr = h.dai.AddValidatorDashboardValidatorsByGraffiti(dashboardId, groupId, graffiti, limit) } - // TODO check validator limit reached - data, err := h.dai.AddValidatorDashboardValidators(dashboardId, groupId, validators) - if err != nil { - handleErr(w, err) + + if dataErr != nil { + handleErr(w, dataErr) return } - response := types.ApiResponse{ Data: data, } diff --git a/backend/pkg/api/handlers/public.go b/backend/pkg/api/handlers/public.go index fdd2e3626..6b9326d57 100644 --- a/backend/pkg/api/handlers/public.go +++ b/backend/pkg/api/handlers/public.go @@ -2,7 +2,9 @@ package handlers import ( "errors" + "fmt" "net/http" + "reflect" "github.com/gobitfly/beaconchain/pkg/api/types" "github.com/gorilla/mux" @@ -125,24 +127,34 @@ func (h *HandlerService) PublicPostValidatorDashboardValidators(w http.ResponseW var v validationError dashboardId := v.checkPrimaryDashboardId(mux.Vars(r)["dashboard_id"]) req := struct { - Validators []string `json:"validators"` - GroupId string `json:"group_id,omitempty"` + GroupId uint64 `json:"group_id,omitempty"` + Validators []string `json:"validators,omitempty"` + DepositAddress string `json:"deposit_address,omitempty"` + WithdrawalAddress string `json:"withdrawal_address,omitempty"` + Graffiti string `json:"graffiti,omitempty"` }{} if err := v.checkBody(&req, r); err != nil { handleErr(w, err) return } - indices, pubkeys := v.checkValidatorArray(req.Validators, forbidEmpty) - groupId := v.checkGroupId(req.GroupId, allowEmpty) + // check if exactly one of validators, deposit_address, withdrawal_address, graffiti is set + fields := []interface{}{req.Validators, req.DepositAddress, req.WithdrawalAddress, req.Graffiti} + var count int + for _, set := range fields { + if !reflect.ValueOf(set).IsZero() { + count++ + } + } + if count != 1 { + v.add("request body", "exactly one of `validators`, `deposit_address`, `withdrawal_address`, `graffiti` must be set. please check the API documentation for more information") + } if v.hasErrors() { handleErr(w, v) return } - // empty group id becomes default group - if groupId == types.AllGroups { - groupId = types.DefaultGroupId - } - groupExists, err := h.dai.GetValidatorDashboardGroupExists(dashboardId, uint64(groupId)) + + groupId := req.GroupId + groupExists, err := h.dai.GetValidatorDashboardGroupExists(dashboardId, groupId) if err != nil { handleErr(w, err) return @@ -151,18 +163,63 @@ func (h *HandlerService) PublicPostValidatorDashboardValidators(w http.ResponseW returnNotFound(w, errors.New("group not found")) return } - validators, err := h.dai.GetValidatorsFromSlices(indices, pubkeys) - if err != nil { - handleErr(w, err) - return + // TODO get real limit once stripe is implemented + limit := ^uint64(0) // user mustn't add more validators than the limit + var data []types.VDBPostValidatorsData + var dataErr error + switch { + case req.Validators != nil: + indices, pubkeys := v.checkValidatorArray(req.Validators, forbidEmpty) + if v.hasErrors() { + handleErr(w, v) + return + } + validators, err := h.dai.GetValidatorsFromSlices(indices, pubkeys) + if err != nil { + handleErr(w, err) + return + } + // check if adding more validators than allowed + existingValidatorCount, err := h.dai.GetValidatorDashboardExistingValidatorCount(dashboardId, validators) + if err != nil { + handleErr(w, err) + return + } + if uint64(len(validators)) > existingValidatorCount+limit { + returnConflict(w, fmt.Errorf("adding more validators than allowed, limit is %v new validators", limit)) + return + } + data, dataErr = h.dai.AddValidatorDashboardValidators(dashboardId, groupId, validators) + + case req.DepositAddress != "": + depositAddress := v.checkRegex(reEthereumAddress, req.DepositAddress, "deposit_address") + if v.hasErrors() { + handleErr(w, v) + return + } + data, dataErr = h.dai.AddValidatorDashboardValidatorsByDepositAddress(dashboardId, groupId, depositAddress, limit) + + case req.WithdrawalAddress != "": + withdrawalAddress := v.checkRegex(reEthereumAddress, req.WithdrawalAddress, "withdrawal_address") + if v.hasErrors() { + handleErr(w, v) + return + } + data, dataErr = h.dai.AddValidatorDashboardValidatorsByWithdrawalAddress(dashboardId, groupId, withdrawalAddress, limit) + + case req.Graffiti != "": + graffiti := v.checkRegex(reNonEmpty, req.Graffiti, "graffiti") + if v.hasErrors() { + handleErr(w, v) + return + } + data, dataErr = h.dai.AddValidatorDashboardValidatorsByGraffiti(dashboardId, groupId, graffiti, limit) } - // TODO check validator limit reached - data, err := h.dai.AddValidatorDashboardValidators(dashboardId, groupId, validators) - if err != nil { - handleErr(w, err) + + if dataErr != nil { + handleErr(w, dataErr) return } - response := types.ApiResponse{ Data: data, } diff --git a/backend/pkg/api/handlers/search_handlers.go b/backend/pkg/api/handlers/search_handlers.go index 83016da9a..2b2186cb4 100644 --- a/backend/pkg/api/handlers/search_handlers.go +++ b/backend/pkg/api/handlers/search_handlers.go @@ -46,10 +46,9 @@ var searchTypeToRegex = map[searchTypeKey]*regexp.Regexp{ func (h *HandlerService) InternalPostSearch(w http.ResponseWriter, r *http.Request) { var v validationError req := struct { - Input string `json:"input"` - Networks []network `json:"networks,omitempty"` - Types []searchTypeKey `json:"types,omitempty"` - IncludeValidators bool `json:"include_validators,omitempty"` + Input string `json:"input"` + Networks []network `json:"networks,omitempty"` + Types []searchTypeKey `json:"types,omitempty"` }{} if err := v.checkBody(&req, r); err != nil { handleErr(w, err) @@ -63,14 +62,6 @@ func (h *HandlerService) InternalPostSearch(w http.ResponseWriter, r *http.Reque return } - // for beta launch check if the include_validators flag is set and only Ethereum is queried - // TODO: Remove this check once the feature is fully implemented - _, containsEthereum := networkSet[1] - if !req.IncludeValidators || !containsEthereum || len(networkSet) > 1 { - returnError(w, http.StatusServiceUnavailable, errors.New("feature not available, please set `include_validators` to true and only query the Ethereum network")) - return - } - g, ctx := errgroup.WithContext(r.Context()) g.SetLimit(20) searchResultChan := make(chan types.SearchResult) @@ -169,11 +160,10 @@ func (h *HandlerService) handleSearchValidatorByIndex(ctx context.Context, input } return &types.SearchResult{ - Type: string(validatorByIndex), - ChainId: chainId, - HashValue: hex.EncodeToString(result.PublicKey), - NumValue: &result.Index, - Validators: []uint64{result.Index}, + Type: string(validatorByIndex), + ChainId: chainId, + HashValue: hex.EncodeToString(result.PublicKey), + NumValue: &result.Index, }, nil } } @@ -194,11 +184,10 @@ func (h *HandlerService) handleSearchValidatorByPublicKey(ctx context.Context, i } return &types.SearchResult{ - Type: string(validatorByPublicKey), - ChainId: chainId, - HashValue: hex.EncodeToString(result.PublicKey), - NumValue: &result.Index, - Validators: []uint64{result.Index}, + Type: string(validatorByPublicKey), + ChainId: chainId, + HashValue: hex.EncodeToString(result.PublicKey), + NumValue: &result.Index, }, nil } } @@ -218,10 +207,10 @@ func (h *HandlerService) handleSearchValidatorsByDepositAddress(ctx context.Cont } return &types.SearchResult{ - Type: string(validatorsByDepositAddress), - ChainId: chainId, - HashValue: hex.EncodeToString(result.Address), - Validators: result.Validators, + Type: string(validatorsByDepositAddress), + ChainId: chainId, + HashValue: hex.EncodeToString(result.Address), + NumValue: &result.Count, }, nil } } @@ -237,10 +226,11 @@ func (h *HandlerService) handleSearchValidatorsByDepositEnsName(ctx context.Cont } return &types.SearchResult{ - Type: string(validatorsByDepositEnsName), - ChainId: chainId, - StrValue: result.EnsName, - Validators: result.Validators, + Type: string(validatorsByDepositEnsName), + ChainId: chainId, + StrValue: result.EnsName, + HashValue: hex.EncodeToString(result.Address), + NumValue: &result.Count, }, nil } } @@ -260,10 +250,10 @@ func (h *HandlerService) handleSearchValidatorsByWithdrawalCredential(ctx contex } return &types.SearchResult{ - Type: string(validatorsByWithdrawalCredential), - ChainId: chainId, - HashValue: hex.EncodeToString(result.WithdrawalCredential), - Validators: result.Validators, + Type: string(validatorsByWithdrawalCredential), + ChainId: chainId, + HashValue: hex.EncodeToString(result.WithdrawalCredential), + NumValue: &result.Count, }, nil } } @@ -284,10 +274,10 @@ func (h *HandlerService) handleSearchValidatorsByWithdrawalAddress(ctx context.C } return &types.SearchResult{ - Type: string(validatorsByWithdrawalAddress), - ChainId: chainId, - HashValue: hex.EncodeToString(result.WithdrawalCredential), - Validators: result.Validators, + Type: string(validatorsByWithdrawalAddress), + ChainId: chainId, + HashValue: hex.EncodeToString(result.WithdrawalCredential), + NumValue: &result.Count, }, nil } } @@ -303,10 +293,11 @@ func (h *HandlerService) handleSearchValidatorsByWithdrawalEnsName(ctx context.C } return &types.SearchResult{ - Type: string(validatorsByWithdrawalEns), - ChainId: chainId, - StrValue: result.EnsName, - Validators: result.Validators, + Type: string(validatorsByWithdrawalEns), + ChainId: chainId, + StrValue: result.EnsName, + HashValue: hex.EncodeToString(result.Address), + NumValue: &result.Count, }, nil } } @@ -322,10 +313,10 @@ func (h *HandlerService) handleSearchValidatorsByGraffiti(ctx context.Context, i } return &types.SearchResult{ - Type: string(validatorsByGraffiti), - ChainId: chainId, - StrValue: result.Graffiti, - Validators: result.Validators, + Type: string(validatorsByGraffiti), + ChainId: chainId, + StrValue: result.Graffiti, + NumValue: &result.Count, }, nil } } diff --git a/backend/pkg/api/types/common.go b/backend/pkg/api/types/common.go index d4834e4ef..5b710477a 100644 --- a/backend/pkg/api/types/common.go +++ b/backend/pkg/api/types/common.go @@ -107,12 +107,11 @@ type ChainConfig struct { } type SearchResult struct { - Type string `json:"type"` - ChainId uint64 `json:"chain_id"` - HashValue string `json:"hash_value,omitempty"` - StrValue string `json:"str_value,omitempty"` - NumValue *uint64 `json:"num_value,omitempty"` - Validators []uint64 `json:"validators,omitempty"` + Type string `json:"type"` + ChainId uint64 `json:"chain_id"` + HashValue string `json:"hash_value,omitempty"` + StrValue string `json:"str_value,omitempty"` + NumValue *uint64 `json:"num_value,omitempty"` } type InternalPostSearchResponse ApiDataResponse[[]SearchResult] diff --git a/backend/pkg/api/types/search_types.go b/backend/pkg/api/types/search_types.go index 4b44c17b5..c289d0e82 100644 --- a/backend/pkg/api/types/search_types.go +++ b/backend/pkg/api/types/search_types.go @@ -8,26 +8,28 @@ type SearchValidator struct { } type SearchValidatorsByDepositEnsName struct { - EnsName string - Validators []uint64 + EnsName string + Address []byte + Count uint64 } type SearchValidatorsByDepositAddress struct { - Address []byte - Validators []uint64 + Address []byte + Count uint64 } type SearchValidatorsByWithdrwalCredential struct { WithdrawalCredential []byte - Validators []uint64 + Count uint64 } type SearchValidatorsByWithrawalEnsName struct { - EnsName string - Validators []uint64 + EnsName string + Address []byte + Count uint64 } type SearchValidatorsByGraffiti struct { - Graffiti string - Validators []uint64 + Graffiti string + Count uint64 } diff --git a/backend/pkg/api/types/validator_dashboard.go b/backend/pkg/api/types/validator_dashboard.go index 9c6ac656e..7013d68c1 100644 --- a/backend/pkg/api/types/validator_dashboard.go +++ b/backend/pkg/api/types/validator_dashboard.go @@ -178,7 +178,7 @@ type InternalGetValidatorDashboardGroupHeatmapResponse ApiDataResponse[VDBHeatma // Deposits Tab type VDBExecutionDepositsTableRow struct { PublicKey PubKey `json:"public_key"` - Index *VDBValidator `json:"index,omitempty"` + Index *uint64 `json:"index,omitempty"` GroupId uint64 `json:"group_id"` Block uint64 `json:"block"` Timestamp int64 `json:"timestamp"` @@ -193,7 +193,7 @@ type InternalGetValidatorDashboardExecutionLayerDepositsResponse ApiPagingRespon type VDBConsensusDepositsTableRow struct { PublicKey PubKey `json:"public_key"` - Index VDBValidator `json:"index"` + Index uint64 `json:"index"` GroupId uint64 `json:"group_id"` Epoch uint64 `json:"epoch"` Slot uint64 `json:"slot"` @@ -220,7 +220,7 @@ type InternalGetValidatorDashboardTotalConsensusDepositsResponse ApiDataResponse type VDBWithdrawalsTableRow struct { Epoch uint64 `json:"epoch"` Slot uint64 `json:"slot"` - Index VDBValidator `json:"index"` + Index uint64 `json:"index"` GroupId uint64 `json:"group_id"` Recipient Address `json:"recipient"` Amount decimal.Decimal `json:"amount"` @@ -237,7 +237,7 @@ type InternalGetValidatorDashboardTotalWithdrawalsResponse ApiDataResponse[VDBTo // ------------------------------------------------------------ // Manage Modal type VDBManageValidatorsTableRow struct { - Index VDBValidator `json:"index"` + Index uint64 `json:"index"` PublicKey PubKey `json:"public_key"` GroupId uint64 `json:"group_id"` Balance decimal.Decimal `json:"balance"` diff --git a/frontend/types/api/common.ts b/frontend/types/api/common.ts index 0c22129b6..e242175a1 100644 --- a/frontend/types/api/common.ts +++ b/frontend/types/api/common.ts @@ -91,7 +91,6 @@ export interface SearchResult { hash_value?: string; str_value?: string; num_value?: number /* uint64 */; - validators?: number /* uint64 */[]; } export type InternalPostSearchResponse = ApiDataResponse; export interface VDBPublicId {