Skip to content

Commit 19e8895

Browse files
committed
drop unnecesary codebase complexity removing the bincode dependency and its usage where is not needed
1 parent f74c43e commit 19e8895

35 files changed

Lines changed: 25 additions & 1355 deletions

key-wallet-ffi/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ name = "key_wallet_ffi"
1313
crate-type = ["cdylib", "staticlib", "lib"]
1414

1515
[features]
16-
default = ["bincode", "eddsa", "bls", "bip38"]
16+
default = ["serde", "eddsa", "bls", "bip38"]
1717
bip38 = ["key-wallet/bip38"]
18-
bincode = ["key-wallet-manager/bincode", "key-wallet/bincode"]
18+
serde = ["key-wallet/serde", "key-wallet-manager/serde"]
1919
eddsa = ["dashcore/eddsa", "key-wallet/eddsa"]
2020
bls = ["dashcore/bls", "key-wallet/bls"]
2121

key-wallet-ffi/src/wallet_manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ pub unsafe extern "C" fn wallet_manager_add_wallet_from_mnemonic(
277277
/// - `error` must be a valid pointer to an FFIError structure or null
278278
/// - The caller must ensure all pointers remain valid for the duration of this call
279279
/// - The caller must free the returned wallet_bytes using wallet_manager_free_wallet_bytes()
280-
#[cfg(feature = "bincode")]
280+
#[cfg(feature = "serde")]
281281
#[no_mangle]
282282
pub unsafe extern "C" fn wallet_manager_add_wallet_from_mnemonic_return_serialized_bytes(
283283
manager: *mut FFIWalletManager,
@@ -397,7 +397,7 @@ pub unsafe extern "C" fn wallet_manager_add_wallet_from_mnemonic_return_serializ
397397
/// - `bytes_len` must match the original allocation size
398398
/// - The pointer must not be used after calling this function
399399
/// - This function must only be called once per buffer
400-
#[cfg(feature = "bincode")]
400+
#[cfg(feature = "serde")]
401401
#[no_mangle]
402402
pub unsafe extern "C" fn wallet_manager_free_wallet_bytes(wallet_bytes: *mut u8, bytes_len: usize) {
403403
if !wallet_bytes.is_null() && bytes_len > 0 {
@@ -422,7 +422,7 @@ pub unsafe extern "C" fn wallet_manager_free_wallet_bytes(wallet_bytes: *mut u8,
422422
/// - `wallet_id_out` must be a valid pointer to a 32-byte array that will receive the wallet ID
423423
/// - `error` must be a valid pointer to an FFIError structure or null
424424
/// - The caller must ensure all pointers remain valid for the duration of this call
425-
#[cfg(feature = "bincode")]
425+
#[cfg(feature = "serde")]
426426
#[no_mangle]
427427
pub unsafe extern "C" fn wallet_manager_import_wallet_from_bytes(
428428
manager: *mut FFIWalletManager,

key-wallet-ffi/src/wallet_manager_serialization_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tests for wallet serialization FFI functions
22
3-
#[cfg(all(test, feature = "bincode"))]
3+
#[cfg(all(test, feature = "serde"))]
44
mod tests {
55
use crate::error::{FFIError, FFIErrorCode};
66
use crate::types::FFIWalletAccountCreationOptions;

key-wallet-ffi/src/wallet_manager_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ mod tests {
864864
}
865865
}
866866

867-
#[cfg(feature = "bincode")]
867+
#[cfg(feature = "serde")]
868868
#[test]
869869
fn test_create_wallet_from_mnemonic_return_serialized_bytes() {
870870
let mut error = FFIError::success();
@@ -1062,7 +1062,7 @@ mod tests {
10621062
}
10631063
}
10641064

1065-
#[cfg(feature = "bincode")]
1065+
#[cfg(feature = "serde")]
10661066
#[test]
10671067
fn test_serialized_wallet_across_managers() {
10681068
let mut error = FFIError::success();

key-wallet-ffi/tests/test_import_wallet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Test for wallet import from bytes via FFI
22
3-
#[cfg(feature = "bincode")]
3+
#[cfg(feature = "serde")]
44
#[cfg(test)]
55
mod tests {
66
use key_wallet_ffi::error::{FFIError, FFIErrorCode};

key-wallet-manager/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ readme = "README.md"
99
license = "CC0-1.0"
1010

1111
[features]
12-
default = ["std", "bincode"]
12+
default = ["std", "serde", "bincode"]
1313
std = ["key-wallet/std", "dashcore/std", "dashcore_hashes/std", "secp256k1/std"]
1414
serde = ["dep:serde", "key-wallet/serde", "dashcore/serde"]
1515
getrandom = ["key-wallet/getrandom"]
16-
bincode = ["dep:bincode", "key-wallet/bincode"]
1716
test-utils = []
1817

1918
[dependencies]
@@ -22,8 +21,8 @@ dashcore = { path = "../dash", default-features = false }
2221
dashcore_hashes = { path = "../hashes", default-features = false }
2322
secp256k1 = { version = "0.30.0", default-features = false, features = ["recovery"] }
2423
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
24+
bincode = { version = "2.0.1", optional = true, features = ["serde"] }
2525
async-trait = "0.1"
26-
bincode = { version = "2.0.1", optional = true }
2726
zeroize = { version = "1.8", features = ["derive"] }
2827
rayon = "1.11"
2928
tokio = { version = "1.32", features = ["full"] }

key-wallet-manager/src/wallet_manager/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<T: WalletInfoInterface> WalletManager<T> {
193193
/// # Security Note
194194
/// When `downgrade_to_pubkey_wallet` is true, the returned wallet contains NO private key material,
195195
/// making it safe to use on potentially compromised systems or for creating watch-only wallets.
196-
#[cfg(feature = "bincode")]
196+
#[cfg(feature = "serde")]
197197
#[allow(clippy::too_many_arguments)]
198198
pub fn create_wallet_from_mnemonic_return_serialized_bytes(
199199
&mut self,
@@ -260,10 +260,10 @@ impl<T: WalletInfoInterface> WalletManager<T> {
260260
}
261261

262262
// Serialize the wallet to bytes
263-
let serialized_bytes = bincode::encode_to_vec(&final_wallet, bincode::config::standard())
264-
.map_err(|e| {
265-
WalletError::InvalidParameter(format!("Failed to serialize wallet: {}", e))
266-
})?;
263+
let serialized_bytes =
264+
bincode::serde::encode_to_vec(&final_wallet, bincode::config::standard()).map_err(
265+
|e| WalletError::InvalidParameter(format!("Failed to serialize wallet: {}", e)),
266+
)?;
267267

268268
// Add the wallet to the manager
269269
let mut managed_info = T::from_wallet(&final_wallet);
@@ -460,17 +460,18 @@ impl<T: WalletInfoInterface> WalletManager<T> {
460460
/// # Returns
461461
/// * `Ok(WalletId)` - The computed wallet ID of the imported wallet
462462
/// * `Err(WalletError)` - If deserialization fails or the wallet already exists
463-
#[cfg(feature = "bincode")]
463+
#[cfg(feature = "serde")]
464464
pub fn import_wallet_from_bytes(
465465
&mut self,
466466
wallet_bytes: &[u8],
467467
) -> Result<WalletId, WalletError> {
468468
// Deserialize the wallet from bincode
469-
let wallet: Wallet = bincode::decode_from_slice(wallet_bytes, bincode::config::standard())
470-
.map_err(|e| {
471-
WalletError::InvalidParameter(format!("Failed to deserialize wallet: {}", e))
472-
})?
473-
.0;
469+
let wallet: Wallet =
470+
bincode::serde::decode_from_slice(wallet_bytes, bincode::config::standard())
471+
.map_err(|e| {
472+
WalletError::InvalidParameter(format!("Failed to deserialize wallet: {}", e))
473+
})?
474+
.0;
474475

475476
// Compute wallet ID from the wallet's root public key
476477
let wallet_id = wallet.compute_wallet_id();

key-wallet/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ license = "CC0-1.0"
1111
[features]
1212
default = ["std"]
1313
std = ["dashcore_hashes/std", "secp256k1/std", "bip39/std", "getrandom", "dash-network/std", "rand"]
14-
serde = ["dep:serde", "dep:serde_json", "dashcore_hashes/serde", "secp256k1/serde", "dash-network/serde", "dashcore/serde"]
15-
bincode = ["serde", "dep:bincode", "dep:bincode_derive", "dash-network/bincode", "dashcore_hashes/bincode", "dashcore/bincode"]
14+
serde = ["dep:serde", "dashcore_hashes/serde", "secp256k1/serde", "dash-network/serde", "dashcore/serde"]
1615
bip38 = ["scrypt", "aes", "bs58", "rand"]
1716
eddsa = ["dashcore/eddsa"]
1817
bls = ["dashcore/bls"]
@@ -36,10 +35,7 @@ sha2 = { version = "0.10", default-features = false }
3635
bs58 = { version = "0.5", default-features = false, features = ["check", "alloc"], optional = true }
3736
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
3837
# Serialization
39-
bincode = { version = "2.0.1", optional = true }
40-
bincode_derive = { version = "2.0.1", optional = true }
4138
base64 = { version = "0.22", optional = true }
42-
serde_json = { version = "1.0", optional = true }
4339
hex = { version = "0.4"}
4440
hkdf = { version = "0.12", default-features = false }
4541
zeroize = { version = "1.8", features = ["derive"] }
@@ -49,6 +45,6 @@ async-trait = "0.1"
4945
[dev-dependencies]
5046
dashcore = { path="../dash", features = ["test-utils"] }
5147
hex = "0.4"
52-
key-wallet = { path = ".", features = ["test-utils", "bip38", "serde", "bincode", "eddsa", "bls"] }
48+
key-wallet = { path = ".", features = ["test-utils", "bip38", "serde", "eddsa", "bls"] }
5349
tokio = { version = "1", features = ["macros", "rt"] }
5450
test-case = "3.3"

key-wallet/src/account/account_collection.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
use alloc::collections::BTreeMap;
66
use alloc::vec::Vec;
7-
#[cfg(feature = "bincode")]
8-
use bincode_derive::{Decode, Encode};
97
#[cfg(feature = "serde")]
108
use serde::{Deserialize, Serialize};
119

@@ -21,7 +19,6 @@ pub type DashpayContactIdentityId = [u8; 32];
2119

2220
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
2321
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
24-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
2522
pub struct DashpayAccountKey {
2623
pub index: u32,
2724
pub user_identity_id: DashpayOurUserIdentityId,
@@ -31,7 +28,6 @@ pub struct DashpayAccountKey {
3128
/// Key for Platform Payment accounts (DIP-17)
3229
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
3330
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
34-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
3531
pub struct PlatformPaymentAccountKey {
3632
/// Account index (hardened)
3733
pub account: u32,
@@ -42,7 +38,6 @@ pub struct PlatformPaymentAccountKey {
4238
/// Collection of accounts organized by type
4339
#[derive(Debug, Clone, Default)]
4440
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
45-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
4641
pub struct AccountCollection {
4742
/// Standard BIP44 accounts by index
4843
pub standard_bip44_accounts: BTreeMap<u32, Account>,

key-wallet/src/account/account_type.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ use crate::transaction_checking::transaction_router::{
88
AccountTypeToCheck, PlatformAccountConversionError,
99
};
1010
use crate::Network;
11-
#[cfg(feature = "bincode")]
12-
use bincode_derive::{Decode, Encode};
1311
#[cfg(feature = "serde")]
1412
use serde::{Deserialize, Serialize};
1513

1614
/// Account types supported by the wallet
1715
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
1816
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
19-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
2017
pub enum StandardAccountType {
2118
/// Standard BIP44 account for regular transactions m/44'/coin_type'/account'/x/x
2219
#[default]
@@ -28,7 +25,6 @@ pub enum StandardAccountType {
2825
/// Account types supported by the wallet
2926
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3027
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
3228
pub enum AccountType {
3329
/// Standard BIP44 account for regular transactions
3430
Standard {

0 commit comments

Comments
 (0)