1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use cw_utils::Expiration;
use dao_voting::{
    status::Status,
    threshold::{PercentageThreshold, Threshold},
    voting::Votes,
};

pub(crate) fn v1_expiration_to_v2(v1: cw_utils_v1::Expiration) -> Expiration {
    match v1 {
        cw_utils_v1::Expiration::AtHeight(height) => Expiration::AtHeight(height),
        cw_utils_v1::Expiration::AtTime(time) => Expiration::AtTime(time),
        cw_utils_v1::Expiration::Never {} => Expiration::Never {},
    }
}

pub(crate) fn v1_percentage_threshold_to_v2(
    v1: voting_v1::PercentageThreshold,
) -> PercentageThreshold {
    match v1 {
        voting_v1::PercentageThreshold::Majority {} => PercentageThreshold::Majority {},
        voting_v1::PercentageThreshold::Percent(p) => PercentageThreshold::Percent(p),
    }
}

pub(crate) fn v1_threshold_to_v2(v1: voting_v1::Threshold) -> Threshold {
    match v1 {
        voting_v1::Threshold::AbsolutePercentage { percentage } => Threshold::AbsolutePercentage {
            percentage: v1_percentage_threshold_to_v2(percentage),
        },
        voting_v1::Threshold::ThresholdQuorum { threshold, quorum } => Threshold::ThresholdQuorum {
            threshold: v1_percentage_threshold_to_v2(threshold),
            quorum: v1_percentage_threshold_to_v2(quorum),
        },
        voting_v1::Threshold::AbsoluteCount { threshold } => Threshold::AbsoluteCount { threshold },
    }
}

pub(crate) fn v1_status_to_v2(v1: voting_v1::Status) -> Status {
    match v1 {
        voting_v1::Status::Open => Status::Open,
        voting_v1::Status::Rejected => Status::Rejected,
        voting_v1::Status::Passed => Status::Passed,
        voting_v1::Status::Executed => Status::Executed,
        voting_v1::Status::Closed => Status::Closed,
    }
}

pub(crate) fn v1_votes_to_v2(v1: voting_v1::Votes) -> Votes {
    Votes {
        yes: v1.yes,
        no: v1.no,
        abstain: v1.abstain,
    }
}