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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions contracts/evoting/json/adminForm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import (
type adminFormFormat struct{}

func (adminFormFormat) Encode(ctx serde.Context, message serde.Message) ([]byte, error) {
switch m := message.(type) {
case types.AdminForm:
adminFormJSON := AdminFormJSON{
FormID: m.FormID,
AdminList: m.AdminList,
}

buff, err := ctx.Marshal(&adminFormJSON)
if err != nil {
return nil, xerrors.Errorf("failed to marshal form: %v", err)
}

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?

return nil, xerrors.Errorf("Unknown format: %T", message)
}

adminFormJSON := AdminFormJSON{
FormID: adminForm.FormID,
AdminList: adminForm.AdminList,
}

buff, err := ctx.Marshal(&adminFormJSON)
if err != nil {
return nil, xerrors.Errorf("failed to marshal form: %v", err)
}

return buff, nil
}

func (adminFormFormat) Decode(ctx serde.Context, data []byte) (serde.Message, error) {
Expand Down
Loading