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

Commit

Permalink
Move CheckIsRegisteringDomainAllowed into ValidateSecondLevelDomainIs…
Browse files Browse the repository at this point in the history
…Registrable
  • Loading branch information
foxytanuki committed Dec 26, 2023
1 parent a865369 commit a29ebf2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
6 changes: 5 additions & 1 deletion x/registry/keeper/query_domain_registration_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 7 additions & 23 deletions x/registry/keeper/second_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit a29ebf2

Please sign in to comment.