Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add formAdmin struct #4

Merged
merged 6 commits into from
Apr 2, 2024
Merged

add formAdmin struct #4

merged 6 commits into from
Apr 2, 2024

Conversation

MaximeZmt
Copy link
Owner

Thank you for opening a pull request with this project, please also:

  • add a brief description of your changes here
  • assign the PR to yourself, or to the person(s) working on it
  • start in draft mode and in progress pipeline in the project (if applicable)
  • if applicable, add this PR to its related issue by one of the special keywords Closing keywords
  • once it's ready
    • put it in the Review or Ready4Merge pipeline in the project (if applicable)
    • remove draft
    • assign a reviewer

@MaximeZmt MaximeZmt marked this pull request as ready for review March 26, 2024 08:07
@MaximeZmt MaximeZmt requested a review from PascalinDe March 26, 2024 08:08
.gitignore Outdated Show resolved Hide resolved
return nil, xerrors.Errorf("failed to marshal form: %v", err)
}

return buff, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

I take it the idea behind the switch statement is to add other formats at a later point?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I just took the same coding style/convention of the equivalent file for the "classic" form: https://github.com/MaximeZmt/d-voting/blob/main/contracts/evoting/json/forms.go

Should I change it ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if there's only one format the switch logic seems to be a bit superfluous to me, especially as you're not doing it in the Decode function - I'd just do something like this:

func (adminFormFormat) Encode(ctx serde.Context, message serde.Message) ([]byte, error) {
    if message.(type) != types.AdminForm {
        return nil, xerrors.Errorf("Unknown format: %T", message)
    }
    <rest of the function>
}

like this it returns immediately if it's not the correct type (no need for an else which makes it more readable), and the logic is simpler (makes it easier to understand)

switch makes only sense if there's multiple cases

MaximeZmt and others added 3 commits March 27, 2024 09:05
edit .gitignore to add new line at the end as before
@MaximeZmt MaximeZmt requested a review from PascalinDe March 27, 2024 08:18
return buff, nil
default:
adminForm, ok := message.(types.AdminForm)
if !ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if there is no error it is the correct format?

@PascalinDe PascalinDe self-requested a review April 2, 2024 09:37
Copy link
Collaborator

@PascalinDe PascalinDe left a comment

Choose a reason for hiding this comment

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

LGTM

@MaximeZmt MaximeZmt merged commit 84360be into main Apr 2, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants