bitpanda_api/model/
transaction.rs

1use std::str::FromStr;
2
3use crate::ApiError;
4
5/// Transaction status
6#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize)]
7pub enum TransactionStatus {
8    Canceled,
9    Finished,
10    OpenInvitation,
11    Pending,
12    Processing,
13    Unconfirmed,
14    UnconfirmedTransactionOut,
15}
16
17impl ToString for TransactionStatus {
18    fn to_string(&self) -> String {
19        match self {
20            TransactionStatus::Canceled => "canceled",
21            TransactionStatus::Finished => "finished",
22            TransactionStatus::OpenInvitation => "open_invitation",
23            TransactionStatus::Pending => "pending",
24            TransactionStatus::Processing => "processing",
25            TransactionStatus::Unconfirmed => "unconfirmed",
26            TransactionStatus::UnconfirmedTransactionOut => "unconfirmed_transaction_out",
27        }
28        .to_string()
29    }
30}
31
32impl FromStr for TransactionStatus {
33    type Err = ApiError;
34
35    fn from_str(s: &str) -> Result<Self, Self::Err> {
36        match s {
37            "canceled" => Ok(Self::Canceled),
38            "finished" => Ok(Self::Finished),
39            "open_invitation" => Ok(Self::OpenInvitation),
40            "pending" => Ok(Self::Pending),
41            "processing" => Ok(Self::Processing),
42            "unconfirmed" => Ok(Self::Unconfirmed),
43            "unconfirmed_transaction_out" => Ok(Self::UnconfirmedTransactionOut),
44            _ => Err(ApiError::UnexpectedValue(s.to_string())),
45        }
46    }
47}
48
49/// Transaction type
50#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize)]
51pub enum TransactionType {
52    Buy,
53    Deposit,
54    Ico,
55    Refund,
56    Sell,
57    Transfer,
58    Withdrawal,
59}
60
61impl FromStr for TransactionType {
62    type Err = ApiError;
63
64    fn from_str(s: &str) -> Result<Self, Self::Err> {
65        match s {
66            "buy" => Ok(Self::Buy),
67            "deposit" => Ok(Self::Deposit),
68            "ico" => Ok(Self::Ico),
69            "refund" => Ok(Self::Refund),
70            "sell" => Ok(Self::Sell),
71            "transfer" => Ok(Self::Transfer),
72            "withdrawal" => Ok(Self::Withdrawal),
73            _ => Err(ApiError::UnexpectedValue(s.to_string())),
74        }
75    }
76}
77
78impl ToString for TransactionType {
79    fn to_string(&self) -> String {
80        match self {
81            TransactionType::Buy => "buy",
82            TransactionType::Sell => "sell",
83            TransactionType::Deposit => "deposit",
84            TransactionType::Ico => "ico",
85            TransactionType::Refund => "ico",
86            TransactionType::Transfer => "transfer",
87            TransactionType::Withdrawal => "withdrawal",
88        }
89        .to_string()
90    }
91}
92
93/// Transaction "direction"
94#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize)]
95pub enum InOrOut {
96    Incoming,
97    Outgoing,
98}
99
100impl FromStr for InOrOut {
101    type Err = ApiError;
102
103    fn from_str(s: &str) -> Result<Self, Self::Err> {
104        match s {
105            "incoming" => Ok(Self::Incoming),
106            "outgoing" => Ok(Self::Outgoing),
107            _ => Err(ApiError::UnexpectedValue(s.to_string())),
108        }
109    }
110}