2023-06-22 16:20:15 -04:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
2021-07-27 23:49:53 -04:00
|
|
|
/// A mobile confirmation. There are multiple things that can be confirmed, like trade offers.
|
2023-06-22 16:20:15 -04:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
2021-07-27 23:49:53 -04:00
|
|
|
pub struct Confirmation {
|
2023-06-22 16:20:15 -04:00
|
|
|
#[serde(rename = "type")]
|
2021-08-08 12:54:46 -04:00
|
|
|
pub conf_type: ConfirmationType,
|
2023-06-22 16:20:15 -04:00
|
|
|
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<String>,
|
2021-07-28 14:10:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Confirmation {
|
2021-08-08 12:54:46 -04:00
|
|
|
/// Human readable representation of this confirmation.
|
|
|
|
pub fn description(&self) -> String {
|
2023-06-22 16:20:15 -04:00
|
|
|
format!(
|
|
|
|
"{:?} - {} - {}",
|
|
|
|
self.conf_type,
|
|
|
|
self.headline,
|
|
|
|
self.summary.join(", ")
|
|
|
|
)
|
2021-08-08 12:54:46 -04:00
|
|
|
}
|
2021-07-27 23:49:53 -04:00
|
|
|
}
|
|
|
|
|
2023-06-22 16:20:15 -04:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)]
|
|
|
|
#[repr(u32)]
|
|
|
|
#[serde(from = "u32")]
|
2021-07-27 23:49:53 -04:00
|
|
|
pub enum ConfirmationType {
|
2021-08-08 12:54:46 -04:00
|
|
|
Generic = 1,
|
|
|
|
Trade = 2,
|
|
|
|
MarketSell = 3,
|
|
|
|
AccountRecovery = 6,
|
2023-06-22 16:20:15 -04:00
|
|
|
Unknown(u32),
|
2021-07-27 23:49:53 -04:00
|
|
|
}
|
|
|
|
|
2023-06-22 16:20:15 -04:00
|
|
|
impl From<u32> for ConfirmationType {
|
|
|
|
fn from(text: u32) -> Self {
|
2021-08-08 12:54:46 -04:00
|
|
|
match text {
|
2023-06-22 16:20:15 -04:00
|
|
|
1 => ConfirmationType::Generic,
|
|
|
|
2 => ConfirmationType::Trade,
|
|
|
|
3 => ConfirmationType::MarketSell,
|
|
|
|
6 => ConfirmationType::AccountRecovery,
|
|
|
|
v => ConfirmationType::Unknown(v),
|
2021-08-08 12:54:46 -04:00
|
|
|
}
|
|
|
|
}
|
2021-07-27 23:49:53 -04:00
|
|
|
}
|
2023-06-22 16:20:15 -04:00
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct ConfirmationListResponse {
|
|
|
|
pub success: bool,
|
|
|
|
pub conf: Vec<Confirmation>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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::<ConfirmationListResponse>(text)?;
|
|
|
|
|
|
|
|
assert_eq!(confirmations.conf.len(), 1);
|
|
|
|
|
|
|
|
let confirmation = &confirmations.conf[0];
|
|
|
|
|
|
|
|
assert_eq!(confirmation.conf_type, ConfirmationType::AccountRecovery);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|