1use chrono::NaiveDateTime;
2use serde::{Deserialize, Serialize};
3use solana_sdk::pubkey::Pubkey;
4
5#[cfg(feature = "redis")]
6use redis_derive::{FromRedisValue, ToRedisArgs};
7
8#[derive(Serialize, Deserialize, Debug, Clone)]
10pub struct AuthResponse {
11 pub token: String,
12}
13
14#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
16pub struct SupplyResponse {
17 pub result: String,
18}
19
20#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
22pub struct ChatSendMessageResponse {
23 pub status: String,
24 pub message: String,
25}
26
27#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
28pub struct User {
29 pub authority: String,
30 pub username: String,
31 pub profile_photo_url: Option<String>,
32 pub discord_user: Option<DiscordUser>,
33 pub updated_at: NaiveDateTime,
34 pub risk_score: i64,
35 pub is_banned: bool,
36 pub role: Option<String>,
37}
38
39#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
41#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
42pub struct ChatNotification {
43 pub authority: String,
44 pub username: String,
45 pub text: String,
46 pub id: u64,
47 pub ts: i64,
48 pub profile_photo_url: Option<String>,
49 pub role: Option<String>,
50 pub discord_user_id: Option<String>,
51 #[serde(default, skip_serializing_if = "Option::is_none")]
53 pub reply_to_id: Option<u64>,
54 #[serde(default, skip_serializing_if = "Option::is_none")]
55 pub reply_to_text: Option<String>,
56 #[serde(default, skip_serializing_if = "Option::is_none")]
57 pub reply_to_username: Option<String>,
58 #[serde(default, skip_serializing_if = "Option::is_none")]
60 pub reactions: Option<ChatReactions>,
61}
62
63#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
66#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
67pub struct ChatReactions {
68 #[serde(default, skip_serializing_if = "is_zero")]
69 pub thumbs_up: u32, #[serde(default, skip_serializing_if = "is_zero")]
71 pub heart: u32, #[serde(default, skip_serializing_if = "is_zero")]
73 pub laughing: u32, #[serde(default, skip_serializing_if = "is_zero")]
75 pub surprised: u32, #[serde(default, skip_serializing_if = "is_zero")]
77 pub sad: u32, #[serde(default, skip_serializing_if = "is_zero")]
79 pub fire: u32, }
81
82fn is_zero(n: &u32) -> bool {
83 *n == 0
84}
85
86impl ChatReactions {
87 pub fn is_empty(&self) -> bool {
89 self.thumbs_up == 0
90 && self.heart == 0
91 && self.laughing == 0
92 && self.surprised == 0
93 && self.sad == 0
94 && self.fire == 0
95 }
96
97 pub fn get(&self, emoji: &str) -> u32 {
99 match emoji {
100 "👍" => self.thumbs_up,
101 "❤️" | "❤" => self.heart,
102 "😂" => self.laughing,
103 "😮" => self.surprised,
104 "😢" => self.sad,
105 "🔥" => self.fire,
106 _ => 0,
107 }
108 }
109
110 pub fn set(&mut self, emoji: &str, count: u32) {
112 match emoji {
113 "👍" => self.thumbs_up = count,
114 "❤️" | "❤" => self.heart = count,
115 "😂" => self.laughing = count,
116 "😮" => self.surprised = count,
117 "😢" => self.sad = count,
118 "🔥" => self.fire = count,
119 _ => {}
120 }
121 }
122}
123
124pub const ALLOWED_REACTION_EMOJI: [&str; 6] = ["👍", "❤️", "😂", "😮", "😢", "🔥"];
126
127pub fn is_valid_reaction_emoji(emoji: &str) -> bool {
129 if emoji == "❤" {
131 return true;
132 }
133 ALLOWED_REACTION_EMOJI.contains(&emoji)
134}
135
136#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
137pub struct ResetNotification {
138 pub block_id: u64,
139}
140
141#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
143#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
144pub struct DeployNotification {
145 pub authority: String,
147 pub amount: u64,
149 pub mask: u64,
151 pub round_id: u64,
153 pub signer: String,
155 pub strategy: u64,
157 pub total_squares: u64,
159 pub ts: i64,
161 pub sig: String,
163}
164
165#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
167pub struct ReactionNotification {
168 pub message_id: u64,
169 pub emoji: String,
170 pub count: u32,
171 pub action: String, }
173
174#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
176pub struct TypingUser {
177 pub authority: String,
178 pub username: String,
179}
180
181#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
183pub struct TypingNotification {
184 pub users: Vec<TypingUser>,
185}
186
187#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
188pub enum Notification {
189 Chat(ChatNotification),
190 Reset(ResetNotification),
191 Deploy(DeployNotification),
192 Reaction(ReactionNotification),
193 Typing(TypingNotification),
194}
195
196impl Notification {
197 pub fn id(&self) -> String {
198 match self {
199 Notification::Chat(chat) => chat.id.to_string(),
200 Notification::Reset(reset) => reset.block_id.to_string(),
201 Notification::Deploy(deploy) => deploy.sig.clone(),
202 Notification::Reaction(reaction) => {
203 format!("{}:{}", reaction.message_id, reaction.emoji)
204 }
205 Notification::Typing(_) => "typing".to_string(),
206 }
207 }
208}
209
210#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
212pub struct ChatReactResponse {
213 pub status: String,
214 pub action: String, pub message_id: u64,
216 pub emoji: String,
217 pub count: u32, }
219
220#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
222pub struct ChatTypingResponse {
223 pub status: String,
224}
225
226#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
227pub struct DailyRevenue {
228 pub day: String,
229 pub revenue: i64,
230}
231
232#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
235pub struct UsernameValidationResponse {
236 pub valid: bool,
237 pub error: Option<String>,
238}
239
240impl UsernameValidationResponse {
241 pub fn valid() -> Self {
242 Self {
243 valid: true,
244 error: None,
245 }
246 }
247
248 pub fn invalid(error: String) -> Self {
249 Self {
250 valid: false,
251 error: Some(error),
252 }
253 }
254}
255
256#[derive(Serialize, Deserialize, Debug, Clone)]
258pub struct DiscordAuthResponse {
259 pub access_token: String,
260}
261
262#[derive(Serialize, Deserialize, Debug, Clone)]
264pub struct GoogleUser {
265 pub email: String,
266 pub name: String,
267 pub picture: Option<String>,
268}
269
270#[derive(Serialize, Deserialize, Debug, Clone)]
272pub struct GoogleAuthResponse {
273 pub jwt: String,
274 pub user: GoogleUser,
275}
276
277#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
278pub struct DiscordUser {
279 pub id: String,
280 pub username: String,
281 pub discriminator: String,
282 #[serde(default, skip_serializing_if = "Option::is_none")]
283 pub global_name: Option<String>,
284 #[serde(default, skip_serializing_if = "Option::is_none")]
285 pub avatar: Option<String>,
286 #[serde(default, skip_serializing_if = "Option::is_none")]
287 pub verified: Option<bool>,
288 #[serde(default, skip_serializing_if = "Option::is_none")]
289 pub email: Option<String>,
290}
291
292#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
293pub struct OreBalance {
294 pub wallet: u64,
295 pub staked: u64,
296 pub unrefined: u64,
297 pub refined: u64,
298 pub lifetime_deployed_sol: u64,
299}
300
301#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
302pub struct LeaderboardEntry {
303 pub authority: String,
304 pub amount: u64,
305 pub username: Option<String>,
306 pub profile_picture_url: Option<String>,
307}
308
309#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
312pub struct ResetEventResponse {
313 pub disc: u8,
314 pub round_id: u64,
315 pub start_slot: u64,
316 pub end_slot: u64,
317 pub winning_square: u64,
318 pub top_miner: Pubkey,
319 pub num_winners: u64,
320 pub motherlode: u64,
321 pub total_deployed: u64,
322 pub total_vaulted: u64,
323 pub total_winnings: u64,
324 pub total_minted: u64,
325 pub ts: i64,
326 pub rng: u64,
327 pub deployed_winning_square: u64,
328 pub top_miner_username: Option<String>,
329 pub top_miner_profile_photo: Option<String>,
330}
331
332#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
334pub struct DeployHistoryEvent {
335 pub sig: String,
336 pub authority: String,
337 pub signer: String,
338 pub amount: u64,
339 pub mask: i64,
340 pub round_id: i64,
341 pub total_squares: i64,
342 pub ts: i64,
343 pub winning_square: i64,
344 pub top_miner: String,
345 pub rewards_sol: u64,
346 pub rewards_ore: u64,
347 pub total_winnings_sol: u64,
348 pub deployed_winning_square: u64,
349 pub motherlode: u64,
350}
351
352#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
354pub struct RoundWinner {
355 pub authority: String,
357 pub username: Option<String>,
359 pub profile_photo_url: Option<String>,
361 pub deployed_on_winning: u64,
363 pub combined_mask: u64,
365}
366
367#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
369pub struct RoundWinnersResponse {
370 pub round_id: u64,
372 pub winning_square: u64,
374 pub total_on_winning: u64,
376 pub total_winnings: u64,
378 pub winners: Vec<RoundWinner>,
380}