1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use num_bigint::BigUint;
use num_traits::ToPrimitive;
use serde::{Deserialize, Serialize};

use crate::impl_from_uint_for_enum;

/// Transaction type.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Hash, Copy)]
pub enum TransactionType {
    /// Wallet register.
    WalletRegister = 100,

    /// Deposit.
    Deposit = 200,

    /// Withdrawal.
    Withdrawal = 201,

    /// Transfer.
    Transfer = 300,

    /// Reset main secret.
    ResetMainSecret = 400,

    /// Create API secret.
    CreateApiSecret = 401,

    /// Destroy API secret.
    DestroyApiSecret = 402,

    /// Submit spot order.
    SubmitSpotOrder = 500,

    /// Cancel spot order.
    CancelSpotOrder = 501,

    /// Add spot liquidity.
    AddAmmV2Liquidity = 600,

    /// Remove spot liquidity.
    RemoveAmmV2Liquidity = 601,

    /// Register asset
    RegisterAsset = 700,

    /// Update global withdrawal fee to
    UpdateGlobalWithdrawalFeeTo = 701,

    /// Update asset withdrawal fee to
    UpdateAssetWithdrawalFeeTo = 702,

    /// Update chain confirmation times
    UpdateChainConfirmationTimes = 800,

    /// Register market
    RegisterMarket = 900,

    /// Update market trading settings
    UpdateMarketTradingSettings = 901,

    /// Update market global fee to
    UpdateMarketGlobalFeeTo = 902,

    /// Update market fee to
    UpdateMarketFeeTo = 903,

    /// Update market global fee
    UpdateMarketGlobalFee = 904,

    /// Update market fee
    UpdateMarketFee = 905,
}

impl TransactionType {
    pub fn iterator() -> impl Iterator<Item = TransactionType> {
        [
            TransactionType::WalletRegister,
            TransactionType::Deposit,
            TransactionType::Withdrawal,
            TransactionType::Transfer,
            TransactionType::ResetMainSecret,
            TransactionType::CreateApiSecret,
            TransactionType::DestroyApiSecret,
            TransactionType::SubmitSpotOrder,
            TransactionType::CancelSpotOrder,
            TransactionType::AddAmmV2Liquidity,
            TransactionType::RemoveAmmV2Liquidity,
            TransactionType::RegisterAsset,
            TransactionType::UpdateGlobalWithdrawalFeeTo,
            TransactionType::UpdateAssetWithdrawalFeeTo,
            TransactionType::UpdateChainConfirmationTimes,
            TransactionType::RegisterMarket,
            TransactionType::UpdateMarketTradingSettings,
            TransactionType::UpdateMarketGlobalFeeTo,
            TransactionType::UpdateMarketFeeTo,
            TransactionType::UpdateMarketGlobalFee,
            TransactionType::UpdateMarketFee,
        ]
        .iter()
        .copied()
    }
}

impl From<BigUint> for TransactionType {
    fn from(value: BigUint) -> Self {
        match value.to_u64().unwrap() {
            100 => TransactionType::WalletRegister,
            200 => TransactionType::Deposit,
            201 => TransactionType::Withdrawal,
            300 => TransactionType::Transfer,
            400 => TransactionType::ResetMainSecret,
            401 => TransactionType::CreateApiSecret,
            402 => TransactionType::DestroyApiSecret,
            500 => TransactionType::SubmitSpotOrder,
            501 => TransactionType::CancelSpotOrder,
            600 => TransactionType::AddAmmV2Liquidity,
            601 => TransactionType::RemoveAmmV2Liquidity,
            700 => TransactionType::RegisterAsset,
            701 => TransactionType::UpdateGlobalWithdrawalFeeTo,
            702 => TransactionType::UpdateAssetWithdrawalFeeTo,
            800 => TransactionType::UpdateChainConfirmationTimes,
            900 => TransactionType::RegisterMarket,
            901 => TransactionType::UpdateMarketTradingSettings,
            902 => TransactionType::UpdateMarketGlobalFeeTo,
            903 => TransactionType::UpdateMarketFeeTo,
            904 => TransactionType::UpdateMarketGlobalFee,
            905 => TransactionType::UpdateMarketFee,
            _ => panic!("Invalid transaction type"),
        }
    }
}

impl Into<BigUint> for TransactionType {
    fn into(self) -> BigUint {
        BigUint::from(self as u128)
    }
}

impl_from_uint_for_enum!(TransactionType, u32, u64, u128);