Skip to content
This repository was archived by the owner on Apr 10, 2026. It is now read-only.

Implement new DeleteName Message Type#92

Merged
hschoenburg merged 29 commits intomasterfrom
aayushijain23/add-new-msg-type-delete
Aug 2, 2019
Merged

Implement new DeleteName Message Type#92
hschoenburg merged 29 commits intomasterfrom
aayushijain23/add-new-msg-type-delete

Conversation

@aayushijain23
Copy link
Copy Markdown
Contributor

Added a new message called DeleteName to this tutorial. The following changes have been made:

  1. Added a new message type for DeleteName
  2. Updated the keeper with a new method for deleting the Whois struct for a particular name.
  3. Updated the Handler with what actions to be taken for a DeleteName message.
  4. Registered the DeleteName interface in Codec.
  5. Added a cli command for the DeleteName transaction and added corresponding changes in the module client.
  6. Finally added a REST endpoint for the same.

- 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.
@alexanderbez alexanderbez changed the base branch from hans/generalization-refactor to master June 4, 2019 17:49
aayushijain23 and others added 7 commits June 6, 2019 16:13
- 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.
@alexanderbez alexanderbez changed the title Added a new message type - DeleteName Implement new DeleteName Message Type Jun 18, 2019
@aayushijain23 aayushijain23 marked this pull request as ready for review June 18, 2019 22:52
Copy link
Copy Markdown
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aayushijain23 -- your first contribution 🎉

Left some general feedback, but overall looks good!

Comment thread tutorial/cli.md Outdated
Comment thread tutorial/cli.md Outdated
Comment thread tutorial/cli.md Outdated
Comment thread tutorial/cli.md Outdated
return err
}

cliCtx.PrintResponse = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

Copy link
Copy Markdown
Contributor Author

@aayushijain23 aayushijain23 Jun 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this prints the response in the cli, when we test the code via cli commands. Will remove it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be removed.

Comment thread x/nameservice/client/rest/rest.go Outdated
Comment thread x/nameservice/handler.go Outdated
Comment thread x/nameservice/handler.go Outdated
Comment thread x/nameservice/handler.go Outdated
Comment thread x/nameservice/handler.go Outdated
Comment thread x/nameservice/keeper.go
}

// Deletes the entire Whois metadata struct for a name
func (k Keeper) DeleteWhois(ctx sdk.Context, name string) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

aayushijain23 and others added 9 commits June 19, 2019 13:56
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.
Copy link
Copy Markdown
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, just a few nitpicks on comments

Comment thread tutorial/delete-name.md Outdated
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant imho

Comment thread tutorial/delete-name.md Outdated
}
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread tutorial/delete-name.md Outdated
if !msg.Owner.Equals(keeper.GetOwner(ctx, msg.Name)) {
return sdk.ErrUnauthorized("Incorrect Owner").Result()
}
// If so, delete the name specified in the msg.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread x/nameservice/handler.go Outdated
// 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment thread x/nameservice/handler.go Outdated
if !keeper.IsNamePresent(ctx, msg.Name) {
return types.ErrNameDoesNotExist(types.DefaultCodespace).Result()
}
// Checks if the msg sender is the same as the current owner
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, will remove the unnecessary comments.

Comment thread tutorial/cli.md Outdated
return err
}

cliCtx.PrintResponse = true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be removed.

Comment thread tutorial/delete-name.md Outdated
```go
// MsgDeleteName defines a DeleteName message
type MsgDeleteName struct {
Name string `json:"name"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting is off.

Copy link
Copy Markdown
Contributor Author

@aayushijain23 aayushijain23 Jun 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a side note, found the preview option in vscode.

…ew-msg-type-delete

Resolved merge conflicts in tutorial/cli.md
@hschoenburg hschoenburg merged commit d9927fe into master Aug 2, 2019
@tac0turtle tac0turtle deleted the aayushijain23/add-new-msg-type-delete branch May 25, 2020 13:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants