Skip to content

Commit 21a5c00

Browse files
remoteramienzo-bitfly
authored andcommitted
refactor!: adjust to new api structure, pectra changes
1 parent 0cdec14 commit 21a5c00

File tree

12 files changed

+286
-178
lines changed

12 files changed

+286
-178
lines changed

backend/pkg/api/data_access/dummy.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,19 +369,19 @@ func (*DummyService) GetValidatorDashboardGroupHeatmap(ctx context.Context, dash
369369
return getDummyStruct[t.VDBHeatmapTooltipData](ctx)
370370
}
371371

372-
func (*DummyService) GetValidatorDashboardElDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, limit uint64) ([]t.VDBExecutionDepositsTableRow, *t.Paging, error) {
372+
func (*DummyService) GetValidatorDashboardElDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBDepositsElColumn], search string, limit uint64) ([]t.VDBExecutionDepositsTableRow, *t.Paging, error) {
373373
return getDummyWithPaging[t.VDBExecutionDepositsTableRow](ctx)
374374
}
375375

376-
func (*DummyService) GetValidatorDashboardClDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, limit uint64) ([]t.VDBConsensusDepositsTableRow, *t.Paging, error) {
376+
func (*DummyService) GetValidatorDashboardClDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBDepositsClColumn], search string, limit uint64) ([]t.VDBConsensusDepositsTableRow, *t.Paging, error) {
377377
return getDummyWithPaging[t.VDBConsensusDepositsTableRow](ctx)
378378
}
379379

380-
func (*DummyService) GetValidatorDashboardTotalElDeposits(ctx context.Context, dashboardId t.VDBId) (*t.VDBTotalExecutionDepositsData, error) {
380+
func (*DummyService) GetValidatorDashboardTotalElDeposits(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBTotalExecutionDepositsData, error) {
381381
return getDummyStruct[t.VDBTotalExecutionDepositsData](ctx)
382382
}
383383

384-
func (*DummyService) GetValidatorDashboardTotalClDeposits(ctx context.Context, dashboardId t.VDBId) (*t.VDBTotalConsensusDepositsData, error) {
384+
func (*DummyService) GetValidatorDashboardTotalClDeposits(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBTotalConsensusDepositsData, error) {
385385
return getDummyStruct[t.VDBTotalConsensusDepositsData](ctx)
386386
}
387387

backend/pkg/api/data_access/vdb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ type ValidatorDashboardRepository interface {
6565
GetValidatorDashboardHeatmap(ctx context.Context, dashboardId t.VDBId, protocolModes t.VDBProtocolModes, aggregation enums.ChartAggregation, afterTs uint64, beforeTs uint64) (*t.VDBHeatmap, error)
6666
GetValidatorDashboardGroupHeatmap(ctx context.Context, dashboardId t.VDBId, groupId uint64, protocolModes t.VDBProtocolModes, aggregation enums.ChartAggregation, timestamp uint64) (*t.VDBHeatmapTooltipData, error)
6767

68-
GetValidatorDashboardElDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, limit uint64) ([]t.VDBExecutionDepositsTableRow, *t.Paging, error)
69-
GetValidatorDashboardClDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, limit uint64) ([]t.VDBConsensusDepositsTableRow, *t.Paging, error)
70-
GetValidatorDashboardTotalElDeposits(ctx context.Context, dashboardId t.VDBId) (*t.VDBTotalExecutionDepositsData, error)
71-
GetValidatorDashboardTotalClDeposits(ctx context.Context, dashboardId t.VDBId) (*t.VDBTotalConsensusDepositsData, error)
68+
GetValidatorDashboardElDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBDepositsElColumn], search string, limit uint64) ([]t.VDBExecutionDepositsTableRow, *t.Paging, error)
69+
GetValidatorDashboardClDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBDepositsClColumn], search string, limit uint64) ([]t.VDBConsensusDepositsTableRow, *t.Paging, error)
70+
GetValidatorDashboardTotalElDeposits(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBTotalExecutionDepositsData, error)
71+
GetValidatorDashboardTotalClDeposits(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBTotalConsensusDepositsData, error)
7272

7373
GetValidatorDashboardWithdrawals(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBWithdrawalsColumn], search string, limit uint64, protocolModes t.VDBProtocolModes) ([]t.VDBWithdrawalsTableRow, *t.Paging, error)
7474
GetValidatorDashboardTotalWithdrawals(ctx context.Context, dashboardId t.VDBId, search string, protocolModes t.VDBProtocolModes) (*t.VDBTotalWithdrawalsData, error)

