From 6c6b884bbfc66a11e70322e817cb35938974c302 Mon Sep 17 00:00:00 2001 From: Orland0x <37511817+Orland0x@users.noreply.github.com> Date: Wed, 28 Sep 2022 14:20:03 +0100 Subject: [PATCH] removed vote data storage --- contracts/starknet/SpaceAccount.cairo | 8 ++++---- contracts/starknet/lib/voting.cairo | 17 +++++++---------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/contracts/starknet/SpaceAccount.cairo b/contracts/starknet/SpaceAccount.cairo index 92e6ce22..7821597b 100644 --- a/contracts/starknet/SpaceAccount.cairo +++ b/contracts/starknet/SpaceAccount.cairo @@ -212,10 +212,10 @@ func cancel_proposal{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check // @view -func get_vote_info{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr: felt}( - voter_address: Address, proposal_id: felt -) -> (vote: Vote) { - return Voting.get_vote_info(voter_address, proposal_id); +func has_voted{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr: felt}( + proposal_id: felt, voter_address: Address +) -> (voted: felt) { + return Voting.has_voted(proposal_id, voter_address); } @view diff --git a/contracts/starknet/lib/voting.cairo b/contracts/starknet/lib/voting.cairo index f439e63b..85197b96 100644 --- a/contracts/starknet/lib/voting.cairo +++ b/contracts/starknet/lib/voting.cairo @@ -96,7 +96,7 @@ func Voting_executed_proposals_store(proposal_id: felt) -> (executed: felt) { } @storage_var -func Voting_vote_registry_store(proposal_id: felt, voter_address: Address) -> (vote: Vote) { +func Voting_vote_registry_store(proposal_id: felt, voter_address: Address) -> (voted: felt) { } @storage_var @@ -462,9 +462,8 @@ namespace Voting { // Make sure voter has not already voted let (prev_vote) = Voting_vote_registry_store.read(proposal_id, voter_address); - with_attr error_message("User already voted") { - assert prev_vote.choice = 0; + assert prev_vote = 0; } // Make sure `choice` is a valid choice @@ -502,10 +501,10 @@ namespace Voting { Voting_vote_power_store.write(proposal_id, choice, new_voting_power); - let vote = Vote(choice=choice, voting_power=user_voting_power); - Voting_vote_registry_store.write(proposal_id, voter_address, vote); + Voting_vote_registry_store.write(proposal_id, voter_address, 1); // Emit event + let vote = Vote(choice=choice, voting_power=user_voting_power); vote_created.emit(proposal_id, voter_address, vote); return (); @@ -800,14 +799,12 @@ namespace Voting { // View functions // - @view - func get_vote_info{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr: felt}( - voter_address: Address, proposal_id: felt - ) -> (vote: Vote) { + func has_voted{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr: felt}( + proposal_id: felt, voter_address: Address + ) -> (voted: felt) { return Voting_vote_registry_store.read(proposal_id, voter_address); } - @view func get_proposal_info{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr: felt}( proposal_id: felt ) -> (proposal_info: ProposalInfo) {