Skip to content

Commit

Permalink
Merge branch 'staging' into BIDS-3236/ch_for_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisei24 committed Aug 2, 2024
2 parents e198df4 + beeabb6 commit f5606e4
Show file tree
Hide file tree
Showing 26 changed files with 1,534 additions and 256 deletions.
146 changes: 146 additions & 0 deletions backend/pkg/api/data_access/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package dataaccess

import (
"context"

t "github.com/gobitfly/beaconchain/pkg/api/types"
)

type BlockRepository interface {
GetBlock(ctx context.Context, chainId, block uint64) (*t.BlockSummary, error)
GetBlockOverview(ctx context.Context, chainId, block uint64) (*t.BlockOverview, error)
GetBlockTransactions(ctx context.Context, chainId, block uint64) ([]t.BlockTransactionTableRow, error)
GetBlockVotes(ctx context.Context, chainId, block uint64) ([]t.BlockVoteTableRow, error)
GetBlockAttestations(ctx context.Context, chainId, block uint64) ([]t.BlockAttestationTableRow, error)
GetBlockWithdrawals(ctx context.Context, chainId, block uint64) ([]t.BlockWithdrawalTableRow, error)
GetBlockBlsChanges(ctx context.Context, chainId, block uint64) ([]t.BlockBlsChangeTableRow, error)
GetBlockVoluntaryExits(ctx context.Context, chainId, block uint64) ([]t.BlockVoluntaryExitTableRow, error)
GetBlockBlobs(ctx context.Context, chainId, block uint64) ([]t.BlockBlobTableRow, error)

GetSlot(ctx context.Context, chainId, block uint64) (*t.BlockSummary, error)
GetSlotOverview(ctx context.Context, chainId, block uint64) (*t.BlockOverview, error)
GetSlotTransactions(ctx context.Context, chainId, block uint64) ([]t.BlockTransactionTableRow, error)
GetSlotVotes(ctx context.Context, chainId, block uint64) ([]t.BlockVoteTableRow, error)
GetSlotAttestations(ctx context.Context, chainId, block uint64) ([]t.BlockAttestationTableRow, error)
GetSlotWithdrawals(ctx context.Context, chainId, block uint64) ([]t.BlockWithdrawalTableRow, error)
GetSlotBlsChanges(ctx context.Context, chainId, block uint64) ([]t.BlockBlsChangeTableRow, error)
GetSlotVoluntaryExits(ctx context.Context, chainId, block uint64) ([]t.BlockVoluntaryExitTableRow, error)
GetSlotBlobs(ctx context.Context, chainId, block uint64) ([]t.BlockBlobTableRow, error)
}

func (d *DataAccessService) GetBlock(ctx context.Context, chainId, block uint64) (*t.BlockSummary, error) {
// @DATA-ACCESS
return d.dummy.GetBlock(ctx, chainId, block)
}

func (d *DataAccessService) GetBlockOverview(ctx context.Context, chainId, block uint64) (*t.BlockOverview, error) {
// @DATA-ACCESS
return d.dummy.GetBlockOverview(ctx, chainId, block)
}

func (d *DataAccessService) GetBlockTransactions(ctx context.Context, chainId, block uint64) ([]t.BlockTransactionTableRow, error) {
// @DATA-ACCESS
return d.dummy.GetBlockTransactions(ctx, chainId, block)
}

func (d *DataAccessService) GetBlockVotes(ctx context.Context, chainId, block uint64) ([]t.BlockVoteTableRow, error) {
// @DATA-ACCESS
return d.dummy.GetBlockVotes(ctx, chainId, block)
}

func (d *DataAccessService) GetBlockAttestations(ctx context.Context, chainId, block uint64) ([]t.BlockAttestationTableRow, error) {
// @DATA-ACCESS
return d.dummy.GetBlockAttestations(ctx, chainId, block)
}

func (d *DataAccessService) GetBlockWithdrawals(ctx context.Context, chainId, block uint64) ([]t.BlockWithdrawalTableRow, error) {
// @DATA-ACCESS
return d.dummy.GetBlockWithdrawals(ctx, chainId, block)
}

func (d *DataAccessService) GetBlockBlsChanges(ctx context.Context, chainId, block uint64) ([]t.BlockBlsChangeTableRow, error) {
// @DATA-ACCESS
return d.dummy.GetBlockBlsChanges(ctx, chainId, block)
}

func (d *DataAccessService) GetBlockVoluntaryExits(ctx context.Context, chainId, block uint64) ([]t.BlockVoluntaryExitTableRow, error) {
// @DATA-ACCESS
return d.dummy.GetBlockVoluntaryExits(ctx, chainId, block)
}

func (d *DataAccessService) GetBlockBlobs(ctx context.Context, chainId, block uint64) ([]t.BlockBlobTableRow, error) {
// @DATA-ACCESS
return d.dummy.GetBlockBlobs(ctx, chainId, block)
}

func (d *DataAccessService) GetSlot(ctx context.Context, chainId, slot uint64) (*t.BlockSummary, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlock(ctx, chainId, block)
}

func (d *DataAccessService) GetSlotOverview(ctx context.Context, chainId, slot uint64) (*t.BlockOverview, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlockOverview(ctx, chainId, block)
}

func (d *DataAccessService) GetSlotTransactions(ctx context.Context, chainId, slot uint64) ([]t.BlockTransactionTableRow, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlockTransactions(ctx, chainId, block)
}

func (d *DataAccessService) GetSlotVotes(ctx context.Context, chainId, slot uint64) ([]t.BlockVoteTableRow, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlockVotes(ctx, chainId, block)
}

func (d *DataAccessService) GetSlotAttestations(ctx context.Context, chainId, slot uint64) ([]t.BlockAttestationTableRow, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlockAttestations(ctx, chainId, block)
}

func (d *DataAccessService) GetSlotWithdrawals(ctx context.Context, chainId, slot uint64) ([]t.BlockWithdrawalTableRow, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlockWithdrawals(ctx, chainId, block)
}

func (d *DataAccessService) GetSlotBlsChanges(ctx context.Context, chainId, slot uint64) ([]t.BlockBlsChangeTableRow, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlockBlsChanges(ctx, chainId, block)
}

func (d *DataAccessService) GetSlotVoluntaryExits(ctx context.Context, chainId, slot uint64) ([]t.BlockVoluntaryExitTableRow, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlockVoluntaryExits(ctx, chainId, block)
}

