Skip to content

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Jan 4, 2026

Move the account balance updates happening within check_transaction into ManagedAccount::update_balance and reuse it in ManagedWalletInfo::update_balance which also already gets called in check_transaction.

Summary by CodeRabbit

  • Refactor

    • Reworked balance computation to aggregate per-account balances from UTXOs and defer updates until after transaction processing, simplifying and stabilizing when totals are calculated.
    • Improved internal balance arithmetic to support efficient accumulation across accounts.
  • Tests

    • Added behavioral tests verifying correct in-place balance accumulation and zero-value behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

📝 Walkthrough

Walkthrough

ManagedAccount::update_balance now computes spendable, unconfirmed, and locked balances by aggregating its UTXOs internally. Wallet-level update_balance delegates to each account's parameterless update and accumulates account balances using a new WalletBalance AddAssign implementation.

Changes

Cohort / File(s) Summary
Account-level balance computation
key-wallet/src/managed_account/mod.rs
pub fn update_balance(&mut self, spendable: u64, unconfirmed: u64, locked: u64)pub fn update_balance(&mut self). Balance fields are now computed internally by iterating and classifying UTXOs (locked, confirmed/spendable, unconfirmed).
Balance operator & tests
key-wallet/src/wallet/balance.rs
Added impl AddAssign for WalletBalance to enable += accumulation across spendable, unconfirmed, and locked fields. Included unit test verifying AddAssign behavior.
Deferred/batched balance updates
key-wallet/src/transaction_checking/wallet_checker.rs
Removed immediate per-UTXO recalculation and call to the old account.update_balance(confirmed, unconfirmed, locked) after transaction processing. Balance updates are deferred to a later aggregated self.update_balance() call.
Wallet-level balance aggregation
key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
Reworked update_balance() to: iterate accounts via all_accounts_mut(), call account.update_balance() for each, accumulate totals using WalletBalance += account.balance(), and set self.balance to the aggregate. Removed direct UTXO-level accumulation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I nibble UTXOs, counting each hop—

spendable, locked, and those not yet dropped.
Accounts whisper sums into wallet delight,
+= stitches them neat, all tidy and right.
A rabbit's small cheer for refactor tonight.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'refactor: consolidate balance calculations' accurately summarizes the main objective of moving and consolidating balance update logic from check_transaction into ManagedAccount::update_balance and reusing it in ManagedWalletInfo::update_balance.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xdustinface xdustinface marked this pull request as draft January 4, 2026 00:36
@xdustinface xdustinface force-pushed the refactor/wallet-balance branch from bad5230 to 2860407 Compare January 5, 2026 19:51
@github-actions github-actions bot added the merge-conflict The PR conflicts with the target branch. label Jan 5, 2026
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@xdustinface xdustinface force-pushed the refactor/wallet-balance-updates branch from 6ea5b3f to 508f2b3 Compare January 5, 2026 22:23
@xdustinface xdustinface changed the base branch from refactor/wallet-balance to v0.42-dev January 5, 2026 22:54
@xdustinface xdustinface closed this Jan 6, 2026
@xdustinface xdustinface reopened this Jan 6, 2026
@github-actions github-actions bot removed the merge-conflict The PR conflicts with the target branch. label Jan 6, 2026
@xdustinface xdustinface marked this pull request as ready for review January 6, 2026 22:05
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI Agents
In @key-wallet/src/wallet/balance.rs:
- Line 8: Replace the import of std::ops::AddAssign with core::ops::AddAssign so
the crate remains no_std compatible; update the use statement that currently
references AddAssign to import from core::ops::AddAssign (the symbol: AddAssign)
to match the existing core::fmt usage and the crate's no_std cfg in lib.rs.
🧹 Nitpick comments (1)
key-wallet/src/managed_account/mod.rs (1)

268-284: Good refactor consolidating balance computation from UTXOs.

The logic correctly prioritizes locked status, then confirmed, then unconfirmed. A few observations:

  1. Potential overflow: The += operations on lines 275, 277, 279 could overflow if an account accumulates an extremely large number of UTXOs. Consider using saturating_add or checked_add for defensive coding.

  2. Semantic concern with last_used: Updating last_used on every update_balance() call (line 283) may not be semantically accurate—a balance recalculation doesn't mean the account was actively used. This was present before, but the refactor amplifies it since update_balance() is now called more frequently (from wallet-level aggregation).

🔎 Consider using saturating arithmetic
     pub fn update_balance(&mut self) {
         let mut spendable = 0;
         let mut unconfirmed = 0;
         let mut locked = 0;
         for utxo in self.utxos.values() {
             let value = utxo.txout.value;
             if utxo.is_locked {
-                locked += value;
+                locked = locked.saturating_add(value);
             } else if utxo.is_confirmed {
-                spendable += value;
+                spendable = spendable.saturating_add(value);
             } else {
-                unconfirmed += value;
+                unconfirmed = unconfirmed.saturating_add(value);
             }
         }
         self.balance = WalletBalance::new(spendable, unconfirmed, locked);
-        self.metadata.last_used = Some(Self::current_timestamp());
+        // Consider: only update last_used when account is actively used (e.g., mark_address_used)
     }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bac762f and 508f2b3.

📒 Files selected for processing (4)
  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/transaction_checking/wallet_checker.rs
  • key-wallet/src/wallet/balance.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
💤 Files with no reviewable changes (1)
  • key-wallet/src/transaction_checking/wallet_checker.rs
🧰 Additional context used
📓 Path-based instructions (3)
key-wallet/**/*.rs

📄 CodeRabbit inference engine (key-wallet/CLAUDE.md)

key-wallet/**/*.rs: Separate immutable structures (Account, Wallet) containing only identity information from mutable wrappers (ManagedAccount, ManagedWalletInfo) with state management
Never serialize or log private keys in production; use public keys or key fingerprints for identification instead
Always validate network consistency when deriving or validating addresses; never mix mainnet and testnet operations
Use BTreeMap for ordered data (accounts, transactions) and HashMap for lookups (address mappings); apply memory management strategies for old transaction data
Apply atomic state updates when managing watch-only wallets: validate that external signatures match expected pubkeys and never attempt signing operations
Use the ? operator for error propagation, provide context in error messages, never panic in library code, and return Result<T> for all fallible operations

Files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/balance.rs
key-wallet/**/managed_account/**/*.rs

📄 CodeRabbit inference engine (key-wallet/CLAUDE.md)

Implement atomic state updates when processing transactions: update transactions, UTXOs, balances, and address usage state together

Files:

  • key-wallet/src/managed_account/mod.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: MSRV (Minimum Supported Rust Version) is 1.89; ensure compatibility with this version for all builds
Unit tests should live alongside code with #[cfg(test)] annotation; integration tests use the tests/ directory
Use snake_case for function and variable names
Use UpperCamelCase for types and traits
Use SCREAMING_SNAKE_CASE for constants
Format code with rustfmt before commits; ensure cargo fmt --all is run
Run cargo clippy --workspace --all-targets -- -D warnings for linting; avoid warnings in CI
Prefer async/await via tokio for asynchronous operations

**/*.rs: Never hardcode network parameters, addresses, or keys in Rust code
Use proper error types (thiserror) and propagate errors appropriately in Rust
Use tokio runtime for async operations in Rust
Use conditional compilation with feature flags for optional features
Write unit tests for new functionality in Rust
Format code using cargo fmt
Run clippy with all features and all targets, treating warnings as errors
Never log or expose private keys in any code
Always validate inputs from untrusted sources in Rust
Use secure random number generation for keys

Files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/balance.rs
🧠 Learnings (9)
📓 Common learnings
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/managed_account/**/*.rs : Implement atomic state updates when processing transactions: update transactions, UTXOs, balances, and address usage state together
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Separate immutable structures (`Account`, `Wallet`) containing only identity information from mutable wrappers (`ManagedAccount`, `ManagedWalletInfo`) with state management
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Use `BTreeMap` for ordered data (accounts, transactions) and `HashMap` for lookups (address mappings); apply memory management strategies for old transaction data
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/managed_account/**/*.rs : Implement atomic state updates when processing transactions: update transactions, UTXOs, balances, and address usage state together

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/balance.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Separate immutable structures (`Account`, `Wallet`) containing only identity information from mutable wrappers (`ManagedAccount`, `ManagedWalletInfo`) with state management

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/balance.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Apply atomic state updates when managing watch-only wallets: validate that external signatures match expected pubkeys and never attempt signing operations

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/balance.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Use `BTreeMap` for ordered data (accounts, transactions) and `HashMap` for lookups (address mappings); apply memory management strategies for old transaction data

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/balance.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/account/**/*.rs : Use enum-based type system for `AccountType` with specific variants (Standard, IdentityAuthentication, IdentityEncryption, MasternodeOperator, etc.) to provide compile-time safety and clear semantics

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/balance.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/transaction_checking/**/*.rs : Implement transaction classification and routing through `TransactionRouter` to avoid checking all accounts for every transaction

Applied to files:

  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/address_pool/**/*.rs : Support multiple `KeySource` variants (Private, Public, NoKeySource) to enable both full wallets and watch-only wallets with the same interface

Applied to files:

  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
  • key-wallet/src/wallet/balance.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Use the `?` operator for error propagation, provide context in error messages, never panic in library code, and return `Result<T>` for all fallible operations

Applied to files:

  • key-wallet/src/wallet/balance.rs
🧬 Code graph analysis (3)
key-wallet/src/managed_account/mod.rs (2)
key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs (2)
  • update_balance (81-81)
  • update_balance (205-212)
key-wallet/src/wallet/balance.rs (3)
  • spendable (33-35)
  • unconfirmed (38-40)
  • locked (43-45)
key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs (1)
key-wallet/src/managed_account/mod.rs (1)
  • balance (858-860)
key-wallet/src/wallet/balance.rs (1)
key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs (2)
  • balance (78-78)
  • balance (201-203)
🔇 Additional comments (4)
key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs (2)

6-6: Import added to support per-account balance method access.

The ManagedAccountTrait import is necessary to call account.balance() on the mutable account references. This aligns with the trait-based architecture separating immutable identity from mutable state management.


205-211: Clean delegation of balance computation to per-account updates.

This refactor properly centralizes balance calculation: each account computes its own balance from its UTXOs, then the wallet aggregates. The use of AddAssign makes the accumulation idiomatic.

One minor note: the dereference *account.balance() is required since balance() returns &WalletBalance. This works correctly with the Copy derive on WalletBalance.

key-wallet/src/wallet/balance.rs (2)

66-72: AddAssign implementation is correct but inherits overflow behavior.

The implementation correctly adds only the stored fields (spendable, unconfirmed, locked), relying on total() being computed on-the-fly.

Note: The existing test_balance_overflow test (line 88-92) documents that overflow panics are expected for total(). The AddAssign operations on lines 68-70 have the same overflow behavior. This is consistent but worth documenting—if accounts with massive balances are aggregated, overflow could occur during +=.


104-118: Good test coverage for AddAssign.

The test validates both:

  1. Adding non-zero balances correctly sums all fields
  2. Adding a default (zero) balance leaves the original unchanged

Consider adding an overflow test case for AddAssign to match the existing test_balance_overflow pattern if overflow behavior should be documented/enforced.

}
}

let _ = account.update_balance(confirmed, unconfirmed, locked);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you can remove this update call??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's just moved into ManagedWalletInfo::update_balance which now calls ManagedAccount::update_balance. Before it only updated its own balance.

Move the account balance updates happening within `check_transaction` into `ManagedAccount::update_balance` and reuse it in `ManagedWalletInfo::update_balance` which also already gets called in `check_transaction`.
@xdustinface xdustinface force-pushed the refactor/wallet-balance-updates branch from 508f2b3 to 7f66b40 Compare January 6, 2026 22:53
@xdustinface xdustinface requested a review from ZocoLini January 6, 2026 22:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI Agents
In @key-wallet/src/managed_account/mod.rs:
- Around line 268-284: The update_balance method misclassifies
InstantSend-locked UTXOs as unconfirmed; modify ManagedAccount::update_balance
to treat utxo.is_instantlocked as spendable (i.e., include utxo in the spendable
branch when utxo.is_confirmed || utxo.is_instantlocked) so its behavior matches
get_spendable_utxos; update the conditional around spendable/unconfirmed/locked
accumulation in update_balance accordingly and leave
WalletBalance::new(spendable, unconfirmed, locked) and metadata updates as-is.
🧹 Nitpick comments (1)
key-wallet/src/managed_account/mod.rs (1)

283-283: Consider semantics of timestamp update during balance recalculation.

Updating last_used on every balance recalculation may not accurately reflect actual account usage, as balance updates can occur passively through transaction confirmations or maturation without user interaction. Consider whether this timestamp should only be updated when addresses are explicitly marked as used (line 260).

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 508f2b3 and 7f66b40.

📒 Files selected for processing (4)
  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/transaction_checking/wallet_checker.rs
  • key-wallet/src/wallet/balance.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
💤 Files with no reviewable changes (1)
  • key-wallet/src/transaction_checking/wallet_checker.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • key-wallet/src/wallet/balance.rs
🧰 Additional context used
📓 Path-based instructions (3)
key-wallet/**/*.rs

📄 CodeRabbit inference engine (key-wallet/CLAUDE.md)

key-wallet/**/*.rs: Separate immutable structures (Account, Wallet) containing only identity information from mutable wrappers (ManagedAccount, ManagedWalletInfo) with state management
Never serialize or log private keys in production; use public keys or key fingerprints for identification instead
Always validate network consistency when deriving or validating addresses; never mix mainnet and testnet operations
Use BTreeMap for ordered data (accounts, transactions) and HashMap for lookups (address mappings); apply memory management strategies for old transaction data
Apply atomic state updates when managing watch-only wallets: validate that external signatures match expected pubkeys and never attempt signing operations
Use the ? operator for error propagation, provide context in error messages, never panic in library code, and return Result<T> for all fallible operations

Files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
key-wallet/**/managed_account/**/*.rs

📄 CodeRabbit inference engine (key-wallet/CLAUDE.md)

Implement atomic state updates when processing transactions: update transactions, UTXOs, balances, and address usage state together

Files:

  • key-wallet/src/managed_account/mod.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: MSRV (Minimum Supported Rust Version) is 1.89; ensure compatibility with this version for all builds
Unit tests should live alongside code with #[cfg(test)] annotation; integration tests use the tests/ directory
Use snake_case for function and variable names
Use UpperCamelCase for types and traits
Use SCREAMING_SNAKE_CASE for constants
Format code with rustfmt before commits; ensure cargo fmt --all is run
Run cargo clippy --workspace --all-targets -- -D warnings for linting; avoid warnings in CI
Prefer async/await via tokio for asynchronous operations

**/*.rs: Never hardcode network parameters, addresses, or keys in Rust code
Use proper error types (thiserror) and propagate errors appropriately in Rust
Use tokio runtime for async operations in Rust
Use conditional compilation with feature flags for optional features
Write unit tests for new functionality in Rust
Format code using cargo fmt
Run clippy with all features and all targets, treating warnings as errors
Never log or expose private keys in any code
Always validate inputs from untrusted sources in Rust
Use secure random number generation for keys

Files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
🧠 Learnings (8)
📓 Common learnings
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/managed_account/**/*.rs : Implement atomic state updates when processing transactions: update transactions, UTXOs, balances, and address usage state together
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/managed_account/**/*.rs : Implement atomic state updates when processing transactions: update transactions, UTXOs, balances, and address usage state together

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Separate immutable structures (`Account`, `Wallet`) containing only identity information from mutable wrappers (`ManagedAccount`, `ManagedWalletInfo`) with state management

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Apply atomic state updates when managing watch-only wallets: validate that external signatures match expected pubkeys and never attempt signing operations

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/*.rs : Use `BTreeMap` for ordered data (accounts, transactions) and `HashMap` for lookups (address mappings); apply memory management strategies for old transaction data

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/account/**/*.rs : Use enum-based type system for `AccountType` with specific variants (Standard, IdentityAuthentication, IdentityEncryption, MasternodeOperator, etc.) to provide compile-time safety and clear semantics

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/address_pool/**/*.rs : Support multiple `KeySource` variants (Private, Public, NoKeySource) to enable both full wallets and watch-only wallets with the same interface

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
📚 Learning: 2025-12-19T00:07:22.904Z
Learnt from: CR
Repo: dashpay/rust-dashcore PR: 0
File: key-wallet/CLAUDE.md:0-0
Timestamp: 2025-12-19T00:07:22.904Z
Learning: Applies to key-wallet/**/transaction_checking/**/*.rs : Implement transaction classification and routing through `TransactionRouter` to avoid checking all accounts for every transaction

Applied to files:

  • key-wallet/src/managed_account/mod.rs
  • key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs
🧬 Code graph analysis (2)
key-wallet/src/managed_account/mod.rs (2)
key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs (2)
  • update_balance (81-81)
  • update_balance (205-212)
key-wallet/src/wallet/balance.rs (3)
  • spendable (33-35)
  • unconfirmed (38-40)
  • locked (43-45)
key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs (2)
key-wallet/src/managed_account/mod.rs (1)
  • balance (858-860)
key-wallet/src/managed_account/managed_account_trait.rs (1)
  • balance (36-36)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: macOS / wallet
  • GitHub Check: fuzz (hashes_sha512)
  • GitHub Check: fuzz (dash_deserialize_address)
  • GitHub Check: fuzz (dash_deserialize_amount)
  • GitHub Check: fuzz (hashes_cbor)
  • GitHub Check: fuzz (dash_deserialize_script)
  • GitHub Check: fuzz (dash_deserialize_block)
  • GitHub Check: fuzz (hashes_sha256)
  • GitHub Check: fuzz (hashes_sha1)
  • GitHub Check: fuzz (dash_deserialize_witness)
  • GitHub Check: fuzz (hashes_json)
  • GitHub Check: fuzz (dash_script_bytes_to_asm_fmt)
  • GitHub Check: fuzz (hashes_sha512_256)
  • GitHub Check: fuzz (hashes_ripemd160)
  • GitHub Check: fuzz (dash_deser_net_msg)
  • GitHub Check: Pre-commit (windows-latest)
  • GitHub Check: Pre-commit (macos-latest)
  • GitHub Check: Pre-commit (ubuntu-latest)
  • GitHub Check: Thread Sanitizer
  • GitHub Check: Address Sanitizer
🔇 Additional comments (2)
key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs (2)

6-6: LGTM!

The import enables trait-based access to account balance methods, supporting the refactored balance calculation flow.


205-212: LGTM! Centralized balance logic is well-structured.

The refactored implementation correctly delegates balance computation to individual accounts and aggregates the results. The use of AddAssign (implemented in balance.rs as noted in the summary) provides clean accumulation semantics.

@xdustinface xdustinface merged commit 0d21901 into v0.42-dev Jan 6, 2026
53 checks passed
@xdustinface xdustinface deleted the refactor/wallet-balance-updates branch January 6, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants