Skip to content

Commit 15d622e

Browse files
refactor(key-wallet): drop unused first_loaded_at and total_transactions from WalletMetadata
Neither field is read by any consumer (FFI, SPV, key-wallet-manager, or key-wallet itself outside of the assertions removed here). `first_loaded_at` was only ever written via `set_first_loaded_at` from `WalletManager`; the trait methods, the field, and all six call sites are gone. `total_transactions` was only incremented in `check_core_transaction` and asserted on in tests; the increment, the helper, and the test assertions are gone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fcaf66e commit 15d622e

6 files changed

Lines changed: 6 additions & 59 deletions

File tree

key-wallet-manager/src/lib.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletManager<T> {
170170

171171
// Create managed wallet info from the wallet to properly initialize accounts
172172
// This ensures the ManagedAccountCollection is synchronized with the Wallet's accounts
173-
let mut managed_info = T::from_wallet(&wallet, birth_height);
174-
managed_info.set_first_loaded_at(current_timestamp());
173+
let managed_info = T::from_wallet(&wallet, birth_height);
175174

176175
// The wallet already has accounts created according to the provided options
177176
// No need to manually add accounts here since that's handled by from_mnemonic/from_mnemonic_with_passphrase
@@ -275,8 +274,7 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletManager<T> {
275274
})?;
276275

277276
// Add the wallet to the manager
278-
let mut managed_info = T::from_wallet(&final_wallet, birth_height);
279-
managed_info.set_first_loaded_at(current_timestamp());
277+
let managed_info = T::from_wallet(&final_wallet, birth_height);
280278

281279
self.wallets.insert(wallet_id, final_wallet);
282280
self.wallet_infos.insert(wallet_id, managed_info);
@@ -309,8 +307,7 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletManager<T> {
309307
}
310308

311309
// Create managed wallet info
312-
let mut managed_info = T::from_wallet(&wallet, self.last_processed_height());
313-
managed_info.set_first_loaded_at(current_timestamp());
310+
let managed_info = T::from_wallet(&wallet, self.last_processed_height());
314311

315312
self.wallets.insert(wallet_id, wallet);
316313
self.wallet_infos.insert(wallet_id, managed_info);
@@ -349,8 +346,7 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletManager<T> {
349346
}
350347

351348
// Create managed wallet info
352-
let mut managed_info = T::from_wallet(&wallet, self.last_processed_height());
353-
managed_info.set_first_loaded_at(current_timestamp());
349+
let managed_info = T::from_wallet(&wallet, self.last_processed_height());
354350

355351
self.wallets.insert(wallet_id, wallet);
356352
self.wallet_infos.insert(wallet_id, managed_info);
@@ -396,8 +392,7 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletManager<T> {
396392
}
397393

398394
// Create managed wallet info
399-
let mut managed_info = T::from_wallet(&wallet, self.last_processed_height());
400-
managed_info.set_first_loaded_at(current_timestamp());
395+
let managed_info = T::from_wallet(&wallet, self.last_processed_height());
401396

402397
self.wallets.insert(wallet_id, wallet);
403398
self.wallet_infos.insert(wallet_id, managed_info);
@@ -440,8 +435,7 @@ impl<T: WalletInfoInterface + Send + Sync + 'static> WalletManager<T> {
440435
// Create managed wallet info from the imported wallet, using the manager's
441436
// current aggregated last-processed height as the fallback birth height
442437
// since the serialized form does not preserve it.
443-
let mut managed_info = T::from_wallet(&wallet, self.last_processed_height());
444-
managed_info.set_first_loaded_at(current_timestamp());
438+
let managed_info = T::from_wallet(&wallet, self.last_processed_height());
445439

446440
self.wallets.insert(wallet_id, wallet);
447441
self.wallet_infos.insert(wallet_id, managed_info);

