Skip to content

Conversation

nicholas-source
Copy link
Owner

Description:

This pull request introduces the foundational vote functionality for the EchoVote decentralized voting system. It includes routes and service methods for casting votes, fetching votes, counting votes, and enhancing the overall robustness of the application with logging and error-handling mechanisms.

Summary of Changes:

  1. Vote Routes and Services:

    • Implemented POST Route for Casting Votes:
      • Added a route to cast a vote for a specific proposal, requiring proposalId and voteOption in the request body.
    • GET Route for Fetching Voter's Vote:
      • Created a route to retrieve a specific voter's vote on a given proposal.
    • Additional Vote Count Routes:
      • Implemented routes to get the vote count by option and the total votes for a proposal.
    • These routes integrate seamlessly with the Stacks smart contract functions via the service layer.
    • Commit: feat(votes): add vote routes and service methods for casting, fetching, and counting votes.
  2. Request Logging Middleware:

    • Added Request Logger:
      • Introduced middleware to log incoming HTTP requests, including method, URL, and timestamp.
      • Enhances visibility into API traffic and aids in debugging and monitoring system activity.
    • Commit: feat(logging): add request logger middleware to log incoming requests.
  3. Global Error Handling Middleware:

    • Implemented Global Error Handler:
      • Added middleware to catch and handle errors globally across the Express application.
      • In production, stack traces are hidden to prevent leakage of sensitive information, while development mode provides full details for easier debugging.
    • Commit: feat(error-handling): add global error handler middleware.
  4. Proposal Routes Placeholder:

    • Added Placeholder Routes for Proposals:
      • Included basic structure for proposal-related functionality to be implemented in future iterations.
      • This allows the proposal framework to be established while focusing on vote functionality.
    • Commit: feat(proposals): integrate proposal routes placeholder.
  5. Network Configuration Refactor:

    • Extracted Network Logic into Utility Function:
      • Refactored logic determining the network (mainnet/testnet) into a reusable utility function.
      • This reduces duplication and ensures consistency across the codebase.
    • Commit: refactor(network): extract network configuration logic into utility function.
  6. Input Validation and Sanitization:

    • Added Input Validation:
      • Introduced express-validator for validating and sanitizing input in vote routes.
      • Ensures proposal IDs and vote options are valid integers and that voter addresses are well-formed, strengthening security.
    • Commit: security(validation): add input validation and sanitization to vote routes.
  7. Enhanced Error Handling Security:

    • Prevented Stack Trace Exposure:
      • Modified the global error handler to only expose error messages in production, while stack traces are available in development mode.
      • Protects against potential security vulnerabilities by avoiding stack trace exposure in production environments.
    • Commit: security(error-handling): prevent stack trace exposure in production mode.
  8. Removal of Placeholder Proposal Route:

    • Reverted Placeholder Proposal Route:
      • Removed the previously added placeholder proposal route until it is fully implemented to avoid confusion in the codebase.
      • This route will be reintroduced once full proposal functionality is developed.
    • Commit: revert(proposals): remove placeholder proposal route until fully implemented.

Next Steps:

  • Continue developing the proposal functionalities to reintroduce and integrate them with the voting system.
  • Enhance testing coverage to ensure reliability and security.

Reviewers:

  • @Senior_Developer
  • @Smart_Contract Specialist with Clarity
  • @QA_Engineer
  • @Team_Lead

- 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.
- Added express import
- Added proposalService import
- Initialized express router
- Added POST route for creating proposals
- Handles request body and calls createProposal service
- Returns 201 status on success
- Returns 500 status on error
- Added createProposal function in proposalService
- Added GET route for fetching proposals by ID
- Handles request params and calls getProposal service
- Returns proposal data on success
- Returns 404 status if proposal not found
- Returns 500 status on error
- Added getProposal function in proposalService
- Improved variable naming
- Added comments for better understanding
- Structured code for better readability
- Fixed bug in proposal ID parsing
- Fixed bug in error handling
- Added validation for request body
- Ensured only authorized users can create proposals
- Reverted previous commit due to identified issues
…g, and counting votes

- Implemented POST route to cast a vote for a proposal, specifying proposalId and voteOption
- Added GET route to fetch a specific voter's vote on a given proposal
- Implemented additional routes to retrieve vote count by option and total votes for a proposal
- These routes integrate with Stacks smart contract functions via the service layer
- Added requestLogger middleware that logs the HTTP method, URL, and timestamp for each incoming request
- Helps with debugging and monitoring API traffic, providing visibility into system activity
- Added errorHandler middleware to catch and handle errors globally within the Express app
- In production mode, the stack trace is hidden to prevent leakage of sensitive information, while in development mode, full details are provided for easier debugging
- Added placeholder routes for proposal-related functionality, to be implemented in future iterations
- Allows the structure for proposals to be set up while focusing on vote functionality for now
…unction

- Refactored the logic that determines the network (mainnet/testnet) into a reusable utility function
- Reduces duplication and ensures consistency across different parts of the codebase that require network information
…outes

- Introduced input validation using `express-validator` to ensure that proposal IDs and vote options are valid integers and that voter addresses are well-formed
- Helps prevent malicious input and strengthens security by ensuring data integrity
…mode

- Modified the global error handler to only expose error messages in production mode, while stack traces are available in development mode
- Protects against potential security vulnerabilities by avoiding stack trace exposure in production environments
…emented

- Removed placeholder proposal route as it was not yet fully functional and created potential confusion in the codebase
- This will be reintroduced once the full proposal functionality has been developed
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