Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions key-wallet/src/managed_account/managed_account_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::managed_account::managed_platform_account::ManagedPlatformAccount;
use crate::managed_account::{ManagedCoreFundsAccount, ManagedCoreKeysAccount};
use crate::transaction_checking::account_checker::CoreAccountTypeMatch;
use crate::KeySource;
use crate::{Account, AccountCollection};
use crate::{Account, AccountCollection, AccountType};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -577,13 +577,76 @@ impl ManagedAccountCollection {
))
}

/// Get the spendable account for an exact [`AccountType`]
pub fn funds_account(&self, account_type: &AccountType) -> Option<&ManagedCoreFundsAccount> {
match account_type {
AccountType::Standard {
index,
standard_account_type,
} => match standard_account_type {
crate::account::StandardAccountType::BIP44Account => {
self.standard_bip44_accounts.get(index)
}
crate::account::StandardAccountType::BIP32Account => {
self.standard_bip32_accounts.get(index)
}
},
AccountType::CoinJoin {
index,
} => self.coinjoin_accounts.get(index),
AccountType::DashpayReceivingFunds {
index,
user_identity_id,
friend_identity_id,
} => self.dashpay_receival_accounts.get(&DashpayAccountKey {
index: *index,
user_identity_id: *user_identity_id,
friend_identity_id: *friend_identity_id,
}),
_ => None,
}
}

/// Mutable twin of [`Self::funds_account`].
pub fn funds_account_mut(
&mut self,
account_type: &AccountType,
) -> Option<&mut ManagedCoreFundsAccount> {
match account_type {
AccountType::Standard {
index,
standard_account_type,
} => match standard_account_type {
crate::account::StandardAccountType::BIP44Account => {
self.standard_bip44_accounts.get_mut(index)
}
crate::account::StandardAccountType::BIP32Account => {
self.standard_bip32_accounts.get_mut(index)
}
},
AccountType::CoinJoin {
index,
} => self.coinjoin_accounts.get_mut(index),
AccountType::DashpayReceivingFunds {
index,
user_identity_id,
friend_identity_id,
} => self.dashpay_receival_accounts.get_mut(&DashpayAccountKey {
index: *index,
user_identity_id: *user_identity_id,
friend_identity_id: *friend_identity_id,
}),
_ => None,
}
}

/// Get a funds-bearing account by primary index across Standard BIP44,
/// Standard BIP32, and CoinJoin accounts.
///
/// Returns only [`ManagedCoreFundsAccount`] entries — keys-only accounts
/// (identity / asset-lock / provider) are not reachable via this index
/// lookup. Use [`Self::get_by_account_type_match`] or direct field access
/// for those.
/// lookup. Use [`Self::funds_account`], [`Self::get_by_account_type_match`]
/// or direct field access for those.
pub fn get(&self, index: u32) -> Option<&ManagedCoreFundsAccount> {
if let Some(account) = self.standard_bip44_accounts.get(&index) {
return Some(account);
Expand Down
19 changes: 19 additions & 0 deletions key-wallet/src/wallet/managed_wallet_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,15 @@ impl ManagedWalletInfo {
debug_assert!(false, "CoinJoin accounts are spend-only in our current use cases");
None
}
// DIP-15 contact accounts have a single address pool and no
// internal (change) branch, so they can never supply change.
AccountTypePreference::DashpayFriendshipReceivingFunds {
..
}
| AccountTypePreference::DashpayIdentityReceivingFunds {
..
}
| AccountTypePreference::AllDashpayReceivingFunds => None,
};

address
Expand Down Expand Up @@ -498,6 +507,16 @@ impl ManagedWalletInfo {
debug_assert!(false, "CoinJoin accounts are spend-only in our current use cases");
None
}
// Addresses of a DIP-15 contact account are handed out through the
// contact flow that knows the identity pair, not through this
// index-addressed helper.
AccountTypePreference::DashpayFriendshipReceivingFunds {
..
}
| AccountTypePreference::DashpayIdentityReceivingFunds {
..
}
| AccountTypePreference::AllDashpayReceivingFunds => None,
};

address
Expand Down
Loading
Loading