Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed storage of vote data #355

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions contracts/starknet/SpaceAccount.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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}(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we have has_voted function twice? Couldnt we reuse the same function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One is external, the other is not. This is to follow OZ's pattern :)

Basically the logic is in a lib file with its namespace: and when you want to write external functions it's mostly wrappers around this lib. It's done to avoid namespace / storage clashing ;)

proposal_id: felt, voter_address: Address
) -> (voted: felt) {
return Voting.has_voted(proposal_id, voter_address);
}

@view
Expand Down
17 changes: 7 additions & 10 deletions contracts/starknet/lib/voting.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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) {
Expand Down