Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:gobitfly/beaconchain into BEDS-9…
Browse files Browse the repository at this point in the history
…81/rocketpool-dashboard
  • Loading branch information
manuelsc committed Nov 25, 2024
2 parents 62b9f64 + 1a2879b commit d2076e8
Show file tree
Hide file tree
Showing 42 changed files with 1,814 additions and 1,142 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/frontend"
schedule:
interval: "weekly"
time: "05:00"
timezone: "Europe/Berlin"
target-branch: "staging"
assignees:
- "marcel-bitfly"
- "benji-bitfly"
commit-message:
prefix: "chore(update)"
1 change: 1 addition & 0 deletions .github/workflows/backend-publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
branches:
- main
- staging
- staging-2

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/frontend-publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
branches:
- main
- staging
- staging-2

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
Expand Down
15 changes: 9 additions & 6 deletions backend/pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@ func TestInternalSearchHandler(t *testing.T) {
}`)).Expect().Status(http.StatusOK).JSON().Decode(&resp)

assert.NotEqual(t, 0, len(resp.Data), "response data should not be empty")
assert.NotNil(t, resp.Data[0].NumValue, "validator index should not be nil")
assert.Equal(t, uint64(5), *resp.Data[0].NumValue, "validator index should be 5")
validatorByIndex, ok := resp.Data[0].Value.(api_types.SearchValidator)
assert.True(t, ok, "response data should be of type SearchValidator")
assert.Equal(t, uint64(5), validatorByIndex.Index, "validator index should be 5")

// search for validator by pubkey
resp = api_types.InternalPostSearchResponse{}
Expand All @@ -324,8 +325,9 @@ func TestInternalSearchHandler(t *testing.T) {
}`)).Expect().Status(http.StatusOK).JSON().Decode(&resp)

assert.NotEqual(t, 0, len(resp.Data), "response data should not be empty")
assert.NotNil(t, resp.Data[0].NumValue, "validator index should not be nil")
assert.Equal(t, uint64(5), *resp.Data[0].NumValue, "validator index should be 5")
validatorByPublicKey, ok := resp.Data[0].Value.(api_types.SearchValidator)
assert.True(t, ok, "response data should be of type SearchValidator")
assert.Equal(t, uint64(5), validatorByPublicKey.Index, "validator index should be 5")

