Skip to content

Commit

Permalink
fix validator set dashboard ids (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuccaBitfly authored Mar 12, 2024
1 parent 8650c71 commit ed121b6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions backend/pkg/api/handlers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
Expand All @@ -16,8 +17,6 @@ import (
"github.com/invopop/jsonschema"
"github.com/xeipuuv/gojsonschema"

b64 "encoding/base64"

dataaccess "github.com/gobitfly/beaconchain/pkg/api/data_access"
"github.com/gobitfly/beaconchain/pkg/api/enums"
types "github.com/gobitfly/beaconchain/pkg/api/types"
Expand All @@ -39,7 +38,7 @@ var (
reNumber = regexp.MustCompile(`^[0-9]+$`)
reValidatorDashboardPublicId = regexp.MustCompile(`^v-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
//reAccountDashboardPublicId = regexp.MustCompile(`^a-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
reValidatorPubkey = regexp.MustCompile(`^[0-9a-fA-F]{96}$`)
reValidatorPubkey = regexp.MustCompile(`^0x[0-9a-fA-F]{96}$`)
reCursor = regexp.MustCompile(`^[0-9a-fA-F]*$`)
)

Expand Down Expand Up @@ -89,12 +88,14 @@ func checkName(handlerErr *error, name string, minLength int) string {

func checkMultipleRegex(handlerErr *error, regexes []*regexp.Regexp, params []string, paramName string) []string {
results := make([]string, len(params))
for i, param := range params {
OUTER:
for _, param := range params {
for _, regex := range regexes {
checkRegex(handlerErr, regex, param, paramName)
if regex.MatchString(param) {
continue OUTER
}
}
// might want to change this later
results[i] = params[i]
joinErr(handlerErr, fmt.Sprintf("given value '%s' for parameter '%s' has incorrect format", param, paramName))
}
return results
}
Expand Down Expand Up @@ -190,7 +191,7 @@ func checkDashboardId(handlerErr *error, id string, acceptValidatorSet bool) int
return nil
}
// given id must be an encoded set of validators
decodedId, err := b64.StdEncoding.DecodeString(id)
decodedId, err := base64.RawURLEncoding.DecodeString(id)
if err != nil {
joinErr(handlerErr, "invalid format for parameter 'dashboard_id'")
return nil
Expand Down

0 comments on commit ed121b6

Please sign in to comment.