Skip to content
Open
6 changes: 3 additions & 3 deletions key-wallet-ffi/src/address_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use key_wallet::account::ManagedAccountCollection;
use key_wallet::managed_account::address_pool::{
AddressInfo, AddressPool, KeySource, PublicKeyType,
};
use key_wallet::managed_account::ManagedAccount;
use key_wallet::managed_account::ManagedCoreAccount;
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 ManagedAccount> {
) -> Option<&'a ManagedCoreAccount> {
match account_type {
AccountType::Standard {
index,
Expand Down Expand Up @@ -70,7 +70,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 ManagedAccount> {
) -> Option<&'a mut ManagedCoreAccount> {
match account_type {
AccountType::Standard {
index,
Expand Down
8 changes: 4 additions & 4 deletions key-wallet-ffi/src/managed_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ use crate::wallet_manager::FFIWalletManager;
use crate::FFINetwork;
use key_wallet::account::account_collection::DashpayAccountKey;
use key_wallet::managed_account::address_pool::AddressPool;
use key_wallet::managed_account::ManagedAccount;
use key_wallet::managed_account::ManagedCoreAccount;
use key_wallet::AccountType;

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

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

/// Get a reference to the inner managed account
pub fn inner(&self) -> &ManagedAccount {
pub fn inner(&self) -> &ManagedCoreAccount {
self.account.as_ref()
}
}
Expand Down
10 changes: 6 additions & 4 deletions key-wallet-ffi/src/managed_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,9 @@ mod tests {

#[test]
fn test_comprehensive_address_generation() {
use key_wallet::account::{ManagedAccount, ManagedAccountCollection, StandardAccountType};
use key_wallet::account::{
ManagedAccountCollection, ManagedCoreAccount, StandardAccountType,
};
use key_wallet::bip32::DerivationPath;
use key_wallet::managed_account::address_pool::{AddressPool, AddressPoolType};

Expand Down Expand Up @@ -894,7 +896,7 @@ mod tests {
)
.expect("Failed to create internal pool");

let managed_account = ManagedAccount::new(
let managed_account = ManagedCoreAccount::new(
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
Expand Down Expand Up @@ -1023,7 +1025,7 @@ mod tests {

#[test]
fn test_managed_wallet_get_balance() {
use key_wallet::wallet::balance::WalletBalance;
use key_wallet::wallet::balance::WalletCoreBalance;

let mut error = FFIError::success();

Expand All @@ -1046,7 +1048,7 @@ mod tests {
let mut managed_info = ManagedWalletInfo::from_wallet(wallet_arc);

// Set some test balance values
managed_info.balance = WalletBalance::new(1000000, 50000, 10000, 25000);
managed_info.balance = WalletCoreBalance::new(1000000, 50000, 10000, 25000);

let ffi_managed = FFIManagedWalletInfo::new(managed_info);
let ffi_managed_ptr = Box::into_raw(Box::new(ffi_managed));
Expand Down
2 changes: 1 addition & 1 deletion key-wallet-ffi/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ pub unsafe extern "C" fn wallet_check_transaction(

// Block on the async check_transaction call
let check_result = tokio::runtime::Handle::current()
.block_on(managed_info.check_transaction(&tx, context, wallet_mut, update_state));
.block_on(managed_info.check_core_transaction(&tx, context, wallet_mut, update_state));

// If we updated state, we need to update the wallet's managed info
// Note: This would require storing ManagedWalletInfo in FFIWallet
Expand Down
51 changes: 15 additions & 36 deletions key-wallet-ffi/src/transaction_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::types::{FFITransactionContext, FFIWallet};
use dashcore::consensus::Decodable;
use dashcore::Transaction;
use key_wallet::transaction_checking::{
account_checker::AccountTypeMatch, TransactionContext, WalletTransactionChecker,
account_checker::CoreAccountTypeMatch, TransactionContext, WalletTransactionChecker,
};
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;

Expand Down Expand Up @@ -209,7 +209,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(

// Block on the async check_transaction call
let check_result = tokio::runtime::Handle::current()
.block_on(managed_wallet.check_transaction(&tx, context, wallet_mut, update_state));
.block_on(managed_wallet.check_core_transaction(&tx, context, wallet_mut, update_state));

// Convert the result to FFI format
let affected_accounts = if check_result.affected_accounts.is_empty() {
Expand All @@ -219,7 +219,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(

for account_match in &check_result.affected_accounts {
match &account_match.account_type_match {
AccountTypeMatch::StandardBIP44 {
CoreAccountTypeMatch::StandardBIP44 {
account_index,
involved_receive_addresses,
involved_change_addresses,
Expand All @@ -240,7 +240,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::StandardBIP32 {
CoreAccountTypeMatch::StandardBIP32 {
account_index,
involved_receive_addresses,
involved_change_addresses,
Expand All @@ -261,7 +261,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::CoinJoin {
CoreAccountTypeMatch::CoinJoin {
account_index,
involved_addresses,
} => {
Expand All @@ -279,7 +279,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::IdentityRegistration {
CoreAccountTypeMatch::IdentityRegistration {
involved_addresses,
} => {
let ffi_match = FFIAccountMatch {
Expand All @@ -296,7 +296,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::IdentityTopUp {
CoreAccountTypeMatch::IdentityTopUp {
account_index,
involved_addresses,
} => {
Expand All @@ -314,7 +314,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::IdentityTopUpNotBound {
CoreAccountTypeMatch::IdentityTopUpNotBound {
involved_addresses,
} => {
let ffi_match = FFIAccountMatch {
Expand All @@ -331,7 +331,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::IdentityInvitation {
CoreAccountTypeMatch::IdentityInvitation {
involved_addresses,
} => {
let ffi_match = FFIAccountMatch {
Expand All @@ -348,7 +348,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::ProviderVotingKeys {
CoreAccountTypeMatch::ProviderVotingKeys {
involved_addresses,
} => {
let ffi_match = FFIAccountMatch {
Expand All @@ -365,7 +365,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::ProviderOwnerKeys {
CoreAccountTypeMatch::ProviderOwnerKeys {
involved_addresses,
} => {
let ffi_match = FFIAccountMatch {
Expand All @@ -382,7 +382,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::ProviderOperatorKeys {
CoreAccountTypeMatch::ProviderOperatorKeys {
involved_addresses,
} => {
let ffi_match = FFIAccountMatch {
Expand All @@ -399,7 +399,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::ProviderPlatformKeys {
CoreAccountTypeMatch::ProviderPlatformKeys {
involved_addresses,
} => {
let ffi_match = FFIAccountMatch {
Expand All @@ -416,7 +416,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::DashpayReceivingFunds {
CoreAccountTypeMatch::DashpayReceivingFunds {
account_index,
involved_addresses,
} => {
Expand All @@ -434,7 +434,7 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::DashpayExternalAccount {
CoreAccountTypeMatch::DashpayExternalAccount {
account_index,
involved_addresses,
} => {
Expand All @@ -452,27 +452,6 @@ pub unsafe extern "C" fn managed_wallet_check_transaction(
ffi_accounts.push(ffi_match);
continue;
}
AccountTypeMatch::PlatformPayment {
account_index,
involved_addresses,
..
} => {
// Note: Platform Payment addresses are NOT used in Core chain transactions
// per DIP-17. This branch should never be reached in practice.
let ffi_match = FFIAccountMatch {
account_type: 13, // PlatformPayment
account_index: *account_index,
registration_index: 0,
received: account_match.received,
sent: account_match.sent,
external_addresses_count: involved_addresses.len() as c_uint,
internal_addresses_count: 0,
has_external_addresses: !involved_addresses.is_empty(),
has_internal_addresses: false,
};
ffi_accounts.push(ffi_match);
continue;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions key-wallet-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub struct FFIBalance {
pub total: u64,
}

impl From<key_wallet::WalletBalance> for FFIBalance {
fn from(balance: key_wallet::WalletBalance) -> Self {
impl From<key_wallet::WalletCoreBalance> for FFIBalance {
fn from(balance: key_wallet::WalletCoreBalance) -> Self {
FFIBalance {
confirmed: balance.spendable(),
unconfirmed: balance.unconfirmed(),
Expand Down
16 changes: 8 additions & 8 deletions key-wallet-ffi/src/utxo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod utxo_tests {
use dashcore::blockdata::script::ScriptBuf;
use dashcore::{Address, OutPoint, TxOut, Txid};
use key_wallet::account::account_type::StandardAccountType;
use key_wallet::managed_account::ManagedAccount;
use key_wallet::managed_account::ManagedCoreAccount;
use key_wallet::utxo::Utxo;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
use key_wallet::Network;
Expand All @@ -191,7 +191,7 @@ mod utxo_tests {
let mut managed_info = ManagedWalletInfo::new(Network::Testnet, [1u8; 32]);

// Create a BIP44 account with UTXOs
let mut bip44_account = ManagedAccount::new(
let mut bip44_account = ManagedCoreAccount::new(
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
Expand Down Expand Up @@ -282,7 +282,7 @@ mod utxo_tests {
fn test_managed_wallet_get_utxos_multiple_accounts() {
use crate::managed_wallet::FFIManagedWalletInfo;
use key_wallet::account::account_type::StandardAccountType;
use key_wallet::managed_account::ManagedAccount;
use key_wallet::managed_account::ManagedCoreAccount;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
use key_wallet::Network;

Expand All @@ -294,7 +294,7 @@ mod utxo_tests {
let mut managed_info = ManagedWalletInfo::new(Network::Testnet, [2u8; 32]);

// Create BIP44 account with 2 UTXOs
let mut bip44_account = ManagedAccount::new(
let mut bip44_account = ManagedCoreAccount::new(
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
Expand All @@ -320,7 +320,7 @@ mod utxo_tests {
managed_info.accounts.insert(bip44_account);

// Create BIP32 account with 1 UTXO
let mut bip32_account = ManagedAccount::new(
let mut bip32_account = ManagedCoreAccount::new(
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP32Account,
Expand All @@ -346,7 +346,7 @@ mod utxo_tests {
managed_info.accounts.insert(bip32_account);

// Create CoinJoin account with 2 UTXOs
let mut coinjoin_account = ManagedAccount::new(
let mut coinjoin_account = ManagedCoreAccount::new(
ManagedAccountType::CoinJoin {
index: 0,
addresses: key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
Expand Down Expand Up @@ -385,7 +385,7 @@ mod utxo_tests {
fn test_managed_wallet_get_utxos() {
use crate::managed_wallet::FFIManagedWalletInfo;
use key_wallet::account::account_type::StandardAccountType;
use key_wallet::managed_account::ManagedAccount;
use key_wallet::managed_account::ManagedCoreAccount;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
use key_wallet::Network;

Expand All @@ -398,7 +398,7 @@ mod utxo_tests {
let mut managed_info = ManagedWalletInfo::new(Network::Testnet, [3u8; 32]);

// Add a UTXO to Testnet account
let mut testnet_account = ManagedAccount::new(
let mut testnet_account = ManagedCoreAccount::new(
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
Expand Down
12 changes: 8 additions & 4 deletions key-wallet-manager/src/wallet_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use key_wallet::wallet::managed_wallet_info::{ManagedWalletInfo, TransactionReco
use key_wallet::wallet::WalletType;
use key_wallet::Utxo;
use key_wallet::{Account, AccountType, Address, ExtendedPrivKey, Mnemonic, Network, Wallet};
use key_wallet::{ExtendedPubKey, WalletBalance};
use key_wallet::{ExtendedPubKey, WalletCoreBalance};
use std::collections::BTreeSet;
use std::str::FromStr;
use zeroize::Zeroize;
Expand Down Expand Up @@ -479,8 +479,9 @@ impl<T: WalletInfoInterface> WalletManager<T> {
let wallet_info_opt = self.wallet_infos.get_mut(&wallet_id);

if let (Some(wallet), Some(wallet_info)) = (wallet_opt, wallet_info_opt) {
let check_result =
wallet_info.check_transaction(tx, context, wallet, update_state_if_found).await;
let check_result = wallet_info
.check_core_transaction(tx, context, wallet, update_state_if_found)
.await;

// If the transaction is relevant
if check_result.is_relevant {
Expand Down Expand Up @@ -896,7 +897,10 @@ impl<T: WalletInfoInterface> WalletManager<T> {
}

/// Get balance for a specific wallet
pub fn get_wallet_balance(&self, wallet_id: &WalletId) -> Result<WalletBalance, WalletError> {
pub fn get_wallet_balance(
&self,
wallet_id: &WalletId,
) -> Result<WalletCoreBalance, WalletError> {
// Get the wallet info
let wallet_info =
self.wallet_infos.get(wallet_id).ok_or(WalletError::WalletNotFound(*wallet_id))?;
Expand Down
6 changes: 5 additions & 1 deletion key-wallet/src/account/account_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ impl From<AccountType> for AccountTypeToCheck {
} => AccountTypeToCheck::DashpayExternalAccount,
AccountType::PlatformPayment {
..
} => AccountTypeToCheck::PlatformPayment,
} => {
// Platform Payment accounts (DIP-17) operate on Dash Platform, not Core chain.
// They should never be converted to AccountTypeToCheck.
panic!("PlatformPayment accounts cannot be converted to AccountTypeToCheck")
}
}
}
}
Expand Down
Loading
Loading