backend/pkg/api/data_access/vdb_deposits.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/doug-martin/goqu/v9"
1313
"github.com/ethereum/go-ethereum/common/hexutil"
14+
"github.com/gobitfly/beaconchain/pkg/api/enums"
1415
t "github.com/gobitfly/beaconchain/pkg/api/types"
1516
"github.com/gobitfly/beaconchain/pkg/commons/db"
1617
"github.com/gobitfly/beaconchain/pkg/commons/types"
@@ -19,7 +20,7 @@ import (
1920
"github.com/shopspring/decimal"
2021
)
2122

22-
func (d *DataAccessService) GetValidatorDashboardElDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, limit uint64) ([]t.VDBExecutionDepositsTableRow, *t.Paging, error) {
23+
func (d *DataAccessService) GetValidatorDashboardElDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBDepositsElColumn], search string, limit uint64) ([]t.VDBExecutionDepositsTableRow, *t.Paging, error) {
2324
// TODO: add default sorting
2425
var err error
2526
var currentCursor t.ELDepositsCursor
@@ -135,8 +136,8 @@ func (d *DataAccessService) GetValidatorDashboardElDeposits(ctx context.Context,
135136
TxHash: t.Hash(hexutil.Encode(row.TxHash)),
136137
WithdrawalCredential: t.Hash(hexutil.Encode(row.WithdrawalCredentials)),
137138
Amount: utils.GWeiToWei(big.NewInt(row.Amount)),
138-
Valid: row.Valid,
139-
From: t.Address{Hash: t.Hash(hexutil.Encode(row.From))},
139+
// Valid: row.Valid,
140+
From: t.Address{Hash: t.Hash(hexutil.Encode(row.From))},
140141
}
141142
addressMapping[hexutil.Encode(row.From)] = nil
142143
fromContractStatusRequests[i] = db.ContractInteractionAtRequest{
@@ -220,7 +221,7 @@ func (d *DataAccessService) GetValidatorDashboardElDeposits(ctx context.Context,
220221
return responseData, p, nil
221222
}
222223

223-
func (d *DataAccessService) GetValidatorDashboardClDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, limit uint64) ([]t.VDBConsensusDepositsTableRow, *t.Paging, error) {
224+
func (d *DataAccessService) GetValidatorDashboardClDeposits(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBDepositsClColumn], search string, limit uint64) ([]t.VDBConsensusDepositsTableRow, *t.Paging, error) {
224225
// TODO: add default sorting
225226
var err error
226227
var currentCursor t.CLDepositsCursor
@@ -371,10 +372,10 @@ func (d *DataAccessService) GetValidatorDashboardClDeposits(ctx context.Context,
371372
responseData := make([]t.VDBConsensusDepositsTableRow, len(data))
372373
for i, row := range data {
373374
responseData[i] = t.VDBConsensusDepositsTableRow{
374-
PublicKey: t.PubKey(pubkeys[i]),
375-
Index: indices[i],
376-
Epoch: utils.EpochOfSlot(uint64(row.Slot)),
377-
Slot: uint64(row.Slot),
375+
PublicKey: t.PubKey(pubkeys[i]),
376+
Index: indices[i],
377+
// Epoch: utils.EpochOfSlot(uint64(row.Slot)),
378+
// Slot: uint64(row.Slot),
378379
WithdrawalCredential: t.Hash(hexutil.Encode(row.WithdrawalCredential)),
379380
Amount: utils.GWeiToWei(big.NewInt(row.Amount)),
380381
Signature: t.Hash(hexutil.Encode(row.Signature)),
@@ -416,7 +417,8 @@ func (d *DataAccessService) GetValidatorDashboardClDeposits(ctx context.Context,
416417
return responseData, p, nil
417418
}
418419

419-
func (d *DataAccessService) GetValidatorDashboardTotalElDeposits(ctx context.Context, dashboardId t.VDBId) (*t.VDBTotalExecutionDepositsData, error) {
420+
func (d *DataAccessService) GetValidatorDashboardTotalElDeposits(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBTotalExecutionDepositsData, error) {
421+
// TODO add filter
420422
responseData := t.VDBTotalExecutionDepositsData{
421423
TotalAmount: decimal.Zero,
422424
}
@@ -456,7 +458,8 @@ func (d *DataAccessService) GetValidatorDashboardTotalElDeposits(ctx context.Con
456458
return &responseData, nil
457459
}
458460

459-
func (d *DataAccessService) GetValidatorDashboardTotalClDeposits(ctx context.Context, dashboardId t.VDBId) (*t.VDBTotalConsensusDepositsData, error) {
461+
func (d *DataAccessService) GetValidatorDashboardTotalClDeposits(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBTotalConsensusDepositsData, error) {
462+
// TODO add filter
460463
responseData := t.VDBTotalConsensusDepositsData{
461464
TotalAmount: decimal.Zero,
462465
}

backend/pkg/api/data_access/vdb_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func (d *DataAccessService) calculateValidatorDashboardBalance(ctx context.Conte
436436
wg.Go(func() error {
437437
// Get the total cl deposits for non-rocketpool validators
438438
if len(nonRpDashboardId.Validators) > 0 {
439-
totalNonRpDeposits, err := d.GetValidatorDashboardTotalClDeposits(ctx, nonRpDashboardId)
439+
totalNonRpDeposits, err := d.GetValidatorDashboardTotalClDeposits(ctx, nonRpDashboardId, "")
440440
if err != nil {
441441
return fmt.Errorf("error retrieving total cl deposits for non-rocketpool validators: %w", err)
442442
}

backend/pkg/api/enums/validator_dashboard_enums.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,76 @@ var VDBWithdrawalsColumns = struct {
248248
VDBWithdrawalAmount,
249249
}
250250

251+
// ----------------
252+
// Validator Dashboard EL Deposits Table
253+
254+
type VDBDepositsElColumn int
255+
256+
var _ EnumFactory[VDBDepositsElColumn] = VDBDepositsElColumn(0)
257+
258+
const (
259+
VDBDepositElBlock VDBDepositsElColumn = iota
260+
VDBDepositElAmount
261+
)
262+
263+
func (c VDBDepositsElColumn) Int() int {
264+
return int(c)
265+
}
266+
267+
func (VDBDepositsElColumn) NewFromString(s string) VDBDepositsElColumn {
268+
switch s {
269+
case "", "block":
270+
return VDBDepositElBlock
271+
case "amount":
272+
return VDBDepositElAmount
273+
default:
274+
return VDBDepositsElColumn(-1)
275+
}
276+
}
277+
278+
var VDBDepositsElColumns = struct {
279+
Block VDBDepositsElColumn
280+
Amount VDBDepositsElColumn
281+
}{
282+
VDBDepositElBlock,
283+
VDBDepositElAmount,
284+
}
285+
286+
// ----------------
287+
// Validator Dashboard CL Deposits Table
288+
289+
type VDBDepositsClColumn int
290+
291+
var _ EnumFactory[VDBDepositsClColumn] = VDBDepositsClColumn(0)
292+
293+
const (
294+
VDBDepositClSlot VDBDepositsClColumn = iota
295+
VDBDepositClAmount
296+
)
297+
298+
func (c VDBDepositsClColumn) Int() int {
299+
return int(c)
300+
}
301+
302+
func (VDBDepositsClColumn) NewFromString(s string) VDBDepositsClColumn {
303+
switch s {
304+
case "", "slot":
305+
return VDBDepositClSlot
306+
case "amount":
307+
return VDBDepositClAmount
308+
default:
309+
return VDBDepositsClColumn(-1)
310+
}
311+
}
312+
313+
var VDBDepositsClColumns = struct {
314+
Slot VDBDepositsClColumn
315+
Amount VDBDepositsClColumn
316+
}{
317+
VDBDepositClSlot,
318+
VDBDepositClAmount,
319+
}
320+
251321
// ----------------
252322
// Validator Dashboard Manage Validators Table
253323

backend/pkg/api/handlers/input_validation.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,24 @@ func (v *validationError) checkPagingParams(q url.Values) Paging {
348348
return paging
349349
}
350350

351+
func (v *validationError) checkPagingMap(params map[string]string) Paging {
352+
paging := Paging{
353+
cursor: params["cursor"],
354+
limit: defaultReturnLimit,
355+
search: params["search"],
356+
}
357+
358+
if limitStr := params["limit"]; limitStr != "" {
359+
paging.limit = v.checkUintMinMax(limitStr, 1, maxQueryLimit, "limit")
360+
}
361+
362+
if paging.cursor != "" {
363+
paging.cursor = v.checkRegex(reCursor, paging.cursor, "cursor")
364+
}
365+
366+
return paging
367+
}
368+
351369
// checkEnum validates the given enum string and returns the corresponding enum value.
352370
func checkEnum[T enums.EnumFactory[T]](v *validationError, enumString string, name string) T {
353371
var e T

backend/pkg/api/handlers/internal.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -451,22 +451,6 @@ func (h *HandlerService) InternalGetValidatorDashboardBlocks(w http.ResponseWrit
451451
h.PublicGetValidatorDashboardBlocks(w, r)
452452
}
453453

454-
func (h *HandlerService) InternalGetValidatorDashboardExecutionLayerDeposits(w http.ResponseWriter, r *http.Request) {
455-
h.PublicGetValidatorDashboardExecutionLayerDeposits(w, r)
456-
}
457-
458-
func (h *HandlerService) InternalGetValidatorDashboardConsensusLayerDeposits(w http.ResponseWriter, r *http.Request) {
459-
h.PublicGetValidatorDashboardConsensusLayerDeposits(w, r)
460-
}
461-
462-
func (h *HandlerService) InternalGetValidatorDashboardTotalConsensusLayerDeposits(w http.ResponseWriter, r *http.Request) {
463-
h.PublicGetValidatorDashboardTotalConsensusLayerDeposits(w, r)
464-
}
465-
466-
func (h *HandlerService) InternalGetValidatorDashboardTotalExecutionLayerDeposits(w http.ResponseWriter, r *http.Request) {
467-
h.PublicGetValidatorDashboardTotalExecutionLayerDeposits(w, r)
468-
}
469-
470454
func (h *HandlerService) InternalGetValidatorDashboardWithdrawals(w http.ResponseWriter, r *http.Request) {
471455
h.PublicGetValidatorDashboardWithdrawals(w, r)
472456
}

backend/pkg/api/handlers/public.go

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,139 +1362,6 @@ func (h *HandlerService) PublicGetValidatorDashboardBlocks(w http.ResponseWriter
13621362
returnOk(w, r, response)
13631363
}
13641364

1365-
// PublicGetValidatorDashboardExecutionLayerDeposits godoc
1366-
//
1367-
// @Description Get execution layer deposits information for a specified dashboard
1368-
// @Tags Validator Dashboard
1369-
// @Produce json
1370-
// @Param dashboard_id path string true "The ID of the dashboard."
1371-
// @Param cursor query string false "Return data for the given cursor value. Pass the `paging.next_cursor`` value of the previous response to navigate to forward, or pass the `paging.prev_cursor`` value of the previous response to navigate to backward."
1372-
// @Param limit query string false "The maximum number of results that may be returned."
1373-
// @Success 200 {object} types.GetValidatorDashboardExecutionLayerDepositsResponse
1374-
// @Failure 400 {object} types.ApiErrorResponse
1375-
// @Router /validator-dashboards/{dashboard_id}/execution-layer-deposits [get]
1376-
func (h *HandlerService) PublicGetValidatorDashboardExecutionLayerDeposits(w http.ResponseWriter, r *http.Request) {
1377-
var v validationError
1378-
dashboardId, err := h.handleDashboardId(r.Context(), mux.Vars(r)["dashboard_id"])
1379-
if err != nil {
1380-
handleErr(w, r, err)
1381-
return
1382-
}
1383-
pagingParams := v.checkPagingParams(r.URL.Query())
1384-
if err := v.AsError(); err != nil {
1385-
handleErr(w, r, err)
1386-
return
1387-
}
1388-
1389-
ctx := r.Context()
1390-
data, paging, err := h.getDataAccessor(ctx).GetValidatorDashboardElDeposits(ctx, *dashboardId, pagingParams.cursor, pagingParams.limit)
1391-
if err != nil {
1392-
handleErr(w, r, err)
1393-
return
1394-
}
1395-
response := types.GetValidatorDashboardExecutionLayerDepositsResponse{
1396-
Data: data,
1397-
Paging: *paging,
1398-
}
1399-
returnOk(w, r, response)
1400-
}
1401-
1402-
// PublicGetValidatorDashboardConsensusLayerDeposits godoc
1403-
//
1404-
// @Description Get consensus layer deposits information for a specified dashboard
1405-
// @Tags Validator Dashboard
1406-
// @Produce json
1407-
// @Param dashboard_id path string true "The ID of the dashboard."
1408-
// @Param cursor query string false "Return data for the given cursor value. Pass the `paging.next_cursor`` value of the previous response to navigate to forward, or pass the `paging.prev_cursor`` value of the previous response to navigate to backward."
1409-
// @Param limit query string false "The maximum number of results that may be returned."
1410-
// @Success 200 {object} types.GetValidatorDashboardConsensusLayerDepositsResponse
1411-
// @Failure 400 {object} types.ApiErrorResponse
1412-
// @Router /validator-dashboards/{dashboard_id}/consensus-layer-deposits [get]
1413-
func (h *HandlerService) PublicGetValidatorDashboardConsensusLayerDeposits(w http.ResponseWriter, r *http.Request) {
1414-
var v validationError
1415-
dashboardId, err := h.handleDashboardId(r.Context(), mux.Vars(r)["dashboard_id"])
1416-
if err != nil {
1417-
handleErr(w, r, err)
1418-
return
1419-
}
1420-
pagingParams := v.checkPagingParams(r.URL.Query())
1421-
if err := v.AsError(); err != nil {
1422-
handleErr(w, r, err)
1423-
return
1424-
}
1425-
1426-
ctx := r.Context()
1427-
data, paging, err := h.getDataAccessor(ctx).GetValidatorDashboardClDeposits(ctx, *dashboardId, pagingParams.cursor, pagingParams.limit)
1428-
if err != nil {
1429-
handleErr(w, r, err)
1430-
return
1431-
}
1432-
1433-
response := types.GetValidatorDashboardConsensusLayerDepositsResponse{
1434-
Data: data,
1435-
Paging: *paging,
1436-
}
1437-
returnOk(w, r, response)
1438-
}
1439-
1440-
// PublicGetValidatorDashboardTotalConsensusLayerDeposits godoc
1441-
//
1442-
// @Description Get total consensus layer deposits information for a specified dashboard
1443-
// @Tags Validator Dashboard
1444-
// @Produce json
1445-
// @Param dashboard_id path string true "The ID of the dashboard."
1446-
// @Success 200 {object} types.GetValidatorDashboardTotalConsensusDepositsResponse
1447-
// @Failure 400 {object} types.ApiErrorResponse
1448-
// @Router /validator-dashboards/{dashboard_id}/total-consensus-layer-deposits [get]
1449-
func (h *HandlerService) PublicGetValidatorDashboardTotalConsensusLayerDeposits(w http.ResponseWriter, r *http.Request) {
1450-
var err error
1451-
dashboardId, err := h.handleDashboardId(r.Context(), mux.Vars(r)["dashboard_id"])
1452-
if err != nil {
1453-
handleErr(w, r, err)
1454-
return
1455-
}
1456-
ctx := r.Context()
1457-
data, err := h.getDataAccessor(ctx).GetValidatorDashboardTotalClDeposits(ctx, *dashboardId)
1458-
if err != nil {
1459-
handleErr(w, r, err)
1460-
return
1461-
}
1462-
1463-
response := types.GetValidatorDashboardTotalConsensusDepositsResponse{
1464-
Data: *data,
1465-
}
1466-
returnOk(w, r, response)
1467-
}
1468-
1469-
// PublicGetValidatorDashboardTotalExecutionLayerDeposits godoc
1470-
//
1471-
// @Description Get total execution layer deposits information for a specified dashboard
1472-
// @Tags Validator Dashboard
1473-
// @Produce json
1474-
// @Param dashboard_id path string true "The ID of the dashboard."
1475-
// @Success 200 {object} types.GetValidatorDashboardTotalExecutionDepositsResponse
1476-
// @Failure 400 {object} types.ApiErrorResponse
1477-
// @Router /validator-dashboards/{dashboard_id}/total-execution-layer-deposits [get]
1478-
func (h *HandlerService) PublicGetValidatorDashboardTotalExecutionLayerDeposits(w http.ResponseWriter, r *http.Request) {
1479-
var err error
1480-
dashboardId, err := h.handleDashboardId(r.Context(), mux.Vars(r)["dashboard_id"])
1481-
if err != nil {
1482-
handleErr(w, r, err)
1483-
return
1484-
}
1485-
ctx := r.Context()
1486-
data, err := h.getDataAccessor(ctx).GetValidatorDashboardTotalElDeposits(ctx, *dashboardId)
1487-
if err != nil {
1488-
handleErr(w, r, err)
1489-
return
1490-
}
1491-
1492-
response := types.GetValidatorDashboardTotalExecutionDepositsResponse{
1493-
Data: *data,
1494-
}
1495-
returnOk(w, r, response)
1496-
}
1497-
14981365
// PublicGetValidatorDashboardWithdrawals godoc
14991366
//
15001367
// @Description Get withdrawals information for a specified dashboard

0 commit comments

Comments
 (0)