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: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ version = "0.39.6"

[patch.crates-io]
dashcore_hashes = { path = "hashes" }
# Use fixed version of elliptic-curve-tools with DefaultIsZeroes trait bound
elliptic-curve-tools = { git = "https://github.com/QuantumExplorer/elliptic-curve-tools", branch = "fix/DefaultIsZeroesToSumOfProducts" }

[profile.release]
# Default to unwinding for most crates
Expand Down
4 changes: 3 additions & 1 deletion dash-network/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Dash network types shared across Dash crates

#[cfg(feature = "bincode")]
use bincode_derive::{Decode, Encode};
use std::fmt;

/// The cryptocurrency network to act on.
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
#[non_exhaustive]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
pub enum Network {
/// Classic Dash Core Payment Chain
Dash,
Expand Down
9 changes: 9 additions & 0 deletions dash/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,15 @@ pub enum Payload {
WitnessProgram(WitnessProgram),
}

impl Payload {
pub fn as_pubkey_hash(&self) -> Option<&PubkeyHash> {
match self {
Payload::PubkeyHash(pubkey_hash) => Some(pubkey_hash),
_ => None,
}
}
}

/// Witness program as defined in BIP141.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WitnessProgram {
Expand Down
2 changes: 1 addition & 1 deletion key-wallet-ffi/src/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub unsafe extern "C" fn wallet_get_account_balance(
let wallet = &*wallet;
let network_rust: key_wallet::Network = network.into();

use key_wallet::account::types::{AccountType, StandardAccountType};
use key_wallet::account::account_type::{AccountType, StandardAccountType};
let _account_type = AccountType::Standard {
index: account_index,
standard_account_type: StandardAccountType::BIP44Account,
Expand Down
5 changes: 5 additions & 0 deletions key-wallet-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ impl From<key_wallet::Error> for FFIError {
Error::KeyError(_) | Error::Bip32(_) | Error::Secp256k1(_) | Error::Base58 => {
(FFIErrorCode::WalletError, err.to_string())
}
Error::NoKeySource => {
(FFIErrorCode::InvalidState, "No key source available".to_string())
}
#[allow(unreachable_patterns)]
_ => (FFIErrorCode::WalletError, err.to_string()),
};

FFIError::error(code, msg)
Expand Down
21 changes: 10 additions & 11 deletions key-wallet-ffi/src/managed_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::ptr;

use crate::error::{FFIError, FFIErrorCode};
use crate::types::{FFINetwork, FFIWallet};
use key_wallet::account::address_pool::KeySource;
use key_wallet::managed_account::address_pool::{AddressPoolType, KeySource};
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;

/// FFI wrapper for ManagedWalletInfo
Expand Down Expand Up @@ -126,7 +126,7 @@ pub unsafe extern "C" fn managed_wallet_get_next_bip44_receive_address(

// Generate the next receive address
let xpub = account.extended_public_key();
match managed_account.get_next_receive_address(&xpub) {
match managed_account.next_receive_address(Some(&xpub)) {
Ok(address) => {
let address_str = address.to_string();
match CString::new(address_str) {
Expand Down Expand Up @@ -246,7 +246,7 @@ pub unsafe extern "C" fn managed_wallet_get_next_bip44_change_address(

// Generate the next change address
let xpub = account.extended_public_key();
match managed_account.get_next_change_address(&xpub) {
match managed_account.next_change_address(Some(&xpub)) {
Ok(address) => {
let address_str = address.to_string();
match CString::new(address_str) {
Expand Down Expand Up @@ -400,7 +400,7 @@ pub unsafe extern "C" fn managed_wallet_get_bip_44_external_address_range(
..
} = &mut managed_account.account_type
{
match external_addresses.get_address_range(start_index, end_index, &key_source) {
match external_addresses.address_range(start_index, end_index, &key_source) {
Ok(addrs) => addrs,
Err(e) => {
FFIError::set_error(
Expand Down Expand Up @@ -582,7 +582,7 @@ pub unsafe extern "C" fn managed_wallet_get_bip_44_internal_address_range(
..
} = &mut managed_account.account_type
{
match internal_addresses.get_address_range(start_index, end_index, &key_source) {
match internal_addresses.address_range(start_index, end_index, &key_source) {
Ok(addrs) => addrs,
Err(e) => {
FFIError::set_error(
Expand Down Expand Up @@ -732,6 +732,7 @@ mod tests {
use crate::managed_wallet::*;
use crate::types::FFINetwork;
use crate::wallet;
use key_wallet::managed_account::managed_account_type::ManagedAccountType;
use std::ffi::{CStr, CString};
use std::ptr;

Expand Down Expand Up @@ -924,12 +925,10 @@ mod tests {

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

let mut error = FFIError::success();
Comment on lines 926 to 933
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Tests use outdated imports and AddressPool::new signature

AddressPool moved to key_wallet::managed_account::address_pool and its new signature requires a KeySource and returns Result. Update imports and handle the Result. Also use the new ManagedAccount/ManagedAccountCollection paths.

-        use key_wallet::account::{ManagedAccount, ManagedAccountCollection, StandardAccountType};
+        use key_wallet::managed_account::{ManagedAccount, managed_account_collection::ManagedAccountCollection};
+        use key_wallet::account::StandardAccountType;
...
-        use key_wallet::managed_account::address_pool::AddressPool;
+        use key_wallet::managed_account::address_pool::{AddressPool, AddressPoolType, KeySource};
...
-        let external_pool = AddressPool::new(
+        let external_pool = AddressPool::new(
             DerivationPath::from(vec![key_wallet::bip32::ChildNumber::from_normal_idx(0).unwrap()]),
-            AddressPoolType::External,
-            20,
-            network,
-        );
+            AddressPoolType::External,
+            20,
+            network,
+            &KeySource::NoKeySource,
+        ).expect("external pool");
-        let internal_pool = AddressPool::new(
+        let internal_pool = AddressPool::new(
             DerivationPath::from(vec![key_wallet::bip32::ChildNumber::from_normal_idx(1).unwrap()]),
-            AddressPoolType::Internal,
-            20,
-            network,
-        );
+            AddressPoolType::Internal,
+            20,
+            network,
+            &KeySource::NoKeySource,
+        ).expect("internal pool");

Also applies to: 963-974, 970-974, 978-987, 989-991

🤖 Prompt for AI Agents
In key-wallet-ffi/src/managed_wallet.rs around lines 926-933 (and also update
the occurrences at 963-974, 970-974, 978-987, 989-991), the test imports and
AddressPool usage are outdated: change imports to use
key_wallet::managed_account::address_pool::AddressPool and update
ManagedAccount/ManagedAccountCollection to their current paths; call
AddressPool::new with the required KeySource parameter and handle the Result it
returns (propagate or unwrap in the test), and adjust any variable names or
types to match the new signatures so the test compiles.


Expand Down Expand Up @@ -963,13 +962,13 @@ mod tests {
// Create a managed account with address pools
let external_pool = AddressPool::new(
DerivationPath::from(vec![key_wallet::bip32::ChildNumber::from_normal_idx(0).unwrap()]),
false,
AddressPoolType::External,
20,
network,
);
let internal_pool = AddressPool::new(
DerivationPath::from(vec![key_wallet::bip32::ChildNumber::from_normal_idx(1).unwrap()]),
true,
AddressPoolType::Internal,
20,
network,
);
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 @@ -168,7 +168,7 @@ impl FFIAccountType {
index: u32,
registration_index: Option<u32>,
) -> Option<key_wallet::AccountType> {
use key_wallet::account::types::StandardAccountType;
use key_wallet::account::account_type::StandardAccountType;
match self {
FFIAccountType::StandardBIP44 => Some(key_wallet::AccountType::Standard {
index,
Expand Down Expand Up @@ -207,7 +207,7 @@ impl FFIAccountType {

/// Convert from AccountType
pub fn from_account_type(account_type: &key_wallet::AccountType) -> (Self, u32, Option<u32>) {
use key_wallet::account::types::StandardAccountType;
use key_wallet::account::account_type::StandardAccountType;
match account_type {
key_wallet::AccountType::Standard {
index,
Expand Down
121 changes: 61 additions & 60 deletions key-wallet-ffi/src/utxo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod utxo_tests {
use super::super::*;
use crate::error::{FFIError, FFIErrorCode};
use crate::types::FFINetwork;
use key_wallet::managed_account::managed_account_type::ManagedAccountType;
use std::ffi::CStr;
use std::ptr;

Expand Down Expand Up @@ -189,10 +190,10 @@ mod utxo_tests {
use crate::managed_wallet::FFIManagedWalletInfo;
use dashcore::blockdata::script::ScriptBuf;
use dashcore::{Address, OutPoint, TxOut, Txid};
use key_wallet::account::managed_account::ManagedAccount;
use key_wallet::account::managed_account_collection::ManagedAccountCollection;
use key_wallet::account::types::{ManagedAccountType, StandardAccountType};
use key_wallet::account::account_type::StandardAccountType;
use key_wallet::gap_limit::GapLimitManager;
use key_wallet::managed_account::managed_account_collection::ManagedAccountCollection;
use key_wallet::managed_account::ManagedAccount;
use key_wallet::utxo::Utxo;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
use key_wallet::Network;
Expand All @@ -211,16 +212,16 @@ mod utxo_tests {
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
external_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
external_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
},
Network::Testnet,
GapLimitManager::default(),
Expand Down Expand Up @@ -304,10 +305,10 @@ mod utxo_tests {
use crate::managed_wallet::FFIManagedWalletInfo;
use dashcore::blockdata::script::ScriptBuf;
use dashcore::{Address, OutPoint, TxOut, Txid};
use key_wallet::account::managed_account::ManagedAccount;
use key_wallet::account::managed_account_collection::ManagedAccountCollection;
use key_wallet::account::types::{ManagedAccountType, StandardAccountType};
use key_wallet::account::account_type::StandardAccountType;
use key_wallet::gap_limit::GapLimitManager;
use key_wallet::managed_account::managed_account_collection::ManagedAccountCollection;
use key_wallet::managed_account::ManagedAccount;
use key_wallet::utxo::Utxo;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
use key_wallet::Network;
Expand All @@ -325,16 +326,16 @@ mod utxo_tests {
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
external_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
external_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
},
Network::Testnet,
GapLimitManager::default(),
Expand Down Expand Up @@ -364,16 +365,16 @@ mod utxo_tests {
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP32Account,
external_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
external_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
},
Network::Testnet,
GapLimitManager::default(),
Expand All @@ -400,7 +401,7 @@ mod utxo_tests {
let mut coinjoin_account = ManagedAccount::new(
ManagedAccountType::CoinJoin {
index: 0,
addresses: key_wallet::account::address_pool::AddressPoolBuilder::default()
addresses: key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
Expand Down Expand Up @@ -456,10 +457,10 @@ mod utxo_tests {
use crate::managed_wallet::FFIManagedWalletInfo;
use dashcore::blockdata::script::ScriptBuf;
use dashcore::{Address, OutPoint, TxOut, Txid};
use key_wallet::account::managed_account::ManagedAccount;
use key_wallet::account::managed_account_collection::ManagedAccountCollection;
use key_wallet::account::types::{ManagedAccountType, StandardAccountType};
use key_wallet::account::account_type::StandardAccountType;
use key_wallet::gap_limit::GapLimitManager;
use key_wallet::managed_account::managed_account_collection::ManagedAccountCollection;
use key_wallet::managed_account::ManagedAccount;
use key_wallet::utxo::Utxo;
use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo;
use key_wallet::Network;
Expand All @@ -477,16 +478,16 @@ mod utxo_tests {
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
external_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
external_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
},
Network::Testnet,
GapLimitManager::default(),
Expand Down Expand Up @@ -516,16 +517,16 @@ mod utxo_tests {
ManagedAccountType::Standard {
index: 0,
standard_account_type: StandardAccountType::BIP44Account,
external_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses: key_wallet::account::address_pool::AddressPoolBuilder::default(
)
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
external_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
internal_addresses:
key_wallet::managed_account::address_pool::AddressPoolBuilder::default()
.base_path(key_wallet::DerivationPath::from(vec![]))
.build()
.unwrap(),
},
Network::Dash,
GapLimitManager::default(),
Expand Down
Loading
Loading