Skip to content

Commit

Permalink
feat: get_user_voted
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveVodrazka committed Dec 21, 2023
1 parent 0a4cba8 commit 1287bc7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// When Components arrive in Cairo 2.?, it will be refactored to take advantage of them. Random change to rerun CI

use starknet::ContractAddress;
use governance::types::{ContractType, PropDetails};
use governance::types::{ContractType, PropDetails, VoteStatus};

#[starknet::interface]
trait IGovernance<TContractState> {
Expand All @@ -16,6 +16,9 @@ trait IGovernance<TContractState> {
) -> felt252;
fn get_proposal_status(self: @TContractState, prop_id: felt252) -> felt252;
fn get_live_proposals(self: @TContractState) -> Array<felt252>;
fn get_user_voted(
self: @TContractState, user_address: ContractAddress, prop_id: felt252
) -> VoteStatus;

// UPGRADES

Expand Down Expand Up @@ -135,6 +138,12 @@ mod Governance {
Proposals::get_live_proposals()
}

fn get_user_voted(
self: @ContractState, user_address: ContractAddress, prop_id: felt252
) -> VoteStatus {
Proposals::get_user_voted(user_address, prop_id)
}

// UPGRADES

fn get_governance_token_address(self: @ContractState) -> ContractAddress {
Expand Down
6 changes: 6 additions & 0 deletions src/proposals.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ mod Proposals {
use governance::types::BlockNumber;
use governance::types::ContractType;
use governance::types::PropDetails;
use governance::types::VoteStatus;
use governance::traits::IERC20Dispatcher;
use governance::traits::IERC20DispatcherTrait;
use governance::constants;
Expand Down Expand Up @@ -126,6 +127,11 @@ mod Proposals {
arr
}

fn get_user_voted(user_address: ContractAddress, prop_id: felt252) -> VoteStatus {
let state = Governance::unsafe_new_contract_state();
state.proposal_voted_by.read((prop_id, user_address))
}

fn submit_proposal(payload: felt252, to_upgrade: ContractType) -> felt252 {
assert_correct_contract_type(to_upgrade);
let mut state = Governance::unsafe_new_contract_state();
Expand Down

0 comments on commit 1287bc7

Please sign in to comment.