|
7 | 7 | ElectionDescription, |
8 | 8 | InternalElectionDescription, |
9 | 9 | ) |
| 10 | +from electionguard.scheduler import Scheduler |
10 | 11 | from electionguard.serializable import read_json_object |
11 | 12 | from electionguard.tally import ( |
12 | 13 | publish_ciphertext_tally, |
13 | 14 | publish_plaintext_tally, |
14 | 15 | CiphertextTally, |
15 | 16 | ) |
16 | | -from fastapi import APIRouter, Body, HTTPException |
17 | | - |
| 17 | +from fastapi import APIRouter, Body, Depends, HTTPException |
18 | 18 |
|
| 19 | +from app.core.scheduler import get_scheduler |
19 | 20 | from ..models import ( |
20 | 21 | convert_tally, |
21 | 22 | AppendTallyRequest, |
|
29 | 30 |
|
30 | 31 |
|
31 | 32 | @router.post("", tags=[TALLY]) |
32 | | -def start_tally(request: StartTallyRequest = Body(...)) -> Any: |
| 33 | +def start_tally( |
| 34 | + request: StartTallyRequest = Body(...), |
| 35 | + scheduler: Scheduler = Depends(get_scheduler), |
| 36 | +) -> Any: |
33 | 37 | """ |
34 | 38 | Start a new tally of a collection of ballots |
35 | 39 | """ |
36 | 40 |
|
37 | 41 | ballots, description, context = _parse_tally_request(request) |
38 | 42 | tally = CiphertextTally("election-results", description, context) |
39 | 43 |
|
40 | | - return _tally_ballots(tally, ballots) |
| 44 | + return _tally_ballots(tally, ballots, scheduler) |
41 | 45 |
|
42 | 46 |
|
43 | 47 | @router.post("/append", tags=[TALLY]) |
44 | | -def append_to_tally(request: AppendTallyRequest = Body(...)) -> Any: |
| 48 | +def append_to_tally( |
| 49 | + request: AppendTallyRequest = Body(...), |
| 50 | + scheduler: Scheduler = Depends(get_scheduler), |
| 51 | +) -> Any: |
45 | 52 | """ |
46 | 53 | Append ballots into an existing tally |
47 | 54 | """ |
48 | 55 |
|
49 | 56 | ballots, description, context = _parse_tally_request(request) |
50 | 57 | tally = convert_tally(request.encrypted_tally, description, context) |
51 | 58 |
|
52 | | - return _tally_ballots(tally, ballots) |
| 59 | + return _tally_ballots(tally, ballots, scheduler) |
53 | 60 |
|
54 | 61 |
|
55 | 62 | @router.post("/decrypt", tags=[TALLY]) |
@@ -100,12 +107,14 @@ def _parse_tally_request( |
100 | 107 |
|
101 | 108 |
|
102 | 109 | def _tally_ballots( |
103 | | - tally: CiphertextTally, ballots: List[CiphertextAcceptedBallot] |
| 110 | + tally: CiphertextTally, |
| 111 | + ballots: List[CiphertextAcceptedBallot], |
| 112 | + scheduler: Scheduler, |
104 | 113 | ) -> Any: |
105 | 114 | """ |
106 | 115 | Append a series of ballots to a new or existing tally |
107 | 116 | """ |
108 | | - tally_succeeded = tally.batch_append(ballots) |
| 117 | + tally_succeeded = tally.batch_append(ballots, scheduler) |
109 | 118 |
|
110 | 119 | if tally_succeeded: |
111 | 120 | published_tally = publish_ciphertext_tally(tally) |
|
0 commit comments