Skip to content

Conversation

@kwvg
Copy link
Collaborator

@kwvg kwvg commented May 23, 2025

Additional Information

  • Even though "DiplayBitcoinUnit" has been Dashified, the associated value is not (see below, from ~/.config/Dash/Dash-Qt-testnet.conf) as renaming "BitcoinUnit" would cause significant conflicts when backporting, so it has retained its upstream name.

    DisplayDashUnit=@Variant(\0\0\0\x7f\0\0\0\x13\x42itcoinUnits::Unit\0\0)
    
  • bitcoin-core/gui#581 affects three Dash-specific signal handlers, m_handler_notify_additional_data_sync_progess_changed, m_handler_notify_chainlock and m_handler_notify_masternodelist_changed and their refactoring needs to be specially reviewed.

Breaking Changes

None expected.

Checklist

  • I have performed a self-review of my own code (note: N/A)
  • I have commented my code, particularly in hard-to-understand areas (note: N/A)
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation (note: N/A)
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@kwvg kwvg added this to the 23 milestone May 23, 2025
@kwvg kwvg marked this pull request as ready for review May 26, 2025 16:45
@kwvg kwvg requested review from PastaPastaPasta, UdjinM6 and knst May 26, 2025 16:46
@coderabbitai
Copy link

coderabbitai bot commented May 26, 2025

Walkthrough

This change set refactors and modernizes the handling of Bitcoin unit types throughout the Qt GUI codebase by replacing plain integer representations with a strongly typed BitcoinUnit enum class. All relevant method signatures, member variables, and signal/slot parameters are updated to use BitcoinUnit instead of int. Serialization support for the enum is added, and Qt meta-type integration is enabled. The display unit setting in the options model is migrated from an integer to a BitcoinUnit-wrapped QVariant, with corresponding changes in initialization, retrieval, and update logic. Additionally, the node interface is streamlined by merging separate reindexing and importing state checks into a single isLoadingBlocks() method, and signal handling in the client model is refactored to use lambdas and a unified handler vector. Several methods are made const for correctness, and minor UI and translation improvements are included. The TransactionStatus class is simplified to a struct with inline initializers, and some unused parameters are removed from transaction description methods. UI components have improved shutdown handling and window title updates. Ban table model gains an unban method, and wallet unlocking logic is enhanced for wallets without private keys.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 206df625960891cc849d9abcaffd41b313f3bedb and a41f4e7.

