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

Modularize ballot unmarshall #147

Merged
merged 10 commits into from
Jun 22, 2022
Prev Previous commit
Next Next commit
adds doc
emduc committed Jun 22, 2022
commit 356d46aafc0e7bea47ced43b7803318a09ee7e2e
8 changes: 8 additions & 0 deletions contracts/evoting/types/ballots.go
Original file line number Diff line number Diff line change
@@ -435,6 +435,8 @@ func (s Select) GetChoicesLength() int {
return len(s.Choices)
}

// unmarshalAnswers interprets the given raw answers into a slice of bool with
// the answer for each choice and ensure the answers are correctly formatted
func (s Select) unmarshalAnswers(selections []string) ([]bool, error) {
if len(selections) != len(s.Choices) {
return nil, fmt.Errorf("question %s has a wrong number of answers:"+
@@ -493,6 +495,9 @@ func (r Rank) GetChoicesLength() int {
return len(r.Choices)
}

// unmarshalAnswers interprets the given raw answers into a slice of integer
// representing the ranking of each choice and ensures the answers are correctly
// formatted
func (r Rank) unmarshalAnswers(ranks []string) ([]int8, error) {
if len(ranks) != len(r.Choices) {
return nil, fmt.Errorf("question %s has a wrong number of answers:"+
@@ -558,6 +563,9 @@ func (t Text) GetChoicesLength() int {
return len(t.Choices)
}

// unmarshalAnswers interprets the given raw answers into a slice with the
// decoded answer corresponding to each choice and ensure the answers are
// correctly formatted
func (t Text) unmarshalAnswers(texts []string) ([]string, error) {
if len(texts) != len(t.Choices) {
return nil, fmt.Errorf("question %s has a wrong number of answers:"+