Skip to content

Commit fcaf66e

Browse files
refactor(key-wallet): drop unused AccountMetadata struct (#717)
Every field of `AccountMetadata` (`name`, `description`, `color`, `tags`, `created_at`, `total_received`, `total_sent`, `tx_count`) was dead. The only field that was ever written, `last_used`, was never read by any caller in the workspace. The associated `metadata()`/`metadata_mut()` trait methods on `ManagedAccountTrait` had no callers either. Remove the struct, the field on `ManagedCoreAccount` and `ManagedPlatformAccount`, the trait methods, the `current_timestamp()` helpers that became dead with the writes, and the corresponding serde/bincode plumbing. This is a breaking change for any persisted wallet snapshot, but the API is still pre-1.0 and there is no consumer of the field's data. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5603fff commit fcaf66e

5 files changed

Lines changed: 4 additions & 95 deletions

File tree

key-wallet/src/account/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use crate::managed_account::address_pool::AddressPoolType;
3434
pub use crate::managed_account::managed_account_collection::ManagedAccountCollection;
3535
pub use crate::managed_account::managed_account_trait::ManagedAccountTrait;
3636
pub use crate::managed_account::managed_account_type::ManagedAccountType;
37-
pub use crate::managed_account::metadata::AccountMetadata;
3837
pub use crate::managed_account::transaction_record::{
3938
InputDetail, OutputDetail, OutputRole, TransactionDirection, TransactionRecord,
4039
};

key-wallet/src/managed_account/managed_account_trait.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
use std::collections::BTreeMap;
66

7-
use crate::account::AccountMetadata;
87
use crate::account::TransactionRecord;
98
use crate::managed_account::managed_account_type::ManagedAccountType;
109
use crate::utxo::Utxo;
@@ -24,12 +23,6 @@ pub trait ManagedAccountTrait {
2423
/// Get the network
2524
fn network(&self) -> Network;
2625

27-
/// Get metadata
28-
fn metadata(&self) -> &AccountMetadata;
29-
30-
/// Get mutable metadata
31-
fn metadata_mut(&mut self) -> &mut AccountMetadata;
32-
3326
/// Check if this is a watch-only account
3427
fn is_watch_only(&self) -> bool;
3528

key-wallet/src/managed_account/managed_platform_account.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use std::collections::BTreeMap;
1313

1414
use super::address_pool::{AddressPool, KeySource};
15-
use super::metadata::AccountMetadata;
1615
use super::platform_address::PlatformP2PKHAddress;
1716
use crate::error::{Error, Result};
1817
use crate::Network;
@@ -48,8 +47,6 @@ pub struct ManagedPlatformAccount {
4847
pub address_balances: BTreeMap<PlatformP2PKHAddress, u64>,
4948
/// Address pool for key derivation and address generation
5049
pub addresses: AddressPool,
51-
/// Account metadata
52-
pub metadata: AccountMetadata,
5350
/// Whether this is a watch-only account
5451
pub is_watch_only: bool,
5552
}
@@ -67,7 +64,6 @@ impl ManagedPlatformAccount {
6764
credit_balance: 0,
6865
address_balances: BTreeMap::new(),
6966
addresses,
70-
metadata: AccountMetadata::default(),
7167
is_watch_only,
7268
}
7369
}
@@ -85,7 +81,6 @@ impl ManagedPlatformAccount {
8581
/// Set the total credit balance
8682
pub fn set_credit_balance(&mut self, credit_balance: u64) {
8783
self.credit_balance = credit_balance;
88-
self.metadata.last_used = Some(Self::current_timestamp());
8984
}
9085

9186
/// Get the credit balance for a specific address
@@ -113,7 +108,6 @@ impl ManagedPlatformAccount {
113108
// Apply delta to total: subtract old, add new
114109
self.credit_balance =
115110
self.credit_balance.saturating_sub(old_balance).saturating_add(credit_balance);
116-
self.metadata.last_used = Some(Self::current_timestamp());
117111

118112
// If address became funded and we have a key source, update address pool
119113
if was_unfunded && is_now_funded {
@@ -143,7 +137,6 @@ impl ManagedPlatformAccount {
143137
self.address_balances.insert(address, new_balance);
144138
// Add the amount to the total (saturating to handle overflow)
145139
self.credit_balance = self.credit_balance.saturating_add(amount);
146-
self.metadata.last_used = Some(Self::current_timestamp());
147140

148141
// If address became funded and we have a key source, update address pool
149142
if was_unfunded && is_now_funded {
@@ -171,7 +164,6 @@ impl ManagedPlatformAccount {
171164
self.address_balances.insert(address, new_balance);
172165
// Subtract only what was actually removed from the total
173166
self.credit_balance = self.credit_balance.saturating_sub(actual_removed);
174-
self.metadata.last_used = Some(Self::current_timestamp());
175167
new_balance
176168
}
177169

@@ -254,11 +246,7 @@ impl ManagedPlatformAccount {
254246

255247
/// Mark an address as used
256248
pub fn mark_address_used(&mut self, address: &Address) -> bool {
257-
let result = self.addresses.mark_used(address);
258-
if result {
259-
self.metadata.last_used = Some(Self::current_timestamp());
260-
}
261-
result
249+
self.addresses.mark_used(address)
262250
}
263251

264252
/// Mark a platform address as used
@@ -300,14 +288,6 @@ impl ManagedPlatformAccount {
300288
self.addresses.address_info(address).cloned()
301289
}
302290

303-
/// Get the current timestamp
304-
fn current_timestamp() -> u64 {
305-
std::time::SystemTime::now()
306-
.duration_since(std::time::UNIX_EPOCH)
307-
.unwrap_or_default()
308-
.as_secs()
309-
}
310-
311291
/// Get pool statistics
312292
pub fn address_pool_stats(&self) -> super::address_pool::PoolStats {
313293
self.addresses.stats()
@@ -347,7 +327,6 @@ impl bincode::Encode for ManagedPlatformAccount {
347327
bincode::Encode::encode(&address_balances_vec, encoder)?;
348328

349329
bincode::Encode::encode(&self.addresses, encoder)?;
350-
bincode::Encode::encode(&self.metadata, encoder)?;
351330
bincode::Encode::encode(&self.is_watch_only, encoder)?;
352331
Ok(())
353332
}
@@ -370,7 +349,6 @@ impl<Context> bincode::Decode<Context> for ManagedPlatformAccount {
370349
address_balances_vec.into_iter().collect();
371350

372351
let addresses = bincode::Decode::decode(decoder)?;
373-
let metadata = bincode::Decode::decode(decoder)?;
374352
let is_watch_only = bincode::Decode::decode(decoder)?;
375353

376354
Ok(Self {
@@ -380,7 +358,6 @@ impl<Context> bincode::Decode<Context> for ManagedPlatformAccount {
380358
credit_balance,
381359
address_balances,
382360
addresses,
383-
metadata,
384361
is_watch_only,
385362
})
386363
}

key-wallet/src/managed_account/metadata.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

key-wallet/src/managed_account/mod.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! This module contains the mutable account state that changes during wallet operation,
44
//! kept separate from the immutable Account structure.
55
6-
use crate::account::AccountMetadata;
76
#[cfg(feature = "bls")]
87
use crate::account::BLSAccount;
98
#[cfg(feature = "eddsa")]
@@ -38,24 +37,21 @@ pub mod managed_account_collection;
3837
pub mod managed_account_trait;
3938
pub mod managed_account_type;
4039
pub mod managed_platform_account;
41-
pub mod metadata;
4240
pub mod platform_address;
4341
pub mod transaction_record;
4442

4543
/// Managed account with mutable state
4644
///
47-
/// This struct contains the mutable state of an account including address pools,
48-
/// metadata, and balance information. It is managed separately from
49-
/// the immutable Account structure.
45+
/// This struct contains the mutable state of an account including address pools
46+
/// and balance information. It is managed separately from the immutable Account
47+
/// structure.
5048
#[derive(Debug, Clone)]
5149
#[cfg_attr(feature = "serde", derive(Serialize))]
5250
pub struct ManagedCoreAccount {
5351
/// Account type with embedded address pools and index
5452
pub managed_account_type: ManagedAccountType,
5553
/// Network this account belongs to
5654
pub network: Network,
57-
/// Account metadata
58-
pub metadata: AccountMetadata,
5955
/// Whether this is a watch-only account
6056
pub is_watch_only: bool,
6157
/// Account balance information
@@ -84,7 +80,6 @@ impl ManagedCoreAccount {
8480
Self {
8581
managed_account_type,
8682
network,
87-
metadata: AccountMetadata::default(),
8883
is_watch_only,
8984
balance: WalletCoreBalance::default(),
9085
transactions: BTreeMap::new(),
@@ -301,9 +296,6 @@ impl ManagedCoreAccount {
301296

302297
/// Mark an address as used
303298
pub fn mark_address_used(&mut self, address: &Address) -> bool {
304-
// Update metadata timestamp
305-
self.metadata.last_used = Some(Self::current_timestamp());
306-
307299
// Use the account type's mark_address_used method
308300
// The address pools already track gap limits internally
309301
self.managed_account_type.mark_address_used(address)
@@ -615,7 +607,6 @@ impl ManagedCoreAccount {
615607
}
616608
}
617609
self.balance = WalletCoreBalance::new(confirmed, unconfirmed, immature, locked);
618-
self.metadata.last_used = Some(Self::current_timestamp());
619610
}
620611

621612
/// Get all addresses from all pools
@@ -1175,14 +1166,6 @@ impl ManagedCoreAccount {
11751166
self.managed_account_type.get_address_derivation_path(address)
11761167
}
11771168

1178-
/// Get the current timestamp (for metadata)
1179-
fn current_timestamp() -> u64 {
1180-
std::time::SystemTime::now()
1181-
.duration_since(std::time::UNIX_EPOCH)
1182-
.unwrap_or_default()
1183-
.as_secs()
1184-
}
1185-
11861169
/// Get total address count across all pools
11871170
pub fn total_address_count(&self) -> usize {
11881171
self.managed_account_type
@@ -1302,14 +1285,6 @@ impl ManagedAccountTrait for ManagedCoreAccount {
13021285
self.network
13031286
}
13041287

1305-
fn metadata(&self) -> &AccountMetadata {
1306-
&self.metadata
1307-
}
1308-
1309-
fn metadata_mut(&mut self) -> &mut AccountMetadata {
1310-
&mut self.metadata
1311-
}
1312-
13131288
fn is_watch_only(&self) -> bool {
13141289
self.is_watch_only
13151290
}
@@ -1349,7 +1324,6 @@ impl<'de> Deserialize<'de> for ManagedCoreAccount {
13491324
struct Helper {
13501325
managed_account_type: ManagedAccountType,
13511326
network: Network,
1352-
metadata: AccountMetadata,
13531327
is_watch_only: bool,
13541328
balance: WalletCoreBalance,
13551329
transactions: BTreeMap<Txid, TransactionRecord>,
@@ -1368,7 +1342,6 @@ impl<'de> Deserialize<'de> for ManagedCoreAccount {
13681342
Ok(ManagedCoreAccount {
13691343
managed_account_type: helper.managed_account_type,
13701344
network: helper.network,
1371-
metadata: helper.metadata,
13721345
is_watch_only: helper.is_watch_only,
13731346
balance: helper.balance,
13741347
transactions: helper.transactions,

0 commit comments

Comments
 (0)