Skip to content

Commit

Permalink
Merge branch 'main' into NOBIDS/json-int-or-string
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/pkg/api/handlers/internal.go
#	backend/pkg/api/handlers/search_handlers.go
  • Loading branch information
LuccaBitfly committed Jun 7, 2024
2 parents 3854074 + 40d969b commit e8f4954
Show file tree
Hide file tree
Showing 72 changed files with 2,228 additions and 1,034 deletions.
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ __gitignore/
local_deployment/config.yml
local_deployment/elconfig.json
local_deployment/.env
__gitignore
__gitignore
cmd/playground
2 changes: 1 addition & 1 deletion backend/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func main() {
defer dataAccessor.Close()

router := api.NewApiRouter(dataAccessor, cfg)
router.Use(api.GetCorsMiddleware(cfg.CorsAllowedHosts), api.GetAuthMiddleware(cfg.ApiKeySecret))
router.Use(api.GetCorsMiddleware(cfg.CorsAllowedHosts))

srv := &http.Server{
Handler: router,
Expand Down
1 change: 1 addition & 0 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ require (
github.com/sethvargo/go-retry v0.2.4 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/stripe/stripe-go/v72 v72.122.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
Expand Down
3 changes: 3 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stripe/stripe-go/v72 v72.122.0 h1:eRXWqnEwGny6dneQ5BsxGzUCED5n180u8n665JHlut8=
github.com/stripe/stripe-go/v72 v72.122.0/go.mod h1:QwqJQtduHubZht9mek5sds9CtQcKFdsykV9ZepRWwo0=
github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4=
github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI=
Expand Down Expand Up @@ -986,6 +988,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191116160921-f9c825593386/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
Expand Down
2 changes: 1 addition & 1 deletion backend/local_deployment/provision-explorer-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ goose postgres "postgres://postgres:pass@localhost:$ALLOY_PORT/alloy?sslmode=dis
echo "alloy db schema initialization completed"

echo "adding test user"
HASHED_PW=$(htpasswd -nbBC 10 user pass | cut -d ":" -sf 2)
HASHED_PW=$(htpasswd -nbBC 10 user password | cut -d ":" -sf 2)
psql postgres://postgres:pass@localhost:$POSTGRES_PORT/db?sslmode=disable -c "INSERT INTO users(password, email, email_confirmed) \
VALUES ('$HASHED_PW', '[email protected]', true);"
echo "created test user with email '[email protected]' and password 'pass' "
9 changes: 8 additions & 1 deletion backend/pkg/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ func getCsrfProtectionMiddleware(cfg *types.Config) func(http.Handler) http.Hand
if cfg.Frontend.SessionSameSiteNone {
sameSite = csrf.SameSiteNoneMode
}
return csrf.Protect(csrfBytes, csrf.Secure(!cfg.Frontend.CsrfInsecure), csrf.Path("/"), csrf.Domain(cfg.Frontend.SessionCookieDomain), csrf.SameSite(sameSite), csrf.CookieName("_v2_csrf"))

return csrf.Protect(
csrfBytes,
csrf.Secure(!cfg.Frontend.CsrfInsecure),
csrf.Path("/"),
csrf.Domain(cfg.Frontend.SessionCookieDomain),
csrf.SameSite(sameSite),
)
}

func csrfInjecterMiddleware(next http.Handler) http.Handler {
Expand Down
6 changes: 1 addition & 5 deletions backend/pkg/api/data_access/data_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@ type DataAccessor interface {
ValidatorDashboardRepository
SearchRepository
NetworkRepository
UserRepository

Close()

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

GetProductSummary() (*t.ProductSummary, error)
// TODO: move to user repository
GetUser(email string) (*t.User, error)

GetValidatorsFromSlices(indices []uint64, publicKeys []string) ([]t.VDBValidator, error)

GetUserInfo(id uint64) (*t.UserInfo, error)
GetUserDashboards(userId uint64) (*t.UserDashboardsData, error)
}

type DataAccessService struct {
Expand Down
60 changes: 57 additions & 3 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ func (d *DummyService) GetUserInfo(userId uint64) (*t.UserInfo, error) {
return &r, err
}

func (d *DummyService) GetUser(email string) (*t.User, error) {
r := t.User{}
func (d *DummyService) GetUserCredentialInfo(email string) (*t.UserCredentialInfo, error) {
r := t.UserCredentialInfo{}
err := commonFakeData(&r)
return &r, err
}

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

func (d *DummyService) GetProductSummary() (*t.ProductSummary, error) {
r := t.ProductSummary{}
err := commonFakeData(&r)
Expand Down Expand Up @@ -133,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
Expand Down Expand Up @@ -355,3 +385,27 @@ func (d *DummyService) GetSearchValidatorsByGraffiti(ctx context.Context, chainI
err := commonFakeData(&r)
return &r, err
}

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

func (d *DummyService) GetValidatorDashboardGroupCount(dashboardId t.VDBIdPrimary) (uint64, error) {
r := uint64(0)
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetValidatorDashboardValidatorsCount(dashboardId t.VDBIdPrimary) (uint64, error) {
r := uint64(0)
err := commonFakeData(&r)
return r, err
}

func (d *DummyService) GetValidatorDashboardPublicIdCount(dashboardId t.VDBIdPrimary) (uint64, error) {
r := uint64(0)
err := commonFakeData(&r)
return r, err
}
4 changes: 4 additions & 0 deletions backend/pkg/api/data_access/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (d *DataAccessService) GetLatestExchangeRates() ([]t.EthConversionRate, err

availableCurrencies := price.GetAvailableCurrencies()
for _, code := range availableCurrencies {
if code == "ETH" {
// Don't return ETH/ETH info
continue
}
rate := price.GetPrice("ETH", code)
result = append(result, t.EthConversionRate{
Currency: price.GetCurrencyLabel(code),
Expand Down
4 changes: 4 additions & 0 deletions backend/pkg/api/data_access/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ func (d *DataAccessService) GetAllNetworks() ([]types.NetworkInfo, error) {
ChainId: 100,
Name: "gnosis",
},
{
ChainId: 17000,
Name: "holesky",
},
}, nil
}
19 changes: 8 additions & 11 deletions backend/pkg/api/data_access/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit e8f4954

Please sign in to comment.