📒 Files selected for processing (17)
  • src/interfaces/node.h (1 hunks)
  • src/node/interfaces.cpp (1 hunks)
  • src/qt/addressbookpage.cpp (3 hunks)
  • src/qt/addressbookpage.h (1 hunks)
  • src/qt/addresstablemodel.cpp (1 hunks)
  • src/qt/addresstablemodel.h (1 hunks)
  • src/qt/bantablemodel.cpp (2 hunks)
  • src/qt/bantablemodel.h (2 hunks)
  • src/qt/bitcoin.cpp (3 hunks)
  • src/qt/bitcoingui.cpp (9 hunks)
  • src/qt/clientmodel.cpp (4 hunks)
  • src/qt/clientmodel.h (5 hunks)
  • src/qt/forms/debugwindow.ui (1 hunks)
  • src/qt/rpcconsole.cpp (3 hunks)
  • src/qt/sendcoinsdialog.cpp (2 hunks)
  • src/qt/walletmodel.cpp (5 hunks)
  • src/qt/walletmodel.h (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (17)
  • src/qt/addressbookpage.h
  • src/qt/addresstablemodel.h
  • src/qt/addresstablemodel.cpp
  • src/qt/bantablemodel.h
  • src/qt/forms/debugwindow.ui
  • src/qt/bitcoin.cpp
  • src/interfaces/node.h
  • src/node/interfaces.cpp
  • src/qt/rpcconsole.cpp
  • src/qt/bantablemodel.cpp
  • src/qt/sendcoinsdialog.cpp
  • src/qt/addressbookpage.cpp
  • src/qt/bitcoingui.cpp
  • src/qt/clientmodel.h
  • src/qt/walletmodel.cpp
  • src/qt/clientmodel.cpp
  • src/qt/walletmodel.h
✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

🔭 Outside diff range comments (1)
src/qt/walletmodel.cpp (1)

280-331: ⚠️ Potential issue

Ensure error handling is preserved after removing return value.

The sendCoins method no longer returns status information. The implementation now relies on:

  • prepareTransaction for validation (which still returns SendCoinsReturn)
  • Signals like coinsSent for notifications
  • Balance updates via checkBalanceChanged

However, if commitTransaction fails, there's no way for the caller to know. Consider whether error conditions in commitTransaction should emit an error signal.

🧹 Nitpick comments (4)
src/qt/addresstablemodel.cpp (1)

452-452: Minor style improvement suggestion.

The implementation correctly delegates to walletModel->getDisplayName() and maintains const correctness. However, consider improving the formatting by placing the semicolon on the same line for better readability:

-QString AddressTableModel::GetWalletDisplayName() const { return walletModel->getDisplayName(); };
+QString AddressTableModel::GetWalletDisplayName() const { return walletModel->getDisplayName(); }

Note: The trailing semicolon after the closing brace is unnecessary for method definitions.

src/qt/walletmodel.cpp (1)

525-532: Good defensive check for wallets with private keys disabled.

This early return prevents incorrectly treating watch-only wallets as encrypted, addressing potential issues from earlier versions. The UnlockContext parameters are appropriate.

Consider slightly rewording the comment for clarity:

-    // Bugs in earlier versions may have resulted in wallets with private keys disabled to become "encrypted"
-    // (encryption keys are present, but not actually doing anything).
-    // To avoid issues with such wallets, check if the wallet has private keys disabled, and if so, return a context
-    // that indicates the wallet is not encrypted.
+    // Earlier versions had a bug where wallets with private keys disabled could have encryption keys set
+    // without actually encrypting anything. For such wallets, return an unlock context indicating
+    // the wallet is not encrypted to avoid incorrect behavior.
src/qt/bitcoinamountfield.cpp (2)

294-297: Good runtime validation of unit conversion.

The assertion ensures the QVariant contains a valid BitcoinUnit. However, consider what happens in release builds where asserts are disabled.

Consider adding graceful error handling for release builds:

 QVariant new_unit = units->data(idx, BitcoinUnits::UnitRole);
-assert(new_unit.isValid());
+if (!new_unit.isValid()) {
+    qWarning() << "Invalid unit data at index" << idx;
+    return;
+}
 amount->setPlaceholderText(tr("Amount in %1").arg(units->data(idx, Qt::DisplayRole).toString()));
 amount->setDisplayUnit(new_unit.value<BitcoinUnit>());

300-302: Inefficient enum-to-int-to-enum conversion.

This method converts BitcoinUnit to int via QVariant, only for unitChanged to convert it back to BitcoinUnit. This appears to be a compatibility layer with index-based unit selection.

Consider refactoring to avoid the double conversion:

-void BitcoinAmountField::setDisplayUnit(BitcoinUnit new_unit)
-{
-    unitChanged(QVariant::fromValue(new_unit).toInt());
-}
+void BitcoinAmountField::setDisplayUnit(BitcoinUnit new_unit)
+{
+    amount->setDisplayUnit(new_unit);
+    // Update tooltip if needed
+    // ...
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da8a475 and 206df625960891cc849d9abcaffd41b313f3bedb.

📒 Files selected for processing (39)
  • src/interfaces/node.h (1 hunks)
  • src/node/interfaces.cpp (1 hunks)
  • src/qt/addressbookpage.cpp (3 hunks)
  • src/qt/addressbookpage.h (1 hunks)
  • src/qt/addresstablemodel.cpp (1 hunks)
  • src/qt/addresstablemodel.h (1 hunks)
  • src/qt/bantablemodel.cpp (2 hunks)
  • src/qt/bantablemodel.h (2 hunks)
  • src/qt/bitcoin.cpp (3 hunks)
  • src/qt/bitcoinamountfield.cpp (7 hunks)
  • src/qt/bitcoinamountfield.h (2 hunks)
  • src/qt/bitcoingui.cpp (9 hunks)
  • src/qt/bitcoingui.h (4 hunks)
  • src/qt/bitcoinunits.cpp (8 hunks)
  • src/qt/bitcoinunits.h (4 hunks)
  • src/qt/clientmodel.cpp (4 hunks)
  • src/qt/clientmodel.h (5 hunks)
  • src/qt/coincontroldialog.cpp (2 hunks)
  • src/qt/forms/debugwindow.ui (1 hunks)
  • src/qt/governancelist.cpp (1 hunks)
  • src/qt/governancelist.h (2 hunks)
  • src/qt/guiutil.cpp (2 hunks)
  • src/qt/intro.cpp (1 hunks)
  • src/qt/optionsmodel.cpp (4 hunks)
  • src/qt/optionsmodel.h (5 hunks)
  • src/qt/overviewpage.cpp (7 hunks)
  • src/qt/overviewpage.h (2 hunks)
  • src/qt/psbtoperationsdialog.cpp (2 hunks)
  • src/qt/rpcconsole.cpp (3 hunks)
  • src/qt/sendcoinsdialog.cpp (2 hunks)
  • src/qt/test/wallettests.cpp (3 hunks)
  • src/qt/transactiondesc.cpp (2 hunks)
  • src/qt/transactiondesc.h (2 hunks)
  • src/qt/transactionrecord.h (2 hunks)
  • src/qt/transactiontablemodel.cpp (2 hunks)
  • src/qt/transactionview.cpp (1 hunks)
  • src/qt/walletmodel.cpp (5 hunks)
  • src/qt/walletmodel.h (4 hunks)
  • src/qt/walletview.h (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (12)
src/qt/bantablemodel.h (1)
src/qt/bantablemodel.cpp (2)
  • index (156-164)
  • index (156-156)
src/qt/overviewpage.h (1)
src/qt/optionsmodel.h (1)
  • m_display_bitcoin_unit (107-107)
src/qt/psbtoperationsdialog.cpp (2)
src/qt/bitcoinunits.cpp (4)
  • formatWithUnit (125-128)
  • formatWithUnit (125-125)
  • out (275-278)
  • out (275-275)
src/qt/bitcoinunits.h (1)
  • out (117-117)
src/qt/governancelist.cpp (4)
src/qt/bitcoinamountfield.h (1)
  • setDisplayUnit (55-55)
src/qt/bitcoinamountfield.cpp (2)
  • setDisplayUnit (300-303)
  • setDisplayUnit (300-300)
src/qt/optionsmodel.cpp (2)
  • setDisplayUnit (855-862)
  • setDisplayUnit (855-855)
src/qt/governancelist.h (1)
  • display_unit (126-126)
src/qt/guiutil.cpp (2)
src/qt/bitcoinamountfield.cpp (2)
  • parse (24-36)
  • parse (24-24)
src/qt/bitcoinunits.cpp (4)
  • parse (171-209)
  • parse (171-171)
  • format (80-114)
  • format (80-80)
src/qt/walletview.h (4)
src/qt/bitcoingui.h (1)
  • date (313-313)
src/qt/bitcoinamountfield.cpp (2)
  • unit (129-142)
  • unit (129-129)
src/qt/bitcoinunits.h (13)
  • unit (65-65)
  • unit (67-67)
  • unit (69-69)
  • unit (71-71)
  • unit (73-73)
  • unit (74-74)
  • unit (76-76)
  • unit (78-78)
  • unit (80-80)
  • unit (82-82)
  • unit (83-83)
  • unit (85-85)
  • unit (87-87)
src/qt/optionsmodel.h (1)
  • unit (150-150)
src/qt/bantablemodel.cpp (1)
src/qt/bantablemodel.h (3)
  • index (62-62)
  • index (65-65)
  • index (71-71)
src/qt/optionsmodel.cpp (5)
src/qt/bitcoinamountfield.cpp (4)
  • unit (129-142)
  • unit (129-129)
  • setDisplayUnit (300-303)
  • setDisplayUnit (300-300)
src/qt/bitcoinunits.h (13)
  • unit (65-65)
  • unit (67-67)
  • unit (69-69)
  • unit (71-71)
  • unit (73-73)
  • unit (74-74)
  • unit (76-76)
  • unit (78-78)
  • unit (80-80)
  • unit (82-82)
  • unit (83-83)
  • unit (85-85)
  • unit (87-87)
src/qt/optionsmodel.h (3)
  • unit (150-150)
  • m_display_bitcoin_unit (107-107)
  • new_unit (101-101)
src/qt/bitcoinamountfield.h (1)
  • setDisplayUnit (55-55)
src/qt/governancelist.cpp (2)
  • setDisplayUnit (289-289)
  • setDisplayUnit (289-289)
src/qt/clientmodel.h (1)
src/node/interfaces.cpp (3)
  • tip (91-99)
  • tip (434-438)
  • tip (455-463)
src/qt/optionsmodel.h (2)
src/qt/bitcoinamountfield.cpp (2)
  • unit (129-142)
  • unit (129-129)
src/qt/bitcoinunits.h (13)
  • unit (65-65)
  • unit (67-67)
  • unit (69-69)
  • unit (71-71)
  • unit (73-73)
  • unit (74-74)
  • unit (76-76)
  • unit (78-78)
  • unit (80-80)
  • unit (82-82)
  • unit (83-83)
  • unit (85-85)
  • unit (87-87)
src/qt/walletmodel.cpp (1)
src/qt/walletmodel.h (11)
  • validateAddress (88-88)
  • sendCoins (106-106)
  • getOptionsModel (80-80)
  • getAddressTableModel (81-81)
  • getTransactionTableModel (82-82)
  • getRecentRequestsTableModel (83-83)
  • UnlockContext (122-122)
  • UnlockContext (123-123)
  • UnlockContext (128-128)
  • UnlockContext (130-130)
  • isMultiwallet (159-159)
src/qt/bitcoinunits.h (3)
src/qt/bitcoinamountfield.cpp (10)
  • unit (129-142)
  • unit (129-129)
  • value (108-112)
  • value (108-108)
  • value (119-122)
  • value (119-119)
  • value (124-127)
  • value (124-124)
  • value (258-261)
  • value (258-258)
src/qt/optionsmodel.h (1)
  • unit (150-150)
src/qt/bitcoinunits.cpp (4)
  • out (275-278)
  • out (275-275)
  • in (280-286)
  • in (280-280)
🔇 Additional comments (109)
src/qt/intro.cpp (1)

307-312: LGTM! Proper implementation of Qt's plural-aware translation.

The changes correctly implement Qt's plural-aware translation mechanism by adding the numeric value as the n parameter in tr() calls. This enables proper pluralization of "GB" units across different languages that have varying plural rules.

The implementation follows Qt's best practices:

  • Empty string as context parameter
  • Numeric value for %n placeholder to determine plural form
src/qt/addresstablemodel.h (1)

83-84: LGTM! Well-designed API addition.

The GetWalletDisplayName() method is properly declared as const and follows consistent naming conventions. This provides a clean interface for UI components to access the wallet's display name.

src/qt/addressbookpage.h (1)

58-58: LGTM! Appropriately scoped helper method.

The updateWindowsTitleWithWalletName() method is correctly declared as private, indicating it's an internal implementation detail for managing dynamic window titles. The method name clearly describes its purpose.

src/qt/psbtoperationsdialog.cpp (1)

181-181: LGTM: Improved type safety with strongly typed Bitcoin unit enum.

The changes replace BitcoinUnits::DASH with BitcoinUnit::DASH, aligning with the broader refactoring to use strongly typed enums instead of raw constants. This improves type safety and code clarity while maintaining the same functionality.

Also applies to: 195-195

src/qt/transactionview.cpp (1)

565-565: LGTM: Type consistency improvement with BitcoinUnit enum.

The change from int nDisplayUnit to BitcoinUnit nDisplayUnit maintains type consistency with the getDisplayUnit() method return type and improves type safety. This aligns with the broader refactoring effort to use strongly typed Bitcoin units throughout the Qt GUI codebase.

src/qt/forms/debugwindow.ui (1)

1181-1181: LGTM: Improved UI clarity for transaction relay field.

The tooltip and label text changes provide better clarity about what the field represents. The new text "Whether we relay transactions to this peer" correctly indicates the direction of transaction relay (from local node to peer), which is more accurate than the previous text that could be misinterpreted as the peer's request for relay.

Also applies to: 1184-1184

src/qt/overviewpage.h (2)

9-9: LGTM: Added necessary header for BitcoinUnit type.

The include for bitcoinunits.h is required for the BitcoinUnit type used in the member variable declaration.


56-56: LGTM: Enhanced type safety and naming convention.

The change from int nDisplayUnit to BitcoinUnit m_display_bitcoin_unit provides multiple improvements:

  • Uses strongly typed enum instead of raw integer for better type safety
  • Follows modern C++ naming conventions with m_ prefix for member variables
  • More descriptive variable name that clearly indicates its purpose

This aligns perfectly with the broader refactoring effort across the Qt GUI codebase.

src/qt/bantablemodel.h (2)

40-41: LGTM: Documentation correction is accurate.

The comment correction properly describes the model as providing information about banned peers rather than connected peers, which aligns with the model's actual purpose.


71-71: LGTM: Well-designed API addition.

The new unban method provides a clean interface for unbanning peers through the model, following Qt's model-view architecture patterns. This centralizes the unbanning logic within the model as mentioned in the summary.

src/qt/test/wallettests.cpp (3)

11-11: LGTM: Necessary include for type safety improvement.

The addition of the bitcoinunits.h include is required to support the BitcoinUnit type used in the updated variable declarations below.


156-156: LGTM: Type safety improvement aligns with broader refactor.

Changing from generic int to strongly typed BitcoinUnit improves type safety and consistency. This aligns with the codebase-wide migration mentioned in the summary.


179-179: LGTM: Consistent type safety improvement.

This change matches the previous type improvement and maintains consistency throughout the test function.

src/qt/bitcoinamountfield.h (2)

9-9: LGTM: Required include for type safety enhancement.

The bitcoinunits.h include is necessary to support the BitcoinUnit type used in the updated method signature.


55-55: LGTM: Interface improvement with strongly typed parameter.

Changing the parameter type from generic int to BitcoinUnit enhances type safety and makes the interface more self-documenting. This prevents arbitrary integers from being passed and aligns with the broader codebase refactor.

src/qt/guiutil.cpp (2)

398-398: LGTM: Correct transition to strongly typed enum.

The change from BitcoinUnits::DASH to BitcoinUnit::DASH properly updates the enum reference to use the new strongly typed BitcoinUnit enum class while maintaining the same functionality.


434-434: LGTM: Consistent enum type update.

This change maintains consistency with the previous enum update and correctly uses the new BitcoinUnit::DASH enum value in the formatting function.

src/qt/governancelist.cpp (1)

289-289: LGTM: Type safety improvement with BitcoinUnit enum

The method signature change from int to BitcoinUnit improves type safety and is consistent with the broader refactoring effort described in the PR. The implementation correctly assigns the strongly-typed parameter to the member variable.

src/qt/bantablemodel.cpp (2)

46-46: LGTM: Accurate comment update

The comment correction from "CNode" to "interfaces::Node" accurately reflects the actual implementation, as the code indeed pulls the banned nodes list from the interfaces::Node interface.


185-189: LGTM: Well-implemented unban method

The new unban method is properly implemented with:

  • Correct extraction of the CCombinedBan pointer from the QModelIndex
  • Proper null pointer checking before calling the interface method
  • Appropriate return value handling

This centralizes ban removal logic within the model as mentioned in the AI summary.

src/qt/coincontroldialog.cpp (2)

565-567: LGTM: Proper type safety improvement

The change from int to BitcoinUnit improves type safety. The default initialization with BitcoinUnit::DASH is appropriate and consistent with the broader refactoring effort to use strongly typed enums for Bitcoin units.


673-673: LGTM: Consistent type usage

The variable type change from int to BitcoinUnit is consistent with the type safety refactor and properly retrieves the strongly-typed display unit from the options model.

src/qt/governancelist.h (2)

97-97: LGTM: Type-safe member variable declaration

The change from int to BitcoinUnit with default initialization {BitcoinUnit::DASH} improves type safety and is consistent with the broader refactoring effort. The default value is appropriate.


126-126: LGTM: Consistent method signature update

The method signature change from int to BitcoinUnit parameter improves type safety and is consistent with the implementation in the corresponding .cpp file (line 289).

src/interfaces/node.h (1)

238-239: LGTM! Good interface simplification.

Consolidating getReindex() and getImporting() into a single isLoadingBlocks() method improves the interface design by abstracting the specific loading states into a more general concept.

src/node/interfaces.cpp (1)

471-471: LGTM! Correct implementation of the consolidated method.

The implementation properly combines both loading states using logical OR, maintaining the same behavior while providing a cleaner interface.

src/qt/sendcoinsdialog.cpp (2)

448-448: LGTM! Type safety improvement.

Good migration to the strongly typed BitcoinUnit enum, consistent with the broader refactor across the Qt GUI codebase.


541-542:

Details

❓ Verification inconclusive

Verify error handling after removing sendCoins return value check.

The coinsSent signal is now emitted unconditionally after calling sendCoins(). This could lead to false success notifications if the send operation fails internally.

Run the following script to verify how errors are handled in the new implementation:


🏁 Script executed:

#!/bin/bash
# Description: Check the new sendCoins implementation and error handling mechanism

# Search for the WalletModel::sendCoins implementation to understand the new error handling
echo "=== Searching for WalletModel::sendCoins implementation ==="
ast-grep --pattern 'void WalletModel::sendCoins($$$) {
  $$$
}'

# Check if there are any error signals or exceptions that might be used instead
echo -e "\n=== Searching for error signals in WalletModel ==="
rg -A 5 "Q_SIGNALS:|signals:" src/qt/walletmodel.h | rg -A 3 "error|fail|Error|Fail"

# Check for any try-catch blocks or error handling in sendCoins
echo -e "\n=== Searching for error handling patterns in walletmodel.cpp ==="
rg -A 10 "sendCoins.*\(" src/qt/walletmodel.cpp | rg -B 3 -A 3 "throw|emit|error|Error|fail|Fail"

Length of output: 643


Verify error handling in WalletModel::sendCoins

We couldn’t locate any implementation of WalletModel::sendCoins or corresponding error signals/exceptions in src/qt/walletmodel.h/.cpp. As it stands, coinsSent is emitted unconditionally—even if the send operation fails—leading to potential false‐positive notifications.

Please manually confirm and/or address the following:

  • Inspect src/qt/walletmodel.cpp for the definition of WalletModel::sendCoins and ensure it propagates errors (via return value, exception, or an error signal).
  • Verify src/qt/walletmodel.h for any error‐related Q_SIGNAL declarations; if none exist, introduce a failure signal or restore the return‐value check.
  • Update the UI logic so that coinsSent is only emitted after a successful transaction.
src/qt/transactiontablemodel.cpp (1)

7-7: LGTM! Proper implementation of BitcoinUnit type safety refactor.

The addition of the bitcoinunits.h include and the method signature change from int unit to BitcoinUnit unit correctly implements the broader type safety refactor mentioned in the PR objectives. This ensures stronger typing for Bitcoin unit handling throughout the Qt GUI.

Also applies to: 252-252

src/qt/walletview.h (1)

9-9: LGTM! Consistent implementation of BitcoinUnit type safety.

The include addition and signal signature change from int unit to BitcoinUnit unit properly aligns with the broader Qt GUI refactor for type safety. This ensures consistent usage of the strongly typed BitcoinUnit enum across signal/slot communications, as evidenced by the matching signature in the relevant code snippets from bitcoingui.h.

Also applies to: 134-134

src/qt/rpcconsole.cpp (3)

1036-1036: LGTM! Good defensive programming.

Adding the null check for clientModel prevents potential crashes when the method is called before the client model is properly initialized.


1307-1312: LGTM! Improved UI data validation.

The conditional checks ensure that peer version and subversion are only set when valid values are available, preventing the display of invalid or empty data in the UI. This improves the user experience by showing meaningful information only.


1495-1502: LGTM! Excellent refactoring using the new BanTableModel API.

The refactored unbanSelectedNode() method properly leverages the new BanTableModel::unban() method mentioned in the AI summary, simplifying the code by removing manual parsing and replacing it with model-based operations. The logic correctly tracks whether any unbanning occurred and refreshes the model only when necessary.

src/qt/bitcoin.cpp (3)

101-101: LGTM: Proper BitcoinUnit meta-type registration.

The registration of stream operators for BitcoinUnit enables proper serialization and QVariant support, aligning with the broader type safety refactoring across the Qt GUI codebase.


351-354: LGTM: Improved shutdown sequence with proper cleanup order.

Calling clientModel->stop() before unsetting ensures that signal handlers are properly disconnected and internal threads are stopped before the model is deleted. This prevents potential race conditions and ensures clean resource cleanup.


574-598: LGTM: Enhanced error handling for configuration parsing.

The restructured initialization flow properly separates data directory validation from configuration file parsing and network parameter selection. The try-catch block ensures exceptions during config parsing or SelectParams() are caught and reported via message boxes, leading to graceful failure handling.

src/qt/addressbookpage.cpp (3)

74-85: LGTM: Simplified constructor mode handling.

The constructor now only handles the ForSelection case, with the ForEditing window title setting moved to updateWindowsTitleWithWalletName(). This allows the window title to include the wallet name dynamically after the model is set.


155-155: LGTM: Dynamic window title update after model is set.

Calling updateWindowsTitleWithWalletName() at the end of setModel() ensures the window title includes the wallet name, which is only available after the model is properly initialized.


342-353: LGTM: Well-implemented dynamic window title method.

The method correctly:

  • Retrieves the wallet display name from the model
  • Only updates the title for ForEditing mode
  • Sets appropriate titles for both sending and receiving address tabs
  • Uses proper string formatting with tr() for internationalization

This design allows the window title to reflect the current wallet context.

src/qt/transactiondesc.h (3)

8-8: LGTM: Required header inclusion for BitcoinUnit.

The inclusion of bitcoinunits.h is necessary to support the BitcoinUnit type used in the toHTML method signature.


29-29: LGTM: Type safety improvement with BitcoinUnit enum.

Changing the parameter from int unit to BitcoinUnit unit enhances type safety and prevents potential confusion between different integer types. This aligns with the broader refactoring to use strongly typed enums throughout the Qt GUI codebase.


34-34: LGTM: Simplified method signature by removing unused parameters.

Removing the unused const interfaces::WalletTx& wtx and int numBlocks parameters from FormatTxStatus improves code clarity and reduces unnecessary coupling. The method now only requires the essential parameters it actually uses.

src/qt/transactionrecord.h (2)

24-24: LGTM: Appropriate change from class to struct.

Converting TransactionStatus from a class to a struct is appropriate since it's primarily a data holder with public members. This change aligns with modern C++ best practices for simple data structures.


38-63: LGTM: Modern C++ with inline default member initializers.

Using brace-or-equal initializers for the member variables is excellent modern C++ practice that:

  • Eliminates the need for an explicit default constructor
  • Makes default values clear at the point of declaration
  • Reduces boilerplate code
  • Improves maintainability

The default values chosen are appropriate for each member type.

src/qt/optionsmodel.cpp (4)

32-32: LGTM: Required include for QVariant support.

The QVariant header is correctly added to support the new enum storage mechanism.


80-89: Excellent migration logic with proper type safety.

The initialization logic properly handles the transition from integer-based units to the strongly-typed BitcoinUnit enum:

  • Uses QVariant::fromValue(BitcoinUnit::DASH) for type-safe storage
  • Includes proper type checking with unit.canConvert<BitcoinUnit>()
  • Provides fallback to BitcoinUnit::DASH if conversion fails
  • The setting name "DisplayDashUnit" aligns with the Dash branding mentioned in the PR objectives

This ensures backward compatibility while migrating to the new type system.


522-522: Correct implementation of type-safe unit retrieval.

The change from returning a raw unit value to QVariant::fromValue(m_display_bitcoin_unit) is consistent with the new strongly-typed approach and maintains compatibility with the Qt model/view framework.


855-862: Well-implemented type-safe setDisplayUnit method.

The refactored method properly:

  • Accepts QVariant parameter for consistency with Qt patterns
  • Includes null check for robustness
  • Uses value<BitcoinUnit>() for type-safe extraction
  • Maintains the same signal emission pattern

The implementation follows Qt best practices for handling strongly-typed enums in QVariant.

src/qt/transactiondesc.cpp (2)

30-56: Excellent code simplification and cleanup.

The FormatTxStatus method has been properly refactored:

  • Removed unused parameters interfaces::WalletTx& wtx and int numBlocks
  • Improved variable naming (nDepthdepth)
  • Maintains the same functional logic while reducing complexity
  • The method now has a cleaner interface with only the necessary parameters

This is a good example of dead code elimination that improves maintainability.


58-58: Consistent migration to strongly-typed BitcoinUnit.

The toHTML method signature change from int unit to BitcoinUnit unit aligns with the broader refactoring goals, and the call to FormatTxStatus has been properly updated to match the new simplified signature.

Also applies to: 76-76

src/qt/overviewpage.cpp (4)

45-46: Proper constructor initialization with strongly-typed enum.

The TxViewDelegate constructor correctly:

  • Initializes the base class with the parent parameter
  • Uses BitcoinUnit::DASH instead of the previous integer constant
  • Maintains the same functionality with improved type safety

129-129: Consistent type migration for member variable.

The change from int unit to BitcoinUnit unit aligns with the systematic refactoring across the codebase.


229-229: Systematic and consistent variable usage.

All instances of the display unit variable have been properly updated from nDisplayUnit to m_display_bitcoin_unit, maintaining consistency throughout the class while improving type safety.

Also applies to: 350-350, 356-356


380-423: Comprehensive formatting method updates.

All formatting calls throughout the CoinJoin progress logic have been consistently updated to use m_display_bitcoin_unit. The changes maintain the same functionality while leveraging the strongly-typed enum for better type safety and clarity.

src/qt/bitcoingui.h (3)

12-12: Required include for BitcoinUnit type.

The inclusion of bitcoinunits.h is necessary to provide the BitcoinUnit type used in the interface declarations.


216-216: Consistent struct member type update.

The change of IncomingTransactionMessage::unit from int to BitcoinUnit aligns with the systematic migration to strongly-typed enums throughout the GUI codebase.


313-313: Interface consistency with strongly-typed parameters.

Both method signatures have been properly updated:

  • incomingTransaction now uses BitcoinUnit unit parameter
  • updateDisplayUnit now uses BitcoinUnit newUnits parameter

This ensures type consistency across the GUI interface and improves compile-time type checking.

Also applies to: 419-419

src/qt/clientmodel.h (6)

26-28: LGTM!

The forward declaration for interfaces::BlockTip is properly added to support the new TipChanged method parameter.


60-60: Good addition for controlled cleanup.

Adding a separate stop() method is a solid design choice that allows for explicit cleanup of resources before destruction. This pattern helps prevent issues with undefined behavior during shutdown.


34-38: Simplification of block source states looks good.

The removal of the REINDEX state and consolidation into the isLoadingBlocks() method simplifies the state machine. The trailing comma after NETWORK is a nice touch for cleaner future diffs.


83-84: Clean modernization of the method signature.

Removing the redundant enum keyword from the return type is good modern C++ practice. The updated comment accurately reflects the consolidated state checking approach.


107-107: Excellent refactoring of event handler management.

Consolidating individual handler pointers into a single vector is a much cleaner approach. This simplifies cleanup logic and makes it easier to manage multiple event subscriptions.


123-123: Well-structured addition for tip update handling.

The TipChanged method signature properly encapsulates all the necessary information for block tip updates. This separation of concerns improves code organization and testability.

src/qt/bitcoingui.cpp (6)

839-839: Good defensive check for shutdown state.

Adding an early return when shutdown is requested prevents potential crashes or undefined behavior from UI operations during node shutdown.


1308-1308: Clean idiomatic null check.

Using !clientModel is more concise and idiomatic C++ compared to explicit nullptr comparison.


1121-1122: Consistent shutdown safety check.

Good addition of early return on shutdown, matching the pattern used in the Mac dock icon handler. This prevents potential issues from menu operations during node shutdown.


1525-1525: Consistent modernization with header file.

Removing the redundant enum keyword here matches the change in the header file, maintaining consistency throughout the codebase.


1794-1794: Excellent type safety improvement.

Changing from int unit to BitcoinUnit unit provides compile-time type safety and makes the code more self-documenting.


2145-2149: Comprehensive type safety improvements in unit display control.

All unit-related operations now consistently use the strongly typed BitcoinUnit enum. The use of QVariant::fromValue for storing the enum in menu actions is the correct Qt approach.

Also applies to: 2165-2166, 2187-2187

src/qt/optionsmodel.h (5)

8-8: Required include for BitcoinUnit type.

The addition of bitcoinunits.h include is necessary for the BitcoinUnit type now used throughout this class.


60-60: Documentation properly updated to reflect type changes.

Good attention to detail in updating both the inline comment and method documentation to reflect the change from int to BitcoinUnit.

Also applies to: 100-101


107-107: Return type correctly updated.

The getDisplayUnit() return type now properly matches the m_display_bitcoin_unit member variable type.


135-135: Core member variable properly typed.

The m_display_bitcoin_unit member now uses the strongly typed BitcoinUnit enum, providing compile-time type safety for this important user preference.


150-150: Signal parameter type safety maintained.

The displayUnitChanged signal now emits the strongly typed BitcoinUnit enum, ensuring type safety across all connected slots.

src/qt/walletmodel.h (3)

80-83: Good improvement in const-correctness!

Marking these getter methods as const is appropriate since they don't modify the object state and just return pointers to member variables. This allows them to be called on const WalletModel instances.


88-88: Appropriate const marking for validation method.

The validateAddress method only performs validation without modifying state, so marking it as const is correct.


159-159: LGTM!

Marking isMultiwallet as const is correct since it's a read-only operation.

src/qt/walletmodel.cpp (6)

188-188: Implementation correctly matches const declaration.

The const implementation properly matches the header declaration.


333-336: LGTM!

Const implementation matches header declaration.


338-341: LGTM!

Const implementation matches header declaration.


343-346: LGTM!

Const implementation matches header declaration.


348-351: LGTM!

Const implementation matches header declaration.


601-604: LGTM!

Const implementation correctly queries wallet count without modifying state.

src/qt/bitcoinamountfield.cpp (7)

15-17: Required includes for type-safe unit handling.

The QVariant and cassert includes are necessary for the BitcoinUnit enum conversions and runtime validation.


24-24: Good type safety improvement.

Using BitcoinUnit enum instead of int prevents invalid unit values from being passed.


43-48: Consistent type safety in AmountValidator.

The class properly uses BitcoinUnit type with appropriate default initialization to BitcoinUnit::DASH.

Also applies to: 60-63


76-76: LGTM!

Proper initialization with BitcoinUnit::DASH.


129-129: Type-safe unit parameter.

Properly updated to use BitcoinUnit parameter.


149-149: Clear use of enum constant.

Using BitcoinUnit::DASH directly improves code clarity.


156-156: Modern C++ member initialization.

Good use of in-class brace initialization with the strongly typed enum.

src/qt/clientmodel.cpp (6)

75-86: Good separation of cleanup logic.

Moving cleanup to a separate stop() method allows for controlled shutdown before destruction. The destructor properly delegates to stop().


191-196: Clean simplification of block source detection.

The use of isLoadingBlocks() consolidates the previous separate checks for reindexing and importing, making the code more maintainable.


253-253: Improved parameter naming.

Removing the f prefix from boolean parameters improves readability and follows modern C++ conventions.


255-267: LGTM!

Implementation properly updated to use the renamed header parameter and access tip fields directly.


277-319: Excellent modernization of event handling.

The refactoring to use lambdas and store handlers in a vector brings several benefits:

  • More concise and readable code
  • Automatic capture of this pointer
  • Simplified cleanup via vector
  • Direct signal emission instead of QMetaObject::invokeMethod

All handlers, including the three Dash-specific ones (handleNotifyAdditionalDataSyncProgressChanged, handleNotifyChainLock, and handleNotifyMasternodeListChanged), are properly converted.


321-324: Clean and simple cleanup.

Clearing the handler vector is much simpler and less error-prone than individually disconnecting each handler.

src/qt/bitcoinunits.h (5)

12-12: LGTM: Necessary include for serialization support.

The addition of <QDataStream> is required for the serialization operators declared at the bottom of the file.


43-49: Excellent type safety improvement with proper Qt integration.

The conversion from enum Unit to enum class Unit significantly improves type safety by preventing implicit conversions to integers. The addition of Q_ENUM(Unit) enables Qt meta-object features like QVariant storage and signal/slot parameter passing.


65-87: Consistent method signature updates for type safety.

All static methods have been properly updated to use the strongly typed Unit parameter instead of int. This ensures compile-time type checking and prevents incorrect unit values from being passed.


113-113: Consistent member variable type update.

The unitlist member variable correctly uses the scoped enum type, maintaining consistency with the method signatures.


117-118: Proper serialization support for Qt data streams.

The QDataStream operators enable BitcoinUnit to be serialized/deserialized, which is essential for storing the enum in QSettings or transmitting it via Qt's data stream mechanisms.

src/qt/bitcoinunits.cpp (8)

24-32: Correct enum class usage in availableUnits().

The method signature and implementation correctly use the scoped enum syntax (Unit::DASH, etc.) and return the proper type.


34-44: Excellent type safety with exhaustive switch statements.

The method signature correctly uses Unit unit and the switch statement properly handles all enum cases without a default clause, allowing the compiler to warn about missing cases. The assert(false) provides a runtime safety net.


46-56: Consistent pattern for description method.

Same excellent pattern as the name() method - exhaustive switch statement with compiler warnings for missing cases and runtime assertion.


58-67: Consistent pattern for factor method.

Maintains the same robust pattern with exhaustive switch and runtime assertion.


69-78: Consistent pattern for decimals method.

Follows the established pattern correctly.


80-214: Method signatures consistently updated for type safety.

All the formatting and parsing methods have been properly updated to use the Unit enum class parameter, maintaining consistency across the API.


240-240: Proper QVariant handling for enum class.

The change from casting to int to using QVariant::fromValue(unit) is correct for enum class values. This ensures the enum is properly stored in the QVariant with its type information preserved.


251-286: Well-implemented serialization support.

The serialization implementation is robust:

  1. Helper functions: ToQint8() and FromQint8() provide safe conversion between the enum and a serializable integer type.
  2. Exhaustive switches: Both conversion functions use exhaustive switch statements without default cases, ensuring compiler warnings for missing enum values.
  3. Stream operators: The operator<< and operator>> correctly use the helper functions to serialize/deserialize the enum via qint8.
  4. Anonymous namespace: Properly scopes the helper functions to avoid symbol pollution.

This design ensures type safety while providing efficient serialization.

Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify error handling after removing return value.

The sendCoins method no longer returns a SendCoinsReturn status. This is a breaking API change that removes the ability for callers to check if the send operation succeeded.

Please ensure:

  1. Error handling is now done through signals/exceptions
  2. All callers have been updated to not expect a return value
  3. The SendCoinsReturn struct (lines 91-100) is still needed for prepareTransaction

Run the following script to verify all callers have been updated:


🏁 Script executed:

#!/bin/bash
# Description: Find all calls to sendCoins method to ensure they don't expect a return value

# Search for sendCoins calls
rg -A 3 "sendCoins\s*\(" --type cpp

Length of output: 1010


🏁 Script executed:

#!/bin/bash
# Inspect send_failure usage in sendcoinsdialog.cpp
echo "=== sendcoinsdialog.cpp around sendCoins call and send_failure ==="
rg -n -C3 "sendCoins" --max-count 1 src/qt/sendcoinsdialog.cpp

echo
echo "=== send_failure references in sendcoinsdialog.cpp ==="
rg -n -C3 "send_failure" src/qt/sendcoinsdialog.cpp

echo
echo "=== sendCoins implementation in walletmodel.cpp ==="
rg -n -C3 "WalletModel::sendCoins" src/qt/walletmodel.cpp

Length of output: 1641


🏁 Script executed:

#!/bin/bash
# Show the full sendCoins implementation to inspect error handling
echo "=== WalletModel::sendCoins implementation ==="
rg -n -A50 "void WalletModel::sendCoins" src/qt/walletmodel.cpp

Length of output: 2447


Fix missing error handling after changing sendCoins return type

The UI no longer checks for errors because sendCoins now throws on failure and returns void, but sendcoinsdialog.cpp never catches those exceptions and send_failure is never set to true. As a result any error will bypass the if (!send_failure) path (or crash the app) and the dialog will always accept.

Please update as follows:

• In src/qt/sendcoinsdialog.cpp (around line 541), wrap the call to model->sendCoins(...) in a try/catch, set send_failure = true on exception, and show an error to the user:

--- a/src/qt/sendcoinsdialog.cpp
+++ b/src/qt/sendcoinsdialog.cpp
@@ -539,7 +539,14 @@
     // now send the prepared transaction
-    model->sendCoins(*m_current_transaction, m_coin_control->IsUsingCoinJoin());
+    try {
+        model->sendCoins(*m_current_transaction, m_coin_control->IsUsingCoinJoin());
+    } catch (const std::exception &e) {
+        send_failure = true;
+        QMessageBox::critical(this,
+            tr("Send Error"),
+            QString::fromStdString(e.what()));
+    }
 
     Q_EMIT coinsSent(m_current_transaction->getWtx()->GetHash());

• Verify bool send_failure = false; is declared before this block and that the final if (!send_failure) logic only runs on success.
• Optionally, consider catching exceptions inside WalletModel::sendCoins and converting them into a Qt error signal for more granular handling.
• Keep SendCoinsReturn around for prepareTransaction, but remove any stale code paths that expect it from sendCoins.

🤖 Prompt for AI Agents
In src/qt/sendcoinsdialog.cpp around line 541, the call to model->sendCoins no
longer returns a status but throws exceptions on failure, yet the code does not
catch these exceptions or set send_failure to true, causing errors to bypass the
failure check and the dialog to always accept. To fix this, wrap the sendCoins
call in a try/catch block, set send_failure to true inside the catch, and
display an error message to the user. Ensure bool send_failure is declared
before this block and that the final if (!send_failure) logic only executes on
success. Also, keep the SendCoinsReturn struct for prepareTransaction but remove
any code expecting it from sendCoins.

@kwvg kwvg requested review from PastaPastaPasta and UdjinM6 and removed request for PastaPastaPasta May 27, 2025 09:43
Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

light ACK a41f4e7

@PastaPastaPasta PastaPastaPasta merged commit a108921 into dashpay:develop May 27, 2025
33 of 34 checks passed
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