diff --git a/x/registry/keeper/query_domain_registration_fee.go b/x/registry/keeper/query_domain_registration_fee.go index c31a7f62..c60d6af1 100644 --- a/x/registry/keeper/query_domain_registration_fee.go +++ b/x/registry/keeper/query_domain_registration_fee.go @@ -53,7 +53,11 @@ func (k Keeper) DomainRegistrationFee(goCtx context.Context, req *types.QueryDom // Second level domain domain := types.SecondLevelDomain{Name: req.Name, Parent: req.Parent} - err := k.ValidateSecondLevelDomainIsRegistrable(ctx, domain) + registerer, err := sdk.AccAddressFromBech32(req.Registerer) + if err != nil { + return nil, err + } + err = k.ValidateSecondLevelDomainIsRegistrable(ctx, domain, registerer) if err != nil { return createErrorResponse(err), nil } diff --git a/x/registry/keeper/second_level_domain.go b/x/registry/keeper/second_level_domain.go index de90c338..82ce03f4 100644 --- a/x/registry/keeper/second_level_domain.go +++ b/x/registry/keeper/second_level_domain.go @@ -175,7 +175,7 @@ func (k Keeper) PaySecondLevelDomainRegstrationFee(ctx sdk.Context, payer sdk.Ac } // Validate second-level-domain is registrable -func (k Keeper) ValidateSecondLevelDomainIsRegistrable(ctx sdk.Context, secondLevelDomain types.SecondLevelDomain) error { +func (k Keeper) ValidateSecondLevelDomainIsRegistrable(ctx sdk.Context, secondLevelDomain types.SecondLevelDomain, sldOwner sdk.AccAddress) error { // Validate second-level-domain err := secondLevelDomain.Validate() if err != nil { @@ -193,21 +193,6 @@ func (k Keeper) ValidateSecondLevelDomainIsRegistrable(ctx sdk.Context, secondLe return errorsmod.Wrapf(types.ErrSecondLevelDomainParentDoesNotExist, "%s", secondLevelDomain.Parent) } - // Check if parent domain has subdomain registration config - if parentDomain.SubdomainConfig.MaxSubdomainRegistrations <= parentDomain.SubdomainCount { - return errorsmod.Wrapf(types.ErrTopLevelDomainMaxSubdomainCountReached, "%d", parentDomain.SubdomainCount) - } - - return nil -} - -func (k Keeper) CheckIsRegisteringDomainAllowed(ctx sdk.Context, secondLevelDomain types.SecondLevelDomain, sldOwner sdk.AccAddress) error { - // Get parent domain of second-level-domain - parentDomain, found := k.GetSecondLevelDomainParent(ctx, secondLevelDomain) - if !found { - return errorsmod.Wrapf(types.ErrSecondLevelDomainParentDoesNotExist, "%s", secondLevelDomain.Parent) - } - // Check if the registering domain is allowed or not isPrivate := parentDomain.RegistrationPolicy == types.RegistrationPolicyType_PRIVATE isOwner := parentDomain.GetRole(sldOwner.String()) == types.DomainRole_OWNER @@ -216,19 +201,18 @@ func (k Keeper) CheckIsRegisteringDomainAllowed(ctx sdk.Context, secondLevelDoma return errorsmod.Wrapf(types.ErrNotAllowedRegisterDomain, "%s", parentDomain.Name) } + // Check if parent domain has subdomain registration config + if parentDomain.SubdomainConfig.MaxSubdomainRegistrations <= parentDomain.SubdomainCount { + return errorsmod.Wrapf(types.ErrTopLevelDomainMaxSubdomainCountReached, "%d", parentDomain.SubdomainCount) + } + return nil } // Register second level domain func (k Keeper) RegisterSecondLevelDomain(ctx sdk.Context, secondLevelDomain types.SecondLevelDomain, owner sdk.AccAddress, registrationPeriodIYear uint64) (err error) { // Validate second-level-domain is registrable - err = k.ValidateSecondLevelDomainIsRegistrable(ctx, secondLevelDomain) - if err != nil { - return err - } - - // Check if the registering domain under the parent domain is allowed or not - err = k.CheckIsRegisteringDomainAllowed(ctx, secondLevelDomain, owner) + err = k.ValidateSecondLevelDomainIsRegistrable(ctx, secondLevelDomain, owner) if err != nil { return err }