Skip to content

Commit f78f84c

Browse files
committed
drop unnecesary codebase complexity removing the bincode usage where is not needed
in the key-wallet crate
1 parent e7c68d9 commit f78f84c

35 files changed

Lines changed: 26 additions & 1354 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/bincode"]
18+
serde = ["key-wallet/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/Cargo.toml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ license = "CC0-1.0"
1111
[features]
1212
default = ["std"]
1313
std = ["secp256k1/std", "bip39/std", "getrandom", "rand"]
14-
serde = ["dep:serde", "dep:serde_json", "dashcore_hashes/serde", "secp256k1/serde", "dashcore/serde"]
15-
bincode = ["serde", "dep:bincode", "dep:bincode_derive", "dashcore_hashes/bincode", "dashcore/bincode"]
14+
serde = ["dep:serde", "dep:bincode", "dashcore_hashes/serde", "secp256k1/serde", "dashcore/serde"]
1615
bip38 = ["scrypt", "aes", "bs58", "rand"]
1716
eddsa = ["dashcore/eddsa"]
1817
bls = ["dashcore/bls"]
@@ -24,7 +23,6 @@ dashcore_hashes = { path = "../hashes" }
2423
dashcore = { path="../dash" }
2524
secp256k1 = { version = "0.30.0", default-features = false, features = ["hashes", "recovery"] }
2625
bip39 = { version = "2.2.0", default-features = false, features = ["chinese-simplified", "chinese-traditional", "czech", "french", "italian", "japanese", "korean", "portuguese", "spanish", "zeroize"] }
27-
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
2826
base58ck = { version = "0.1.0", default-features = false }
2927
bitflags = { version = "2.6", default-features = false }
3028
getrandom = { version = "0.2", optional = true }
@@ -35,10 +33,9 @@ sha2 = { version = "0.10", default-features = false }
3533
bs58 = { version = "0.5", default-features = false, features = ["check", "alloc"], optional = true }
3634
rand = { version = "0.8", default-features = false, features = ["std", "std_rng"], optional = true }
3735
# Serialization
38-
bincode = { version = "2.0.1", optional = true }
39-
bincode_derive = { version = "2.0.1", optional = true }
36+
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
37+
bincode = { version = "2.0.1", default-features = false, features = ["serde"], optional = true }
4038
base64 = { version = "0.22", optional = true }
41-
serde_json = { version = "1.0", optional = true }
4239
hex = { version = "0.4"}
4340
zeroize = { version = "1.8", features = ["derive"] }
4441
tracing = "0.1"
@@ -49,5 +46,5 @@ rayon = { version = "1.11" }
4946
[dev-dependencies]
5047
dashcore = { path="../dash", features = ["test-utils"] }
5148
hex = "0.4"
52-
key-wallet = { path = ".", features = ["test-utils", "bip38", "serde", "bincode", "eddsa", "bls"] }
49+
key-wallet = { path = ".", features = ["test-utils", "bip38", "serde", "eddsa", "bls"] }
5350
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 {

key-wallet/src/account/bls_account.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ use dashcore::Address;
1717
use serde::{Deserialize, Serialize};
1818

1919
use crate::bip32::{ChainCode, Fingerprint};
20-
#[cfg(feature = "bincode")]
21-
use bincode_derive::{Decode, Encode};
2220
use dashcore::blsful::{Bls12381G2Impl, SerializationFormat};
2321

2422
use crate::account::derivation::AccountDerivation;
@@ -28,7 +26,6 @@ pub use dashcore::blsful::SecretKey;
2826
/// BLS account structure for Platform and masternode operations
2927
#[derive(Debug, Clone)]
3028
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
31-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
3229
pub struct BLSAccount {
3330
/// Wallet id (stored as Vec for serialization)
3431
pub parent_wallet_id: Option<Vec<u8>>,
@@ -164,21 +161,6 @@ impl BLSAccount {
164161
watch_only.is_watch_only = true;
165162
watch_only
166163
}
167-
168-
/// Serialize account to bytes
169-
#[cfg(feature = "bincode")]
170-
pub fn serialize(&self) -> Result<Vec<u8>> {
171-
bincode::encode_to_vec(self, bincode::config::standard())
172-
.map_err(|e| Error::Serialization(e.to_string()))
173-
}
174-
175-
/// Deserialize account from bytes
176-
#[cfg(feature = "bincode")]
177-
pub fn deserialize(data: &[u8]) -> Result<Self> {
178-
bincode::decode_from_slice(data, bincode::config::standard())
179-
.map(|(account, _)| account)
180-
.map_err(|e| Error::Serialization(e.to_string()))
181-
}
182164
}
183165

184166
impl AccountTrait for BLSAccount {

key-wallet/src/account/coinjoin.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
//! This module contains structures for managing CoinJoin address pools.
44
55
use crate::managed_account::address_pool::AddressPool;
6-
#[cfg(feature = "bincode")]
7-
use bincode_derive::{Decode, Encode};
86
#[cfg(feature = "serde")]
97
use serde::{Deserialize, Serialize};
108

119
/// CoinJoin-specific address pools
1210
#[derive(Debug, Clone)]
1311
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14-
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
1512
pub struct CoinJoinPools {
1613
/// CoinJoin receive addresses
1714
pub external: AddressPool,

0 commit comments

Comments
 (0)