key-wallet/src/transaction_checking/wallet_checker.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ impl WalletTransactionChecker for ManagedWalletInfo {
199199
if context.is_instant_send() {
200200
self.instant_send_locks.insert(txid);
201201
}
202-
self.increment_transactions();
203202

204203
let wallet_net = result.total_received as i64 - result.total_sent as i64;
205204
tracing::info!(
@@ -723,11 +722,6 @@ mod tests {
723722
"Transaction should be stored"
724723
);
725724
let tx_count_before = managed_account.transactions.len();
726-
let total_tx_count_before = managed_wallet.metadata.total_transactions;
727-
assert_eq!(
728-
total_tx_count_before, 1,
729-
"total_transactions should be 1 after first processing"
730-
);
731725

732726
// Second processing (simulating rescan) - should be marked as existing
733727
let result2 =
@@ -749,12 +743,6 @@ mod tests {
749743
"Transaction count should not increase on rescan"
750744
);
751745

752-
// Verify total_transactions metadata hasn't changed on rescan
753-
assert_eq!(
754-
managed_wallet.metadata.total_transactions, total_tx_count_before,
755-
"total_transactions should not increase on rescan"
756-
);
757-
758746
// Verify UTXO state is unchanged after rescan
759747
assert_eq!(managed_account.utxos.len(), 1, "Should still have exactly one UTXO");
760748
let utxo = managed_account.utxos.values().next().expect("Should have UTXO");
@@ -880,8 +868,6 @@ mod tests {
880868
assert_eq!(ctx.transaction(&txid).context, TransactionContext::Mempool);
881869
assert!(!ctx.first_utxo().is_confirmed, "Mempool UTXO should be unconfirmed");
882870

883-
let total_tx_before = ctx.managed_wallet.metadata.total_transactions;
884-
885871
// Same transaction now seen in a block
886872
let block_hash = BlockHash::from_slice(&[5u8; 32]).expect("Should create block hash");
887873
let block_context =
@@ -898,11 +884,6 @@ mod tests {
898884
assert_eq!(record.block_info().unwrap().block_hash, block_hash);
899885
assert_eq!(record.block_info().unwrap().timestamp, 1700000000);
900886
assert!(ctx.first_utxo().is_confirmed, "UTXO should now be confirmed");
901-
902-
assert_eq!(
903-
ctx.managed_wallet.metadata.total_transactions, total_tx_before,
904-
"total_transactions should not increase for confirmation of existing tx"
905-
);
906887
}
907888

908889
/// Test the full lifecycle: mempool -> IS -> block -> chain-locked block -> late IS
@@ -916,7 +897,6 @@ mod tests {
916897
assert_eq!(ctx.managed_wallet.balance().unconfirmed(), 200_000);
917898
assert_eq!(ctx.managed_wallet.balance().confirmed(), 0);
918899
assert_eq!(ctx.managed_wallet.balance().spendable(), 200_000);
919-
assert_eq!(ctx.managed_wallet.metadata.total_transactions, 1);
920900

921901
// Stage 2: IS lock
922902
let is_lock = InstantLock {
@@ -930,7 +910,6 @@ mod tests {
930910
assert_eq!(ctx.managed_wallet.balance().unconfirmed(), 0);
931911
assert!(ctx.first_utxo().is_instantlocked);
932912
assert!(!ctx.first_utxo().is_confirmed);
933-
assert_eq!(ctx.managed_wallet.metadata.total_transactions, 1);
934913
assert!(ctx.managed_wallet.instant_send_locks.contains(&txid));
935914

936915
// Verify the TransactionRecord stores the IS lock payload
@@ -966,7 +945,6 @@ mod tests {
966945
let result = ctx.check_transaction(&tx, cl_context).await;
967946
assert!(!result.is_new_transaction);
968947
assert_eq!(ctx.managed_wallet.balance().spendable(), 200_000);
969-
assert_eq!(ctx.managed_wallet.metadata.total_transactions, 1);
970948

971949
// Stage 5: late IS lock on already-confirmed tx should be ignored
972950
let balance_before = ctx.managed_wallet.balance();
@@ -1004,7 +982,6 @@ mod tests {
1004982
.await;
1005983
assert!(!result2.is_new_transaction);
1006984
assert_eq!(ctx.managed_wallet.balance().spendable(), 150_000);
1007-
assert_eq!(ctx.managed_wallet.metadata.total_transactions, 1);
1008985
}
1009986

1010987
/// Test that the InstantSend branch backfills a `TransactionRecord` on accounts

key-wallet/src/wallet/managed_wallet_info/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,6 @@ impl ManagedWalletInfo {
122122
self.network
123123
}
124124

125-
/// Increment the transaction count
126-
pub fn increment_transactions(&mut self) {
127-
self.metadata.total_transactions += 1;
128-
}
129-
130125
/// Read-only access to the InstantSend lock txid set.
131126
///
132127
/// Exposes `instant_send_locks` (a `pub(crate)` field marked

key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ pub trait WalletInfoInterface: Sized + WalletTransactionChecker + ManagedAccount
5252
/// Get the birth height of the wallet
5353
fn birth_height(&self) -> CoreBlockHeight;
5454

55-
/// Get the timestamp when first loaded
56-
fn first_loaded_at(&self) -> u64;
57-
58-
/// Set the timestamp when first loaded
59-
fn set_first_loaded_at(&mut self, timestamp: u64);
60-
6155
/// Update last synced timestamp
6256
fn update_last_synced(&mut self, timestamp: u64);
6357

@@ -180,14 +174,6 @@ impl WalletInfoInterface for ManagedWalletInfo {
180174
self.metadata.synced_height
181175
}
182176

183-
fn first_loaded_at(&self) -> u64 {
184-
self.metadata.first_loaded_at
185-
}
186-
187-
fn set_first_loaded_at(&mut self, timestamp: u64) {
188-
self.metadata.first_loaded_at = timestamp;
189-
}
190-
191177
fn update_last_synced(&mut self, timestamp: u64) {
192178
self.metadata.last_synced = Some(timestamp);
193179
}

key-wallet/src/wallet/metadata.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use serde::{Deserialize, Serialize};
1212
#[derive(Debug, Clone, Default)]
1313
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
1414
pub struct WalletMetadata {
15-
/// Wallet creation timestamp
16-
pub first_loaded_at: u64,
1715
/// Birth height (when wallet was created/restored) - 0 (genesis) if unknown
1816
pub birth_height: CoreBlockHeight,
1917
/// Last processed block height
@@ -22,8 +20,6 @@ pub struct WalletMetadata {
2220
pub synced_height: CoreBlockHeight,
2321
/// Last sync timestamp
2422
pub last_synced: Option<u64>,
25-
/// Total transactions
26-
pub total_transactions: u64,
2723
/// Wallet version
2824
pub version: u32,
2925
/// Custom metadata fields

key-wallet/src/wallet/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ mod tests {
425425
assert_eq!(managed_info.metadata.birth_height, 100);
426426
assert_eq!(managed_info.metadata.synced_height, 99);
427427
assert_eq!(managed_info.metadata.last_processed_height, 99);
428-
assert_eq!(managed_info.metadata.first_loaded_at, 0); // Default value
429428
assert!(managed_info.metadata.last_synced.is_none());
430429

431430
// Test updating metadata

0 commit comments

Comments
 (0)