func (d *DataAccessService) GetSlotBlobs(ctx context.Context, chainId, slot uint64) ([]t.BlockBlobTableRow, error) {
block, err := d.GetBlockHeightAt(slot)
if err != nil {
return nil, err
}
return d.GetBlockBlobs(ctx, chainId, block)
}
3 changes: 3 additions & 0 deletions backend/pkg/api/data_access/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ type DataAccessor interface {
UserRepository
NotificationsRepository
AdminRepository
BlockRepository

Close()

GetLatestSlot() (uint64, error)
GetLatestBlock() (uint64, error)
GetBlockHeightAt(slot uint64) (uint64, error)
GetLatestExchangeRates() ([]t.EthConversionRate, error)

GetProductSummary(ctx context.Context) (*t.ProductSummary, error)
Expand Down
137 changes: 136 additions & 1 deletion backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ func (d *DummyService) GetLatestSlot() (uint64, error) {
return r, err
}

func (d *DummyService) GetLatestBlock() (uint64, error) {
r := uint64(0)
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetBlockHeightAt(slot uint64) (uint64, error) {
r := uint64(0)
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetLatestExchangeRates() ([]t.EthConversionRate, error) {
r := []t.EthConversionRate{}
err := commonFakeData(&r)
Expand Down Expand Up @@ -161,6 +173,15 @@ func (d *DummyService) GetValidatorDashboardInfoByPublicId(ctx context.Context,
return &r, err
}

func (d *DummyService) GetValidatorDashboard(ctx context.Context, dashboardId t.VDBId) (*t.ValidatorDashboard, error) {
r := t.ValidatorDashboard{}
// return semi-valid data to not break staging
//nolint:errcheck
commonFakeData(&r)
r.IsArchived = false
return &r, nil
}

func (d *DummyService) GetValidatorDashboardName(ctx context.Context, dashboardId t.VDBIdPrimary) (string, error) {
r := ""
err := commonFakeData(&r)
Expand Down Expand Up @@ -195,6 +216,12 @@ func (d *DummyService) RemoveValidatorDashboard(ctx context.Context, dashboardId
return nil
}

func (d *DummyService) UpdateValidatorDashboardArchiving(ctx context.Context, dashboardId t.VDBIdPrimary, archived bool) (*t.VDBPostArchivingReturnData, error) {
r := t.VDBPostArchivingReturnData{}
err := commonFakeData(&r)
return &r, err
}

func (d *DummyService) UpdateValidatorDashboardName(ctx context.Context, dashboardId t.VDBIdPrimary, name string) (*t.VDBPostReturnData, error) {
r := t.VDBPostReturnData{}
err := commonFakeData(&r)
Expand Down Expand Up @@ -511,7 +538,7 @@ func (d *DummyService) GetSearchValidatorsByGraffiti(ctx context.Context, chainI
return &r, err
}

func (d *DummyService) GetUserValidatorDashboardCount(ctx context.Context, userId uint64) (uint64, error) {
func (d *DummyService) GetUserValidatorDashboardCount(ctx context.Context, userId uint64, active bool) (uint64, error) {
r := uint64(0)
err := commonFakeData(&r)
return r, err
Expand Down Expand Up @@ -646,3 +673,111 @@ func (d *DummyService) UpdateAdConfiguration(ctx context.Context, key, jquerySel
func (d *DummyService) RemoveAdConfiguration(ctx context.Context, key string) error {
return nil
}

func (d *DummyService) GetBlock(ctx context.Context, chainId, block uint64) (*t.BlockSummary, error) {
r := t.BlockSummary{}
err := commonFakeData(&r)
return &r, err
}

func (d *DummyService) GetBlockOverview(ctx context.Context, chainId, block uint64) (*t.BlockOverview, error) {
r := t.BlockOverview{}
err := commonFakeData(&r)
return &r, err
}

func (d *DummyService) GetBlockTransactions(ctx context.Context, chainId, block uint64) ([]t.BlockTransactionTableRow, error) {
r := []t.BlockTransactionTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetBlockVotes(ctx context.Context, chainId, block uint64) ([]t.BlockVoteTableRow, error) {
r := []t.BlockVoteTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetBlockAttestations(ctx context.Context, chainId, block uint64) ([]t.BlockAttestationTableRow, error) {
r := []t.BlockAttestationTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetBlockWithdrawals(ctx context.Context, chainId, block uint64) ([]t.BlockWithdrawalTableRow, error) {
r := []t.BlockWithdrawalTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetBlockBlsChanges(ctx context.Context, chainId, block uint64) ([]t.BlockBlsChangeTableRow, error) {
r := []t.BlockBlsChangeTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetBlockVoluntaryExits(ctx context.Context, chainId, block uint64) ([]t.BlockVoluntaryExitTableRow, error) {
r := []t.BlockVoluntaryExitTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetBlockBlobs(ctx context.Context, chainId, block uint64) ([]t.BlockBlobTableRow, error) {
r := []t.BlockBlobTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetSlot(ctx context.Context, chainId, block uint64) (*t.BlockSummary, error) {
r := t.BlockSummary{}
err := commonFakeData(&r)
return &r, err
}

func (d *DummyService) GetSlotOverview(ctx context.Context, chainId, block uint64) (*t.BlockOverview, error) {
r := t.BlockOverview{}
err := commonFakeData(&r)
return &r, err
}

func (d *DummyService) GetSlotTransactions(ctx context.Context, chainId, block uint64) ([]t.BlockTransactionTableRow, error) {
r := []t.BlockTransactionTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetSlotVotes(ctx context.Context, chainId, block uint64) ([]t.BlockVoteTableRow, error) {
r := []t.BlockVoteTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetSlotAttestations(ctx context.Context, chainId, block uint64) ([]t.BlockAttestationTableRow, error) {
r := []t.BlockAttestationTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetSlotWithdrawals(ctx context.Context, chainId, block uint64) ([]t.BlockWithdrawalTableRow, error) {
r := []t.BlockWithdrawalTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetSlotBlsChanges(ctx context.Context, chainId, block uint64) ([]t.BlockBlsChangeTableRow, error) {
r := []t.BlockBlsChangeTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetSlotVoluntaryExits(ctx context.Context, chainId, block uint64) ([]t.BlockVoluntaryExitTableRow, error) {
r := []t.BlockVoluntaryExitTableRow{}
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetSlotBlobs(ctx context.Context, chainId, block uint64) ([]t.BlockBlobTableRow, error) {
r := []t.BlockBlobTableRow{}
err := commonFakeData(&r)
return r, err
}
10 changes: 10 additions & 0 deletions backend/pkg/api/data_access/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ func (d *DataAccessService) GetLatestSlot() (uint64, error) {
return latestSlot, nil
}

func (d *DataAccessService) GetLatestBlock() (uint64, error) {
// @DATA-ACCESS implement
return d.dummy.GetLatestBlock()
}

func (d *DataAccessService) GetBlockHeightAt(slot uint64) (uint64, error) {
// @DATA-ACCESS implement; return error if no block at slot
return d.dummy.GetBlockHeightAt(slot)
}

func (d *DataAccessService) GetLatestExchangeRates() ([]t.EthConversionRate, error) {
result := []t.EthConversionRate{}

Expand Down
7 changes: 5 additions & 2 deletions backend/pkg/api/data_access/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type UserRepository interface {
GetUserIdByConfirmationHash(hash string) (uint64, error)
GetUserInfo(ctx context.Context, id uint64) (*t.UserInfo, error)
GetUserDashboards(ctx context.Context, userId uint64) (*t.UserDashboardsData, error)
GetUserValidatorDashboardCount(ctx context.Context, userId uint64) (uint64, error)
GetUserValidatorDashboardCount(ctx context.Context, userId uint64, active bool) (uint64, error)
}

func (d *DataAccessService) GetUserByEmail(ctx context.Context, email string) (uint64, error) {
Expand Down Expand Up @@ -539,6 +539,7 @@ func (d *DataAccessService) GetFreeTierPerks(ctx context.Context) (*t.PremiumPer
}

func (d *DataAccessService) GetUserDashboards(ctx context.Context, userId uint64) (*t.UserDashboardsData, error) {
// TODO @DATA-ACCESS Adjust to api changes: return archival related fields
result := &t.UserDashboardsData{}

dbReturn := []struct {
Expand Down Expand Up @@ -603,7 +604,9 @@ func (d *DataAccessService) GetUserDashboards(ctx context.Context, userId uint64
return result, nil
}

func (d *DataAccessService) GetUserValidatorDashboardCount(ctx context.Context, userId uint64) (uint64, error) {
// return number of active / archived dashboards
func (d *DataAccessService) GetUserValidatorDashboardCount(ctx context.Context, userId uint64, active bool) (uint64, error) {
// @DATA-ACCESS return number of dashboards depending on archival status (see comment above)
var count uint64
err := d.alloyReader.GetContext(ctx, &count, `
SELECT COUNT(*) FROM users_val_dashboards
Expand Down
3 changes: 3 additions & 0 deletions backend/pkg/api/data_access/vdb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import (
type ValidatorDashboardRepository interface {
GetValidatorDashboardInfo(ctx context.Context, dashboardId t.VDBIdPrimary) (*t.DashboardInfo, error)
GetValidatorDashboardInfoByPublicId(ctx context.Context, publicDashboardId t.VDBIdPublic) (*t.DashboardInfo, error)
GetValidatorDashboard(ctx context.Context, dashboardId t.VDBId) (*t.ValidatorDashboard, error)
GetValidatorDashboardName(ctx context.Context, dashboardId t.VDBIdPrimary) (string, error)
CreateValidatorDashboard(ctx context.Context, userId uint64, name string, network uint64) (*t.VDBPostReturnData, error)
RemoveValidatorDashboard(ctx context.Context, dashboardId t.VDBIdPrimary) error

UpdateValidatorDashboardArchiving(ctx context.Context, dashboardId t.VDBIdPrimary, archived bool) (*t.VDBPostArchivingReturnData, error)

UpdateValidatorDashboardName(ctx context.Context, dashboardId t.VDBIdPrimary, name string) (*t.VDBPostReturnData, error)

GetValidatorDashboardOverview(ctx context.Context, dashboardId t.VDBId, protocolModes t.VDBProtocolModes) (*t.VDBOverviewData, error)
Expand Down
Loading

0 comments on commit f5606e4

Please sign in to comment.