diff --git a/x/registry/keeper/events.go b/x/registry/keeper/events.go index ec6f830f..5bd1414b 100644 --- a/x/registry/keeper/events.go +++ b/x/registry/keeper/events.go @@ -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()), + ), + ) +} diff --git a/x/registry/keeper/msg_server_update_top_level_domain_registration_policy.go b/x/registry/keeper/msg_server_update_top_level_domain_registration_policy.go index 1018a792..86f5fbb5 100644 --- a/x/registry/keeper/msg_server_update_top_level_domain_registration_policy.go +++ b/x/registry/keeper/msg_server_update_top_level_domain_registration_policy.go @@ -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 } diff --git a/x/registry/keeper/top_level_domain.go b/x/registry/keeper/top_level_domain.go index f6af0c94..6308ae52 100644 --- a/x/registry/keeper/top_level_domain.go +++ b/x/registry/keeper/top_level_domain.go @@ -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 +} diff --git a/x/registry/types/top_level_domain.go b/x/registry/types/top_level_domain.go index c63ee194..647f335a 100644 --- a/x/registry/types/top_level_domain.go +++ b/x/registry/types/top_level_domain.go @@ -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 { diff --git a/x/registry/types/validate_top_level_domain.go b/x/registry/types/validate_top_level_domain.go index f9641f2b..69f5c7eb 100644 --- a/x/registry/types/validate_top_level_domain.go +++ b/x/registry/types/validate_top_level_domain.go @@ -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