1use crate::primitives::{Address, Timestamp};
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct WalletInfo {
12 pub wallet_id: String,
14 pub wallet_type: WalletType,
16 pub accounts: Vec<Address>,
18 pub label: Option<String>,
20 pub created_at: Timestamp,
22 pub last_accessed: Option<Timestamp>,
24}
25
26impl WalletInfo {
27 pub fn new(wallet_id: String, wallet_type: WalletType) -> Self {
29 Self {
30 wallet_id,
31 wallet_type,
32 accounts: Vec::new(),
33 label: None,
34 created_at: Timestamp::now(),
35 last_accessed: None,
36 }
37 }
38
39 pub fn with_label(mut self, label: String) -> Self {
41 self.label = Some(label);
42 self
43 }
44
45 pub fn add_account(&mut self, address: Address) {
47 if !self.accounts.contains(&address) {
48 self.accounts.push(address);
49 }
50 }
51
52 pub fn update_last_accessed(&mut self) {
54 self.last_accessed = Some(Timestamp::now());
55 }
56
57 pub fn account_count(&self) -> usize {
59 self.accounts.len()
60 }
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
65pub enum WalletType {
66 HD,
68 SingleKey,
70 MultiSig,
72 Hardware,
74 SmartContract,
76 Custodial,
78}
79
80impl WalletType {
81 pub fn as_str(&self) -> &str {
83 match self {
84 Self::HD => "HD",
85 Self::SingleKey => "Single Key",
86 Self::MultiSig => "Multi-Signature",
87 Self::Hardware => "Hardware",
88 Self::SmartContract => "Smart Contract",
89 Self::Custodial => "Custodial",
90 }
91 }
92
93 pub fn supports_multiple_accounts(&self) -> bool {
95 matches!(self, Self::HD | Self::MultiSig | Self::SmartContract | Self::Custodial)
96 }
97}
98
99#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
101pub struct MultiSigConfig {
102 pub threshold: u32,
104 pub total_signers: u32,
106 pub signers: Vec<Address>,
108}
109
110impl MultiSigConfig {
111 pub fn new(threshold: u32, signers: Vec<Address>) -> Self {
113 Self {
114 threshold,
115 total_signers: signers.len() as u32,
116 signers,
117 }
118 }
119
120 pub fn is_valid(&self) -> bool {
122 self.threshold > 0
123 && self.threshold <= self.total_signers
124 && self.signers.len() == self.total_signers as usize
125 }
126
127 pub fn is_signer(&self, address: &Address) -> bool {
129 self.signers.contains(address)
130 }
131}