ore_types/
response.rs

1use chrono::NaiveDateTime;
2use serde::{Deserialize, Serialize};
3use solana_sdk::pubkey::Pubkey;
4
5#[cfg(feature = "redis")]
6use redis_derive::{FromRedisValue, ToRedisArgs};
7
8/// Response for a successful login, containing the JWT.
9#[derive(Serialize, Deserialize, Debug, Clone)]
10pub struct AuthResponse {
11    pub token: String,
12}
13
14/// Response for a successful supply endpoint.
15#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
16pub struct SupplyResponse {
17    pub result: String,
18}
19
20/// Response after successfully sending a chat message.
21#[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// Notifications
40#[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    // Reply fields (optional - null if not a reply)
52    #[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}
59
60#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
61#[cfg_attr(feature = "redis", derive(FromRedisValue, ToRedisArgs))]
62pub struct DeployNotification {
63    pub id: u64,
64    pub authority: String,
65    pub username: Option<String>,
66    pub profile_photo_url: Option<String>,
67    pub total_squares: u64,
68    pub mask: i64,
69    pub amount: u64,
70    pub round_id: u64,
71    pub ts: i64,
72}
73
74#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
75pub struct ResetNotification {
76    pub block_id: u64,
77}
78
79#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
80pub enum Notification {
81    Chat(ChatNotification),
82    Reset(ResetNotification),
83    Deploy(DeployNotification),
84}
85
86impl Notification {
87    pub fn id(&self) -> String {
88        match self {
89            Notification::Chat(chat) => chat.id.to_string(),
90            Notification::Reset(reset) => reset.block_id.to_string(),
91            Notification::Deploy(deploy) => deploy.id.to_string(),
92        }
93    }
94}
95
96#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
97pub struct DailyRevenue {
98    pub day: String,
99    pub revenue: i64,
100}
101
102// Username validation
103
104#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
105pub struct UsernameValidationResponse {
106    pub valid: bool,
107    pub error: Option<String>,
108}
109
110impl UsernameValidationResponse {
111    pub fn valid() -> Self {
112        Self {
113            valid: true,
114            error: None,
115        }
116    }
117
118    pub fn invalid(error: String) -> Self {
119        Self {
120            valid: false,
121            error: Some(error),
122        }
123    }
124}
125
126/// Response for a successful Discord authentication.
127#[derive(Serialize, Deserialize, Debug, Clone)]
128pub struct DiscordAuthResponse {
129    pub access_token: String,
130}
131
132#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
133pub struct DiscordUser {
134    pub id: String,
135    pub username: String,
136    pub discriminator: String,
137    #[serde(default, skip_serializing_if = "Option::is_none")]
138    pub global_name: Option<String>,
139    #[serde(default, skip_serializing_if = "Option::is_none")]
140    pub avatar: Option<String>,
141    #[serde(default, skip_serializing_if = "Option::is_none")]
142    pub verified: Option<bool>,
143    #[serde(default, skip_serializing_if = "Option::is_none")]
144    pub email: Option<String>,
145}
146
147#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
148pub struct OreBalance {
149    pub wallet: u64,
150    pub staked: u64,
151    pub unrefined: u64,
152    pub refined: u64,
153    pub lifetime_deployed_sol: u64,
154}
155
156#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
157pub struct LeaderboardEntry {
158    pub authority: String,
159    pub amount: u64,
160    pub username: Option<String>,
161    pub profile_picture_url: Option<String>,
162}
163
164/// Response type for reset events with enriched top miner user info.
165/// Maintains field order matching ore_api::event::ResetEvent for backwards compatibility.
166#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
167pub struct ResetEventResponse {
168    pub disc: u8,
169    pub round_id: u64,
170    pub start_slot: u64,
171    pub end_slot: u64,
172    pub winning_square: u64,
173    pub top_miner: Pubkey,
174    pub num_winners: u64,
175    pub motherlode: u64,
176    pub total_deployed: u64,
177    pub total_vaulted: u64,
178    pub total_winnings: u64,
179    pub total_minted: u64,
180    pub ts: i64,
181    pub rng: u64,
182    pub deployed_winning_square: u64,
183    pub top_miner_username: Option<String>,
184    pub top_miner_profile_photo: Option<String>,
185}
186
187/// Response type for a user's deploy history event.
188#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
189pub struct DeployHistoryEvent {
190    pub sig: String,
191    pub authority: String,
192    pub signer: String,
193    pub amount: u64,
194    pub mask: i64,
195    pub round_id: i64,
196    pub total_squares: i64,
197    pub ts: i64,
198    pub winning_square: i64,
199    pub top_miner: String,
200    pub rewards_sol: u64,
201    pub rewards_ore: u64,
202    pub total_winnings_sol: u64,
203    pub deployed_winning_square: u64,
204    pub motherlode: u64,
205}