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
2 changes: 1 addition & 1 deletion dash-spv/src/sync/mempool/sync_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<W: WalletInterface + 'static> SyncManager for MempoolManager<W> {
// Rebuild bloom filter if the wallet's monitored set has changed.
//
// We poll the revision counter rather than using push-based wallet events
// for simplicity: the revision lives on `ManagedCoreAccount` and auto-bumps
// for simplicity: the revision lives on `ManagedCoreFundsAccount` and auto-bumps
// on address generation and UTXO mutations, giving us a single source of
// truth without needing event emission after every wallet operation.
// Adding a push-based approach would require a new `select!` branch in the
Expand Down
9 changes: 7 additions & 2 deletions dash-spv/tests/dashd_sync/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use dash_spv::network::NetworkEvent;
use dash_spv::sync::{ProgressPercentage, SyncEvent, SyncProgress, SyncState};
use dash_spv::test_utils::DashCoreNode;
use dashcore::Txid;
use key_wallet::managed_account::managed_account_trait::ManagedAccountTrait;
use key_wallet::transaction_checking::TransactionContext;
use key_wallet::wallet::managed_wallet_info::wallet_info_interface::WalletInfoInterface;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
Expand Down Expand Up @@ -67,8 +68,12 @@ pub(super) async fn count_wallet_transactions(
) -> usize {
let wallet_read = wallet.read().await;
let wallet_info = wallet_read.get_wallet_info(wallet_id).expect("Wallet info not found");
let txids: HashSet<_> =
wallet_info.accounts().all_accounts().iter().flat_map(|a| a.transactions.keys()).collect();
let txids: HashSet<_> = wallet_info
.accounts()
.all_accounts()
.iter()
.flat_map(|a| a.transactions().keys())
.collect();
txids.len()
}

