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
use ex3_timestamp::TimeInNs;
use serde::{Deserialize, Serialize};

use crate::chain::Chain;
use crate::{AssetAmount, AssetId};

/// Withdrawal
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Withdrawal {
    /// Specify the blockchain
    pub chain: Chain,

    /// Specify the network
    pub network: u8,

    /// Withdrawal to address
    pub address: String,

    /// Withdrawal asset id
    pub asset_id: AssetId,

    /// Withdrawal amount
    /// Note: This is the amount that the user will receive
    pub amount: AssetAmount,

    /// Withdrawal fee
    pub fee: AssetAmount,
}

/// Force withdrawal
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ForceWithdrawal {
    /// Specify the blockchain
    pub chain: Chain,

    /// Specify the network
    pub network: u8,

    /// Withdrawal to address
    pub address: String,

    /// Withdrawal asset id
    pub asset_id: AssetId,

    /// Withdrawal amount
    /// Note: This is the amount that the user will receive
    pub amount: AssetAmount,

    /// Withdrawal fee
    pub fee: AssetAmount,

    /// Timestamp
    pub timestamp: TimeInNs,
}

#[cfg(test)]
mod tests {
    use ex3_serde::{bincode, cbor};

    use super::*;

    #[test]
    fn test_serde() {
        let withdrawal = Withdrawal {
            chain: Chain::Ethereum,
            network: 1,
            address: "0x0000001312312321313213".to_string(),
            asset_id: AssetId::from(2000u32),
            amount: AssetAmount::from(10000u64),
            fee: AssetAmount::from(100u64),
        };

        // bincode
        let encoded = bincode::serialize(&withdrawal).unwrap();
        let decoded: Withdrawal = bincode::deserialize(&encoded).unwrap();
        assert_eq!(withdrawal, decoded);

        // cbor
        let encoded = cbor::serialize(&withdrawal).unwrap();
        let decoded: Withdrawal = cbor::deserialize(&encoded).unwrap();
        assert_eq!(withdrawal, decoded);
    }
}