ex3_node_types/transaction/
types.rs

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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
use num_bigint::BigUint;
use num_traits::ToPrimitive;
use serde::{Deserialize, Serialize};

use crate::impl_from_uint_for;

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

    /// Deposit.
    Deposit = 200,

    /// Withdrawal.
    Withdrawal = 201,

    /// Force withdrawal.
    ForceWithdrawal = 202,

    /// Withdrawal.
    WithdrawalV2 = 203,

    /// 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 spot market
    RegisterSpotMarket = 900,

    /// Update spot market trading settings
    UpdateSpotMarketTradingSettings = 901,

    /// Update spot market initial fee to
    UpdateSpotMarketInitialFeeTo = 902,

    /// Update spot market fee to
    UpdateSpotMarketFeeTo = 903,

    /// Update spot market initial trading fee
    UpdateSpotMarketInitialTradingFee = 904,

    /// Update spot market trading fee
    UpdateSpotMarketTradingFee = 905,

    /// Claim spot market trading fee
    ClaimSpotMarketTradingFee = 906,

    /// Update spot market royalty
    UpdateSpotMarketRoyalty = 907,

    /// Claim spot market royalty
    ClaimSpotMarketRoyalty = 908,

    /// Asset account binding
    AssetAccountBinding = 1000,

    /// Asset account unbinding
    AssetAccountUnbinding = 1001,

    /// Submit meme order.
    SubmitMemeOrder,

    /// Cancel meme order.
    CancelMemeOrder = 1101,

    /// Register meme market
    RegisterMemeMarket = 1200,

    /// Update meme market initial trading settings
    UpdateMemeMarketInitialTradingSettings = 1201,

    /// Update meme market trading settings
    UpdateMemeMarketTradingSettings = 1202,

    /// Update meme market initial fee to
    UpdateMemeMarketInitialFeeTo = 1203,

    /// Update meme market fee to
    UpdateMemeMarketFeeTo = 1204,

    /// Update meme market initial trading fee
    UpdateMemeMarketInitialTradingFee = 1205,

    /// Update meme market trading fee
    UpdateMemeMarketTradingFee = 1206,

    /// Claim meme market trading fee
    ClaimMemeMarketTradingFee = 1207,
}

impl TransactionType {
    pub fn iterator() -> impl Iterator<Item = TransactionType> {
        [
            TransactionType::WalletRegister,
            TransactionType::Deposit,
            TransactionType::Withdrawal,
            TransactionType::ForceWithdrawal,
            TransactionType::WithdrawalV2,
            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::RegisterSpotMarket,
            TransactionType::UpdateSpotMarketTradingSettings,
            TransactionType::UpdateSpotMarketInitialFeeTo,
            TransactionType::UpdateSpotMarketFeeTo,
            TransactionType::UpdateSpotMarketInitialTradingFee,
            TransactionType::UpdateSpotMarketTradingFee,
            TransactionType::ClaimSpotMarketTradingFee,
            TransactionType::UpdateSpotMarketRoyalty,
            TransactionType::ClaimSpotMarketRoyalty,
            TransactionType::AssetAccountBinding,
            TransactionType::AssetAccountUnbinding,
            TransactionType::SubmitMemeOrder,
            TransactionType::CancelMemeOrder,
            TransactionType::RegisterMemeMarket,
            TransactionType::UpdateMemeMarketInitialTradingSettings,
            TransactionType::UpdateMemeMarketTradingSettings,
            TransactionType::UpdateMemeMarketInitialFeeTo,
            TransactionType::UpdateMemeMarketFeeTo,
            TransactionType::UpdateMemeMarketInitialTradingFee,
            TransactionType::UpdateMemeMarketTradingFee,
            TransactionType::ClaimMemeMarketTradingFee,
        ]
        .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,
            202 => TransactionType::ForceWithdrawal,
            203 => TransactionType::WithdrawalV2,
            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::RegisterSpotMarket,
            901 => TransactionType::UpdateSpotMarketTradingSettings,
            902 => TransactionType::UpdateSpotMarketInitialFeeTo,
            903 => TransactionType::UpdateSpotMarketFeeTo,
            904 => TransactionType::UpdateSpotMarketInitialTradingFee,
            905 => TransactionType::UpdateSpotMarketTradingFee,
            906 => TransactionType::ClaimSpotMarketTradingFee,
            907 => TransactionType::UpdateSpotMarketRoyalty,
            908 => TransactionType::ClaimSpotMarketRoyalty,
            1000 => TransactionType::AssetAccountBinding,
            1001 => TransactionType::AssetAccountUnbinding,
            1100 => TransactionType::SubmitMemeOrder,
            1101 => TransactionType::CancelMemeOrder,
            1200 => TransactionType::RegisterMemeMarket,
            1201 => TransactionType::UpdateMemeMarketInitialTradingSettings,
            1202 => TransactionType::UpdateMemeMarketTradingSettings,
            1203 => TransactionType::UpdateMemeMarketInitialFeeTo,
            1204 => TransactionType::UpdateMemeMarketFeeTo,
            1205 => TransactionType::UpdateMemeMarketInitialTradingFee,
            1206 => TransactionType::UpdateMemeMarketTradingFee,
            1207 => TransactionType::ClaimMemeMarketTradingFee,
            _ => panic!("Invalid transaction type: {}", value),
        }
    }
}

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

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