Skip to content

Commit 590ec64

Browse files
cleanup
1 parent 84cc984 commit 590ec64

File tree

11 files changed

+193
-271
lines changed

11 files changed

+193
-271
lines changed

key-wallet-manager/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ extern crate alloc;
2222
extern crate std;
2323

2424
pub mod spv_wallet_manager;
25-
pub mod wallet_info_trait;
2625
pub mod wallet_interface;
2726
pub mod wallet_manager;
2827

key-wallet-manager/src/spv_wallet_manager.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use dashcore::prelude::CoreBlockHeight;
1515
use dashcore::{BlockHash, Txid};
1616
use key_wallet::Network;
1717

18-
use crate::wallet_info_trait::WalletInfoInterface;
1918
use crate::wallet_interface::WalletInterface;
2019
use crate::wallet_manager::{WalletId, WalletManager};
2120
use key_wallet::transaction_checking::TransactionContext;

key-wallet-manager/src/wallet_manager/mod.rs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ use dashcore::Txid;
1515
use key_wallet::wallet::managed_wallet_info::{ManagedWalletInfo, TransactionRecord};
1616
use key_wallet::WalletBalance;
1717
use key_wallet::{Account, AccountType, Address, Mnemonic, Network, Wallet, WalletConfig};
18+
use std::collections::BTreeSet;
1819

19-
use crate::wallet_info_trait::WalletInfoInterface;
20-
21-
use key_wallet::transaction_checking::{TransactionContext, WalletTransactionChecker};
20+
use key_wallet::transaction_checking::TransactionContext;
2221
use key_wallet::wallet::managed_wallet_info::transaction_building::AccountTypePreference;
2322
use key_wallet::wallet::managed_wallet_info::wallet_info_interface::WalletInfoInterface;
2423
use key_wallet::{Utxo, UtxoSet};
@@ -301,24 +300,8 @@ impl<T: WalletInfoInterface> WalletManager<T> {
301300
for wallet_id in wallet_ids {
302301
// Check the transaction for this wallet
303302
if let Some(wallet_info) = self.wallet_infos.get_mut(&wallet_id) {
304-
// Convert TransactionContext to the expected format
305-
let context_tuple = match context {
306-
TransactionContext::InBlock {
307-
height,
308-
..
309-
}
310-
| TransactionContext::InChainLockedBlock {
311-
height,
312-
..
313-
} => Some((height, tx.txid())),
314-
TransactionContext::Mempool => None,
315-
};
316-
let result = wallet_info.check_transaction(
317-
tx,
318-
network,
319-
context_tuple,
320-
update_state_if_found,
321-
);
303+
let result =
304+
wallet_info.check_transaction(tx, network, context, update_state_if_found);
322305

323306
// If the transaction is relevant
324307
if result.is_relevant {
@@ -776,7 +759,7 @@ impl<T: WalletInfoInterface> WalletManager<T> {
776759
let managed_info =
777760
self.wallet_infos.get(wallet_id).ok_or(WalletError::WalletNotFound(*wallet_id))?;
778761

779-
Ok(managed_info.get_transaction_history())
762+
Ok(managed_info.transaction_history())
780763
}
781764

782765
/// Get UTXOs for all wallets across all networks
@@ -789,13 +772,13 @@ impl<T: WalletInfoInterface> WalletManager<T> {
789772
}
790773

791774
/// Get UTXOs for a specific wallet
792-
pub fn get_wallet_utxos(&self, wallet_id: &WalletId) -> Result<Vec<Utxo>, WalletError> {
775+
pub fn wallet_utxos(&self, wallet_id: &WalletId) -> Result<BTreeSet<&Utxo>, WalletError> {
793776
// Get the wallet info
794777
let wallet_info =
795778
self.wallet_infos.get(wallet_id).ok_or(WalletError::WalletNotFound(*wallet_id))?;
796779

797780
// Get UTXOs from the wallet info and clone them
798-
let utxos = wallet_info.get_utxos();
781+
let utxos = wallet_info.utxos();
799782

800783
Ok(utxos)
801784
}
@@ -812,7 +795,7 @@ impl<T: WalletInfoInterface> WalletManager<T> {
812795
self.wallet_infos.get(wallet_id).ok_or(WalletError::WalletNotFound(*wallet_id))?;
813796

814797
// Get balance from the wallet info
815-
Ok(wallet_info.get_balance())
798+
Ok(wallet_info.balance())
816799
}
817800

818801
/// Update the cached balance for a specific wallet

key-wallet-manager/src/wallet_manager/process_block.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::wallet_info_trait::WalletInfoInterface;
21
use crate::{Network, WalletManager};
32
use dashcore::bip158::BlockFilter;
43
use dashcore::prelude::CoreBlockHeight;

key-wallet-manager/src/wallet_manager/transaction_building.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Transaction building functionality for the wallet manager
22
33
use super::{WalletError, WalletId, WalletManager};
4-
use crate::wallet_info_trait::WalletInfoInterface;
54
use dashcore::Transaction;
65
use key_wallet::wallet::managed_wallet_info::fee::FeeLevel;
76
use key_wallet::wallet::managed_wallet_info::transaction_building::{

key-wallet-manager/tests/integration_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn test_utxo_management() {
140140
// The WalletManager doesn't have an add_utxo method directly
141141
// Instead, UTXOs are created by processing transactions
142142

143-
let utxos = manager.get_wallet_utxos(&wallet_id);
143+
let utxos = manager.wallet_utxos(&wallet_id);
144144
assert!(utxos.is_ok());
145145
// Initially empty
146146
assert_eq!(utxos.unwrap().len(), 0);

key-wallet/src/transaction_checking/wallet_checker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
pub(crate) use super::account_checker::TransactionCheckResult;
77
use super::transaction_router::TransactionRouter;
88
use crate::wallet::immature_transaction::ImmatureTransaction;
9+
use crate::wallet::managed_wallet_info::wallet_info_interface::WalletInfoInterface;
910
use crate::wallet::managed_wallet_info::ManagedWalletInfo;
1011
use crate::Network;
1112
use dashcore::blockdata::transaction::Transaction;

key-wallet/src/wallet/managed_wallet_info/mod.rs

Lines changed: 0 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -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

key-wallet/src/wallet/managed_wallet_info/transaction_building.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum TransactionError {
3939
impl ManagedWalletInfo {
4040
/// Create an unsigned payment transaction
4141
#[allow(clippy::too_many_arguments)]
42-
pub fn create_unsigned_payment_transaction(
42+
pub(crate) fn create_unsigned_payment_transaction_internal(
4343
&mut self,
4444
wallet: &Wallet,
4545
network: Network,
@@ -169,15 +169,11 @@ impl ManagedWalletInfo {
169169
mod tests {
170170
use super::*;
171171
use crate::wallet::managed_wallet_info::transaction_builder::TransactionBuilder;
172-
use crate::wallet::Wallet;
173172
use crate::Utxo;
174173
use dashcore::blockdata::script::ScriptBuf;
175-
use dashcore::blockdata::transaction::special_transaction::asset_lock::AssetLockPayload;
176174
use dashcore::blockdata::transaction::special_transaction::TransactionPayload;
177175
use dashcore::{Address, Network, OutPoint, Transaction, TxOut, Txid};
178176
use dashcore_hashes::{sha256d, Hash};
179-
use secp256k1::SecretKey;
180-
use std::collections::BTreeMap;
181177
use std::str::FromStr;
182178

183179
fn test_utxo(value: u64, confirmed: bool) -> Utxo {

0 commit comments

Comments
 (0)