@@ -91,68 +91,11 @@ impl ManagedWalletInfo {
9191 info
9292 }
9393
94- /// Set the wallet name
95- pub fn set_name ( & mut self , name : String ) {
96- self . name = Some ( name) ;
97- }
98-
99- /// Set the wallet description
100- pub fn set_description ( & mut self , description : String ) {
101- self . description = Some ( description) ;
102- }
103-
104- /// Update the last synced timestamp
105- pub fn update_last_synced ( & mut self , timestamp : u64 ) {
106- self . metadata . last_synced = Some ( timestamp) ;
107- }
108-
10994 /// Increment the transaction count
11095 pub fn increment_transactions ( & mut self ) {
11196 self . metadata . total_transactions += 1 ;
11297 }
11398
114- /// Get a managed account by network and index
115- pub fn get_account ( & self , network : Network , index : u32 ) -> Option < & ManagedAccount > {
116- self . accounts . get ( & network) . and_then ( |collection| collection. get ( index) )
117- }
118-
119- /// Get a mutable managed account by network and index
120- pub fn get_account_mut ( & mut self , network : Network , index : u32 ) -> Option < & mut ManagedAccount > {
121- self . accounts . get_mut ( & network) . and_then ( |collection| collection. get_mut ( index) )
122- }
123-
124- /// Update the cached wallet balance by summing all accounts
125- pub fn update_balance ( & mut self ) {
126- let mut confirmed = 0u64 ;
127- let mut unconfirmed = 0u64 ;
128- let mut locked = 0u64 ;
129-
130- // Sum balances from all accounts across all networks
131- for collection in self . accounts . values ( ) {
132- for account in collection. all_accounts ( ) {
133- for utxo in account. utxos . values ( ) {
134- let value = utxo. txout . value ;
135- if utxo. is_locked {
136- locked += value;
137- } else if utxo. is_confirmed {
138- confirmed += value;
139- } else {
140- unconfirmed += value;
141- }
142- }
143- }
144- }
145-
146- // Update balance, ignoring overflow errors as we're recalculating from scratch
147- self . balance = WalletBalance :: new ( confirmed, unconfirmed, locked)
148- . unwrap_or_else ( |_| WalletBalance :: default ( ) ) ;
149- }
150-
151- /// Get the cached wallet balance
152- pub fn get_balance ( & self ) -> WalletBalance {
153- self . balance
154- }
155-
15699 /// Get total wallet balance by recalculating from all accounts (for verification)
157100 pub fn calculate_balance ( & self ) -> WalletBalance {
158101 let mut confirmed = 0u64 ;
@@ -178,167 +121,6 @@ impl ManagedWalletInfo {
178121 WalletBalance :: new ( confirmed, unconfirmed, locked)
179122 . unwrap_or_else ( |_| WalletBalance :: default ( ) )
180123 }
181-
182- /// Get all transaction history across all accounts
183- pub fn get_transaction_history ( & self ) -> Vec < & TransactionRecord > {
184- let mut transactions = Vec :: new ( ) ;
185-
186- // Collect transactions from all accounts across all networks
187- for collection in self . accounts . values ( ) {
188- for account in collection. all_accounts ( ) {
189- transactions. extend ( account. transactions . values ( ) ) ;
190- }
191- }
192-
193- transactions
194- }
195-
196- /// Get all UTXOs across all accounts
197- pub fn get_utxos ( & self ) -> BTreeSet < & Utxo > {
198- let mut utxos = BTreeSet :: new ( ) ;
199-
200- // Collect UTXOs from all accounts across all networks
201- for collection in self . accounts . values ( ) {
202- for account in collection. all_accounts ( ) {
203- utxos. extend ( account. utxos . values ( ) ) ;
204- }
205- }
206-
207- utxos
208- }
209-
210- /// Get spendable UTXOs (confirmed and not locked)
211- pub fn get_spendable_utxos ( & self ) -> Vec < & Utxo > {
212- self . get_utxos ( )
213- . into_iter ( )
214- . filter ( |utxo| !utxo. is_locked && ( utxo. is_confirmed || utxo. is_instantlocked ) )
215- . collect ( )
216- }
217-
218- /// Add an immature transaction
219- pub fn add_immature_transaction (
220- & mut self ,
221- network : Network ,
222- tx : super :: immature_transaction:: ImmatureTransaction ,
223- ) {
224- self . immature_transactions
225- . entry ( network)
226- . or_insert_with ( ImmatureTransactionCollection :: new)
227- . insert ( tx) ;
228- }
229-
230- /// Process matured transactions for a given chain height
231- pub fn process_matured_transactions (
232- & mut self ,
233- network : Network ,
234- current_height : u32 ,
235- ) -> Vec < super :: immature_transaction:: ImmatureTransaction > {
236- if let Some ( collection) = self . immature_transactions . get_mut ( & network) {
237- let matured = collection. remove_matured ( current_height) ;
238-
239- // Update accounts with matured transactions
240- if let Some ( account_collection) = self . accounts . get_mut ( & network) {
241- for tx in & matured {
242- // Process BIP44 accounts
243- for & index in & tx. affected_accounts . bip44_accounts {
244- if let Some ( account) =
245- account_collection. standard_bip44_accounts . get_mut ( & index)
246- {
247- // Add transaction record as confirmed
248- let tx_record = crate :: account:: TransactionRecord :: new_confirmed (
249- tx. transaction . clone ( ) ,
250- tx. height ,
251- tx. block_hash ,
252- tx. timestamp ,
253- tx. total_received as i64 ,
254- false , // Not ours (we received)
255- ) ;
256- account. transactions . insert ( tx. txid , tx_record) ;
257- }
258- }
259-
260- // Process BIP32 accounts
261- for & index in & tx. affected_accounts . bip32_accounts {
262- if let Some ( account) =
263- account_collection. standard_bip32_accounts . get_mut ( & index)
264- {
265- let tx_record = crate :: account:: TransactionRecord :: new_confirmed (
266- tx. transaction . clone ( ) ,
267- tx. height ,
268- tx. block_hash ,
269- tx. timestamp ,
270- tx. total_received as i64 ,
271- false ,
272- ) ;
273- account. transactions . insert ( tx. txid , tx_record) ;
274- }
275- }
276-
277- // Process CoinJoin accounts
278- for & index in & tx. affected_accounts . coinjoin_accounts {
279- if let Some ( account) = account_collection. coinjoin_accounts . get_mut ( & index)
280- {
281- let tx_record = crate :: account:: TransactionRecord :: new_confirmed (
282- tx. transaction . clone ( ) ,
283- tx. height ,
284- tx. block_hash ,
285- tx. timestamp ,
286- tx. total_received as i64 ,
287- false ,
288- ) ;
289- account. transactions . insert ( tx. txid , tx_record) ;
290- }
291- }
292- }
293- }
294-
295- // Update balance after processing matured transactions
296- self . update_balance ( ) ;
297-
298- matured
299- } else {
300- Vec :: new ( )
301- }
302- }
303-
304- /// Get immature transactions for a network
305- pub fn get_immature_transactions (
306- & self ,
307- network : Network ,
308- ) -> Option < & ImmatureTransactionCollection > {
309- self . immature_transactions . get ( & network)
310- }
311-
312- /// Get total immature balance across all networks
313- pub fn total_immature_balance ( & self ) -> u64 {
314- self . immature_transactions
315- . values ( )
316- . map ( |collection| collection. total_immature_balance ( ) )
317- . sum ( )
318- }
319-
320- /// Get immature balance for a specific network
321- pub fn network_immature_balance ( & self , network : Network ) -> u64 {
322- self . immature_transactions
323- . get ( & network)
324- . map ( |collection| collection. total_immature_balance ( ) )
325- . unwrap_or ( 0 )
326- }
327-
328- /// Get monitored addresses for a specific network
329- /// These are automatically collected from all accounts in the network
330- pub fn monitored_addresses ( & self , network : Network ) -> Vec < Address > {
331- let mut addresses = Vec :: new ( ) ;
332-
333- if let Some ( collection) = self . accounts . get ( & network) {
334- // Collect from all accounts using the account's get_all_addresses method
335- for account in collection. all_accounts ( ) {
336- addresses. extend ( account. get_all_addresses ( ) ) ;
337- }
338- }
339-
340- addresses
341- }
342124}
343125
344126/// Re-export types from account module for convenience
0 commit comments