-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathsubmit_votes_step.py
More file actions
57 lines (48 loc) · 1.9 KB
/
submit_votes_step.py
File metadata and controls
57 lines (48 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from typing import List
from electionguard.data_store import DataStore
from electionguard.ballot_box import BallotBox
from electionguard.election import CiphertextElectionContext
from electionguard.manifest import InternalManifest
from electionguard.utils import get_optional
from electionguard.ballot import (
CiphertextBallot,
)
from ..cli_models import BuildElectionResults, EncryptResults
from ..cli_steps import CliStepBase
from .e2e_inputs import E2eInputs
from print_utils import print_message
class SubmitVotesStep(CliStepBase):
"""Responsible for submitting ballots into a ballot store."""
def submit(
self,
e2e_inputs: E2eInputs,
build_election_results: BuildElectionResults,
e2e_encrypt_results: EncryptResults,
) -> DataStore:
self.print_header("Submitting Ballots")
internal_manifest = build_election_results.internal_manifest
context = build_election_results.context
ballot_store = SubmitVotesStep._cast_and_spoil(
internal_manifest,
context,
e2e_encrypt_results.ciphertext_ballots,
e2e_inputs,
)
return ballot_store
@staticmethod
def _cast_and_spoil(
internal_manifest: InternalManifest,
context: CiphertextElectionContext,
ciphertext_ballots: List[CiphertextBallot],
e2e_inputs: E2eInputs,
) -> DataStore:
ballot_store: DataStore = DataStore()
ballot_box = BallotBox(internal_manifest, context, ballot_store)
for ballot in ciphertext_ballots:
spoil = ballot.object_id == e2e_inputs.spoil_id
if spoil:
submitted_ballot = ballot_box.spoil(ballot)
else:
submitted_ballot = ballot_box.cast(ballot)
print_message(f"Submitted Ballot Id: {ballot.object_id} state: {get_optional(submitted_ballot).state}")
return ballot_store