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

Commit

Permalink
Impl x/registry/keeper/msg_server_update_top_level_domain_registratio…
Browse files Browse the repository at this point in the history
…n_policy.go
  • Loading branch information
foxytanuki committed Dec 22, 2023
1 parent 44659be commit d0715ba
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
10 changes: 10 additions & 0 deletions x/registry/keeper/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,13 @@ func EmitExtendTopLevelDomainExpirationDateEvent(ctx sdk.Context, domain types.T
),
)
}

// Update top-level-domain registration policy
func EmitUpdateTopLevelDomainRegistrationPolicyEvent(ctx sdk.Context, domain types.TopLevelDomain) {
ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeUpdateTopLevelDomainRegistrationPolicy,
sdk.NewAttribute(types.AttributeUpdateTopLevelDomainRegistrationPolicyEventDomainName, domain.Name),
sdk.NewAttribute(types.AttributeUpdateTopLevelDomainRegistrationPolicyEventRegistrationPolicy, domain.RegistrationPolicy.String()),
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
func (k msgServer) UpdateTopLevelDomainRegistrationPolicy(goCtx context.Context, msg *types.MsgUpdateTopLevelDomainRegistrationPolicy) (*types.MsgUpdateTopLevelDomainRegistrationPolicyResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// TODO: Handling the message
_ = ctx
err := k.Keeper.UpdateTopLevelDomainRegistrationPolicy(ctx, msg.Creator, msg.Name, msg.RegistrationPolicy)
if err != nil {
return nil, err
}

return &types.MsgUpdateTopLevelDomainRegistrationPolicyResponse{}, nil
}
29 changes: 29 additions & 0 deletions x/registry/keeper/top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,32 @@ func (k Keeper) ExtendTopLevelDomainExpirationDate(ctx sdk.Context, creator stri

return topLevelDomain, fee, err
}

func (k Keeper) UpdateTopLevelDomainRegistrationPolicy(ctx sdk.Context, creator string, domainName string, registrationPolicy string) (err error) {
// Get domain
topLevelDomain, found := k.GetTopLevelDomain(ctx, domainName)
if !found {
return errorsmod.Wrapf(types.ErrTopLevelDomainNotFound, "%s", domainName)
}

// Check if the domain is editable
_, err = topLevelDomain.IsEditable(creator)
if err != nil {
return err
}

// Validate registrationPolicy
rp, err := topLevelDomain.ValidateTopLevelDomainRegistrationPolicy(registrationPolicy)
if err != nil {
return err
}

// Update domain store
topLevelDomain.UpdateRegistrationPolicy(rp)
k.SetTopLevelDomain(ctx, topLevelDomain)

// Emit event
EmitUpdateTopLevelDomainRegistrationPolicyEvent(ctx, topLevelDomain)

return nil
}
4 changes: 4 additions & 0 deletions x/registry/types/top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func (topLevelDomain *TopLevelDomain) ExtendExpirationDate(from time.Time, exten
return expirationDate
}

func (topLevelDomain *TopLevelDomain) UpdateRegistrationPolicy(rp RegistrationPolicyType) {
topLevelDomain.RegistrationPolicy = rp
}

func (topLevelDomain TopLevelDomain) IsEditable(sender string) (isEditable bool, err error) {
role := topLevelDomain.GetRole(sender)
if role == DomainRole_NO_ROLE {
Expand Down
9 changes: 9 additions & 0 deletions x/registry/types/validate_top_level_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ func ValidateTopLevelDomainName(name string) (err error) {
return err
}

func (topLevelDomain TopLevelDomain) ValidateTopLevelDomainRegistrationPolicy(rps string) (RegistrationPolicyType, error) {
i, isFound := RegistrationPolicyType_value[rps]
if !isFound {
err := errorsmod.Wrapf(ErrInvalidRegistrationPolicy, "%s", rps)
return RegistrationPolicyType_PRIVATE, err
}
return RegistrationPolicyType(i), nil
}

func (topLevelDomain TopLevelDomain) ValidateName() (err error) {
err = ValidateTopLevelDomainName(topLevelDomain.Name)
return err
Expand Down

0 comments on commit d0715ba

Please sign in to comment.