use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct UserLock {
#[serde(rename = "type")]
pub lock_type: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub currency: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reason: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiration_timestamp: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub locked: Option<bool>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_user_lock_deserialization() {
let json = r#"{
"type": "withdrawal",
"currency": "BTC",
"reason": "security_review",
"timestamp": 1550058362000,
"locked": true
}"#;
let lock: UserLock = serde_json::from_str(json).expect("Failed to parse");
assert_eq!(lock.lock_type, "withdrawal");
assert_eq!(lock.currency, Some("BTC".to_string()));
assert_eq!(lock.locked, Some(true));
}
#[test]
fn test_user_lock_minimal() {
let json = r#"{
"type": "trading"
}"#;
let lock: UserLock = serde_json::from_str(json).expect("Failed to parse");
assert_eq!(lock.lock_type, "trading");
assert!(lock.currency.is_none());
}
}