diff --git a/backend/pkg/api/data_access/data_access.go b/backend/pkg/api/data_access/data_access.go index bb0ee849d..b0a66512f 100644 --- a/backend/pkg/api/data_access/data_access.go +++ b/backend/pkg/api/data_access/data_access.go @@ -20,6 +20,7 @@ import ( type DataAccessInterface interface { GetUserDashboards(userId uint64) (t.UserDashboardsData, error) + GetValidatorsFromStrings(validators []string) ([]t.VDBValidator, error) CreateValidatorDashboard(userId uint64, name string, network uint64) (t.VDBPostReturnData, error) RemoveValidatorDashboard(dashboardId t.VDBIdPrimary) error @@ -34,8 +35,8 @@ type DataAccessInterface interface { CreateValidatorDashboardGroup(dashboardId t.VDBIdPrimary, name string) (t.VDBOverviewGroup, error) RemoveValidatorDashboardGroup(dashboardId t.VDBIdPrimary, groupId uint64) error - AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []string) ([]t.VDBPostValidatorsData, error) - RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []string) error + AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) + RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error GetValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, cursor string, sort []t.Sort[enums.VDBManageValidatorsColumn], search string, limit uint64) ([]t.VDBManageValidatorsTableRow, t.Paging, error) GetValidatorDashboardValidatorsByPublicId(dashboardId t.VDBIdPublic, groupId uint64, cursor string, sort []t.Sort[enums.VDBManageValidatorsColumn], search string, limit uint64) ([]t.VDBManageValidatorsTableRow, t.Paging, error) GetValidatorDashboardValidatorsByValidators(dashboardId t.VDBIdValidatorSet, cursor string, sort []t.Sort[enums.VDBManageValidatorsColumn], search string, limit uint64) ([]t.VDBManageValidatorsTableRow, t.Paging, error) @@ -205,6 +206,12 @@ func (d DataAccessService) GetUserDashboards(userId uint64) (t.UserDashboardsDat return d.dummy.GetUserDashboards(userId) } +// param validators: slice of validator public keys or indices, a index should resolve to the newest index version +func (d DataAccessService) GetValidatorsFromStrings(validators []string) ([]t.VDBValidator, error) { + // TODO @recy21 + return d.dummy.GetValidatorsFromStrings(validators) +} + func (d DataAccessService) CreateValidatorDashboard(userId uint64, name string, network uint64) (t.VDBPostReturnData, error) { return d.dummy.CreateValidatorDashboard(userId, name, network) } @@ -254,7 +261,7 @@ func (d DataAccessService) RemoveValidatorDashboardGroup(dashboardId t.VDBIdPrim return d.dummy.RemoveValidatorDashboardGroup(dashboardId, groupId) } -func (d DataAccessService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []string) ([]t.VDBPostValidatorsData, error) { +func (d DataAccessService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) { // TODO @recy21 return d.dummy.AddValidatorDashboardValidators(dashboardId, groupId, validators) } @@ -274,7 +281,7 @@ func (d DataAccessService) GetValidatorDashboardValidatorsByValidators(dashboard return d.dummy.GetValidatorDashboardValidatorsByValidators(dashboardId, cursor, sort, search, limit) } -func (d DataAccessService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []string) error { +func (d DataAccessService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error { // TODO @recy21 return d.dummy.RemoveValidatorDashboardValidators(dashboardId, validators) } diff --git a/backend/pkg/api/data_access/dummy.go b/backend/pkg/api/data_access/dummy.go index 2d8eb1369..48c769f56 100644 --- a/backend/pkg/api/data_access/dummy.go +++ b/backend/pkg/api/data_access/dummy.go @@ -33,6 +33,12 @@ func (d DummyService) GetUserDashboards(userId uint64) (t.UserDashboardsData, er return r, err } +func (d DummyService) GetValidatorsFromStrings(validators []string) ([]t.VDBValidator, error) { + r := []t.VDBValidator{} + err := commonFakeData(&r) + return r, err +} + func (d DummyService) CreateValidatorDashboard(userId uint64, name string, network uint64) (t.VDBPostReturnData, error) { r := t.VDBPostReturnData{} err := commonFakeData(&r) @@ -87,7 +93,7 @@ func (d DummyService) RemoveValidatorDashboardGroup(dashboardId t.VDBIdPrimary, return nil } -func (d DummyService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []string) ([]t.VDBPostValidatorsData, error) { +func (d DummyService) AddValidatorDashboardValidators(dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error) { r := []t.VDBPostValidatorsData{} err := commonFakeData(&r) return r, err @@ -117,7 +123,7 @@ func (d DummyService) GetValidatorDashboardValidatorsByValidators(dashboardId t. return r, p, err } -func (d DummyService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []string) error { +func (d DummyService) RemoveValidatorDashboardValidators(dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error { return nil } diff --git a/backend/pkg/api/handlers/internal.go b/backend/pkg/api/handlers/internal.go index 73b4175e4..55355e9d0 100644 --- a/backend/pkg/api/handlers/internal.go +++ b/backend/pkg/api/handlers/internal.go @@ -320,11 +320,16 @@ func (h HandlerService) InternalPostValidatorDashboardValidators(w http.Response vars := mux.Vars(r) dashboardId := checkDashboardId(&err, vars["dashboard_id"], false) groupId := checkGroupId(&err, req.GroupId) - validators := checkValidatorArray(&err, req.Validators) + validatorArr := checkValidatorArray(&err, req.Validators) if err != nil { returnBadRequest(w, err) return } + validators, err := h.dai.GetValidatorsFromStrings(validatorArr) + if err != nil { + returnInternalServerError(w, err) + return + } var dashboardInfo types.DashboardInfo switch dashboardId := dashboardId.(type) { @@ -398,11 +403,16 @@ func (h HandlerService) InternalDeleteValidatorDashboardValidators(w http.Respon vars := mux.Vars(r) q := r.URL.Query() dashboardId := checkDashboardId(&err, vars["dashboard_id"], false) - validators := checkValidatorList(&err, q.Get("validators")) + validatorArr := checkValidatorList(&err, q.Get("validators")) if err != nil { returnBadRequest(w, err) return } + validators, err := h.dai.GetValidatorsFromStrings(validatorArr) + if err != nil { + returnInternalServerError(w, err) + return + } var dashboardInfo types.DashboardInfo switch dashboardId := dashboardId.(type) {