upbit/response/
transaction_info.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api_deposit::DepositState,
5    constant::{TransactionType, TransferType},
6    request::{Request, RequestWithQuery},
7};
8
9use super::{AccountsInfo, AccountsInfoSource};
10
11/// Deserialized derived TransactionInfoDerived data
12#[derive(Serialize, Deserialize, Debug)]
13pub struct TransactionInfoDerived {
14    pub r#type: TransferType,
15    pub uuid: String,
16    pub currency: String,
17    pub net_type: Option<String>,
18    pub txid: String,
19    pub state: DepositState,
20
21    #[cfg(feature = "chrono")]
22    pub created_at: chrono::NaiveDateTime,
23    #[cfg(not(any(feature = "chrono")))]
24    pub created_at: String,
25
26    #[cfg(feature = "chrono")]
27    pub done_at: Option<chrono::NaiveDateTime>,
28    #[cfg(not(any(feature = "chrono")))]
29    pub done_at: Option<String>,
30
31    pub amount: f64,
32    pub fee: f64,
33    // pub krw_amount: f64,
34    pub transaction_type: TransactionType,
35    pub is_cancelable: bool,
36}
37
38/// Raw derived withdraw info from serialized data
39#[derive(Deserialize)]
40pub struct TransactionInfoDerivedSource {
41    r#type: String,
42    uuid: String,
43    currency: String,
44    net_type: Option<String>,
45    txid: String,
46    state: String,
47    created_at: String,
48    done_at: Option<String>,
49    amount: String,
50    fee: String,
51    // krw_amount: String,
52    transaction_type: String,
53    is_cancelable: String,
54}
55
56impl TransactionInfoDerivedSource {
57    /// Convert [String] type value into [TransactionType]
58    pub fn r#type(&self) -> TransferType {
59        self.r#type.as_str().into()
60    }
61    /// Get uuid
62    pub fn uuid(&self) -> String {
63        self.uuid.clone()
64    }
65    /// Get currency
66    pub fn currency(&self) -> String {
67        self.currency.clone()
68    }
69    /// Get net_type
70    pub fn net_type(&self) -> Option<String> {
71        self.net_type.clone().or(None)
72    }
73    /// Get txid
74    pub fn txid(&self) -> String {
75        self.txid.clone()
76    }
77    /// Convert [String] state value into [DepositState]
78    pub fn state(&self) -> DepositState {
79        self.state.as_str().into()
80    }
81
82    #[cfg(not(any(feature = "chrono")))]
83    /// Convert [String] created_at value into [chrono::NaiveDateTime]
84    pub fn created_at(&self) -> String {
85        self.created_at.clone()
86    }
87
88    #[cfg(feature = "chrono")]
89    pub fn created_at(&self) -> chrono::NaiveDateTime {
90        chrono::DateTime::parse_from_rfc3339(&self.created_at)
91            .map(|dt| dt.naive_local())
92            .unwrap()
93    }
94
95    #[cfg(not(any(feature = "chrono")))]
96    /// Convert [String] done_at value into [chrono::NaiveDateTime]
97    pub fn done_at(&self) -> Option<String> {
98        self.done_at.clone().or(None)
99    }
100
101    #[cfg(feature = "chrono")]
102    pub fn done_at(&self) -> Option<chrono::NaiveDateTime> {
103        chrono::NaiveDateTime::parse_from_str(
104            &self.done_at.clone().or(None)?,
105            "%Y-%m-%dT%H:%M:%S%z",
106        )
107        .ok()
108    }
109
110    /// Convert [String] amount value into [f64]
111    pub fn amount(&self) -> f64 {
112        self.amount.parse().unwrap()
113    }
114    /// Convert [String] fee value into [f64]
115    pub fn fee(&self) -> f64 {
116        self.fee.parse().unwrap()
117    }
118    /// Convert [String] krw_amount value into [f64]
119    // pub fn krw_amount(&self) -> f64 { self.krw_amount.parse().unwrap() }
120    /// Convert [String] transaction_type value into [WithdrawType]
121    pub fn transaction_type(&self) -> TransactionType {
122        self.transaction_type.as_str().into()
123    }
124
125    /// Check if transaction is cancelable
126    /// Returns true if it is cancelable, false otherwise
127    pub fn is_cancelable(&self) -> bool {
128        self.is_cancelable == "true"
129    }
130}
131
132/// Deserialized TransactionInfo data
133#[derive(Debug)]
134pub struct TransactionInfo {
135    pub r#type: TransferType,
136    pub uuid: String,
137    pub currency: String,
138    pub net_type: Option<String>,
139    pub txid: String,
140    pub state: DepositState,
141
142    #[cfg(feature = "chrono")]
143    pub created_at: chrono::NaiveDateTime,
144    #[cfg(not(any(feature = "chrono")))]
145    pub created_at: String,
146
147    #[cfg(feature = "chrono")]
148    pub done_at: Option<chrono::NaiveDateTime>,
149    #[cfg(not(any(feature = "chrono")))]
150    pub done_at: Option<String>,
151
152    pub amount: f64,
153    pub fee: f64,
154    pub transaction_type: TransactionType,
155
156    pub holder: Option<String>,
157    pub bank: Option<String>,
158    pub fiat_amount: Option<String>,
159    pub memo: Option<String>,
160    pub fiat_currency: Option<String>,
161    pub confirmations: Option<String>,
162    pub krw_amount: Option<String>,
163    pub network_name: Option<String>,
164    pub cancelable: Option<String>,
165    pub blockchain_url: Option<String>,
166    pub state_i18n: Option<String>,
167    pub address: Option<String>,
168}
169
170impl RequestWithQuery for TransactionInfo {}
171
172/// Raw withdraw info from serialized data
173#[derive(Deserialize)]
174pub struct TransactionInfoSource {
175    r#type: String,
176    uuid: String,
177    currency: String,
178    net_type: Option<String>,
179    txid: String,
180    state: String,
181    created_at: String,
182    done_at: Option<String>,
183    amount: String,
184    fee: String,
185    transaction_type: String,
186
187    holder: Option<String>,
188    bank: Option<String>,
189    fiat_amount: Option<String>,
190    memo: Option<String>,
191    fiat_currency: Option<String>,
192    confirmations: Option<String>,
193    krw_amount: Option<String>,
194    network_name: Option<String>,
195    cancelable: Option<String>,
196    blockchain_url: Option<String>,
197    state_i18n: Option<String>,
198    address: Option<String>,
199}
200
201impl TransactionInfoSource {
202    /// Convert [String] type value into [TransactionType]
203    pub fn r#type(&self) -> TransferType {
204        self.r#type.as_str().into()
205    }
206    /// Get uuid
207    pub fn uuid(&self) -> String {
208        self.uuid.clone()
209    }
210    /// Get currency
211    pub fn currency(&self) -> String {
212        self.currency.clone()
213    }
214    /// Get net_type
215    pub fn net_type(&self) -> Option<String> {
216        self.net_type.clone().or(None)
217    }
218    /// Get txid
219    pub fn txid(&self) -> String {
220        self.txid.clone()
221    }
222
223    /// Convert [String] state value into [DepositState]
224    pub fn state(&self) -> DepositState {
225        self.state.as_str().into()
226    }
227
228    #[cfg(not(any(feature = "chrono")))]
229    /// Convert [String] created_at value into [chrono::NaiveDateTime]
230    pub fn created_at(&self) -> String {
231        self.created_at.clone()
232    }
233
234    #[cfg(feature = "chrono")]
235    pub fn created_at(&self) -> chrono::NaiveDateTime {
236        chrono::DateTime::parse_from_rfc3339(&self.created_at)
237            .map(|dt| dt.naive_local())
238            .unwrap()
239    }
240
241    #[cfg(not(any(feature = "chrono")))]
242    /// Convert [String] done_at value into [chrono::NaiveDateTime]
243    pub fn done_at(&self) -> Option<String> {
244        self.done_at.clone().or(None)
245    }
246
247    #[cfg(feature = "chrono")]
248    pub fn done_at(&self) -> Option<chrono::NaiveDateTime> {
249        chrono::NaiveDateTime::parse_from_str(
250            &self.done_at.clone().or(None)?,
251            "%Y-%m-%dT%H:%M:%S%z",
252        )
253        .ok()
254    }
255
256    /// Convert [String] amount value into [f64]
257    pub fn amount(&self) -> f64 {
258        self.amount.parse().unwrap()
259    }
260    /// Convert [String] fee value into [f64]
261    pub fn fee(&self) -> f64 {
262        self.fee.parse().unwrap()
263    }
264    /// Convert [String] transaction_type value into [WithdrawType]
265    pub fn transaction_type(&self) -> TransactionType {
266        self.transaction_type.as_str().into()
267    }
268    pub fn holder(&self) -> Option<String> {
269        self.holder.clone()
270    }
271    pub fn bank(&self) -> Option<String> {
272        self.bank.clone()
273    }
274    pub fn fiat_amount(&self) -> Option<String> {
275        self.fiat_amount.clone()
276    }
277    pub fn memo(&self) -> Option<String> {
278        self.memo.clone()
279    }
280    pub fn fiat_currency(&self) -> Option<String> {
281        self.fiat_currency.clone()
282    }
283    pub fn confirmations(&self) -> Option<String> {
284        self.confirmations.clone()
285    }
286    pub fn krw_amount(&self) -> Option<String> {
287        self.krw_amount.clone()
288    }
289    pub fn network_name(&self) -> Option<String> {
290        self.network_name.clone()
291    }
292    pub fn cancelable(&self) -> Option<String> {
293        self.cancelable.clone()
294    }
295    pub fn blockchain_url(&self) -> Option<String> {
296        self.blockchain_url.clone()
297    }
298    pub fn state_i18n(&self) -> Option<String> {
299        self.state_i18n.clone()
300    }
301    pub fn address(&self) -> Option<String> {
302        self.address.clone()
303    }
304}
305
306/// Raw MemberLevel of [WithdrawChanceSource] from serialized data
307#[derive(Deserialize, Debug)]
308pub struct MemberLevel {
309    pub security_level: i32,
310    pub fee_level: i32,
311    pub email_verified: bool,
312    pub identity_auth_verified: bool,
313    pub bank_account_verified: bool,
314    pub two_factor_auth_verified: bool,
315    // pub kakao_pay_auth_verified: bool,
316    pub locked: bool,
317    pub wallet_locked: bool,
318}
319
320/// Deserialized WithdrawCurrency of [WithdrawChance] data
321#[derive(Debug)]
322pub struct WithdrawCurrency {
323    pub code: String,
324    pub withdraw_fee: f64,
325    pub is_coin: bool,
326    pub wallet_state: String,
327    pub wallet_support: Vec<String>,
328}
329
330/// Raw withdraw currency from serialized data
331#[derive(Deserialize)]
332pub struct WithdrawCurrencySource {
333    code: String,
334    withdraw_fee: String,
335    is_coin: bool,
336    wallet_state: String,
337    wallet_support: Vec<String>,
338}
339
340impl WithdrawCurrencySource {
341    pub fn code(&self) -> String {
342        self.code.clone()
343    }
344    pub fn withdraw_fee(&self) -> f64 {
345        self.withdraw_fee.parse().unwrap()
346    }
347    pub fn is_coin(&self) -> bool {
348        self.is_coin
349    }
350    pub fn wallet_state(&self) -> String {
351        self.wallet_state.clone()
352    }
353    pub fn wallet_support(&self) -> Vec<String> {
354        self.wallet_support.clone()
355    }
356}
357
358/// Deserialized WithdrawLimit of [WithdrawChanceSource] data
359#[derive(Debug)]
360pub struct WithdrawLimit {
361    pub currency: String,
362    pub minimum: Option<f64>,
363    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
364    pub onetime: Option<f64>,
365    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
366    pub daily: Option<f64>,
367    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
368    pub remaining_daily: f64,
369    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
370    pub remaining_daily_krw: f64,
371    pub remaining_daily_fiat: f64,
372    pub fixed: Option<i32>,
373    pub can_withdraw: bool,
374}
375
376/// Raw withdraw limit from serialized data
377#[derive(Deserialize)]
378pub struct WithdrawLimitSource {
379    currency: String,
380    minimum: Option<String>,
381    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
382    onetime: Option<String>,
383    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
384    daily: Option<String>,
385    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
386    remaining_daily: String,
387    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
388    remaining_daily_krw: String,
389    remaining_daily_fiat: String,
390    fixed: Option<i32>,
391    can_withdraw: bool,
392}
393
394impl WithdrawLimitSource {
395    pub fn currency(&self) -> String {
396        self.currency.clone()
397    }
398    pub fn minimum(&self) -> Option<f64> {
399        self.minimum.clone().map(|x| x.parse::<f64>().unwrap())
400    }
401    #[allow(deprecated)]
402    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
403    pub fn onetime(&self) -> Option<f64> {
404        self.onetime.clone().map(|x| x.parse::<f64>().unwrap())
405    }
406    #[allow(deprecated)]
407    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
408    pub fn daily(&self) -> Option<f64> {
409        self.daily.as_ref().and_then(|x| x.parse::<f64>().ok())
410    }
411    #[allow(deprecated)]
412    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
413    pub fn remaining_daily(&self) -> f64 {
414        self.remaining_daily.parse().unwrap()
415    }
416    #[allow(deprecated)]
417    #[deprecated(since = "1.7.3", note = "Use remaining_daily_fiat instead")]
418    pub fn remaining_daily_krw(&self) -> f64 {
419        self.remaining_daily_krw.parse().unwrap()
420    }
421    pub fn remaining_daily_fiat(&self) -> f64 {
422        self.remaining_daily_fiat.parse().unwrap()
423    }
424    pub fn fixed(&self) -> Option<i32> {
425        self.fixed
426    }
427    pub fn can_withdraw(&self) -> bool {
428        self.can_withdraw
429    }
430}
431
432/// Deserialized WithdrawChance of [WithdrawChanceSource] data
433#[derive(Debug)]
434pub struct WithdrawChance {
435    pub member_level: MemberLevel,
436    pub currency: WithdrawCurrency,
437    pub account: AccountsInfo,
438    pub withdraw_limit: WithdrawLimit,
439}
440
441/// Raw withdraw chance info from serialized data
442#[derive(Deserialize)]
443pub struct WithdrawChanceSource {
444    pub member_level: MemberLevel,
445    pub currency: WithdrawCurrencySource,
446    pub account: AccountsInfoSource,
447    pub withdraw_limit: WithdrawLimitSource,
448}
449
450/// Raw withdraw chance info from serialized data
451#[derive(Deserialize, Debug)]
452pub struct WithdrawCoinAddress {
453    pub currency: String,
454    pub net_type: String,
455    pub network_name: String,
456    pub withdraw_address: String,
457    pub secondary_address: Option<String>,
458}
459
460impl Request for WithdrawCoinAddress {}
461
462/// Kind of response body of coin address Generator
463#[derive(Deserialize, Debug)]
464#[serde(untagged)]
465pub enum CoinAddressGenResponse {
466    First(CoinAddressGenFirstResponse),
467    Second(CoinAddressGenSecondaryResponse),
468}
469
470/// Response body of coin address generator
471#[derive(Deserialize, Debug)]
472pub struct CoinAddressGen {
473    pub response: CoinAddressGenResponse,
474}
475
476impl RequestWithQuery for CoinAddressGen {}
477
478/// Raw CoinAddressGenFirstResponse from serialized data
479///
480/// Which is first response
481#[derive(Deserialize, Debug)]
482pub struct CoinAddressGenFirstResponse {
483    pub success: bool,
484    pub message: String,
485}
486
487/// Raw CoinAddressGenSecondResponse from serialized data
488#[derive(Deserialize, Debug)]
489pub struct CoinAddressGenSecondaryResponse {
490    pub currency: String,
491    pub net_type: Option<String>,
492    pub deposit_address: String,
493    pub secondary_address: Option<String>,
494}
495
496/// Response body of coin address info
497#[derive(Deserialize, Debug)]
498pub struct CoinAddressResponse {
499    pub currency: String,
500    pub net_type: String,
501    pub deposit_address: Option<String>,
502    pub secondary_address: Option<String>,
503}
504
505impl Request for CoinAddressResponse {}
506impl RequestWithQuery for CoinAddressResponse {}