You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhance the existing smart-contract to include a new view method that returns detailed voting participation information of all users.
This includes their voting choices (Approve, Reject, Abstain) across all proposals and the number of proposals they have created.
Existing Structure Summary
The current smart-contract includes structures for recording individual votes and proposals. However, it lacks a consolidated view of voting participation by each user.
Implementation Steps
1. Define New Structure CollectedResults
This structure will aggregate voting results for each user.
Fields:
approves: u16 - Total number of approvals.
rejects: u16 - Total number of rejections.
abstains: u16 - Total number of abstentions.
created: u16 - Number of proposals created by the user.
2. Add New Data Storage user_collected_results
Type: UnorderedMap<AccountId, CollectedResults>.
Purpose: Store the aggregated voting results for each user with ability to return the data in a single view method.
3. Develop a Method to Populate user_collected_results from Existing Data
Iterate over existing proposals.
For each proposal, update CollectedResults for each voter and the proposer.
Ensure data consistency and integrity during the aggregation process.
4. Modify Voting Mechanism to Update user_collected_results on Each Vote
When a vote is cast, update the corresponding user's CollectedResults in user_collected_results.
When a new proposal is created, increment the proposals_created count for the proposer in user_collected_results.
5. Create a View Method get_voting_participation
Returns: A list of all users along with their aggregated voting results.
Functionality: Provides a complete list of users along with their voting records and proposal counts.
Considerations
Performance: Ensure that the updates to user_collected_results are efficient, especially for large number of proposals and users.
Data Migration: Consider the need for data migration for existing proposals to populate user_collected_results.
Security: Review and test for potential security vulnerabilities, especially in the data aggregation logic.
Documentation
Update the contract documentation to reflect the new features and changes.
Smart-Contracts to Update
The following deployed smart-contracts will be updated with the new features:
Objective
Enhance the existing smart-contract to include a new view method that returns detailed voting participation information of all users.
This includes their voting choices (Approve, Reject, Abstain) across all proposals and the number of proposals they have created.
Existing Structure Summary
The current smart-contract includes structures for recording individual votes and proposals. However, it lacks a consolidated view of voting participation by each user.
Implementation Steps
1. Define New Structure
CollectedResults
approves: u16
- Total number of approvals.rejects: u16
- Total number of rejections.abstains: u16
- Total number of abstentions.created: u16
- Number of proposals created by the user.2. Add New Data Storage
user_collected_results
UnorderedMap<AccountId, CollectedResults>
.3. Develop a Method to Populate
user_collected_results
from Existing DataCollectedResults
for each voter and the proposer.4. Modify Voting Mechanism to Update
user_collected_results
on Each VoteCollectedResults
inuser_collected_results
.proposals_created
count for the proposer inuser_collected_results
.5. Create a View Method
get_voting_participation
Considerations
user_collected_results
are efficient, especially for large number of proposals and users.user_collected_results
.Documentation
Smart-Contracts to Update
The following deployed smart-contracts will be updated with the new features:
congress-hom-v1.ndc-gwg.near
congress-tc-v1.ndc-gwg.near
congress-coa-v1.ndc-gwg.near
The current project repository is available at NEAR NDC Voting V1.
The text was updated successfully, but these errors were encountered: