Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
amityadav0 committed Aug 21, 2023
1 parent f3a9d7c commit b24620c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions elections/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ impl Proposal {
}

/// returns proposal status
pub fn status(&self) -> ProposalStatus {
let current_time = env::block_timestamp_ms();
if current_time < self.start {
/// now: time in miliseconds
pub fn status(&self, now: u64) -> ProposalStatus {
if now < self.start {
return ProposalStatus::NOT_STARTED;
} else if current_time <= self.end {
} else if now <= self.end {
return ProposalStatus::ONGOING;
} else if current_time <= self.cooldown + self.end {
} else if now <= self.cooldown + self.end {
return ProposalStatus::COOLDOWN;
} else {
return ProposalStatus::ENDED;
Expand Down
5 changes: 3 additions & 2 deletions elections/src/view.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_sdk::{near_bindgen, AccountId};
use near_sdk::{near_bindgen, AccountId, env};
use uint::hex;

use crate::proposal::*;
Expand Down Expand Up @@ -35,6 +35,7 @@ impl Contract {

/// Returns the proposal status
pub fn proposal_status(&self, prop_id: u32) -> Option<ProposalStatus> {
return self.proposals.get(&prop_id).map(|p| p.status())
let now = env::block_timestamp_ms();
return self.proposals.get(&prop_id).map(|p| p.status(now))
}
}

0 comments on commit b24620c

Please sign in to comment.