use serde::Deserialize; /// A mobile confirmation. There are multiple things that can be confirmed, like trade offers. #[derive(Debug, Clone, PartialEq, Eq, Deserialize)] pub struct Confirmation { #[serde(rename = "type")] pub conf_type: ConfirmationType, pub type_name: String, pub id: String, /// Trade offer ID or market transaction ID pub creator_id: String, pub nonce: String, pub creation_time: u64, pub cancel: String, pub accept: String, pub icon: String, pub multi: bool, pub headline: String, pub summary: Vec, } impl Confirmation { /// Human readable representation of this confirmation. pub fn description(&self) -> String { format!( "{:?} - {} - {}", self.conf_type, self.headline, self.summary.join(", ") ) } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] #[repr(u32)] #[serde(from = "u32")] pub enum ConfirmationType { Generic = 1, Trade = 2, MarketSell = 3, AccountRecovery = 6, Unknown(u32), } impl From for ConfirmationType { fn from(text: u32) -> Self { match text { 1 => ConfirmationType::Generic, 2 => ConfirmationType::Trade, 3 => ConfirmationType::MarketSell, 6 => ConfirmationType::AccountRecovery, v => ConfirmationType::Unknown(v), } } } #[derive(Debug, Deserialize)] pub struct ConfirmationListResponse { pub success: bool, pub conf: Vec, } #[derive(Debug, Clone, Copy, Deserialize)] pub struct SendConfirmationResponse { pub success: bool, } #[cfg(test)] mod tests { use super::*; #[test] fn test_parse_email_change() -> anyhow::Result<()> { let text = include_str!("fixtures/confirmations/email-change.json"); let confirmations = serde_json::from_str::(text)?; assert_eq!(confirmations.conf.len(), 1); let confirmation = &confirmations.conf[0]; assert_eq!(confirmation.conf_type, ConfirmationType::AccountRecovery); Ok(()) } }