diff --git a/x/registry/keeper/msg_server.go b/x/registry/keeper/msg_server.go index 018d916c..4152d62f 100644 --- a/x/registry/keeper/msg_server.go +++ b/x/registry/keeper/msg_server.go @@ -21,6 +21,7 @@ func NewMsgServerImpl(keeper Keeper) registrytypes.MsgServer { func (ms msgServer) SetRecord(c context.Context, msg *registrytypes.MsgSetRecord) (*registrytypes.MsgSetRecordResponse, error) { ctx := sdk.UnwrapSDKContext(c) + _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return nil, err @@ -114,6 +115,7 @@ func (ms msgServer) ReserveName(c context.Context, msg *registrytypes.MsgReserve // nolint: all func (ms msgServer) SetAuthorityBond(c context.Context, msg *registrytypes.MsgSetAuthorityBond) (*registrytypes.MsgSetAuthorityBondResponse, error) { ctx := sdk.UnwrapSDKContext(c) + _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return nil, err @@ -140,14 +142,16 @@ func (ms msgServer) SetAuthorityBond(c context.Context, msg *registrytypes.MsgSe func (ms msgServer) DeleteName(c context.Context, msg *registrytypes.MsgDeleteNameAuthority) (*registrytypes.MsgDeleteNameAuthorityResponse, error) { ctx := sdk.UnwrapSDKContext(c) + _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return nil, err } - err = ms.k.ProcessDeleteName(ctx, *msg) + err = ms.k.DeleteName(ctx, *msg) if err != nil { return nil, err } + ctx.EventManager().EmitEvents(sdk.Events{ sdk.NewEvent( registrytypes.EventTypeDeleteName, diff --git a/x/registry/keeper/naming_keeper.go b/x/registry/keeper/naming_keeper.go index 4634a8c6..173a4788 100644 --- a/x/registry/keeper/naming_keeper.go +++ b/x/registry/keeper/naming_keeper.go @@ -329,9 +329,27 @@ func (k Keeper) SetAuthorityBond(ctx sdk.Context, msg registrytypes.MsgSetAuthor return nil } -// ProcessDeleteName removes a CRN -> Record ID mapping. -func (k Keeper) ProcessDeleteName(ctx sdk.Context, msg registrytypes.MsgDeleteNameAuthority) error { - panic("unimplemented") +// DeleteName removes a CRN -> Record ID mapping. +func (k Keeper) DeleteName(ctx sdk.Context, msg registrytypes.MsgDeleteNameAuthority) error { + signerAddress, err := sdk.AccAddressFromBech32(msg.Signer) + if err != nil { + return err + } + err = k.checkCRNAccess(ctx, signerAddress, msg.Crn) + if err != nil { + return err + } + + crnExists, err := k.HasNameRecord(ctx, msg.Crn) + if err != nil { + return err + } + if !crnExists { + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "Name not found.") + } + + // Set CID to empty string. + return k.SaveNameRecord(ctx, msg.Crn, "") } func (k Keeper) GetAuthorityExpiryQueue(ctx sdk.Context) []*registrytypes.ExpiryQueueRecord { diff --git a/x/registry/module/autocli.go b/x/registry/module/autocli.go index c9115569..e08271ec 100644 --- a/x/registry/module/autocli.go +++ b/x/registry/module/autocli.go @@ -111,6 +111,14 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { {ProtoField: "cid"}, }, }, + { + RpcMethod: "DeleteName", + Use: "delete-name [crn]", + Short: "Delete CRN", + PositionalArgs: []*autocliv1.PositionalArgDescriptor{ + {ProtoField: "crn"}, + }, + }, }, EnhanceCustomCommand: true, // Allow additional manual commands },