// search for validator by withdawal address
resp = api_types.InternalPostSearchResponse{}
Expand All @@ -349,8 +351,9 @@ func TestInternalSearchHandler(t *testing.T) {
}`)).Expect().Status(http.StatusOK).JSON().Decode(&resp)

assert.NotEqual(t, 0, len(resp.Data), "response data should not be empty")
assert.NotNil(t, resp.Data[0].NumValue, "validator index should not be nil")
assert.Greater(t, *resp.Data[0].NumValue, uint64(0), "returned number of validators should be greater than 0")
validatorsByWithdrawalAddress, ok := resp.Data[0].Value.(api_types.SearchValidatorsByWithdrwalCredential)
assert.True(t, ok, "response data should be of type SearchValidator")
assert.Greater(t, validatorsByWithdrawalAddress.Count, uint64(0), "returned number of validators should be greater than 0")
}

func TestPublicAndSharedDashboards(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (d *DummyService) AddValidatorDashboardValidatorsByDepositAddress(ctx conte
return getDummyData[[]t.VDBPostValidatorsData](ctx)
}

func (d *DummyService) AddValidatorDashboardValidatorsByWithdrawalAddress(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) {
func (d *DummyService) AddValidatorDashboardValidatorsByWithdrawalCredential(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) {
return getDummyData[[]t.VDBPostValidatorsData](ctx)
}

Expand Down Expand Up @@ -514,16 +514,16 @@ func (d *DummyService) GetSearchValidatorsByDepositAddress(ctx context.Context,
return getDummyStruct[t.SearchValidatorsByDepositAddress](ctx)
}

func (d *DummyService) GetSearchValidatorsByDepositEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByDepositEnsName, error) {
return getDummyStruct[t.SearchValidatorsByDepositEnsName](ctx)
func (d *DummyService) GetSearchValidatorsByDepositEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByDepositAddress, error) {
return getDummyStruct[t.SearchValidatorsByDepositAddress](ctx)
}

func (d *DummyService) GetSearchValidatorsByWithdrawalCredential(ctx context.Context, chainId uint64, credential []byte) (*t.SearchValidatorsByWithdrwalCredential, error) {
return getDummyStruct[t.SearchValidatorsByWithdrwalCredential](ctx)
}

func (d *DummyService) GetSearchValidatorsByWithdrawalEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByWithrawalEnsName, error) {
return getDummyStruct[t.SearchValidatorsByWithrawalEnsName](ctx)
func (d *DummyService) GetSearchValidatorsByWithdrawalEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByWithdrwalCredential, error) {
return getDummyStruct[t.SearchValidatorsByWithdrwalCredential](ctx)
}

func (d *DummyService) GetSearchValidatorsByGraffiti(ctx context.Context, chainId uint64, graffiti string) (*t.SearchValidatorsByGraffiti, error) {
Expand Down
19 changes: 10 additions & 9 deletions backend/pkg/api/data_access/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type SearchRepository interface {
GetSearchValidatorByIndex(ctx context.Context, chainId, index uint64) (*t.SearchValidator, error)
GetSearchValidatorByPublicKey(ctx context.Context, chainId uint64, publicKey []byte) (*t.SearchValidator, error)
GetSearchValidatorsByDepositAddress(ctx context.Context, chainId uint64, address []byte) (*t.SearchValidatorsByDepositAddress, error)
GetSearchValidatorsByDepositEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByDepositEnsName, error)
GetSearchValidatorsByDepositEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByDepositAddress, error)
GetSearchValidatorsByWithdrawalCredential(ctx context.Context, chainId uint64, credential []byte) (*t.SearchValidatorsByWithdrwalCredential, error)
GetSearchValidatorsByWithdrawalEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByWithrawalEnsName, error)
GetSearchValidatorsByWithdrawalEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByWithdrwalCredential, error)
GetSearchValidatorsByGraffiti(ctx context.Context, chainId uint64, graffiti string) (*t.SearchValidatorsByGraffiti, error)
}

Expand All @@ -28,7 +28,7 @@ func (d *DataAccessService) GetSearchValidatorByIndex(ctx context.Context, chain
if int(index) < len(validatorMapping.ValidatorPubkeys) {
return &t.SearchValidator{
Index: index,
PublicKey: hexutil.MustDecode(validatorMapping.ValidatorPubkeys[index]),
PublicKey: validatorMapping.ValidatorPubkeys[index],
}, nil
}

Expand All @@ -46,7 +46,7 @@ func (d *DataAccessService) GetSearchValidatorByPublicKey(ctx context.Context, c
if index, found := validatorMapping.ValidatorIndices[b]; found {
return &t.SearchValidator{
Index: index,
PublicKey: publicKey,
PublicKey: b,
}, nil
}

Expand All @@ -56,9 +56,10 @@ 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,
DepositAddress: hexutil.Encode(address),
}
err := db.ReaderDb.GetContext(ctx, &ret.Count, "select count(validatorindex) from validators where pubkey in (select publickey from eth1_deposits where from_address = $1);", address)
err := db.ReaderDb.GetContext(ctx, &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
}
Expand All @@ -68,7 +69,7 @@ func (d *DataAccessService) GetSearchValidatorsByDepositAddress(ctx context.Cont
return ret, nil
}

func (d *DataAccessService) GetSearchValidatorsByDepositEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByDepositEnsName, error) {
func (d *DataAccessService) GetSearchValidatorsByDepositEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByDepositAddress, error) {
// TODO: implement handling of chainid
// TODO: finalize ens implementation first
return nil, ErrNotFound
Expand All @@ -77,7 +78,7 @@ func (d *DataAccessService) GetSearchValidatorsByDepositEnsName(ctx context.Cont
func (d *DataAccessService) GetSearchValidatorsByWithdrawalCredential(ctx context.Context, chainId uint64, credential []byte) (*t.SearchValidatorsByWithdrwalCredential, error) {
// TODO: implement handling of chainid
ret := &t.SearchValidatorsByWithdrwalCredential{
WithdrawalCredential: credential,
WithdrawalCredential: hexutil.Encode(credential),
}
err := db.ReaderDb.GetContext(ctx, &ret.Count, "select count(validatorindex) from validators where withdrawalcredentials = $1;", credential)
if err != nil {
Expand All @@ -89,7 +90,7 @@ func (d *DataAccessService) GetSearchValidatorsByWithdrawalCredential(ctx contex
return ret, nil
}

func (d *DataAccessService) GetSearchValidatorsByWithdrawalEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByWithrawalEnsName, error) {
func (d *DataAccessService) GetSearchValidatorsByWithdrawalEnsName(ctx context.Context, chainId uint64, ensName string) (*t.SearchValidatorsByWithdrwalCredential, error) {
// TODO: implement handling of chainid
// TODO: finalize ens implementation first
return nil, ErrNotFound
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/api/data_access/vdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ValidatorDashboardRepository interface {

AddValidatorDashboardValidators(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, validators []t.VDBValidator) ([]t.VDBPostValidatorsData, error)
AddValidatorDashboardValidatorsByDepositAddress(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error)
AddValidatorDashboardValidatorsByWithdrawalAddress(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error)
AddValidatorDashboardValidatorsByWithdrawalCredential(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, credential string, limit uint64) ([]t.VDBPostValidatorsData, error)
AddValidatorDashboardValidatorsByGraffiti(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, graffiti string, limit uint64) ([]t.VDBPostValidatorsData, error)

RemoveValidatorDashboardValidators(ctx context.Context, dashboardId t.VDBIdPrimary, validators []t.VDBValidator) error
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/api/data_access/vdb_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,10 +953,10 @@ func (d *DataAccessService) AddValidatorDashboardValidatorsByDepositAddress(ctx

// Updates the group for validators already in the dashboard linked to the withdrawal address.
// Adds up to limit new validators associated with the withdrawal address, if not already in the dashboard.
func (d *DataAccessService) AddValidatorDashboardValidatorsByWithdrawalAddress(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, address string, limit uint64) ([]t.VDBPostValidatorsData, error) {
func (d *DataAccessService) AddValidatorDashboardValidatorsByWithdrawalCredential(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, credential string, limit uint64) ([]t.VDBPostValidatorsData, error) {
result := []t.VDBPostValidatorsData{}

addressParsed, err := hex.DecodeString(strings.TrimPrefix(address, "0x"))
addressParsed, err := hex.DecodeString(strings.TrimPrefix(credential, "0x"))
if err != nil {
return nil, err
}
Expand Down
24 changes: 12 additions & 12 deletions backend/pkg/api/handlers/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,19 +533,19 @@ func (h *HandlerService) PublicDeleteValidatorDashboardGroupValidators(w http.Re
// @Accept json
// @Produce json
// @Param dashboard_id path integer true "The ID of the dashboard."
// @Param request body handlers.PublicPostValidatorDashboardValidators.request true "`group_id`: (optional) Provide a single group id, to which all validators get added to. If omitted, the default group will be used.<br><br>To add validators or update their group, only one of the following fields can be set:<ul><li>`validators`: Provide a list of validator indices or public keys.</li><li>`deposit_address`: (limited to subscription tiers with 'Bulk adding') Provide a deposit address from which as many validators as possible will be added to the dashboard.</li><li>`withdrawal_address`: (limited to subscription tiers with 'Bulk adding') Provide a withdrawal address from which as many validators as possible will be added to the dashboard.</li><li>`graffiti`: (limited to subscription tiers with 'Bulk adding') Provide a graffiti string from which as many validators as possible will be added to the dashboard.</li></ul>"
// @Param request body handlers.PublicPostValidatorDashboardValidators.request true "`group_id`: (optional) Provide a single group id, to which all validators get added to. If omitted, the default group will be used.<br><br>To add validators or update their group, only one of the following fields can be set:<ul><li>`validators`: Provide a list of validator indices or public keys.</li><li>`deposit_address`: (limited to subscription tiers with 'Bulk adding') Provide a deposit address from which as many validators as possible will be added to the dashboard.</li><li>`withdrawal_credential`: (limited to subscription tiers with 'Bulk adding') Provide a withdrawal credential from which as many validators as possible will be added to the dashboard.</li><li>`graffiti`: (limited to subscription tiers with 'Bulk adding') Provide a graffiti string from which as many validators as possible will be added to the dashboard.</li></ul>"
// @Success 201 {object} types.ApiDataResponse[[]types.VDBPostValidatorsData] "Returns a list of added validators."
// @Failure 400 {object} types.ApiErrorResponse
// @Router /validator-dashboards/{dashboard_id}/validators [post]
func (h *HandlerService) PublicPostValidatorDashboardValidators(w http.ResponseWriter, r *http.Request) {
var v validationError
dashboardId := v.checkPrimaryDashboardId(mux.Vars(r)["dashboard_id"])
type request struct {
GroupId uint64 `json:"group_id,omitempty" x-nullable:"true"`
Validators []intOrString `json:"validators,omitempty"`
DepositAddress string `json:"deposit_address,omitempty"`
WithdrawalAddress string `json:"withdrawal_address,omitempty"`
Graffiti string `json:"graffiti,omitempty"`
GroupId uint64 `json:"group_id,omitempty" x-nullable:"true"`
Validators []intOrString `json:"validators,omitempty"`
DepositAddress string `json:"deposit_address,omitempty"`
WithdrawalCredential string `json:"withdrawal_credential,omitempty"`
Graffiti string `json:"graffiti,omitempty"`
}
req := request{
GroupId: types.DefaultGroupId, // default value
Expand All @@ -559,11 +559,11 @@ func (h *HandlerService) PublicPostValidatorDashboardValidators(w http.ResponseW
return
}
groupId := req.GroupId
// check if exactly one of validators, deposit_address, withdrawal_address, graffiti is set
// check if exactly one of validators, deposit_address, withdrawal_credential, graffiti is set
nilFields := []bool{
req.Validators == nil,
req.DepositAddress == "",
req.WithdrawalAddress == "",
req.WithdrawalCredential == "",
req.Graffiti == "",
}
var count int
Expand All @@ -573,7 +573,7 @@ func (h *HandlerService) PublicPostValidatorDashboardValidators(w http.ResponseW
}
}
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")
v.add("request body", "exactly one of `validators`, `deposit_address`, `withdrawal_credential`, `graffiti` must be set. please check the API documentation for more information")
}
if v.hasErrors() {
handleErr(w, r, v)
Expand Down Expand Up @@ -644,13 +644,13 @@ func (h *HandlerService) PublicPostValidatorDashboardValidators(w http.ResponseW
}
data, dataErr = h.getDataAccessor(r).AddValidatorDashboardValidatorsByDepositAddress(ctx, dashboardId, groupId, depositAddress, limit)

case req.WithdrawalAddress != "":
withdrawalAddress := v.checkRegex(reWithdrawalCredential, req.WithdrawalAddress, "withdrawal_address")
case req.WithdrawalCredential != "":
withdrawalCredential := v.checkRegex(reWithdrawalCredential, req.WithdrawalCredential, "withdrawal_credential")
if v.hasErrors() {
handleErr(w, r, v)
return
}
data, dataErr = h.getDataAccessor(r).AddValidatorDashboardValidatorsByWithdrawalAddress(ctx, dashboardId, groupId, withdrawalAddress, limit)
data, dataErr = h.getDataAccessor(r).AddValidatorDashboardValidatorsByWithdrawalCredential(ctx, dashboardId, groupId, withdrawalCredential, limit)

case req.Graffiti != "":
graffiti := v.checkRegex(reGraffiti, req.Graffiti, "graffiti")
Expand Down
Loading

0 comments on commit d2076e8

Please sign in to comment.