Expand Down
11 changes: 6 additions & 5 deletions dash-spv/tests/dashd_sync/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use dash_spv::{
use dashcore::network::address::AddrV2Message;
use dashcore::network::constants::ServiceFlags;
use dashcore::Txid;
use key_wallet::managed_account::managed_account_trait::ManagedAccountTrait;
use key_wallet::managed_account::managed_account_type::ManagedAccountType;
use key_wallet::wallet::initialization::WalletAccountCreationOptions;
use key_wallet::wallet::managed_wallet_info::wallet_info_interface::WalletInfoInterface;
Expand Down Expand Up @@ -121,7 +122,7 @@ impl TestContext {
let wallet_read = self.wallet.read().await;
let wallet_info =
wallet_read.get_wallet_info(&self.wallet_id).expect("Wallet info not found");
wallet_info.accounts().all_accounts().iter().map(|a| a.transactions.len()).sum()
wallet_info.accounts().all_accounts().iter().map(|a| a.transactions().len()).sum()
}
/// Retrieves the spendable balance of the wallet.
pub(super) async fn spendable_balance(&self) -> u64 {
Expand All @@ -146,7 +147,7 @@ impl TestContext {
let ManagedAccountType::Standard {
external_addresses,
..
} = &account.managed_account_type
} = account.managed_account_type()
else {
panic!("Account 0 is not a Standard account type");
};
Expand All @@ -167,7 +168,7 @@ impl TestContext {
.accounts()
.all_accounts()
.iter()
.any(|account| account.transactions.contains_key(txid))
.any(|account| account.transactions().contains_key(txid))
|| wallet_info.immature_transactions().iter().any(|tx| &tx.txid() == txid)
}

Expand Down Expand Up @@ -196,7 +197,7 @@ impl TestContext {

let mut spv_txids = HashSet::new();
for managed_account in wallet_info.accounts().all_accounts() {
for txid in managed_account.transactions.keys() {
for txid in managed_account.transactions().keys() {
spv_txids.insert(txid.to_string());
}
}
Expand Down Expand Up @@ -304,7 +305,7 @@ pub(super) async fn client_has_transaction(
.accounts()
.all_accounts()
.iter()
.any(|account| account.transactions.contains_key(txid))
.any(|account| account.transactions().contains_key(txid))
|| wallet_info.immature_transactions().iter().any(|tx| &tx.txid() == txid)
}

Expand Down
25 changes: 13 additions & 12 deletions key-wallet-ffi/src/address_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ use key_wallet::account::ManagedAccountCollection;
use key_wallet::managed_account::address_pool::{
AddressInfo, AddressPool, KeySource, PublicKeyType,
};
use key_wallet::managed_account::ManagedCoreAccount;
use key_wallet::managed_account::managed_account_trait::ManagedAccountTrait;
use key_wallet::managed_account::ManagedCoreFundsAccount;
use key_wallet::AccountType;

// Helper functions to get managed accounts by type
fn get_managed_account_by_type<'a>(
collection: &'a ManagedAccountCollection,
account_type: &AccountType,
) -> Option<&'a ManagedCoreAccount> {
) -> Option<&'a ManagedCoreFundsAccount> {
match account_type {
AccountType::Standard {
index,
Expand Down Expand Up @@ -75,7 +76,7 @@ fn get_managed_account_by_type<'a>(
fn get_managed_account_by_type_mut<'a>(
collection: &'a mut ManagedAccountCollection,
account_type: &AccountType,
) -> Option<&'a mut ManagedCoreAccount> {
) -> Option<&'a mut ManagedCoreFundsAccount> {
match account_type {
AccountType::Standard {
index,
Expand Down Expand Up @@ -310,7 +311,7 @@ pub unsafe extern "C" fn managed_wallet_get_address_pool_info(
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
external_addresses,
..
} = &managed_account.managed_account_type {
} = managed_account.managed_account_type() {
external_addresses
} else {
(*error).set(FFIErrorCode::InvalidInput, "Account type does not have external address pool");
Expand All @@ -322,7 +323,7 @@ pub unsafe extern "C" fn managed_wallet_get_address_pool_info(
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
internal_addresses,
..
} = &managed_account.managed_account_type {
} = managed_account.managed_account_type() {
internal_addresses
} else {
(*error).set(FFIErrorCode::InvalidInput, "Account type does not have internal address pool");
Expand All @@ -331,7 +332,7 @@ pub unsafe extern "C" fn managed_wallet_get_address_pool_info(
}
FFIAddressPoolType::Single => {
// Get the first (and only) address pool for non-standard accounts
let pools = managed_account.managed_account_type.address_pools();
let pools = managed_account.managed_account_type().address_pools();
if pools.is_empty() {
(*error).set(FFIErrorCode::InvalidInput, "Account has no address pools");
return false;
Expand Down Expand Up @@ -395,7 +396,7 @@ pub unsafe extern "C" fn managed_wallet_set_gap_limit(
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
external_addresses,
..
} = &mut managed_account.managed_account_type {
} = managed_account.managed_account_type_mut() {
external_addresses
} else {
(*error).set(FFIErrorCode::InvalidInput, "Account type does not have external address pool");
Expand All @@ -407,7 +408,7 @@ pub unsafe extern "C" fn managed_wallet_set_gap_limit(
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
internal_addresses,
..
} = &mut managed_account.managed_account_type {
} = managed_account.managed_account_type_mut() {
internal_addresses
} else {
(*error).set(FFIErrorCode::InvalidInput, "Account type does not have internal address pool");
Expand All @@ -416,7 +417,7 @@ pub unsafe extern "C" fn managed_wallet_set_gap_limit(
}
FFIAddressPoolType::Single => {
// Get the first (and only) address pool for non-standard accounts
let pools = managed_account.managed_account_type.address_pools_mut();
let pools = managed_account.managed_account_type_mut().address_pools_mut();
if pools.is_empty() {
(*error).set(FFIErrorCode::InvalidInput, "Account has no address pools");
return false;
Expand Down Expand Up @@ -482,7 +483,7 @@ pub unsafe extern "C" fn managed_wallet_generate_addresses_to_index(
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
external_addresses,
..
} = &mut managed_account.managed_account_type {
} = managed_account.managed_account_type_mut() {
{
let current = external_addresses.highest_generated.unwrap_or(0);
if target_index > current {
Expand All @@ -502,7 +503,7 @@ pub unsafe extern "C" fn managed_wallet_generate_addresses_to_index(
if let key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
internal_addresses,
..
} = &mut managed_account.managed_account_type {
} = managed_account.managed_account_type_mut() {
{
let current = internal_addresses.highest_generated.unwrap_or(0);
if target_index > current {
Expand All @@ -519,7 +520,7 @@ pub unsafe extern "C" fn managed_wallet_generate_addresses_to_index(
}
FFIAddressPoolType::Single => {
// Get the first (and only) address pool for non-standard accounts
let mut pools = managed_account.managed_account_type.address_pools_mut();
let mut pools = managed_account.managed_account_type_mut().address_pools_mut();
if pools.is_empty() {
(*error).set(FFIErrorCode::InvalidInput, "Account has no address pools");
return false;
Expand Down
35 changes: 18 additions & 17 deletions key-wallet-ffi/src/managed_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@ use crate::wallet_manager::FFIWalletManager;
use key_wallet::account::account_collection::{DashpayAccountKey, PlatformPaymentAccountKey};
use key_wallet::account::TransactionRecord;
use key_wallet::managed_account::address_pool::AddressPool;
use key_wallet::managed_account::managed_account_trait::ManagedAccountTrait;
use key_wallet::managed_account::managed_platform_account::ManagedPlatformAccount;
use key_wallet::managed_account::ManagedCoreAccount;
use key_wallet::managed_account::ManagedCoreFundsAccount;
use key_wallet::AccountType;

/// Opaque managed account handle that wraps ManagedAccount
pub struct FFIManagedCoreAccount {
/// The underlying managed account
pub(crate) account: Arc<ManagedCoreAccount>,
pub(crate) account: Arc<ManagedCoreFundsAccount>,
}

impl FFIManagedCoreAccount {
/// Create a new FFI managed account handle
pub fn new(account: &ManagedCoreAccount) -> Self {
pub fn new(account: &ManagedCoreFundsAccount) -> Self {
FFIManagedCoreAccount {
account: Arc::new(account.clone()),
}
}

/// Get a reference to the inner managed account
pub fn inner(&self) -> &ManagedCoreAccount {
pub fn inner(&self) -> &ManagedCoreFundsAccount {
self.account.as_ref()
}
}
Expand Down Expand Up @@ -497,7 +498,7 @@ pub unsafe extern "C" fn managed_core_account_get_network(
}

let account = &*account;
account.inner().network.into()
account.inner().network().into()
}

/// Get the parent wallet ID of a managed account
Expand Down Expand Up @@ -536,7 +537,7 @@ pub unsafe extern "C" fn managed_core_account_get_account_type(

let account = &*account;
let managed_account = account.inner();
let account_type_rust = managed_account.managed_account_type.to_account_type();
let account_type_rust = managed_account.managed_account_type().to_account_type();

// Set the index if output pointer is provided
if !index_out.is_null() {
Expand Down Expand Up @@ -598,7 +599,7 @@ pub unsafe extern "C" fn managed_core_account_get_is_watch_only(
}

let account = &*account;
account.inner().is_watch_only
account.inner().is_watch_only()
}

/// Get the balance of a managed account
Expand All @@ -617,7 +618,7 @@ pub unsafe extern "C" fn managed_core_account_get_balance(
}

let account = &*account;
let balance = &account.inner().balance;
let balance = account.inner().balance;

*balance_out = crate::types::FFIBalance {
confirmed: balance.confirmed(),
Expand All @@ -644,7 +645,7 @@ pub unsafe extern "C" fn managed_core_account_get_transaction_count(
}

let account = &*account;
account.inner().transactions.len() as c_uint
account.inner().transactions().len() as c_uint
}

/// Get the number of UTXOs in a managed account
Expand Down Expand Up @@ -951,7 +952,7 @@ pub unsafe extern "C" fn managed_core_account_get_transactions(
}

let account = &*account;
let transactions = &account.inner().transactions;
let transactions = account.inner().transactions();

if transactions.is_empty() {
*transactions_out = std::ptr::null_mut();
Expand Down Expand Up @@ -1078,7 +1079,7 @@ pub unsafe extern "C" fn managed_core_account_get_index(
}

let account = &*account;
account.inner().managed_account_type.index_or_default()
account.inner().managed_account_type().index_or_default()
}

/// Get the external address pool from a managed account
Expand All @@ -1102,7 +1103,7 @@ pub unsafe extern "C" fn managed_core_account_get_external_address_pool(
let managed_account = account.inner();

// Get external address pool if this is a standard account
match &managed_account.managed_account_type {
match managed_account.managed_account_type() {
key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
external_addresses,
..
Expand Down Expand Up @@ -1138,7 +1139,7 @@ pub unsafe extern "C" fn managed_core_account_get_internal_address_pool(
let managed_account = account.inner();

// Get internal address pool if this is a standard account
match &managed_account.managed_account_type {
match managed_account.managed_account_type() {
key_wallet::managed_account::managed_account_type::ManagedAccountType::Standard {
internal_addresses,
..
Expand Down Expand Up @@ -1182,7 +1183,7 @@ pub unsafe extern "C" fn managed_core_account_get_address_pool(
match pool_type {
FFIAddressPoolType::External => {
// Only standard accounts have external pools
match &managed_account.managed_account_type {
match managed_account.managed_account_type() {
ManagedAccountType::Standard {
external_addresses,
..
Expand All @@ -1198,7 +1199,7 @@ pub unsafe extern "C" fn managed_core_account_get_address_pool(
}
FFIAddressPoolType::Internal => {
// Only standard accounts have internal pools
match &managed_account.managed_account_type {
match managed_account.managed_account_type() {
ManagedAccountType::Standard {
internal_addresses,
..
Expand All @@ -1214,7 +1215,7 @@ pub unsafe extern "C" fn managed_core_account_get_address_pool(
}
FFIAddressPoolType::Single => {
// Get the single address pool for non-standard accounts
let pool_ref = match &managed_account.managed_account_type {
let pool_ref = match managed_account.managed_account_type() {
ManagedAccountType::Standard {
..
} => {
Expand Down Expand Up @@ -1631,7 +1632,7 @@ mod tests {
// Verify the account was created successfully
let account = &*result.account;
// Account should exist and be valid
assert!(!account.inner().is_watch_only);
assert!(!account.inner().is_watch_only());

// Clean up
managed_core_account_free(result.account);
Expand Down
9 changes: 5 additions & 4 deletions key-wallet-ffi/src/managed_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::error::{FFIError, FFIErrorCode};
use crate::types::FFIWallet;
use crate::{check_ptr, deref_ptr, deref_ptr_mut, unwrap_or_return};
use key_wallet::managed_account::address_pool::KeySource;
use key_wallet::managed_account::managed_account_trait::ManagedAccountTrait;
use key_wallet::wallet::managed_wallet_info::wallet_info_interface::WalletInfoInterface;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
use std::ffi::c_void;
Expand Down Expand Up @@ -170,7 +171,7 @@ pub unsafe extern "C" fn managed_wallet_get_bip_44_external_address_range(
let addresses = if let key_wallet::account::ManagedAccountType::Standard {
external_addresses,
..
} = &mut managed_account.managed_account_type
} = managed_account.managed_account_type_mut()
{
unwrap_or_return!(
external_addresses.address_range(start_index, end_index, &key_source),
Expand Down Expand Up @@ -250,7 +251,7 @@ pub unsafe extern "C" fn managed_wallet_get_bip_44_internal_address_range(
let addresses = if let key_wallet::account::ManagedAccountType::Standard {
internal_addresses,
..
} = &mut managed_account.managed_account_type
} = managed_account.managed_account_type_mut()
{
unwrap_or_return!(
internal_addresses.address_range(start_index, end_index, &key_source),
Expand Down Expand Up @@ -554,7 +555,7 @@ mod tests {
#[test]
fn test_comprehensive_address_generation() {
use key_wallet::account::{
ManagedAccountCollection, ManagedCoreAccount, StandardAccountType,
ManagedAccountCollection, ManagedCoreFundsAccount, StandardAccountType,
};
use key_wallet::bip32::DerivationPath;
use key_wallet::managed_account::address_pool::{AddressPool, AddressPoolType};
Expand Down Expand Up @@ -608,7 +609,7 @@ mod tests {
)
.expect("Failed to create internal pool");

let managed_account = ManagedCoreAccount::new(
let managed_account = ManagedCoreFundsAccount::new(
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
Expand Down
Loading
Loading