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
use ex3_canister_types::chain::Chain;
use serde::{Deserialize, Serialize};

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: AssetId,

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

    /// Withdrawal fee
    pub fee: AssetAmount,
}

#[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: 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);
    }
}