From b59ccf0a3978015109a3b58440898be4a8d9bbb2 Mon Sep 17 00:00:00 2001 From: tarumi Date: Thu, 14 Sep 2023 18:06:24 +0200 Subject: [PATCH] add validation --- .../types/valdiate_second_level_domain.go | 23 ++++++++++++++----- .../keeper/query_query_wallet_record.go | 20 ++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/x/registry/types/valdiate_second_level_domain.go b/x/registry/types/valdiate_second_level_domain.go index 57ff5419..af33bab2 100644 --- a/x/registry/types/valdiate_second_level_domain.go +++ b/x/registry/types/valdiate_second_level_domain.go @@ -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) { diff --git a/x/resolver/keeper/query_query_wallet_record.go b/x/resolver/keeper/query_query_wallet_record.go index e8229c60..3d16e142 100644 --- a/x/resolver/keeper/query_query_wallet_record.go +++ b/x/resolver/keeper/query_query_wallet_record.go @@ -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) { @@ -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 }