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
use num_bigint::BigUint;
use ex3_error::OtherError;
use ex3_serde::bincode::{deserialize, serialize};
use crate::{CanisterId, WalletRegisterId};
#[derive(Clone, Debug)]
pub struct Vault {
pub canister_id: CanisterId,
pub wallet_start_id: WalletRegisterId,
pub max_wallet_count: BigUint,
}
impl Vault {
pub fn encode(&self) -> Vec<u8> {
serialize(&(
&self.canister_id,
&self.wallet_start_id,
&self.max_wallet_count,
))
.unwrap()
}
}
impl TryFrom<&[u8]> for Vault {
type Error = OtherError;
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
let (canister_id, wallet_start_id, max_wallet_count) = deserialize(value)
.map_err(|e| OtherError::new(format!("Failed to deserialize vault: {}", e)))?;
Ok(Vault {
canister_id,
wallet_start_id,
max_wallet_count,
})
}
}
pub type BalanceVault = Vault;
pub type SecretVault = Vault;
pub type WalletRegistry = Vault;