diff --git a/.github/ci-groups.yml b/.github/ci-groups.yml index e996ce208..8265011c0 100644 --- a/.github/ci-groups.yml +++ b/.github/ci-groups.yml @@ -6,6 +6,7 @@ groups: - dashcore - dashcore_hashes - dashcore-private + - dash-network spv: - dash-spv diff --git a/Cargo.toml b/Cargo.toml index 7be8607fa..dc4ad6587 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["dash", "hashes", "internals", "fuzz", "rpc-client", "rpc-json", "rpc-integration-test", "key-wallet", "key-wallet-manager", "key-wallet-ffi", "dash-spv", "dash-spv-ffi"] +members = ["dash", "dash-network", "hashes", "internals", "fuzz", "rpc-client", "rpc-json", "rpc-integration-test", "key-wallet", "key-wallet-manager", "key-wallet-ffi", "dash-spv", "dash-spv-ffi"] resolver = "2" [workspace.package] diff --git a/dash-network/Cargo.toml b/dash-network/Cargo.toml new file mode 100644 index 000000000..e8c5fa407 --- /dev/null +++ b/dash-network/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "dash-network" +version = { workspace = true } +edition = "2024" +authors = ["Dash Core Team"] +description = "The `Network` enum and its pure helpers (magic bytes, activation heights, default P2P ports) extracted from `dashcore` into a minimal-dependency crate so that lightweight consumers can depend on it without pulling in the full protocol library." +license = "MIT" +repository = "https://github.com/dashpay/rust-dashcore" + +[lib] +name = "dash_network" +path = "src/lib.rs" + +[features] +default = [] +# serde::{Serialize, Deserialize} impls for Network. +serde = ["dep:serde"] +# bincode::{Encode, Decode} impls for Network. +bincode = ["dep:bincode", "dep:bincode_derive"] +# C-ABI `FFINetwork` mirror + `dashcore_network_get_name` extern fn. +ffi = [] + +[dependencies] +serde = { version = "1.0.219", default-features = false, features = ["derive"], optional = true } +bincode = { version = "2.0.1", optional = true } +bincode_derive = { version = "2.0.1", optional = true } + +[build-dependencies] +cbindgen = "0.29" diff --git a/dash-network/build.rs b/dash-network/build.rs new file mode 100644 index 000000000..7bcf382a6 --- /dev/null +++ b/dash-network/build.rs @@ -0,0 +1,37 @@ +use std::{env, fs, path::Path}; + +fn main() { + if std::env::var("CARGO_FEATURE_FFI").is_ok() { + generate_bindings(); + } +} + +fn generate_bindings() { + let crate_name = env::var("CARGO_PKG_NAME").unwrap(); + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let out_dir = env::var("OUT_DIR").unwrap(); + + println!("cargo:rerun-if-changed=cbindgen.toml"); + println!("cargo:rerun-if-changed=src/"); + + let target_dir = Path::new(&out_dir) + .ancestors() + .nth(3) // This line moves up to the target/ directory + .expect("Failed to find target dir"); + + let include_dir = target_dir.join("include").join(&crate_name); + + fs::create_dir_all(&include_dir).unwrap(); + + let output_path = include_dir.join(format!("{}.h", &crate_name)); + + let config_path = Path::new(&crate_dir).join("cbindgen.toml"); + let config = cbindgen::Config::from_file(&config_path).expect("Failed to read cbindgen.toml"); + + cbindgen::Builder::new() + .with_crate(&crate_dir) + .with_config(config) + .generate() + .expect("Unable to generate bindings") + .write_to_file(&output_path); +} diff --git a/dash/cbindgen.toml b/dash-network/cbindgen.toml similarity index 89% rename from dash/cbindgen.toml rename to dash-network/cbindgen.toml index f29c577fd..177ad2c9c 100644 --- a/dash/cbindgen.toml +++ b/dash-network/cbindgen.toml @@ -1,6 +1,6 @@ language = "C" header = "/* dashcore C bindings - Auto-generated by cbindgen */" -include_guard = "DASHCORE_H" +include_guard = "DASH_NETWORK_H" autogen_warning = "/* Warning: This file is auto-generated by cbindgen. Do not modify manually. */" include_version = true diff --git a/dash/src/ffi/network.rs b/dash-network/src/ffi.rs similarity index 92% rename from dash/src/ffi/network.rs rename to dash-network/src/ffi.rs index 4eb4c311d..532d3a6d4 100644 --- a/dash/src/ffi/network.rs +++ b/dash-network/src/ffi.rs @@ -34,6 +34,10 @@ impl From for Network { } } +/// Return a pointer to the canonical lowercase name of `network`. +/// +/// The returned pointer is to a static null-terminated string owned by +/// `dash-network`; callers must not free it. #[unsafe(no_mangle)] pub extern "C" fn dashcore_network_get_name(network: FFINetwork) -> *const ffi::c_char { match network { diff --git a/dash-network/src/lib.rs b/dash-network/src/lib.rs new file mode 100644 index 000000000..e94e181cc --- /dev/null +++ b/dash-network/src/lib.rs @@ -0,0 +1,219 @@ +//! The Dash [`Network`] enum and its pure helpers, extracted from the main +//! `dashcore` crate so that lightweight consumers can depend on it without +//! pulling in the full protocol library. +//! +//! This crate carries **no** dependencies beyond its optional `serde` / +//! `bincode` impls. If you need Network::known_genesis_block_hash — which +//! returns a `BlockHash` — use the extension trait provided by `dashcore`. +//! +//! # Example +//! +//! ```rust +//! use dash_network::Network; +//! +//! assert_eq!(Network::Mainnet.magic(), 0xBD6B0CBF); +//! assert_eq!(Network::from_magic(0xBD6B0CBF), Some(Network::Mainnet)); +//! assert_eq!("testnet".parse::().unwrap(), Network::Testnet); +//! assert_eq!(Network::Mainnet.default_p2p_port(), 9999); +//! ``` + +use core::fmt; + +#[cfg(feature = "ffi")] +pub mod ffi; + +#[cfg(feature = "bincode")] +use bincode_derive::{Decode, Encode}; + +/// The Dash 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"))] +#[cfg_attr(feature = "bincode", derive(Encode, Decode))] +#[repr(u8)] +pub enum Network { + /// Dash mainnet, the production network for real transactions. + Mainnet, + /// Dash public test network for protocol-level testing without real funds. + Testnet, + /// Dash development network, an isolated environment for feature development and testing. + Devnet, + /// Local regression testing network for deterministic, offline testing with instant block generation. + Regtest, +} + +impl Network { + /// Creates a `Network` from the network magic bytes. + /// + /// # Examples + /// + /// ```rust + /// use dash_network::Network; + /// + /// assert_eq!(Some(Network::Mainnet), Network::from_magic(0xBD6B0CBF)); + /// assert_eq!(None, Network::from_magic(0xFFFFFFFF)); + /// ``` + pub const fn from_magic(magic: u32) -> Option { + // Note: any new entries here must be added to `magic` below. + match magic { + 0xBD6B0CBF => Some(Network::Mainnet), + 0xFFCAE2CE => Some(Network::Testnet), + 0xCEFFCAE2 => Some(Network::Devnet), + 0xDCB7C1FC => Some(Network::Regtest), + _ => None, + } + } + + /// Return the network magic bytes, which should be encoded little-endian + /// at the start of every message + /// + /// # Examples + /// + /// ```rust + /// use dash_network::Network; + /// + /// let network = Network::Mainnet; + /// assert_eq!(network.magic(), 0xBD6B0CBF); + /// ``` + pub const fn magic(self) -> u32 { + // Note: any new entries here must be added to `from_magic` above. + match self { + Network::Mainnet => 0xBD6B0CBF, + Network::Testnet => 0xFFCAE2CE, + Network::Devnet => 0xCEFFCAE2, + Network::Regtest => 0xDCB7C1FC, + } + } + + /// The block height at which Dash consensus version 20 activates. + /// + /// Devnet and regtest activate V20 immediately (height 0). + pub const fn v20_activation_height(self) -> u32 { + match self { + Network::Mainnet => 1_987_776, + Network::Testnet => 905_100, + // Devnet and regtest activate V20 immediately. + Network::Devnet | Network::Regtest => 0, + } + } + + /// The default P2P port for this network. + /// + /// Regtest's default is the typical Dash Core regtest value; devnets can + /// vary and should usually come from configuration. + /// + /// # Examples + /// + /// ```rust + /// use dash_network::Network; + /// + /// assert_eq!(Network::Mainnet.default_p2p_port(), 9999); + /// assert_eq!(Network::Testnet.default_p2p_port(), 19999); + /// ``` + pub const fn default_p2p_port(self) -> u16 { + match self { + Network::Mainnet => 9999, + Network::Testnet => 19999, + Network::Devnet => 19799, + Network::Regtest => 19899, + } + } +} + +impl fmt::Display for Network { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(match self { + Network::Mainnet => "mainnet", + Network::Testnet => "testnet", + Network::Devnet => "devnet", + Network::Regtest => "regtest", + }) + } +} + +impl core::str::FromStr for Network { + type Err = ParseNetworkError; + + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + "mainnet" | "main" => Ok(Network::Mainnet), + "testnet" | "test" => Ok(Network::Testnet), + "devnet" | "dev" => Ok(Network::Devnet), + "regtest" => Ok(Network::Regtest), + _ => Err(ParseNetworkError(s.to_string())), + } + } +} + +/// Error returned from Network::from_str when the input doesn't name a +/// known network. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct ParseNetworkError(pub String); + +impl fmt::Display for ParseNetworkError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "unknown network type: {}", self.0) + } +} + +impl std::error::Error for ParseNetworkError {} + +// ---------- Tests ---------- + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn magic_round_trip_covers_all_variants() { + for n in [Network::Mainnet, Network::Testnet, Network::Devnet, Network::Regtest] { + let magic = n.magic(); + assert_eq!(Network::from_magic(magic), Some(n), "round-trip failed for {:?}", n); + } + } + + #[test] + fn from_magic_unknown_is_none() { + assert_eq!(Network::from_magic(0), None); + assert_eq!(Network::from_magic(0xFFFFFFFF), None); + } + + #[test] + fn from_str_accepts_aliases_and_is_case_insensitive() { + assert_eq!("MAINNET".parse::().unwrap(), Network::Mainnet); + assert_eq!("main".parse::().unwrap(), Network::Mainnet); + assert_eq!("Testnet".parse::().unwrap(), Network::Testnet); + assert_eq!("test".parse::().unwrap(), Network::Testnet); + assert_eq!("devnet".parse::().unwrap(), Network::Devnet); + assert_eq!("dev".parse::().unwrap(), Network::Devnet); + assert_eq!("regtest".parse::().unwrap(), Network::Regtest); + } + + #[test] + fn from_str_rejects_nonsense() { + let err = "bogus".parse::().unwrap_err(); + assert_eq!(err.0, "bogus"); + } + + #[test] + fn display_matches_canonical_lowercase() { + assert_eq!(Network::Mainnet.to_string(), "mainnet"); + assert_eq!(Network::Testnet.to_string(), "testnet"); + assert_eq!(Network::Devnet.to_string(), "devnet"); + assert_eq!(Network::Regtest.to_string(), "regtest"); + } + + #[test] + fn activation_heights_are_stable() { + assert_eq!(Network::Mainnet.v20_activation_height(), 1_987_776); + assert_eq!(Network::Testnet.v20_activation_height(), 905_100); + assert_eq!(Network::Devnet.v20_activation_height(), 0); + assert_eq!(Network::Regtest.v20_activation_height(), 0); + } + + #[test] + fn default_p2p_ports_match_conventions() { + assert_eq!(Network::Mainnet.default_p2p_port(), 9999); + assert_eq!(Network::Testnet.default_p2p_port(), 19999); + } +} diff --git a/dash-spv-ffi/Cargo.toml b/dash-spv-ffi/Cargo.toml index d44969dae..7521ba57a 100644 --- a/dash-spv-ffi/Cargo.toml +++ b/dash-spv-ffi/Cargo.toml @@ -13,7 +13,8 @@ crate-type = ["cdylib", "staticlib", "rlib"] [dependencies] dash-spv = { path = "../dash-spv" } -dashcore = { path = "../dash", package = "dashcore", features= ["ffi"] } +dashcore = { path = "../dash" } +dash-network = { path = "../dash-network", features = ["ffi"] } tokio = { version = "1", features = ["full"] } tokio-util = "0.7" hex = "0.4" diff --git a/dash-spv-ffi/cbindgen.toml b/dash-spv-ffi/cbindgen.toml index 41e113a0b..ebb6cbc9c 100644 --- a/dash-spv-ffi/cbindgen.toml +++ b/dash-spv-ffi/cbindgen.toml @@ -4,7 +4,7 @@ include_guard = "DASH_SPV_FFI_H" autogen_warning = "/* Warning: This file is auto-generated by cbindgen. Do not modify manually. */" include_version = true cpp_compat = true -includes = ["../key-wallet-ffi/key-wallet-ffi.h", "../dashcore/dashcore.h"] +includes = ["../key-wallet-ffi/key-wallet-ffi.h", "../dash-network/dash-network.h"] [export] include = ["FFI"] diff --git a/dash-spv-ffi/src/bin/ffi_cli.rs b/dash-spv-ffi/src/bin/ffi_cli.rs index 348452d0b..1ffd967be 100644 --- a/dash-spv-ffi/src/bin/ffi_cli.rs +++ b/dash-spv-ffi/src/bin/ffi_cli.rs @@ -3,9 +3,8 @@ use std::os::raw::{c_char, c_void}; use std::ptr; use clap::{Arg, ArgAction, Command}; - +use dash_network::ffi::FFINetwork; use dash_spv_ffi::*; -use dashcore::ffi::FFINetwork; use key_wallet_ffi::managed_account::FFITransactionRecord; use key_wallet_ffi::types::FFITransactionContext; use key_wallet_ffi::wallet_manager::wallet_manager_add_wallet_from_mnemonic; diff --git a/dash-spv-ffi/src/config.rs b/dash-spv-ffi/src/config.rs index e60f65138..fdd01dcb7 100644 --- a/dash-spv-ffi/src/config.rs +++ b/dash-spv-ffi/src/config.rs @@ -1,7 +1,7 @@ use crate::{null_check, set_last_error, FFIErrorCode, FFIMempoolStrategy}; use dash_spv::{ClientConfig, ValidationMode}; -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; use std::ffi::CStr; use std::net::{IpAddr, SocketAddr, ToSocketAddrs}; use std::os::raw::c_char; @@ -119,7 +119,6 @@ pub unsafe extern "C" fn dash_spv_ffi_config_add_peer( dashcore::Network::Testnet => 19999, dashcore::Network::Regtest => 19899, dashcore::Network::Devnet => 29999, - _ => 9999, }; let addr_str = match CStr::from_ptr(addr).to_str() { diff --git a/dash-spv-ffi/tests/dashd_sync/context.rs b/dash-spv-ffi/tests/dashd_sync/context.rs index d9b4699a5..2c015e761 100644 --- a/dash-spv-ffi/tests/dashd_sync/context.rs +++ b/dash-spv-ffi/tests/dashd_sync/context.rs @@ -7,6 +7,10 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; +use super::callbacks::{ + create_network_callbacks, create_sync_callbacks, create_wallet_callbacks, CallbackTracker, +}; +use dash_network::ffi::FFINetwork; use dash_spv::logging::{LogFileConfig, LoggingConfig, LoggingGuard}; use dash_spv::test_utils::{retain_test_dir, SYNC_TIMEOUT}; use dash_spv_ffi::client::{ @@ -21,7 +25,6 @@ use dash_spv_ffi::config::{ }; use dash_spv_ffi::types::FFIWalletManager as FFIWalletManagerOpaque; use dash_spv_ffi::FFIEventCallbacks; -use dashcore::ffi::FFINetwork; use dashcore::hashes::Hash; use dashcore::{Address, Txid}; use key_wallet_ffi::managed_account::{ @@ -43,10 +46,6 @@ use key_wallet_ffi::{ }; use tempfile::TempDir; -use super::callbacks::{ - create_network_callbacks, create_sync_callbacks, create_wallet_callbacks, CallbackTracker, -}; - /// State that stays fixed across client restarts (temp dir, logging, config). struct FixedState { _temp_dir: TempDir, diff --git a/dash-spv-ffi/tests/test_client.rs b/dash-spv-ffi/tests/test_client.rs index f3615a17b..11397b1cb 100644 --- a/dash-spv-ffi/tests/test_client.rs +++ b/dash-spv-ffi/tests/test_client.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { + use dash_network::ffi::FFINetwork; use dash_spv_ffi::*; - use dashcore::ffi::FFINetwork; use serial_test::serial; use std::ffi::CString; use tempfile::TempDir; diff --git a/dash-spv-ffi/tests/test_config.rs b/dash-spv-ffi/tests/test_config.rs index caf7013ee..634bd0953 100644 --- a/dash-spv-ffi/tests/test_config.rs +++ b/dash-spv-ffi/tests/test_config.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { + use dash_network::ffi::FFINetwork; use dash_spv_ffi::*; - use dashcore::ffi::FFINetwork; use serial_test::serial; use std::ffi::CString; diff --git a/dash-spv-ffi/tests/test_types.rs b/dash-spv-ffi/tests/test_types.rs index 417f87d3c..4b807fa9a 100644 --- a/dash-spv-ffi/tests/test_types.rs +++ b/dash-spv-ffi/tests/test_types.rs @@ -1,12 +1,11 @@ #[cfg(test)] mod tests { + use dash_network::ffi::FFINetwork; use dash_spv::sync::{ BlockHeadersProgress, BlocksProgress, ChainLockProgress, FilterHeadersProgress, FiltersProgress, InstantSendProgress, MasternodesProgress, SyncProgress, SyncState, }; use dash_spv_ffi::*; - use dashcore::ffi::FFINetwork; - #[test] fn test_ffi_string_new_and_destroy() { let test_str = "Hello, FFI!"; diff --git a/dash-spv-ffi/tests/test_wallet_manager.rs b/dash-spv-ffi/tests/test_wallet_manager.rs index 1c173a680..dde3af4d6 100644 --- a/dash-spv-ffi/tests/test_wallet_manager.rs +++ b/dash-spv-ffi/tests/test_wallet_manager.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { + use dash_network::ffi::FFINetwork; use dash_spv_ffi::*; - use dashcore::ffi::FFINetwork; use key_wallet::wallet::initialization::WalletAccountCreationOptions; use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo; use key_wallet_ffi::{ diff --git a/dash-spv-ffi/tests/unit/test_async_operations.rs b/dash-spv-ffi/tests/unit/test_async_operations.rs index b6f5a4c94..0a3d9613e 100644 --- a/dash-spv-ffi/tests/unit/test_async_operations.rs +++ b/dash-spv-ffi/tests/unit/test_async_operations.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { use crate::*; - use dashcore::ffi::FFINetwork; + use dash_network::ffi::FFINetwork; use serial_test::serial; use std::ffi::CString; use std::os::raw::c_void; diff --git a/dash-spv-ffi/tests/unit/test_client_lifecycle.rs b/dash-spv-ffi/tests/unit/test_client_lifecycle.rs index ee2544af6..bf50abeb7 100644 --- a/dash-spv-ffi/tests/unit/test_client_lifecycle.rs +++ b/dash-spv-ffi/tests/unit/test_client_lifecycle.rs @@ -6,7 +6,7 @@ #[cfg(test)] mod tests { use crate::*; - use dashcore::ffi::FFINetwork; + use dash_network::ffi::FFINetwork; use serial_test::serial; use std::ffi::CString; use std::sync::mpsc; diff --git a/dash-spv-ffi/tests/unit/test_configuration.rs b/dash-spv-ffi/tests/unit/test_configuration.rs index f8bc76239..513638333 100644 --- a/dash-spv-ffi/tests/unit/test_configuration.rs +++ b/dash-spv-ffi/tests/unit/test_configuration.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { use crate::*; - use dashcore::ffi::FFINetwork; + use dash_network::ffi::FFINetwork; use serial_test::serial; use std::ffi::CString; diff --git a/dash-spv-ffi/tests/unit/test_error_handling.rs b/dash-spv-ffi/tests/unit/test_error_handling.rs index 61b24fe70..134620520 100644 --- a/dash-spv-ffi/tests/unit/test_error_handling.rs +++ b/dash-spv-ffi/tests/unit/test_error_handling.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { use crate::*; - use dashcore::ffi::FFINetwork; + use dash_network::ffi::FFINetwork; use serial_test::serial; use std::ffi::CStr; use std::sync::{Arc, Barrier}; diff --git a/dash-spv-ffi/tests/unit/test_memory_management.rs b/dash-spv-ffi/tests/unit/test_memory_management.rs index 9acd7ab2a..04194c2c9 100644 --- a/dash-spv-ffi/tests/unit/test_memory_management.rs +++ b/dash-spv-ffi/tests/unit/test_memory_management.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { use crate::*; - use dashcore::ffi::FFINetwork; + use dash_network::ffi::FFINetwork; use serial_test::serial; use std::ffi::{CStr, CString}; use std::os::raw::{c_char, c_void}; diff --git a/dash-spv-ffi/tests/unit/test_type_conversions.rs b/dash-spv-ffi/tests/unit/test_type_conversions.rs index b5e17b432..127702774 100644 --- a/dash-spv-ffi/tests/unit/test_type_conversions.rs +++ b/dash-spv-ffi/tests/unit/test_type_conversions.rs @@ -1,8 +1,7 @@ #[cfg(test)] mod tests { - use dashcore::ffi::FFINetwork; - use crate::*; + use dash_network::ffi::FFINetwork; #[test] fn test_ffi_string_utf8_edge_cases() { diff --git a/dash-spv/src/client/lifecycle.rs b/dash-spv/src/client/lifecycle.rs index f65f4cf9d..0ae87165d 100644 --- a/dash-spv/src/client/lifecycle.rs +++ b/dash-spv/src/client/lifecycle.rs @@ -8,9 +8,6 @@ //! - Genesis block initialization //! - Wallet data loading -use std::sync::Arc; -use tokio::sync::{Mutex, RwLock}; - use super::{ClientConfig, DashSpvClient, EventHandler}; use crate::chain::checkpoints::{mainnet_checkpoints, testnet_checkpoints, CheckpointManager}; use crate::error::{Result, SpvError}; @@ -23,9 +20,12 @@ use crate::sync::{ BlockHeadersManager, BlocksManager, ChainLockManager, FilterHeadersManager, FiltersManager, InstantSendManager, Managers, MasternodesManager, MempoolManager, SyncCoordinator, }; +use dashcore::network::constants::NetworkExt; use dashcore::sml::masternode_list_engine::MasternodeListEngine; use dashcore_hashes::Hash; use key_wallet_manager::WalletInterface; +use std::sync::Arc; +use tokio::sync::{Mutex, RwLock}; impl DashSpvClient diff --git a/dash/Cargo.toml b/dash/Cargo.toml index ff25a7334..a6574f853 100644 --- a/dash/Cargo.toml +++ b/dash/Cargo.toml @@ -23,7 +23,7 @@ default = ["secp-recovery", "bincode" ] base64 = [ "base64-compat" ] rand-std = ["secp256k1/rand"] rand = ["secp256k1/rand"] -serde = ["dep:serde", "dashcore_hashes/serde", "secp256k1/serde"] +serde = ["dep:serde", "dashcore_hashes/serde", "secp256k1/serde", "dash-network/serde"] secp-lowmemory = ["secp256k1/lowmemory"] secp-recovery = ["secp256k1/recovery"] signer = ["secp-recovery", "rand", "base64"] @@ -32,8 +32,7 @@ bls = ["blsful"] eddsa = ["ed25519-dalek"] quorum_validation = ["bls"] message_verification = ["bls"] -bincode = [ "dep:bincode", "dep:bincode_derive", "dashcore_hashes/bincode" ] -ffi = [] +bincode = [ "dep:bincode", "dep:bincode_derive", "dashcore_hashes/bincode", "dash-network/bincode" ] test-utils = [] [package.metadata.docs.rs] @@ -44,6 +43,7 @@ rustdoc-args = ["--cfg", "docsrs"] internals = { path = "../internals", package = "dashcore-private" } bech32 = { version = "0.9.1" } dashcore_hashes = { path = "../hashes" } +dash-network = { path = "../dash-network" } secp256k1 = { features = ["hashes"], version= "0.30.0" } rustversion = { version="1.0.20"} serde = { version = "1.0.219", default-features = false, features = [ "derive", "alloc" ], optional = true } @@ -73,9 +73,6 @@ dashcore = { path = ".", features = ["core-block-hash-use-x11", "message_verific criterion = "0.5" key-wallet = { path = "../key-wallet" } -[build-dependencies] -cbindgen = "0.29" - [[example]] name = "handshake" diff --git a/dash/build.rs b/dash/build.rs index fb94f768d..4621b7f12 100644 --- a/dash/build.rs +++ b/dash/build.rs @@ -1,10 +1,4 @@ -use std::{env, fs, path::Path}; - fn main() { - if std::env::var("CARGO_FEATURE_FFI").is_ok() { - generate_bindings(); - } - let rustc = std::env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); let output = std::process::Command::new(rustc) .arg("--version") @@ -35,33 +29,3 @@ fn main() { } } } - -fn generate_bindings() { - let crate_name = env::var("CARGO_PKG_NAME").unwrap(); - let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); - let out_dir = env::var("OUT_DIR").unwrap(); - - println!("cargo:rerun-if-changed=cbindgen.toml"); - println!("cargo:rerun-if-changed=src/"); - - let target_dir = Path::new(&out_dir) - .ancestors() - .nth(3) // This line moves up to the target/ directory - .expect("Failed to find target dir"); - - let include_dir = target_dir.join("include").join(&crate_name); - - fs::create_dir_all(&include_dir).unwrap(); - - let output_path = include_dir.join(format!("{}.h", &crate_name)); - - let config_path = Path::new(&crate_dir).join("cbindgen.toml"); - let config = cbindgen::Config::from_file(&config_path).expect("Failed to read cbindgen.toml"); - - cbindgen::Builder::new() - .with_crate(&crate_dir) - .with_config(config) - .generate() - .expect("Unable to generate bindings") - .write_to_file(&output_path); -} diff --git a/dash/src/ffi/mod.rs b/dash/src/ffi/mod.rs deleted file mode 100644 index 48f80d4b7..000000000 --- a/dash/src/ffi/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod network; - -pub use network::FFINetwork; diff --git a/dash/src/lib.rs b/dash/src/lib.rs index 7f171d8a7..1b74873db 100644 --- a/dash/src/lib.rs +++ b/dash/src/lib.rs @@ -90,40 +90,29 @@ mod parse; #[cfg(feature = "serde")] pub mod serde_utils; -/// cbindgen:ignore #[macro_use] pub mod network; pub mod address; -/// cbindgen:ignore pub mod amount; pub mod base58; pub mod bip152; pub mod bip158; -/// cbindgen:ignore pub mod blockdata; -/// cbindgen:ignore pub mod bloom; -/// cbindgen:ignore pub mod consensus; // Private until we either make this a crate or flatten it - still to be decided. pub mod bls_sig_utils; pub mod crypto; pub mod ephemerealdata; pub mod error; -#[cfg(feature = "ffi")] -pub mod ffi; pub mod hash_types; pub mod merkle_tree; -/// cbindgen:ignore pub mod policy; -/// cbindgen:ignore pub mod pow; pub mod sign_message; pub mod signer; -/// cbindgen:ignore pub mod sml; pub mod string; -/// cbindgen:ignore pub mod taproot; pub mod util; @@ -152,7 +141,7 @@ pub use crate::hash_types::{ TxMerkleNode, Txid, WPubkeyHash, WScriptHash, Wtxid, }; pub use crate::merkle_tree::MerkleBlock; -pub use crate::network::constants::Network; +pub use crate::network::constants::{Network, ParseNetworkError}; pub use crate::pow::{CompactTarget, Target, Work}; pub use crate::transaction::outpoint::OutPoint; pub use crate::transaction::txin::TxIn; diff --git a/dash/src/network/constants.rs b/dash/src/network/constants.rs index 64beddac1..324789cf6 100644 --- a/dash/src/network/constants.rs +++ b/dash/src/network/constants.rs @@ -18,26 +18,15 @@ //! Dash network constants. //! //! This module provides various constants relating to the Dash network -//! protocol, such as protocol versioning and magic header bytes and the -//! different network types supported by Dash. -//! -//! # Example: encoding a network's magic bytes -//! -//! ```rust -//! use dashcore::Network; -//! use dashcore::consensus::encode::serialize; -//! -//! let network = Network::Mainnet; -//! let bytes = serialize(&network.magic()); -//! -//! assert_eq!(&bytes[..], &[0xBF, 0x0C, 0x6B, 0xBD]); -//! ``` +//! protocol. use core::convert::From; use core::{fmt, ops}; use hashes::Hash; +pub use dash_network::{Network, ParseNetworkError}; + use crate::consensus::encode::{self, Decodable, Encodable}; use crate::{BlockHash, io}; @@ -61,71 +50,16 @@ pub const NODE_HEADERS_COMPRESSED: ServiceFlags = ServiceFlags::NODE_HEADERS_COM /// 60001 - Support `pong` message and nonce in `ping` message pub const PROTOCOL_VERSION: u32 = 70237; -#[cfg(feature = "bincode")] -use bincode_derive::{Decode, Encode}; - -/// 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] -#[repr(u8)] -#[cfg_attr(feature = "bincode", derive(Encode, Decode))] -pub enum Network { - /// Dash mainnet, the production network for real transactions. - Mainnet, - /// Dash public test network for protocol-level testing without real funds. - Testnet, - /// Dash development network, an isolated environment for feature development and testing. - Devnet, - /// Local regression testing network for deterministic, offline testing with instant block generation. - Regtest, -} - -impl Network { - /// Creates a `Network` from the magic bytes. - /// - /// # Examples - /// - /// ```rust - /// use dashcore::Network; - /// - /// assert_eq!(Some(Network::Mainnet), Network::from_magic(0xBD6B0CBF)); - /// assert_eq!(None, Network::from_magic(0xFFFFFFFF)); - /// ``` - pub fn from_magic(magic: u32) -> Option { - // Note: any new entries here must be added to `magic` below - match magic { - 0xBD6B0CBF => Some(Network::Mainnet), - 0xFFCAE2CE => Some(Network::Testnet), - 0xCEFFCAE2 => Some(Network::Devnet), - 0xDCB7C1FC => Some(Network::Regtest), - _ => None, - } - } - - /// Return the network magic bytes, which should be encoded little-endian - /// at the start of every message - /// - /// # Examples +pub trait NetworkExt { + /// Returns the known genesis block hash for `network`, if one is hardcoded. /// - /// ```rust - /// use dashcore::Network; - /// - /// let network = Network::Mainnet; - /// assert_eq!(network.magic(), 0xBD6B0CBF); - /// ``` - pub fn magic(self) -> u32 { - // Note: any new entries here must be added to `from_magic` above - match self { - Network::Mainnet => 0xBD6B0CBF, - Network::Testnet => 0xFFCAE2CE, - Network::Devnet => 0xCEFFCAE2, - Network::Regtest => 0xDCB7C1FC, - } - } + /// `Network::Devnet` returns `None` because devnets use dynamically-generated + /// genesis blocks. + fn known_genesis_block_hash(&self) -> Option; +} - pub fn known_genesis_block_hash(&self) -> Option { +impl NetworkExt for Network { + fn known_genesis_block_hash(&self) -> Option { match self { Network::Mainnet => { let mut block_hash = @@ -151,42 +85,7 @@ impl Network { } } } - - pub fn v20_activation_height(&self) -> u32 { - match self { - Network::Mainnet => 1_987_776, - Network::Testnet => 905_100, - // Devnet and regtest activate V20 immediately - _ => 0, - } - } } - -impl fmt::Display for Network { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - Network::Mainnet => write!(f, "mainnet"), - Network::Testnet => write!(f, "testnet"), - Network::Devnet => write!(f, "devnet"), - Network::Regtest => write!(f, "regtest"), - } - } -} - -impl std::str::FromStr for Network { - type Err = String; - - fn from_str(s: &str) -> Result { - match s.to_lowercase().as_str() { - "mainnet" | "main" => Ok(Network::Mainnet), - "testnet" | "test" => Ok(Network::Testnet), - "devnet" | "dev" => Ok(Network::Devnet), - "regtest" => Ok(Network::Regtest), - _ => Err(format!("Unknown network type: {}", s)), - } - } -} - /// Flags to indicate which network services a node supports. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ServiceFlags(u64); diff --git a/dash/src/sml/masternode_list/from_diff.rs b/dash/src/sml/masternode_list/from_diff.rs index 866101279..54c62e450 100644 --- a/dash/src/sml/masternode_list/from_diff.rs +++ b/dash/src/sml/masternode_list/from_diff.rs @@ -1,6 +1,7 @@ use crate::bls_sig_utils::BLSSignature; use crate::Network; +use crate::network::constants::NetworkExt; use crate::network::message_sml::MnListDiff; use crate::sml::error::SmlError; use crate::sml::llmq_entry_verification::{ diff --git a/dash/src/sml/masternode_list_engine/mod.rs b/dash/src/sml/masternode_list_engine/mod.rs index 3d1fc8bea..064b58d68 100644 --- a/dash/src/sml/masternode_list_engine/mod.rs +++ b/dash/src/sml/masternode_list_engine/mod.rs @@ -10,6 +10,7 @@ use std::collections::{BTreeMap, BTreeSet}; use crate::Network; use crate::bls_sig_utils::{BLSPublicKey, BLSSignature}; +use crate::network::constants::NetworkExt; use crate::network::message_qrinfo::{QRInfo, QuorumSnapshot}; use crate::network::message_sml::MnListDiff; use crate::prelude::CoreBlockHeight; diff --git a/ffi-c-tests/header-tests/all.c b/ffi-c-tests/header-tests/all.c index bf656c5c9..0a23b0c35 100644 --- a/ffi-c-tests/header-tests/all.c +++ b/ffi-c-tests/header-tests/all.c @@ -1,5 +1,5 @@ #include "dash-spv-ffi/dash-spv-ffi.h" #include "key-wallet-ffi/key-wallet-ffi.h" -#include "dashcore/dashcore.h" +#include "dash-network/dash-network.h" int main() { return 0; } diff --git a/ffi-c-tests/header-tests/dash-network.c b/ffi-c-tests/header-tests/dash-network.c new file mode 100644 index 000000000..cd1657070 --- /dev/null +++ b/ffi-c-tests/header-tests/dash-network.c @@ -0,0 +1,3 @@ +#include "dash-network/dash-network.h" + +int main() { return 0; } diff --git a/ffi-c-tests/header-tests/dashcore.c b/ffi-c-tests/header-tests/dashcore.c deleted file mode 100644 index 1352b44ec..000000000 --- a/ffi-c-tests/header-tests/dashcore.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "dashcore/dashcore.h" - -int main() { return 0; } diff --git a/key-wallet-ffi/Cargo.toml b/key-wallet-ffi/Cargo.toml index 41acd93df..3237e0579 100644 --- a/key-wallet-ffi/Cargo.toml +++ b/key-wallet-ffi/Cargo.toml @@ -22,7 +22,8 @@ bls = ["dashcore/bls", "key-wallet/bls"] [dependencies] key-wallet = { path = "../key-wallet" } key-wallet-manager = { path = "../key-wallet-manager" } -dashcore = { path = "../dash", features = ["ffi"] } +dashcore = { path = "../dash" } +dash-network = { path = "../dash-network", features = ["ffi"] } secp256k1 = { version = "0.30.0", features = ["global-context"] } tokio = { version = "1.32", features = ["rt-multi-thread", "sync"] } libc = "0.2" diff --git a/key-wallet-ffi/cbindgen.toml b/key-wallet-ffi/cbindgen.toml index bf453808c..673c331d2 100644 --- a/key-wallet-ffi/cbindgen.toml +++ b/key-wallet-ffi/cbindgen.toml @@ -14,7 +14,7 @@ autogen_warning = "/* Warning: This file is auto-generated by cbindgen. Do not m include_version = true usize_is_size_t = true no_includes = false -includes = ["../dashcore/dashcore.h"] +includes = ["../dash-network/dash-network.h"] sys_includes = ["stdint.h", "stddef.h", "stdbool.h"] # Style options diff --git a/key-wallet-ffi/src/account.rs b/key-wallet-ffi/src/account.rs index 0c933095b..773eaed05 100644 --- a/key-wallet-ffi/src/account.rs +++ b/key-wallet-ffi/src/account.rs @@ -3,7 +3,7 @@ use crate::deref_ptr; use crate::error::{FFIError, FFIErrorCode}; use crate::types::{FFIAccountResult, FFIAccountType, FFIWallet}; -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; #[cfg(feature = "bls")] use key_wallet::account::BLSAccount; #[cfg(feature = "eddsa")] diff --git a/key-wallet-ffi/src/account_collection.rs b/key-wallet-ffi/src/account_collection.rs index e37c7a133..6c8a59942 100644 --- a/key-wallet-ffi/src/account_collection.rs +++ b/key-wallet-ffi/src/account_collection.rs @@ -1056,10 +1056,9 @@ pub unsafe extern "C" fn account_collection_summary_free( #[cfg(test)] mod tests { - use dashcore::ffi::FFINetwork; - use super::*; use crate::wallet::wallet_create_from_mnemonic_with_options; + use dash_network::ffi::FFINetwork; use std::ffi::CString; #[test] diff --git a/key-wallet-ffi/src/account_derivation_tests.rs b/key-wallet-ffi/src/account_derivation_tests.rs index 3d505b8a4..f4c15c2fe 100644 --- a/key-wallet-ffi/src/account_derivation_tests.rs +++ b/key-wallet-ffi/src/account_derivation_tests.rs @@ -2,8 +2,6 @@ #[cfg(test)] mod tests { - use dashcore::ffi::FFINetwork; - use crate::account::account_free; use crate::account_derivation::*; use crate::derivation::*; @@ -11,6 +9,7 @@ mod tests { use crate::keys::{extended_private_key_free, private_key_free}; use crate::types::FFIAccountType; use crate::wallet; + use dash_network::ffi::FFINetwork; const MNEMONIC: &str = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; diff --git a/key-wallet-ffi/src/address.rs b/key-wallet-ffi/src/address.rs index c79627b63..ce9800161 100644 --- a/key-wallet-ffi/src/address.rs +++ b/key-wallet-ffi/src/address.rs @@ -4,13 +4,11 @@ #[path = "address_tests.rs"] mod tests; -use std::ffi::{CStr, CString}; -use std::os::raw::{c_char, c_uchar}; - -use dashcore::ffi::FFINetwork; - use crate::error::FFIError; use crate::{deref_ptr, unwrap_or_return}; +use dash_network::ffi::FFINetwork; +use std::ffi::{CStr, CString}; +use std::os::raw::{c_char, c_uchar}; /// Free address string /// diff --git a/key-wallet-ffi/src/address_pool.rs b/key-wallet-ffi/src/address_pool.rs index ce2bc3225..3dd8f8667 100644 --- a/key-wallet-ffi/src/address_pool.rs +++ b/key-wallet-ffi/src/address_pool.rs @@ -894,9 +894,8 @@ pub unsafe extern "C" fn address_info_array_free(infos: *mut *mut FFIAddressInfo #[cfg(test)] mod tests { - use dashcore::ffi::FFINetwork; - use super::*; + use dash_network::ffi::FFINetwork; #[test] fn test_address_pool_type_values() { diff --git a/key-wallet-ffi/src/address_tests.rs b/key-wallet-ffi/src/address_tests.rs index a4d80ba87..1840e962a 100644 --- a/key-wallet-ffi/src/address_tests.rs +++ b/key-wallet-ffi/src/address_tests.rs @@ -2,10 +2,9 @@ #[cfg(test)] mod address_tests { - use dashcore::ffi::FFINetwork; - use crate::address::{address_array_free, address_free, address_get_type, address_validate}; use crate::error::{FFIError, FFIErrorCode}; + use dash_network::ffi::FFINetwork; use std::ffi::CString; use std::ptr; diff --git a/key-wallet-ffi/src/derivation.rs b/key-wallet-ffi/src/derivation.rs index 57d77ff3a..db0dd8b86 100644 --- a/key-wallet-ffi/src/derivation.rs +++ b/key-wallet-ffi/src/derivation.rs @@ -4,7 +4,7 @@ use crate::error::{FFIError, FFIErrorCode}; use crate::keys::FFIExtendedPrivKey; use crate::keys::FFIExtendedPubKey; use crate::{check_ptr, deref_ptr, unwrap_or_return}; -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; use dashcore::Network; use key_wallet::{ExtendedPrivKey, ExtendedPubKey}; use secp256k1::Secp256k1; diff --git a/key-wallet-ffi/src/keys.rs b/key-wallet-ffi/src/keys.rs index 283fb98cb..9a39e76f7 100644 --- a/key-wallet-ffi/src/keys.rs +++ b/key-wallet-ffi/src/keys.rs @@ -1,10 +1,9 @@ //! Key derivation and management -use dashcore::ffi::FFINetwork; - use crate::error::{FFIError, FFIErrorCode}; use crate::types::FFIWallet; use crate::{check_ptr, deref_ptr, unwrap_or_return}; +use dash_network::ffi::FFINetwork; use std::ffi::{CStr, CString}; use std::os::raw::{c_char, c_uint}; use std::ptr; diff --git a/key-wallet-ffi/src/keys_tests.rs b/key-wallet-ffi/src/keys_tests.rs index 7e52054eb..5ae315bc9 100644 --- a/key-wallet-ffi/src/keys_tests.rs +++ b/key-wallet-ffi/src/keys_tests.rs @@ -3,8 +3,6 @@ #[cfg(test)] #[allow(clippy::module_inception)] mod tests { - use dashcore::ffi::FFINetwork; - use crate::error::{FFIError, FFIErrorCode}; use crate::keys::*; use crate::wallet; diff --git a/key-wallet-ffi/src/managed_account.rs b/key-wallet-ffi/src/managed_account.rs index 4321c4c52..0feda56a5 100644 --- a/key-wallet-ffi/src/managed_account.rs +++ b/key-wallet-ffi/src/managed_account.rs @@ -4,13 +4,12 @@ //! ManagedAccount instances from the key-wallet crate. FFIManagedCoreAccount is a //! simple wrapper around `Arc` without additional fields. +use dash_network::ffi::FFINetwork; +use dashcore::hashes::Hash; use std::os::raw::{c_char, c_uint}; use std::ptr::slice_from_raw_parts_mut; use std::sync::Arc; -use dashcore::ffi::FFINetwork; -use dashcore::hashes::Hash; - use crate::address_pool::{FFIAddressPool, FFIAddressPoolType}; use crate::check_ptr; use crate::error::{FFIError, FFIErrorCode}; @@ -1440,6 +1439,7 @@ mod tests { wallet_manager_add_wallet_from_mnemonic_with_options, wallet_manager_create, wallet_manager_free, wallet_manager_free_wallet_ids, wallet_manager_get_wallet_ids, }; + use dash_network::ffi::FFINetwork; use std::ffi::CString; use std::ptr; diff --git a/key-wallet-ffi/src/managed_wallet.rs b/key-wallet-ffi/src/managed_wallet.rs index 05e2c1062..bb240cf60 100644 --- a/key-wallet-ffi/src/managed_wallet.rs +++ b/key-wallet-ffi/src/managed_wallet.rs @@ -507,7 +507,7 @@ mod tests { use crate::error::{FFIError, FFIErrorCode}; use crate::managed_wallet::*; use crate::wallet; - use dashcore::ffi::FFINetwork; + use dash_network::ffi::FFINetwork; use key_wallet::managed_account::managed_account_type::ManagedAccountType; use std::ffi::{CStr, CString}; use std::ptr; diff --git a/key-wallet-ffi/src/managed_wallet_tests.rs b/key-wallet-ffi/src/managed_wallet_tests.rs index 8cbfdcd36..a91ddeed4 100644 --- a/key-wallet-ffi/src/managed_wallet_tests.rs +++ b/key-wallet-ffi/src/managed_wallet_tests.rs @@ -2,8 +2,6 @@ #[cfg(test)] mod tests { - use dashcore::ffi::FFINetwork; - use crate::address_pool::managed_wallet_mark_address_used; use crate::error::{FFIError, FFIErrorCode}; use crate::managed_wallet::*; @@ -15,6 +13,7 @@ mod tests { wallet_manager_free_wallet_ids, wallet_manager_get_managed_wallet_info, wallet_manager_get_wallet, wallet_manager_get_wallet_ids, }; + use dash_network::ffi::FFINetwork; use std::ffi::CString; use std::ptr; diff --git a/key-wallet-ffi/src/transaction.rs b/key-wallet-ffi/src/transaction.rs index cd8917155..a10489f2c 100644 --- a/key-wallet-ffi/src/transaction.rs +++ b/key-wallet-ffi/src/transaction.rs @@ -5,7 +5,13 @@ use std::os::raw::c_char; use std::ptr; use std::slice; -use dashcore::ffi::FFINetwork; +use crate::error::{FFIError, FFIErrorCode}; +use crate::types::{ + transaction_context_from_ffi, FFIBlockInfo, FFITransactionContextType, FFIWallet, +}; +use crate::{check_ptr, FFIWalletManager}; +use crate::{deref_ptr, deref_ptr_mut, unwrap_or_return}; +use dash_network::ffi::FFINetwork; use dashcore::{ consensus, hashes::Hash, sighash::SighashCache, EcdsaSighashType, Network, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut, Txid, @@ -18,13 +24,6 @@ use key_wallet::wallet::managed_wallet_info::transaction_building::AccountTypePr use key_wallet::wallet::managed_wallet_info::wallet_info_interface::WalletInfoInterface; use secp256k1::{Message, Secp256k1, SecretKey}; -use crate::error::{FFIError, FFIErrorCode}; -use crate::types::{ - transaction_context_from_ffi, FFIBlockInfo, FFITransactionContextType, FFIWallet, -}; -use crate::{check_ptr, FFIWalletManager}; -use crate::{deref_ptr, deref_ptr_mut, unwrap_or_return}; - // MARK: - Transaction Types /// Opaque handle for a transaction diff --git a/key-wallet-ffi/src/wallet.rs b/key-wallet-ffi/src/wallet.rs index f3567d55f..83ad81306 100644 --- a/key-wallet-ffi/src/wallet.rs +++ b/key-wallet-ffi/src/wallet.rs @@ -4,16 +4,15 @@ #[path = "wallet_tests.rs"] mod tests; +use crate::types::FFIAccountResult; +use dash_network::ffi::FFINetwork; +use key_wallet::wallet::initialization::WalletAccountCreationOptions; +use key_wallet::{Mnemonic, Seed, Wallet}; use std::ffi::{CStr, CString}; use std::os::raw::{c_char, c_uint}; use std::ptr; use std::slice; -use crate::types::FFIAccountResult; -use dashcore::ffi::FFINetwork; -use key_wallet::wallet::initialization::WalletAccountCreationOptions; -use key_wallet::{Mnemonic, Seed, Wallet}; - use crate::error::{FFIError, FFIErrorCode}; use crate::types::{FFIWallet, FFIWalletAccountCreationOptions}; use crate::{check_ptr, deref_ptr, unwrap_or_return}; diff --git a/key-wallet-ffi/src/wallet_manager.rs b/key-wallet-ffi/src/wallet_manager.rs index 2cb4cbc92..8e52734bd 100644 --- a/key-wallet-ffi/src/wallet_manager.rs +++ b/key-wallet-ffi/src/wallet_manager.rs @@ -8,18 +8,17 @@ mod tests; #[path = "wallet_manager_serialization_tests.rs"] mod serialization_tests; -use dashcore::ffi::FFINetwork; -use std::ffi::{CStr, CString}; -use std::os::raw::{c_char, c_uint}; -use std::ptr; -use std::sync::Arc; -use tokio::sync::RwLock; - use crate::error::{FFIError, FFIErrorCode}; use crate::{check_ptr, deref_ptr, deref_ptr_mut, unwrap_or_return}; +use dash_network::ffi::FFINetwork; use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo; use key_wallet_manager::WalletInterface; use key_wallet_manager::WalletManager; +use std::ffi::{CStr, CString}; +use std::os::raw::{c_char, c_uint}; +use std::ptr; +use std::sync::Arc; +use tokio::sync::RwLock; /// FFI wrapper for WalletManager /// diff --git a/key-wallet-ffi/src/wallet_manager_serialization_tests.rs b/key-wallet-ffi/src/wallet_manager_serialization_tests.rs index dd80c290f..1e97d8095 100644 --- a/key-wallet-ffi/src/wallet_manager_serialization_tests.rs +++ b/key-wallet-ffi/src/wallet_manager_serialization_tests.rs @@ -2,11 +2,10 @@ #[cfg(all(test, feature = "bincode"))] mod tests { - use dashcore::ffi::FFINetwork; - use crate::error::{FFIError, FFIErrorCode}; use crate::types::FFIWalletAccountCreationOptions; use crate::wallet_manager; + use dash_network::ffi::FFINetwork; use std::ffi::CString; use std::ptr; diff --git a/key-wallet-ffi/src/wallet_manager_tests.rs b/key-wallet-ffi/src/wallet_manager_tests.rs index 5c1ba66a5..d3b3c8b0d 100644 --- a/key-wallet-ffi/src/wallet_manager_tests.rs +++ b/key-wallet-ffi/src/wallet_manager_tests.rs @@ -5,7 +5,7 @@ mod tests { use crate::error::{FFIError, FFIErrorCode}; use crate::{wallet, wallet_manager}; - use dashcore::ffi::FFINetwork; + use dash_network::ffi::FFINetwork; use key_wallet_manager::WalletInterface; use std::ffi::{CStr, CString}; use std::ptr; diff --git a/key-wallet-ffi/src/wallet_tests.rs b/key-wallet-ffi/src/wallet_tests.rs index 0340be035..d3a67f571 100644 --- a/key-wallet-ffi/src/wallet_tests.rs +++ b/key-wallet-ffi/src/wallet_tests.rs @@ -2,12 +2,11 @@ #[cfg(test)] mod wallet_tests { - use dashcore::ffi::FFINetwork; - use crate::account::account_free; use crate::error::{FFIError, FFIErrorCode}; use crate::types::FFIAccountType; use crate::wallet; + use dash_network::ffi::FFINetwork; use std::ffi::CString; use std::ptr; diff --git a/key-wallet-ffi/tests/debug_wallet_add.rs b/key-wallet-ffi/tests/debug_wallet_add.rs index e5409fd00..dfab07850 100644 --- a/key-wallet-ffi/tests/debug_wallet_add.rs +++ b/key-wallet-ffi/tests/debug_wallet_add.rs @@ -1,4 +1,4 @@ -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; #[test] fn test_debug_wallet_add() { diff --git a/key-wallet-ffi/tests/integration_test.rs b/key-wallet-ffi/tests/integration_test.rs index fe160dd40..cf3115c41 100644 --- a/key-wallet-ffi/tests/integration_test.rs +++ b/key-wallet-ffi/tests/integration_test.rs @@ -2,7 +2,7 @@ //! //! These tests verify the interaction between different FFI modules -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; use key_wallet_ffi::error::{FFIError, FFIErrorCode}; use std::ffi::CString; use std::ptr; diff --git a/key-wallet-ffi/tests/test_account_collection.rs b/key-wallet-ffi/tests/test_account_collection.rs index 014e6a18a..ecaf7aa1e 100644 --- a/key-wallet-ffi/tests/test_account_collection.rs +++ b/key-wallet-ffi/tests/test_account_collection.rs @@ -1,6 +1,6 @@ //! Integration tests for account collection FFI functions -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; use key_wallet_ffi::account::account_free; use key_wallet_ffi::account_collection::*; use key_wallet_ffi::types::{FFIAccountCreationOptionType, FFIWalletAccountCreationOptions}; diff --git a/key-wallet-ffi/tests/test_addr_simple.rs b/key-wallet-ffi/tests/test_addr_simple.rs index c13002b88..6fae7e2a5 100644 --- a/key-wallet-ffi/tests/test_addr_simple.rs +++ b/key-wallet-ffi/tests/test_addr_simple.rs @@ -1,4 +1,4 @@ -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; #[test] fn test_address_simple() { diff --git a/key-wallet-ffi/tests/test_import_wallet.rs b/key-wallet-ffi/tests/test_import_wallet.rs index dabd00eeb..b28cdfece 100644 --- a/key-wallet-ffi/tests/test_import_wallet.rs +++ b/key-wallet-ffi/tests/test_import_wallet.rs @@ -3,7 +3,7 @@ #[cfg(feature = "bincode")] #[cfg(test)] mod tests { - use dashcore::ffi::FFINetwork; + use dash_network::ffi::FFINetwork; use key_wallet_ffi::error::{FFIError, FFIErrorCode}; use key_wallet_ffi::wallet::wallet_free_const; use key_wallet_ffi::wallet_manager::*; diff --git a/key-wallet-ffi/tests/test_managed_account_collection.rs b/key-wallet-ffi/tests/test_managed_account_collection.rs index 5a16c6470..5517a6060 100644 --- a/key-wallet-ffi/tests/test_managed_account_collection.rs +++ b/key-wallet-ffi/tests/test_managed_account_collection.rs @@ -1,6 +1,6 @@ //! Tests for managed account collection FFI bindings -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; use key_wallet_ffi::error::{FFIError, FFIErrorCode}; use key_wallet_ffi::managed_account_collection::*; use key_wallet_ffi::types::{FFIAccountCreationOptionType, FFIWalletAccountCreationOptions}; diff --git a/key-wallet-ffi/tests/test_passphrase_wallets.rs b/key-wallet-ffi/tests/test_passphrase_wallets.rs index 627ac9404..1dea85e93 100644 --- a/key-wallet-ffi/tests/test_passphrase_wallets.rs +++ b/key-wallet-ffi/tests/test_passphrase_wallets.rs @@ -1,7 +1,7 @@ //! Tests for wallet creation with passphrase through FFI //! These tests demonstrate current issues with passphrase handling in the FFI layer -use dashcore::ffi::FFINetwork; +use dash_network::ffi::FFINetwork; use key_wallet_ffi::error::{FFIError, FFIErrorCode}; use std::ffi::CString; diff --git a/key-wallet/src/account/account_type.rs b/key-wallet/src/account/account_type.rs index ba1830e2d..ca3cd08b5 100644 --- a/key-wallet/src/account/account_type.rs +++ b/key-wallet/src/account/account_type.rs @@ -307,7 +307,6 @@ impl AccountType { Network::Testnet | Network::Devnet | Network::Regtest => { Ok(DerivationPath::from(crate::dip9::IDENTITY_REGISTRATION_PATH_TESTNET)) } - _ => Err(crate::error::Error::InvalidNetwork), } } Self::IdentityTopUp { @@ -319,7 +318,6 @@ impl AccountType { Network::Testnet | Network::Devnet | Network::Regtest => { crate::dip9::IDENTITY_TOPUP_PATH_TESTNET } - _ => return Err(crate::error::Error::InvalidNetwork), }; let mut path = DerivationPath::from(base_path); path.push( @@ -337,7 +335,6 @@ impl AccountType { Network::Testnet | Network::Devnet | Network::Regtest => { Ok(DerivationPath::from(crate::dip9::IDENTITY_TOPUP_PATH_TESTNET)) } - _ => Err(crate::error::Error::InvalidNetwork), } } Self::IdentityInvitation => { @@ -349,7 +346,6 @@ impl AccountType { Network::Testnet | Network::Devnet | Network::Regtest => { Ok(DerivationPath::from(crate::dip9::IDENTITY_INVITATION_PATH_TESTNET)) } - _ => Err(crate::error::Error::InvalidNetwork), } } Self::AssetLockAddressTopUp => { @@ -361,7 +357,6 @@ impl AccountType { Network::Testnet | Network::Devnet | Network::Regtest => { Ok(DerivationPath::from(crate::dip9::ASSET_LOCK_ADDRESS_TOPUP_PATH_TESTNET)) } - _ => Err(crate::error::Error::InvalidNetwork), } } Self::AssetLockShieldedAddressTopUp => { @@ -375,7 +370,6 @@ impl AccountType { crate::dip9::ASSET_LOCK_SHIELDED_ADDRESS_TOPUP_PATH_TESTNET, )) } - _ => Err(crate::error::Error::InvalidNetwork), } } Self::ProviderVotingKeys => { @@ -431,7 +425,6 @@ impl AccountType { Network::Testnet | Network::Devnet | Network::Regtest => { DerivationPath::from(crate::dip9::DASHPAY_ROOT_PATH_TESTNET) } - _ => return Err(crate::error::Error::InvalidNetwork), }; path.push(ChildNumber::from_hardened_idx(0).map_err(crate::error::Error::Bip32)?); path.push(ChildNumber::Normal256 { @@ -455,7 +448,6 @@ impl AccountType { Network::Testnet | Network::Devnet | Network::Regtest => { DerivationPath::from(crate::dip9::DASHPAY_ROOT_PATH_TESTNET) } - _ => return Err(crate::error::Error::InvalidNetwork), }; path.push(ChildNumber::from_hardened_idx(0).map_err(crate::error::Error::Bip32)?); path.push(ChildNumber::Normal256 { @@ -479,7 +471,6 @@ impl AccountType { Network::Testnet | Network::Devnet | Network::Regtest => { DerivationPath::from(crate::dip9::PLATFORM_PAYMENT_ROOT_PATH_TESTNET) } - _ => return Err(crate::error::Error::InvalidNetwork), }; path.push( ChildNumber::from_hardened_idx(*account).map_err(crate::error::Error::Bip32)?, diff --git a/key-wallet/src/derivation.rs b/key-wallet/src/derivation.rs index 1a5f97c1b..b401e8e44 100644 --- a/key-wallet/src/derivation.rs +++ b/key-wallet/src/derivation.rs @@ -194,7 +194,6 @@ impl DerivationPathBuilder { let coin_type = match network { Network::Mainnet => 5, Network::Testnet | Network::Devnet | Network::Regtest => 1, - _ => 5, // Default to Dash }; self.purpose(44)