Skip to main content

truthlinked_governance/
types.rs

1//! Governance domain types shared across protocol boundaries.
2//!
3//! These records describe proposals, registrations, visibility policy, schema
4//! approvals, and authority transitions that must remain serializable and stable
5//! across node, runtime, and explorer components.
6
7use serde::{Deserialize, Serialize};
8use truthlinked_core::pq_execution::AccountId;
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct PendingNameRegistration {
12    pub name: String,
13    pub cell_id: AccountId,
14    pub owner: AccountId,
15    pub is_cell: bool,
16    pub proposer: Vec<u8>,
17    pub votes: std::collections::HashSet<Vec<u8>>,
18    pub total_stake_voted: u64,
19    pub proposed_at: u64,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct TokenAuthorityProposal {
24    pub token_cell: AccountId,
25    pub proposer: Vec<u8>,
26    pub voters: std::collections::HashSet<Vec<u8>>,
27    pub votes_for_stake: u64,
28    pub created_at: u64,
29    pub voting_ends_at: u64,
30    pub set_mint_authority: bool,
31    pub new_mint_authority: Option<AccountId>,
32    pub set_freeze_authority: bool,
33    pub new_freeze_authority: Option<AccountId>,
34}
35
36impl TokenAuthorityProposal {
37    pub fn voting_open(&self, current_height: u64) -> bool {
38        current_height <= self.voting_ends_at
39    }
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
43pub struct NameRegistration {
44    pub name: String,
45    pub owner: AccountId,
46    pub target: AccountId,
47    pub registered_at: u64,
48    pub expires_at: u64,
49    pub is_cell: bool,
50}
51
52/// URL approval proposal for public cells. Lives in State::url_proposals.
53#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
54#[serde(rename_all = "snake_case")]
55pub enum UrlResponseFormat {
56    Raw,
57    JsonCanonical,
58    PriceUsd,
59}
60
61impl Default for UrlResponseFormat {
62    fn default() -> Self {
63        Self::Raw
64    }
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct UrlProposal {
69    pub url_pattern: String,
70    pub proposer: [u8; 32],
71    pub bond_amount: u128,
72    #[serde(default)]
73    pub voters: std::collections::HashSet<Vec<u8>>,
74    pub votes_for_stake: u64,
75    pub votes_against_stake: u64,
76    pub created_at: u64,
77    pub voting_ends_at: u64,
78    pub approved: bool,
79    pub rejected: bool,
80    pub slashed: bool,
81    #[serde(default)]
82    pub response_format: UrlResponseFormat,
83    #[serde(default)]
84    pub schema_id: Option<[u8; 32]>,
85}
86
87impl UrlProposal {
88    pub fn voting_open(&self, current_height: u64) -> bool {
89        !self.approved && !self.rejected && current_height <= self.voting_ends_at
90    }
91}
92
93/// Cell visibility - controls HTTP request access tier.
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
95pub enum CellVisibility {
96    Private,
97    Public,
98}
99
100#[derive(Debug, Clone, Serialize, Deserialize)]
101pub struct SchemaProposal {
102    pub schema_id: [u8; 32],
103    pub keys: Vec<String>,
104    pub proposer: [u8; 32],
105    pub voters: std::collections::HashSet<Vec<u8>>,
106    pub votes_for_stake: u64,
107    pub votes_against_stake: u64,
108    pub created_at: u64,
109    pub voting_ends_at: u64,
110    pub approved: bool,
111    pub rejected: bool,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct SchemaEntry {
116    pub schema_id: [u8; 32],
117    pub keys: Vec<String>,
118    pub created_at: u64,
119    pub approved: bool,
120}