electora-vote / electora-app

Decentralized Voting Application - leveraging the power of zk-proofs, conditions based decryption, and decentralized storage
https://app.electora.eu/
8 stars 2 forks source link

Sweep: Add function to return all ballots from the smart contract #72

Closed theref closed 1 year ago

theref commented 1 year ago

Details

The function should return the mapping ballots that is contained in the solidity file contracts/BallotManager.sol. It will be used by ScrollStore in client_code/services/storage.py so it needs to contain the ballot id and all the information contained in the BallotInfo struct.

sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/electora-vote/electora-app/pull/73.

⚡ Sweep Free Trial: I used GPT-4 to create this ticket. You have 1 GPT-4 tickets left. For more GPT-4 tickets, visit our payment portal.To get Sweep to recreate this ticket, leave a comment prefixed with "sweep:" or edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/electora-vote/electora-app/blob/e48fc6033ac73dfa72ff351934b7cdebf74fea31/client_code/services/storage.py#L1-L96 https://github.com/electora-vote/electora-app/blob/e48fc6033ac73dfa72ff351934b7cdebf74fea31/contracts/BallotManager.sol#L1-L49 https://github.com/electora-vote/electora-app/blob/e48fc6033ac73dfa72ff351934b7cdebf74fea31/client_code/forms/routes/ballot/Index/__init__.py#L1-L61 https://github.com/electora-vote/electora-app/blob/e48fc6033ac73dfa72ff351934b7cdebf74fea31/client_code/forms/routes/vote/ChooseCandidate/__init__.py#L1-L35 https://github.com/electora-vote/electora-app/blob/e48fc6033ac73dfa72ff351934b7cdebf74fea31/server_code/api.py#L1-L13

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
contracts/BallotManager.sol Add a new function getAllBallots that iterates over the ballots mapping and returns an array of all ballots. This function should be marked as view.
client_code/services/storage.py Add a new method in the ScrollStore class that calls the new function getAllBallots from the BallotManager contract and returns the result.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Add function to return all ballots from the smart contract sweep/add-return-all-ballots-function

Description

This PR adds a new function to the BallotManager contract that allows retrieving all ballots stored in the contract. It also modifies the ScrollStore class in the storage.py file to call this new function and return the result.

Summary

  • Added a new function getAllBallots to the BallotManager contract that iterates over the ballots mapping and returns an array of all ballots.
  • Modified the ScrollStore class in the storage.py file to call the new getAllBallots function from the BallotManager contract and return the result.

These changes enable the ScrollStore class to retrieve all ballots from the smart contract, providing the necessary functionality for the application.


Step 4: ⌨️ Coding

File Instructions Progress
contracts/BallotManager.sol Add a new function getAllBallots that iterates over the ballots mapping and returns an array of all ballots. This function should be marked as view. ✅ Done with commit e48fc60
client_code/services/storage.py Add a new method in the ScrollStore class that calls the new function getAllBallots from the BallotManager contract and returns the result. ✅ Done with commit 9611862 I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are the my self-reviews of my changes at sweep/add-return-all-ballots-function.

Here is the 1st review

No changes required. The added function getAllBallots() in the BallotManager contract is correctly implemented and does not contain any errors or unimplemented sections. Good job!

I finished incorporating these changes.


To recreate the pull request, leave a comment prefixed with "sweep:" or edit the issue. Join Our Discord