Add a command to delete a name
This commit is contained in:
parent
22f6e05de0
commit
75737915ab
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user