From 1287bc73cad21639d5ed6cf7bfa9a922c593f198 Mon Sep 17 00:00:00 2001 From: DaveVodrazka Date: Fri, 22 Dec 2023 00:29:15 +0100 Subject: [PATCH] feat: get_user_voted --- src/contract.cairo | 11 ++++++++++- src/proposals.cairo | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/contract.cairo b/src/contract.cairo index 71badde6..b7853689 100644 --- a/src/contract.cairo +++ b/src/contract.cairo @@ -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 { @@ -16,6 +16,9 @@ trait IGovernance { ) -> felt252; fn get_proposal_status(self: @TContractState, prop_id: felt252) -> felt252; fn get_live_proposals(self: @TContractState) -> Array; + fn get_user_voted( + self: @TContractState, user_address: ContractAddress, prop_id: felt252 + ) -> VoteStatus; // UPGRADES @@ -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 { diff --git a/src/proposals.cairo b/src/proposals.cairo index 4c17ea1b..d5b6a477 100644 --- a/src/proposals.cairo +++ b/src/proposals.cairo @@ -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; @@ -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();