Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
taryune committed Sep 14, 2023
1 parent 7d49548 commit b59ccf0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
23 changes: 17 additions & 6 deletions x/registry/types/valdiate_second_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,31 @@ const (
NamePattern = `-a-z0-9\p{So}\p{Sk}`
)

func (secondLevelDomain SecondLevelDomain) ValidateName() (err error) {
func ValidateName(name string) (err error) {
regex := regexp.MustCompile(fmt.Sprintf(`(^[%s]+$)`, NamePattern))
if !regex.MatchString(secondLevelDomain.Name) {
err = sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s", secondLevelDomain.Name)), ErrInvalidDomainName.Error())
if !regex.MatchString(name) {
err = sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s", name)), ErrInvalidDomainName.Error())
}
return err
}

func (secondLevelDomain SecondLevelDomain) ValidateParent() (err error) {
func (secondLevelDomain SecondLevelDomain) ValidateName() (err error) {
err = ValidateName(secondLevelDomain.Name)
return err
}

func ValidateParent(parent string) (err error) {
regex := regexp.MustCompile(fmt.Sprintf(`(^[%s]+[%[1]s\.]*[%[1]s]$)|^$`, NamePattern))
if !regex.MatchString(secondLevelDomain.Parent) {
err = sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s", secondLevelDomain.Parent)), ErrInvalidDomainParent.Error())
if !regex.MatchString(parent) {
err = sdkerrors.Wrapf(errors.New(fmt.Sprintf("%s", parent)), ErrInvalidDomainParent.Error())
}
return err

}

func (secondLevelDomain SecondLevelDomain) ValidateParent() (err error) {
err = ValidateParent(secondLevelDomain.Parent)
return err
}

func (secondLevelDomain SecondLevelDomain) Validate() (err error) {
Expand Down
20 changes: 20 additions & 0 deletions x/resolver/keeper/query_query_wallet_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/mycel-domain/mycel/x/resolver/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

registrytypes "github.com/mycel-domain/mycel/x/registry/types"
)

func (k Keeper) QueryWalletRecord(goCtx context.Context, req *types.QueryQueryWalletRecordRequest) (*types.QueryQueryWalletRecordResponse, error) {
Expand All @@ -19,5 +21,23 @@ func (k Keeper) QueryWalletRecord(goCtx context.Context, req *types.QueryQueryWa
// TODO: Process the query
_ = ctx

// Validate request parameters
walletAddressFormat, err := registrytypes.GetWalletAddressFormat(req.NetworkName)
if err != nil {
return nil, err
}
err = registrytypes.ValidateName(req.DomainName)
if err != nil {
return nil, err
}
err = registrytypes.ValidateParent(req.DomainParent)
if err != nil {
return nil, err
}
_ = walletAddressFormat

// TODO: Query domain QueryWalletRecord


return &types.QueryQueryWalletRecordResponse{}, nil
}

0 comments on commit b59ccf0

Please sign in to comment.