types.rs (11184B)
1 use serde::{Deserialize, Serialize}; 2 3 use crate::{ 4 adapters::{config_store::UiConfig, ui_data_store::BlockMetricRow}, 5 domain::{Amount, BurnLeaderRank, OutPoint, Transaction, TxOutput}, 6 }; 7 8 #[derive(Debug, Deserialize)] 9 pub(super) struct AuthForm { 10 pub(super) password: String, 11 } 12 13 #[derive(Debug, Deserialize)] 14 pub(super) struct ChangePasswordForm { 15 pub(super) old_password: String, 16 pub(super) new_password: String, 17 } 18 19 #[derive(Debug, Serialize)] 20 pub(super) struct AuthStatusResponse { 21 pub(super) configured: bool, 22 pub(super) authenticated: bool, 23 } 24 25 #[derive(Debug, Serialize)] 26 pub(super) struct NetworkHealthResponse { 27 pub(super) ok: bool, 28 pub(super) state: String, 29 pub(super) local_height: u64, 30 pub(super) best_known_height: u64, 31 pub(super) shared_height: u64, 32 pub(super) lag_blocks: u64, 33 pub(super) outbound_peers: usize, 34 pub(super) inbound_peers: usize, 35 pub(super) healthy_peers: usize, 36 pub(super) failed_peers: usize, 37 pub(super) stale_peers: usize, 38 pub(super) banned_peers: usize, 39 pub(super) pending_transactions: usize, 40 pub(super) pending_plain_transactions: usize, 41 pub(super) pending_blinded_transactions: usize, 42 pub(super) pending_blinded_reveals: usize, 43 pub(super) network_time_offset_ms: Option<i64>, 44 pub(super) bad_clock_peers: usize, 45 pub(super) last_error: Option<String>, 46 } 47 48 #[derive(Clone, Copy, Debug, Default)] 49 pub(super) struct MempoolCounts { 50 pub(super) plain_transactions: usize, 51 pub(super) blinded_transactions: usize, 52 pub(super) blinded_reveals: usize, 53 } 54 55 impl MempoolCounts { 56 pub(super) fn total(&self) -> usize { 57 self.plain_transactions 58 .saturating_add(self.blinded_transactions) 59 .saturating_add(self.blinded_reveals) 60 } 61 } 62 63 #[derive(Clone, Copy, Debug)] 64 pub(super) struct NetworkHealthLocalState { 65 pub(super) height: u64, 66 pub(super) pending_transactions: usize, 67 } 68 69 #[derive(Debug, Deserialize)] 70 pub(super) struct BurnSettingsForm { 71 pub(super) enabled: Option<bool>, 72 pub(super) amount: Amount, 73 pub(super) fee_per_byte: Option<Amount>, 74 } 75 76 #[derive(Debug, Deserialize)] 77 pub(super) struct RecoveryVdfSettingsForm { 78 pub(super) top_rank_percent: u8, 79 } 80 81 #[derive(Debug, Deserialize)] 82 pub(super) struct PowMiningForm { 83 pub(super) enabled: bool, 84 pub(super) workers: Option<u8>, 85 } 86 87 #[derive(Debug, Deserialize)] 88 pub(super) struct MetricsSettingsForm { 89 pub(super) enabled: bool, 90 } 91 92 #[derive(Debug, Deserialize)] 93 pub(super) struct ChainResetForm { 94 pub(super) confirm: String, 95 } 96 97 #[derive(Debug, Deserialize)] 98 pub(super) struct P2pAnnounceForm { 99 pub(super) addr: String, 100 } 101 102 #[derive(Debug, Deserialize)] 103 pub(super) struct P2pInboundForm { 104 pub(super) enabled: bool, 105 pub(super) bind_port: Option<u16>, 106 } 107 108 #[derive(Debug, Serialize)] 109 pub(super) struct ConfigResponse { 110 #[serde(flatten)] 111 pub(super) config: UiConfig, 112 pub(super) p2p_inbound_runtime_active: bool, 113 pub(super) p2p_runtime_bind_addr: String, 114 } 115 116 #[derive(Debug, Deserialize)] 117 pub(super) struct TransferForm { 118 pub(super) to: String, 119 pub(super) amount: Amount, 120 pub(super) fee_per_byte: Option<Amount>, 121 #[serde(default)] 122 pub(super) utxos: String, 123 } 124 125 #[derive(Debug, Deserialize)] 126 pub(super) struct PeerForm { 127 pub(super) peer: String, 128 } 129 130 #[derive(Debug, Deserialize)] 131 pub(super) struct AddressBookForm { 132 pub(super) address: String, 133 pub(super) name: String, 134 pub(super) old_address: Option<String>, 135 } 136 137 #[derive(Debug, Deserialize)] 138 pub(super) struct AddressBookDeleteForm { 139 pub(super) address: String, 140 } 141 142 #[derive(Debug, Deserialize)] 143 pub(super) struct ConfigForm { 144 pub(super) setup_complete: bool, 145 #[serde(default)] 146 pub(super) peer: String, 147 } 148 149 #[derive(Debug, Deserialize)] 150 pub(super) struct SeedPhraseForm { 151 pub(super) seed_phrase: String, 152 } 153 154 #[derive(Debug, Deserialize)] 155 pub(super) struct BlocksQuery { 156 pub(super) before_height: Option<u64>, 157 pub(super) limit: Option<usize>, 158 } 159 160 #[derive(Debug, Deserialize)] 161 pub(super) struct MetricsQuery { 162 pub(super) limit: Option<usize>, 163 } 164 165 #[derive(Debug, Default, Deserialize)] 166 pub(super) struct PageQuery { 167 pub(super) offset: Option<usize>, 168 pub(super) limit: Option<usize>, 169 } 170 171 #[derive(Debug, Default, Deserialize)] 172 pub(super) struct WalletTransactionsQuery { 173 pub(super) tx: Option<bool>, 174 pub(super) mine: Option<bool>, 175 pub(super) burn: Option<bool>, 176 pub(super) offset: Option<usize>, 177 pub(super) limit: Option<usize>, 178 } 179 180 impl WalletTransactionsQuery { 181 pub(super) fn page(&self) -> PageQuery { 182 PageQuery { 183 offset: self.offset, 184 limit: self.limit, 185 } 186 } 187 } 188 189 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 190 pub(super) struct WalletTransactionFilters { 191 pub(super) transfer: bool, 192 pub(super) mine: bool, 193 pub(super) burn: bool, 194 } 195 196 impl Default for WalletTransactionFilters { 197 fn default() -> Self { 198 Self { 199 transfer: true, 200 mine: false, 201 burn: false, 202 } 203 } 204 } 205 206 impl WalletTransactionFilters { 207 pub(super) fn from_query(query: WalletTransactionsQuery) -> Self { 208 Self { 209 transfer: query.tx.unwrap_or(true), 210 mine: query.mine.unwrap_or(false), 211 burn: query.burn.unwrap_or(false), 212 } 213 } 214 215 pub(super) fn allows(self, transaction: &Transaction) -> bool { 216 match transaction { 217 Transaction::Transfer { .. } => self.transfer, 218 Transaction::Mine { .. } => self.mine, 219 Transaction::Burn { .. } => self.burn, 220 } 221 } 222 } 223 224 #[derive(Debug, Serialize)] 225 pub(super) struct ActionResponse { 226 pub(super) ok: bool, 227 pub(super) error: Option<String>, 228 } 229 230 #[derive(Clone, Debug, Eq, PartialEq, Serialize)] 231 #[serde(rename_all = "camelCase")] 232 pub(super) struct Page<T> { 233 pub(super) items: Vec<T>, 234 pub(super) offset: usize, 235 pub(super) limit: usize, 236 pub(super) total: usize, 237 pub(super) has_more: bool, 238 pub(super) next_offset: Option<usize>, 239 } 240 241 #[derive(Clone, Debug, PartialEq, Serialize)] 242 #[serde(rename_all = "camelCase")] 243 pub(super) struct MetricsResponse { 244 pub(super) enabled: bool, 245 pub(super) latest: Option<BlockMetricRow>, 246 pub(super) charts: Vec<MetricsChart>, 247 } 248 249 #[derive(Clone, Debug, PartialEq, Serialize)] 250 #[serde(rename_all = "camelCase")] 251 pub(super) struct MetricsChart { 252 pub(super) id: &'static str, 253 pub(super) title: &'static str, 254 pub(super) unit: &'static str, 255 pub(super) value_kind: MetricsValueKind, 256 pub(super) points: Vec<MetricsPoint>, 257 } 258 259 #[derive(Clone, Debug, PartialEq, Serialize)] 260 #[serde(rename_all = "camelCase")] 261 pub(super) struct MetricsPoint { 262 pub(super) height: u64, 263 pub(super) value: f64, 264 } 265 266 #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)] 267 #[serde(rename_all = "camelCase")] 268 pub(super) enum MetricsValueKind { 269 Number, 270 Seconds, 271 Iuna, 272 } 273 274 #[derive(Debug, Serialize)] 275 #[serde(rename_all = "camelCase")] 276 pub(super) struct FeeEstimateResponse { 277 pub(super) ok: bool, 278 pub(super) error: Option<String>, 279 pub(super) bytes: Option<usize>, 280 pub(super) fee: Option<Amount>, 281 } 282 283 #[derive(Debug, Serialize)] 284 pub(super) struct WalletSetupResponse { 285 pub(super) ok: bool, 286 pub(super) error: Option<String>, 287 pub(super) address: Option<String>, 288 pub(super) seed_phrase: Option<String>, 289 pub(super) dev_verify_bypass: bool, 290 pub(super) requires_peer: bool, 291 } 292 293 #[derive(Clone, Debug, Eq, PartialEq, Serialize)] 294 #[serde(rename_all = "camelCase")] 295 pub(super) struct WalletTransactionRow { 296 pub(super) kind: &'static str, 297 pub(super) from: String, 298 pub(super) to: Option<String>, 299 pub(super) amount: Amount, 300 pub(super) fee: Amount, 301 pub(super) inputs: Vec<UiTxInput>, 302 pub(super) outputs: Vec<TxOutput>, 303 pub(super) change: Vec<TxOutput>, 304 pub(super) signature: String, 305 pub(super) status: &'static str, 306 pub(super) block_height: Option<u64>, 307 pub(super) timestamp_ms: Option<u64>, 308 pub(super) block_finalizer: Option<String>, 309 pub(super) direction: &'static str, 310 pub(super) blinded: bool, 311 pub(super) difficulty_bits: Option<u32>, 312 pub(super) proof_bits: Option<u32>, 313 pub(super) proof_hash: Option<String>, 314 } 315 316 #[derive(Clone, Debug, Eq, PartialEq, Serialize)] 317 #[serde(rename_all = "camelCase")] 318 pub(super) struct WalletUtxoRow { 319 pub(super) outpoint: OutPoint, 320 pub(super) address: String, 321 pub(super) amount: Amount, 322 pub(super) spendable: bool, 323 } 324 325 #[derive(Clone, Debug)] 326 pub(super) struct WalletTransactionContext { 327 pub(super) status: &'static str, 328 pub(super) block_height: Option<u64>, 329 pub(super) timestamp_ms: Option<u64>, 330 pub(super) block_finalizer: Option<String>, 331 pub(super) blinded: bool, 332 } 333 334 #[derive(Clone, Debug, Eq, PartialEq, Serialize)] 335 pub(super) struct UiBlock { 336 pub(super) height: u64, 337 pub(super) prev_hash: String, 338 pub(super) timestamp_ms: u64, 339 pub(super) miner: String, 340 pub(super) finalizer_mode: crate::domain::FinalizerMode, 341 pub(super) finalizer_rank: u32, 342 pub(super) reward: Amount, 343 pub(super) total_fees: Amount, 344 pub(super) total_bytes: usize, 345 pub(super) transaction_bytes: usize, 346 pub(super) transaction_byte_breakdown: Vec<UiByteBreakdown>, 347 pub(super) blinded_transaction_bytes: usize, 348 pub(super) reveal_bundle_bytes: usize, 349 pub(super) vdf_rounds: u64, 350 pub(super) vdf_output: String, 351 pub(super) leader_proof: Option<crate::domain::LeaderProof>, 352 pub(super) burn_leader_ranks: Vec<BurnLeaderRank>, 353 pub(super) transactions: Vec<UiTransaction>, 354 pub(super) revealed_transactions: Vec<UiTransaction>, 355 pub(super) reveal_bundles: Vec<UiRevealBundle>, 356 pub(super) hash: String, 357 } 358 359 #[derive(Clone, Debug, Eq, PartialEq, Serialize)] 360 pub(super) struct UiByteBreakdown { 361 pub(super) label: &'static str, 362 pub(super) bytes: usize, 363 } 364 365 #[derive(Clone, Debug, Eq, PartialEq, Serialize)] 366 #[serde(rename_all = "camelCase")] 367 pub(super) struct UiRevealBundle { 368 pub(super) slot: u8, 369 pub(super) member: String, 370 pub(super) hash: String, 371 pub(super) byte_size: usize, 372 pub(super) reveals: Vec<UiTransaction>, 373 } 374 375 #[derive(Clone, Debug, Eq, PartialEq, Serialize)] 376 pub(super) struct UiTransaction { 377 pub(super) kind: &'static str, 378 pub(super) from: String, 379 pub(super) to: Option<String>, 380 pub(super) amount: Amount, 381 pub(super) fee: Amount, 382 pub(super) inputs: Vec<UiTxInput>, 383 pub(super) outputs: Vec<TxOutput>, 384 pub(super) change: Vec<TxOutput>, 385 pub(super) signature: String, 386 pub(super) difficulty_bits: Option<u32>, 387 pub(super) proof_bits: Option<u32>, 388 pub(super) proof_hash: Option<String>, 389 pub(super) commitment: Option<String>, 390 pub(super) encrypted_size: Option<u32>, 391 pub(super) expires_at_height: Option<u64>, 392 pub(super) revealed: bool, 393 } 394 395 #[derive(Clone, Debug, Eq, PartialEq, Serialize)] 396 pub(super) struct UiTxInput { 397 pub(super) outpoint: OutPoint, 398 pub(super) owner: String, 399 pub(super) signature: String, 400 pub(super) amount: Option<Amount>, 401 pub(super) address: Option<String>, 402 }