Skip to main content

junobuild_cdn/proposals/state/
types.rs

1use candid::{CandidType, Deserialize, Principal};
2use ic_stable_structures::StableBTreeMap;
3use junobuild_shared::types::core::Hash;
4use junobuild_shared::types::memory::Memory;
5use junobuild_shared::types::state::{Timestamp, Version};
6use serde::Serialize;
7
8pub type ProposalsStable = StableBTreeMap<ProposalKey, Proposal, Memory>;
9
10pub type ProposalId = u128;
11
12#[derive(CandidType, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
13pub struct ProposalKey {
14    pub proposal_id: ProposalId,
15}
16
17#[derive(CandidType, Serialize, Deserialize, Clone)]
18pub struct Proposal {
19    pub owner: Principal,
20    pub sha256: Option<Hash>,
21    pub status: ProposalStatus,
22    pub executed_at: Option<Timestamp>,
23    pub created_at: Timestamp,
24    pub updated_at: Timestamp,
25    pub version: Option<Version>,
26    pub proposal_type: ProposalType,
27}
28
29#[derive(CandidType, Serialize, Deserialize, Clone)]
30pub enum ProposalType {
31    AssetsUpgrade(AssetsUpgradeOptions),
32    SegmentsDeployment(SegmentsDeploymentOptions),
33}
34
35#[derive(CandidType, Serialize, Deserialize, Clone)]
36pub struct AssetsUpgradeOptions {
37    pub clear_existing_assets: Option<bool>,
38}
39
40pub type SegmentDeploymentVersion = String;
41
42#[derive(CandidType, Serialize, Deserialize, Clone)]
43pub struct SegmentsDeploymentOptions {
44    pub satellite_version: Option<SegmentDeploymentVersion>,
45    pub mission_control_version: Option<SegmentDeploymentVersion>,
46    pub orbiter: Option<SegmentDeploymentVersion>,
47}
48
49#[derive(CandidType, Serialize, Deserialize, Clone, Debug, PartialEq)]
50pub enum ProposalStatus {
51    Initialized,
52    Open,
53    Rejected,
54    Accepted,
55    Executed,
56    Failed,
57}
58
59#[derive(CandidType, Deserialize, Clone)]
60pub struct ListProposalsParams {
61    pub paginate: Option<ListProposalsPaginate>,
62    pub order: Option<ListProposalsOrder>,
63}
64
65#[derive(Default, CandidType, Deserialize, Clone)]
66pub struct ListProposalsPaginate {
67    pub start_after: Option<ProposalId>,
68    pub limit: Option<u128>,
69}
70
71#[derive(Default, CandidType, Deserialize, Clone)]
72pub struct ListProposalsOrder {
73    pub desc: bool,
74}
75
76#[derive(Default, CandidType, Deserialize, Clone)]
77pub struct ListProposalResults {
78    pub items: Vec<(ProposalKey, Proposal)>,
79    pub items_length: usize,
80    pub matches_length: usize,
81}