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

voting-body: use proposal.executed_at instead of approved_at #129

Merged
merged 1 commit into from
Oct 26, 2023
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
5 changes: 4 additions & 1 deletion voting_body/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Contract {
supported: HashSet::new(),
votes: HashMap::new(),
start: now,
approved_at: None,
executed_at: None,
proposal_storage: 0,
};
if active {
Expand Down Expand Up @@ -369,6 +369,7 @@ impl Contract {

prop.refund_bond();
prop.status = ProposalStatus::Executed;
prop.executed_at = Some(env::block_timestamp_ms());
let mut out = PromiseOrValue::Value(ExecResponse::Executed);
match &prop.kind {
PropKind::Dismiss { dao, member } => {
Expand Down Expand Up @@ -505,6 +506,7 @@ impl Contract {
PromiseResult::Failed => {
let mut prop = self.assert_proposal(prop_id);
prop.status = ProposalStatus::Failed;
prop.executed_at = None;
self.proposals.insert(&prop_id, &prop);
emit_executed(prop_id);
}
Expand Down Expand Up @@ -942,6 +944,7 @@ mod unit_tests {
));
p = ctr.get_proposal(id).unwrap();
assert_eq!(p.proposal.status, ProposalStatus::Executed);
assert_eq!(p.proposal.executed_at, Some(ctx.block_timestamp / MSECOND));

//
// check spam transaction
Expand Down
6 changes: 3 additions & 3 deletions voting_body/src/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ pub struct Proposal {
pub votes: HashMap<AccountId, Vote>,
/// start time (for voting period).
pub start: u64,
/// Unix time in miliseconds when the proposal reached approval threshold. `None` if it is not approved.
pub approved_at: Option<u64>,
/// Unix time in miliseconds when the proposal was executed. `None` if it is not approved
/// or execution failed.
pub executed_at: Option<u64>,
/// Proposal storage cost (excluding vote)
pub proposal_storage: u128,
}
Expand Down Expand Up @@ -122,7 +123,6 @@ impl Proposal {

if self.approve > qualified * consent.threshold as u32 / 100 {
self.status = ProposalStatus::Approved;
self.approved_at = Some(env::block_timestamp_ms()); // TODO: update to executed at
} else if self.spam > self.reject
&& total_no >= qualified * (100 - consent.threshold) as u32 / 100
{
Expand Down
Loading