Implement new DeleteName Message Type#92
Conversation
- Added a new message type for DeleteName. - Added a method for deleting the Whois struct for a particular name in the keeper. - Added a corresponding handler for DeleteName messages. - Registered the DeleteName message interface in codec. - Added a cli command for DeleteName transaction and made necessary changes in the module client. - Added a rest endpoint for the same.
…to aayushijain23/add-new-msg-type-delete
…ew-msg-type-delete
…ew-msg-type-delete
- Tested the code by running the cli commands - Updated the documentation for the new message deletename
…ew-msg-type-delete - After Marko's merge, some of the code got refactored. Hence I made changes accordingly in the code for DeleteName. - While testing the code via REST APIs, I also realized that the Delete endpoint need not have the restName. Hence I removed that too.
…ew-msg-type-delete
…ew-msg-type-delete
…s of how to delete a name.
…ew-msg-type-delete
alexanderbez
left a comment
There was a problem hiding this comment.
Thanks @aayushijain23 -- your first contribution 🎉
Left some general feedback, but overall looks good!
| return err | ||
| } | ||
|
|
||
| cliCtx.PrintResponse = true |
There was a problem hiding this comment.
I thought this prints the response in the cli, when we test the code via cli commands. Will remove it.
There was a problem hiding this comment.
This still needs to be removed.
| } | ||
|
|
||
| // Deletes the entire Whois metadata struct for a name | ||
| func (k Keeper) DeleteWhois(ctx sdk.Context, name string) { |
There was a problem hiding this comment.
How is this different that DeleteName? Why not just have a single method DeleteWhois or DeleteName. We should also return an error if the name doesn't exist.
There was a problem hiding this comment.
You're right. There isn't any difference between the two methods. Actually, Getter and Setter methods were defined in the form of SetWhoIs and GetWhoIs. And then additional methods were added for getting specific parameters from the store based on the name, such as: SetOwner(), GetOwner() etc. I thought of maintaining consistency by following the same structure. But yeah in the case of deleting the name, there aren't any additional methods that can be specified. Will keep DeleteWhoIs. And yeah I'll return an error if the name doesn't exist.
Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
The comment for explaining the deletion operation is not needed. Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-Authored-By: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
- Added an errors.go file to handle errors custom to the module.
…ew-msg-type-delete
…ted does not exist in the store.
…ew-msg-type-delete
…ew-msg-type-delete
alexanderbez
left a comment
There was a problem hiding this comment.
ACK, just a few nitpicks on comments
| func handleMsgDeleteName(ctx sdk.Context, keeper Keeper, msg MsgDeleteName) sdk.Result { | ||
| if !msg.Owner.Equals(keeper.GetOwner(ctx, msg.Name)) { // Checks if the the msg sender is the same as the current owner | ||
| return sdk.ErrUnauthorized("Incorrect Owner").Result() // If not, throw an error | ||
| // Checks if the name is present in the store or not |
There was a problem hiding this comment.
This comment is redundant imho
| } | ||
| keeper.DeleteWhois(ctx, msg.Name) // If so, delete the name specified in the msg. | ||
| return sdk.Result{} // return | ||
| // Checks if the the msg sender is the same as the current owner |
| if !msg.Owner.Equals(keeper.GetOwner(ctx, msg.Name)) { | ||
| return sdk.ErrUnauthorized("Incorrect Owner").Result() | ||
| } | ||
| // If so, delete the name specified in the msg. |
| // Handle a message to delete name | ||
| func handleMsgDeleteName(ctx sdk.Context, keeper Keeper, msg MsgDeleteName) sdk.Result { | ||
| // Checks if the the msg sender is the same as the current owner | ||
| // Checks if the name is present in the store or not |
| if !keeper.IsNamePresent(ctx, msg.Name) { | ||
| return types.ErrNameDoesNotExist(types.DefaultCodespace).Result() | ||
| } | ||
| // Checks if the msg sender is the same as the current owner |
There was a problem hiding this comment.
Cool, will remove the unnecessary comments.
| return err | ||
| } | ||
|
|
||
| cliCtx.PrintResponse = true |
There was a problem hiding this comment.
This still needs to be removed.
| ```go | ||
| // MsgDeleteName defines a DeleteName message | ||
| type MsgDeleteName struct { | ||
| Name string `json:"name"` |
There was a problem hiding this comment.
Didn't quite understand this one. I followed the same format as buy-name.md and set-name.md. Everywhere I have noticed that the json names are structured in a column, one after the other. Hence the code looks as follows:
type MsgDeleteName struct {
Name string `json:"name"`
Owner sdk.AccAddress `json:"owner"`
}
Since sdk.AccAddress as a term takes more space than string, the term json:"name" is pushed more towards the right to align with json:"owner"
There was a problem hiding this comment.
The formatting of Go is not correct. See: https://github.com/cosmos/sdk-application-tutorial/blob/88709734312254089c3c1e3ff5935b436fce4cba/tutorial/delete-name.md
The field tags need to be aligned. You can just copy-paste this from the actual gocode.
There was a problem hiding this comment.
Oh I thought you meant the alignment of the field tags in the code is not right. Yeah I couldn't see the preview before pushing the code. I'll copy it from there.
There was a problem hiding this comment.
On a side note, found the preview option in vscode.
…ew-msg-type-delete
…ew-msg-type-delete
…ew-msg-type-delete Resolved merge conflicts in tutorial/cli.md
Added a new message called DeleteName to this tutorial. The following changes have been made: