Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion key-wallet/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use crate::managed_account::address_pool::AddressPoolType;
pub use crate::managed_account::managed_account_collection::ManagedAccountCollection;
pub use crate::managed_account::managed_account_trait::ManagedAccountTrait;
pub use crate::managed_account::managed_account_type::ManagedAccountType;
pub use crate::managed_account::metadata::AccountMetadata;
pub use crate::managed_account::transaction_record::{
InputDetail, OutputDetail, OutputRole, TransactionDirection, TransactionRecord,
};
Expand Down
7 changes: 0 additions & 7 deletions key-wallet/src/managed_account/managed_account_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use std::collections::BTreeMap;

use crate::account::AccountMetadata;
use crate::account::TransactionRecord;
use crate::managed_account::managed_account_type::ManagedAccountType;
use crate::utxo::Utxo;
Expand All @@ -24,12 +23,6 @@ pub trait ManagedAccountTrait {
/// Get the network
fn network(&self) -> Network;

/// Get metadata
fn metadata(&self) -> &AccountMetadata;

/// Get mutable metadata
fn metadata_mut(&mut self) -> &mut AccountMetadata;

/// Check if this is a watch-only account
fn is_watch_only(&self) -> bool;

Expand Down
25 changes: 1 addition & 24 deletions key-wallet/src/managed_account/managed_platform_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use std::collections::BTreeMap;

use super::address_pool::{AddressPool, KeySource};
use super::metadata::AccountMetadata;
use super::platform_address::PlatformP2PKHAddress;
use crate::error::{Error, Result};
use crate::Network;
Expand Down Expand Up @@ -48,8 +47,6 @@ pub struct ManagedPlatformAccount {
pub address_balances: BTreeMap<PlatformP2PKHAddress, u64>,
/// Address pool for key derivation and address generation
pub addresses: AddressPool,
/// Account metadata
pub metadata: AccountMetadata,
/// Whether this is a watch-only account
pub is_watch_only: bool,
}
Expand All @@ -67,7 +64,6 @@ impl ManagedPlatformAccount {
credit_balance: 0,
address_balances: BTreeMap::new(),
addresses,
metadata: AccountMetadata::default(),
is_watch_only,
}
}
Expand All @@ -85,7 +81,6 @@ impl ManagedPlatformAccount {
/// Set the total credit balance
pub fn set_credit_balance(&mut self, credit_balance: u64) {
self.credit_balance = credit_balance;
self.metadata.last_used = Some(Self::current_timestamp());
}

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

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

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

Expand Down Expand Up @@ -254,11 +246,7 @@ impl ManagedPlatformAccount {

/// Mark an address as used
pub fn mark_address_used(&mut self, address: &Address) -> bool {
let result = self.addresses.mark_used(address);
if result {
self.metadata.last_used = Some(Self::current_timestamp());
}
result
self.addresses.mark_used(address)
}

/// Mark a platform address as used
Expand Down Expand Up @@ -300,14 +288,6 @@ impl ManagedPlatformAccount {
self.addresses.address_info(address).cloned()
}

/// Get the current timestamp
fn current_timestamp() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
}

/// Get pool statistics
pub fn address_pool_stats(&self) -> super::address_pool::PoolStats {
self.addresses.stats()
Expand Down Expand Up @@ -347,7 +327,6 @@ impl bincode::Encode for ManagedPlatformAccount {
bincode::Encode::encode(&address_balances_vec, encoder)?;

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

let addresses = bincode::Decode::decode(decoder)?;
let metadata = bincode::Decode::decode(decoder)?;
let is_watch_only = bincode::Decode::decode(decoder)?;

Ok(Self {
Expand All @@ -380,7 +358,6 @@ impl<Context> bincode::Decode<Context> for ManagedPlatformAccount {
credit_balance,
address_balances,
addresses,
metadata,
is_watch_only,
})
}
Expand Down
33 changes: 0 additions & 33 deletions key-wallet/src/managed_account/metadata.rs

This file was deleted.

33 changes: 3 additions & 30 deletions key-wallet/src/managed_account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! This module contains the mutable account state that changes during wallet operation,
//! kept separate from the immutable Account structure.

use crate::account::AccountMetadata;
#[cfg(feature = "bls")]
use crate::account::BLSAccount;
#[cfg(feature = "eddsa")]
Expand Down Expand Up @@ -38,24 +37,21 @@ pub mod managed_account_collection;
pub mod managed_account_trait;
pub mod managed_account_type;
pub mod managed_platform_account;
pub mod metadata;
pub mod platform_address;
pub mod transaction_record;

/// Managed account with mutable state
///
/// This struct contains the mutable state of an account including address pools,
/// metadata, and balance information. It is managed separately from
/// the immutable Account structure.
/// This struct contains the mutable state of an account including address pools
/// and balance information. It is managed separately from the immutable Account
/// structure.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct ManagedCoreAccount {
/// Account type with embedded address pools and index
pub managed_account_type: ManagedAccountType,
/// Network this account belongs to
pub network: Network,
/// Account metadata
pub metadata: AccountMetadata,
/// Whether this is a watch-only account
pub is_watch_only: bool,
/// Account balance information
Expand Down Expand Up @@ -84,7 +80,6 @@ impl ManagedCoreAccount {
Self {
managed_account_type,
network,
metadata: AccountMetadata::default(),
is_watch_only,
balance: WalletCoreBalance::default(),
transactions: BTreeMap::new(),
Expand Down Expand Up @@ -301,9 +296,6 @@ impl ManagedCoreAccount {

/// Mark an address as used
pub fn mark_address_used(&mut self, address: &Address) -> bool {
// Update metadata timestamp
self.metadata.last_used = Some(Self::current_timestamp());

// Use the account type's mark_address_used method
// The address pools already track gap limits internally
self.managed_account_type.mark_address_used(address)
Expand Down Expand Up @@ -615,7 +607,6 @@ impl ManagedCoreAccount {
}
}
self.balance = WalletCoreBalance::new(confirmed, unconfirmed, immature, locked);
self.metadata.last_used = Some(Self::current_timestamp());
}

/// Get all addresses from all pools
Expand Down Expand Up @@ -1175,14 +1166,6 @@ impl ManagedCoreAccount {
self.managed_account_type.get_address_derivation_path(address)
}

/// Get the current timestamp (for metadata)
fn current_timestamp() -> u64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
}

/// Get total address count across all pools
pub fn total_address_count(&self) -> usize {
self.managed_account_type
Expand Down Expand Up @@ -1302,14 +1285,6 @@ impl ManagedAccountTrait for ManagedCoreAccount {
self.network
}

fn metadata(&self) -> &AccountMetadata {
&self.metadata
}

fn metadata_mut(&mut self) -> &mut AccountMetadata {
&mut self.metadata
}

fn is_watch_only(&self) -> bool {
self.is_watch_only
}
Expand Down Expand Up @@ -1349,7 +1324,6 @@ impl<'de> Deserialize<'de> for ManagedCoreAccount {
struct Helper {
managed_account_type: ManagedAccountType,
network: Network,
metadata: AccountMetadata,
is_watch_only: bool,
balance: WalletCoreBalance,
transactions: BTreeMap<Txid, TransactionRecord>,
Expand All @@ -1368,7 +1342,6 @@ impl<'de> Deserialize<'de> for ManagedCoreAccount {
Ok(ManagedCoreAccount {
managed_account_type: helper.managed_account_type,
network: helper.network,
metadata: helper.metadata,
is_watch_only: helper.is_watch_only,
balance: helper.balance,
transactions: helper.transactions,
Expand Down
Loading