ex3_node_types/
vault.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
use num_bigint::BigUint;

use serde::{Deserialize, Serialize};

use crate::{CanisterId, WalletRegisterId};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SnapshotVault {
    pub canister_id: CanisterId,
    pub seq_id: u64,
    pub wallet_start_id: WalletRegisterId,
    pub max_wallet_count: BigUint,
}

pub type BalanceVault = SnapshotVault;
pub type SecretVault = SnapshotVault;
pub type WalletRegistry = SnapshotVault;

#[cfg(test)]
mod tests {
    use crate::vault::SnapshotVault;
    use candid::Principal;
    use ex3_serde::bincode;

    #[test]
    fn test_bincode_seder() {
        let vault = SnapshotVault {
            canister_id: Principal::management_canister().into(),
            seq_id: 1,
            wallet_start_id: 0u8.into(),
            max_wallet_count: 100u64.into(),
        };

        let bytes = bincode::serialize(&vault).unwrap();
        let vault2: SnapshotVault = bincode::deserialize(&bytes).unwrap();

        assert_eq!(vault.canister_id, vault2.canister_id);
    }
}