Skip to content

Enhance EchoVote Smart Contract with Comments, Configuration, and API Endpoint#1

Open
nicholas-source wants to merge 12 commits intomainfrom
feature/voting-system
Open

Enhance EchoVote Smart Contract with Comments, Configuration, and API Endpoint#1
nicholas-source wants to merge 12 commits intomainfrom
feature/voting-system

Conversation

@nicholas-source
Copy link
Owner

Overview:
This pull request introduces a series of enhancements to the EchoVote decentralized voting system, primarily focusing on improving code clarity, maintainability, and extending functionality. Key changes include the addition of detailed comments, configuration setup, and the implementation of a basic API endpoint.

Changes:

  1. Added Detailed Comments:

    • All functions, constants, data variables, and maps have been supplemented with clear and concise comments to improve code readability and ease of maintenance.
    • Comments aim to clarify the purpose and usage of each component in the contract, ensuring that the logic is easier to follow and understand for future contributors.
  2. Initial Contract Setup:

    • Introduced key constants including contract-owner and various error codes.
    • Added core data variables and maps such as proposal-count, proposals, votes, and vote-counts to support the EchoVote functionality.
  3. Core Functionality Implementation:

    • create-proposal: Allows the contract owner to create new proposals with validation on the proposal’s title, description, and start/end blocks.
    • vote: Enables users to vote on active proposals while ensuring the proposal exists, is active, and the vote option is valid.
    • get-proposal, get-vote, get-vote-count, and get-total-votes: Implemented read-only functions to retrieve proposal details, vote information, and vote statistics.
  4. Validation and Error Handling:

    • Introduced validation for proposal titles, descriptions, and block constraints.
    • Added error handling for common scenarios such as unauthorized actions, already cast votes, and invalid proposals.
  5. Refactoring:

    • Refactored the increment-total-votes and get-total-votes functions to use match expressions for cleaner and more concise logic.
    • Added a new error constant for handling cases where a proposal is not found.
  6. Configuration and API Endpoint:

    • Added a new configuration file index.ts to manage various configuration options for the EchoVote application.
    • Implemented a new API endpoint that returns a simple message to confirm the EchoVote API is operational.

Commit History:

  • e721e3e: Added contract-owner constant and error constants.
  • 75a4255: Added proposal-count data variable and core maps (proposals, votes, vote-counts).
  • 8893839: Implemented create-proposal function with validation and proposal count update.
  • f425c1c: Implemented vote function with necessary validation and vote counting logic.
  • a09ef13: Added read-only functions for retrieving proposal details, vote data, and total votes.
  • 1c1c10c: Implemented validation for proposal title, description, and block constraints.
  • 62a4f1c: Refactored vote counting logic and added error constant for proposal not found.
  • 8cde11d: Added detailed comments to all aspects of the smart contract.
  • index.ts: Added configuration file and new API endpoint to indicate the status of the EchoVote API.

Testing:

  • Ensure that all smart contract functions behave as expected with valid and invalid inputs.
  • Verify that the new API endpoint responds correctly and confirms the API status.

Notes:

  • Future work could include enhancing the validation logic for more complex voting rules, adding additional endpoints, and expanding the API.

This PR represents a significant improvement to the EchoVote smart contract and application, making the code more maintainable while laying the groundwork for future extensions. Please review the changes and provide feedback.

- Added contract-owner constant
- Added error constants
- Added proposal-count data variable
- Added proposals map
- Added votes map
- Added vote-counts map
- Added create-proposal function to create new proposals
- Includes validation for contract owner
- Updates proposal-count
- Added vote function to allow voting on proposals
- Includes validation for proposal existence, active status, and vote option range
- Updates votes and vote-counts maps
- Added get-proposal function to retrieve proposal details
- Added get-vote function to retrieve a specific vote
- Added get-vote-count function to retrieve vote count for an option
- Added get-total-votes function to retrieve total votes for a proposal
Refactor increment-total-votes function to use match expression
Refactor get-total-votes function to use match expression
This commit adds a new configuration file, `index.ts`, which exports an object containing various configuration options for the application. It also adds a new API endpoint in the `index.ts` file, which responds with a simple message to indicate that the EchoVote API is running.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant