ore_types/
response.rs

1use chrono::NaiveDateTime;
2use serde::{Deserialize, Serialize};
3
4#[cfg(feature = "redis")]
5use redis_derive::{FromRedisValue, ToRedisArgs};
6
7/// Response for a successful login, containing the JWT.
8#[derive(Serialize, Deserialize, Debug, Clone)]
9pub struct AuthResponse {
10    pub token: String,
11}
12
13/// Response for a successful supply endpoint.
14#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
15pub struct SupplyResponse {
16    pub result: String,
17}
18
19/// Response after successfully sending a chat message.
20#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
21pub struct ChatSendMessageResponse {
22    pub status: String,
23    pub message: String,
24}
25
26#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
27pub struct User {
28    pub authority: String,
29    pub username: String,
30    pub profile_photo_url: Option<String>,
31    pub discord_user: Option<DiscordUser>,
32    pub updated_at: NaiveDateTime,
33    pub risk_score: i64,
34    pub is_banned: bool,
35    pub role: Option<String>,
36}
37
38// Notifications
39#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
40#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
41pub struct ChatNotification {
42    pub authority: String,
43    pub username: String,
44    pub text: String,
45    pub id: u64,
46    pub ts: i64,
47    pub profile_photo_url: Option<String>,
48    pub role: Option<String>,
49    pub discord_user_id: Option<String>,
50    // Reply fields (optional - null if not a reply)
51    #[serde(default, skip_serializing_if = "Option::is_none")]
52    pub reply_to_id: Option<u64>,
53    #[serde(default, skip_serializing_if = "Option::is_none")]
54    pub reply_to_text: Option<String>,
55    #[serde(default, skip_serializing_if = "Option::is_none")]
56    pub reply_to_username: Option<String>,
57}
58
59#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
60#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
61pub struct DeployNotification {
62    pub id: u64,
63    pub authority: String,
64    pub username: Option<String>,
65    pub profile_photo_url: Option<String>,
66    pub total_squares: u64,
67    pub mask: i64,
68    pub amount: u64,
69    pub round_id: u64,
70    pub ts: i64,
71}
72
73#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
74pub struct ResetNotification {
75    pub block_id: u64,
76}
77
78#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
79pub enum Notification {
80    Chat(ChatNotification),
81    Reset(ResetNotification),
82    Deploy(DeployNotification),
83}
84
85impl Notification {
86    pub fn id(&self) -> String {
87        match self {
88            Notification::Chat(chat) => chat.id.to_string(),
89            Notification::Reset(reset) => reset.block_id.to_string(),
90            Notification::Deploy(deploy) => deploy.id.to_string(),
91        }
92    }
93}
94
95#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
96pub struct DailyRevenue {
97    pub day: String,
98    pub revenue: i64,
99}
100
101// Username validation
102
103#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
104pub struct UsernameValidationResponse {
105    pub valid: bool,
106    pub error: Option<String>,
107}
108
109impl UsernameValidationResponse {
110    pub fn valid() -> Self {
111        Self {
112            valid: true,
113            error: None,
114        }
115    }
116
117    pub fn invalid(error: String) -> Self {
118        Self {
119            valid: false,
120            error: Some(error),
121        }
122    }
123}
124
125/// Response for a successful Discord authentication.
126#[derive(Serialize, Deserialize, Debug, Clone)]
127pub struct DiscordAuthResponse {
128    pub access_token: String,
129}
130
131#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
132pub struct DiscordUser {
133    pub id: String,
134    pub username: String,
135    pub discriminator: String,
136    #[serde(default, skip_serializing_if = "Option::is_none")]
137    pub global_name: Option<String>,
138    #[serde(default, skip_serializing_if = "Option::is_none")]
139    pub avatar: Option<String>,
140    #[serde(default, skip_serializing_if = "Option::is_none")]
141    pub verified: Option<bool>,
142    #[serde(default, skip_serializing_if = "Option::is_none")]
143    pub email: Option<String>,
144}
145
146#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
147pub struct OreBalance {
148    pub wallet: u64,
149    pub staked: u64,
150    pub unrefined: u64,
151    pub refined: u64,
152    pub lifetime_deployed_sol: u64,
153}
154
155#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
156pub struct LeaderboardEntry {
157    pub authority: String,
158    pub amount: u64,
159    pub username: Option<String>,
160    pub profile_picture_url: Option<String>,
161}
162
163/// Response type for a user's deploy history event.
164#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
165pub struct DeployHistoryEvent {
166    pub sig: String,
167    pub authority: String,
168    pub signer: String,
169    pub amount: u64,
170    pub mask: i64,
171    pub round_id: i64,
172    pub total_squares: i64,
173    pub ts: i64,
174    pub winning_square: i64,
175    pub top_miner: String,
176    pub rewards_sol: u64,
177    pub rewards_ore: u64,
178    pub total_winnings_sol: u64,
179    pub deployed_winning_square: u64,
180    pub motherlode: u64,
181}