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
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 @@ -62,8 +63,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
19 changes: 10 additions & 9 deletions key-wallet-ffi/src/address_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use key_wallet::account::ManagedAccountCollection;
use key_wallet::managed_account::address_pool::{
AddressInfo, AddressPool, KeySource, PublicKeyType,
};
use key_wallet::managed_account::managed_account_trait::ManagedAccountTrait;
use key_wallet::managed_account::ManagedCoreFundsAccount;
use key_wallet::AccountType;

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
27 changes: 14 additions & 13 deletions key-wallet-ffi/src/managed_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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::ManagedCoreFundsAccount;
use key_wallet::AccountType;
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
5 changes: 3 additions & 2 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
3 changes: 2 additions & 1 deletion key-wallet-ffi/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use dashcore::{
consensus, hashes::Hash, sighash::SighashCache, EcdsaSighashType, Network, OutPoint, Script,
ScriptBuf, Transaction, TxIn, TxOut, Txid,
};
use key_wallet::managed_account::managed_account_trait::ManagedAccountTrait;
use key_wallet::wallet::managed_wallet_info::asset_lock_builder::{
AssetLockFundingType, CreditOutputFunding,
};
Expand Down Expand Up @@ -194,7 +195,7 @@ pub unsafe extern "C" fn wallet_build_and_sign_transaction(
HashMap::new();

// Collect from all address pools (receive, change, etc.)
for pool in managed_account.managed_account_type.address_pools() {
for pool in managed_account.managed_account_type().address_pools() {
for addr_info in pool.addresses.values() {
address_to_path.insert(addr_info.address.clone(), addr_info.path.clone());
}
Expand Down
1 change: 1 addition & 0 deletions key-wallet-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub use wallet_interface::{BlockProcessingResult, MempoolTransactionResult, Wall
use dashcore::blockdata::transaction::Transaction;
use dashcore::prelude::CoreBlockHeight;
use key_wallet::account::AccountCollection;
use key_wallet::managed_account::managed_account_trait::ManagedAccountTrait;
use key_wallet::managed_account::transaction_record::TransactionRecord;
use key_wallet::transaction_checking::TransactionContext;
use key_wallet::wallet::managed_wallet_info::transaction_building::AccountTypePreference;
Expand Down
7 changes: 4 additions & 3 deletions key-wallet/src/managed_account/managed_account_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::gap_limit::{
DEFAULT_SPECIAL_GAP_LIMIT, DIP17_GAP_LIMIT,
};
use crate::managed_account::address_pool::{AddressPool, AddressPoolType};
use crate::managed_account::managed_account_trait::ManagedAccountTrait;
use crate::managed_account::managed_account_type::ManagedAccountType;
use crate::managed_account::managed_platform_account::ManagedPlatformAccount;
use crate::managed_account::ManagedCoreFundsAccount;
Expand Down Expand Up @@ -72,7 +73,7 @@ macro_rules! get_by_account_type_match_impl {
account_index,
involved_addresses,
} => $self.dashpay_receival_accounts.$values().find(|account| {
match &account.managed_account_type {
match account.managed_account_type() {
ManagedAccountType::DashpayReceivingFunds {
index,
addresses,
Expand All @@ -90,7 +91,7 @@ macro_rules! get_by_account_type_match_impl {
account_index,
involved_addresses,
} => $self.dashpay_external_accounts.$values().find(|account| {
match &account.managed_account_type {
match account.managed_account_type() {
ManagedAccountType::DashpayExternalAccount {
index,
addresses,
Expand Down Expand Up @@ -269,7 +270,7 @@ impl ManagedAccountCollection {
pub fn insert(&mut self, account: ManagedCoreFundsAccount) -> Result<(), crate::error::Error> {
use crate::account::StandardAccountType;

match &account.managed_account_type {
match account.managed_account_type() {
ManagedAccountType::Standard {
index,
standard_account_type,
Expand Down
Loading
Loading