-
Notifications
You must be signed in to change notification settings - Fork 1.2k
backport: bitcoin-core/gui#557, #552, #556, #590, #581, #608, #673, #676, #681, #690, #697, #717, #757, #751, #773, #801 (qt backports: part 4) #6681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…` and `TransactionStatus`
WalkthroughThis 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 📜 Recent review detailsConfiguration used: CodeRabbit UI 📥 CommitsReviewing files that changed from the base of the PR and between 206df625960891cc849d9abcaffd41b313f3bedb and a41f4e7. 📒 Files selected for processing (17)
🚧 Files skipped from review as they are similar to previous changes (17)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 issueEnsure error handling is preserved after removing return value.
The
sendCoinsmethod no longer returns status information. The implementation now relies on:
prepareTransactionfor validation (which still returnsSendCoinsReturn)- Signals like
coinsSentfor notifications- Balance updates via
checkBalanceChangedHowever, if
commitTransactionfails, there's no way for the caller to know. Consider whether error conditions incommitTransactionshould 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
BitcoinUnittointviaQVariant, only forunitChangedto convert it back toBitcoinUnit. 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
nparameter intr()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
%nplaceholder to determine plural formsrc/qt/addresstablemodel.h (1)
83-84: LGTM! Well-designed API addition.The
GetWalletDisplayName()method is properly declared asconstand 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::DASHwithBitcoinUnit::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 nDisplayUnittoBitcoinUnit nDisplayUnitmaintains type consistency with thegetDisplayUnit()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.his required for theBitcoinUnittype used in the member variable declaration.
56-56: LGTM: Enhanced type safety and naming convention.The change from
int nDisplayUnittoBitcoinUnit m_display_bitcoin_unitprovides 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
unbanmethod 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
intto strongly typedBitcoinUnitimproves 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
inttoBitcoinUnitenhances 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::DASHtoBitcoinUnit::DASHproperly updates the enum reference to use the new strongly typedBitcoinUnitenum 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::DASHenum value in the formatting function.src/qt/governancelist.cpp (1)
289-289: LGTM: Type safety improvement with BitcoinUnit enumThe method signature change from
inttoBitcoinUnitimproves 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 updateThe comment correction from "CNode" to "interfaces::Node" accurately reflects the actual implementation, as the code indeed pulls the banned nodes list from the
interfaces::Nodeinterface.
185-189: LGTM: Well-implemented unban methodThe new
unbanmethod is properly implemented with:
- Correct extraction of the
CCombinedBanpointer from theQModelIndex- 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 improvementThe change from
inttoBitcoinUnitimproves type safety. The default initialization withBitcoinUnit::DASHis appropriate and consistent with the broader refactoring effort to use strongly typed enums for Bitcoin units.
673-673: LGTM: Consistent type usageThe variable type change from
inttoBitcoinUnitis 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 declarationThe change from
inttoBitcoinUnitwith 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 updateThe method signature change from
inttoBitcoinUnitparameter 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()andgetImporting()into a singleisLoadingBlocks()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
BitcoinUnitenum, 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
coinsSentsignal is now emitted unconditionally after callingsendCoins(). 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::sendCoinsor corresponding error signals/exceptions insrc/qt/walletmodel.h/.cpp. As it stands,coinsSentis 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.cppfor the definition ofWalletModel::sendCoinsand ensure it propagates errors (via return value, exception, or an error signal).- Verify
src/qt/walletmodel.hfor any error‐relatedQ_SIGNALdeclarations; if none exist, introduce a failure signal or restore the return‐value check.- Update the UI logic so that
coinsSentis 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.hinclude and the method signature change fromint unittoBitcoinUnit unitcorrectly 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 unittoBitcoinUnit unitproperly aligns with the broader Qt GUI refactor for type safety. This ensures consistent usage of the strongly typedBitcoinUnitenum across signal/slot communications, as evidenced by the matching signature in the relevant code snippets frombitcoingui.h.Also applies to: 134-134
src/qt/rpcconsole.cpp (3)
1036-1036: LGTM! Good defensive programming.Adding the null check for
clientModelprevents 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 newBanTableModel::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
BitcoinUnitenables 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
ForSelectioncase, with theForEditingwindow title setting moved toupdateWindowsTitleWithWalletName(). 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 ofsetModel()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
ForEditingmode- Sets appropriate titles for both sending and receiving address tabs
- Uses proper string formatting with
tr()for internationalizationThis 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.his necessary to support theBitcoinUnittype used in thetoHTMLmethod signature.
29-29: LGTM: Type safety improvement with BitcoinUnit enum.Changing the parameter from
int unittoBitcoinUnit unitenhances 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& wtxandint numBlocksparameters fromFormatTxStatusimproves 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
TransactionStatusfrom 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
BitcoinUnitenum:
- Uses
QVariant::fromValue(BitcoinUnit::DASH)for type-safe storage- Includes proper type checking with
unit.canConvert<BitcoinUnit>()- Provides fallback to
BitcoinUnit::DASHif 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
QVariantparameter 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
FormatTxStatusmethod has been properly refactored:
- Removed unused parameters
interfaces::WalletTx& wtxandint numBlocks- Improved variable naming (
nDepth→depth)- 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
toHTMLmethod signature change fromint unittoBitcoinUnit unitaligns with the broader refactoring goals, and the call toFormatTxStatushas 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
TxViewDelegateconstructor correctly:
- Initializes the base class with the parent parameter
- Uses
BitcoinUnit::DASHinstead 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 unittoBitcoinUnit unitaligns 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
nDisplayUnittom_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.his necessary to provide theBitcoinUnittype used in the interface declarations.
216-216: Consistent struct member type update.The change of
IncomingTransactionMessage::unitfrominttoBitcoinUnitaligns 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:
incomingTransactionnow usesBitcoinUnit unitparameterupdateDisplayUnitnow usesBitcoinUnit newUnitsparameterThis 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::BlockTipis properly added to support the newTipChangedmethod 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
REINDEXstate and consolidation into theisLoadingBlocks()method simplifies the state machine. The trailing comma afterNETWORKis a nice touch for cleaner future diffs.
83-84: Clean modernization of the method signature.Removing the redundant
enumkeyword 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
TipChangedmethod 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
!clientModelis 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
enumkeyword here matches the change in the header file, maintaining consistency throughout the codebase.
1794-1794: Excellent type safety improvement.Changing from
int unittoBitcoinUnit unitprovides 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
BitcoinUnitenum. The use ofQVariant::fromValuefor 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.hinclude is necessary for theBitcoinUnittype 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
inttoBitcoinUnit.Also applies to: 100-101
107-107: Return type correctly updated.The
getDisplayUnit()return type now properly matches them_display_bitcoin_unitmember variable type.
135-135: Core member variable properly typed.The
m_display_bitcoin_unitmember now uses the strongly typedBitcoinUnitenum, providing compile-time type safety for this important user preference.
150-150: Signal parameter type safety maintained.The
displayUnitChangedsignal now emits the strongly typedBitcoinUnitenum, ensuring type safety across all connected slots.src/qt/walletmodel.h (3)
80-83: Good improvement in const-correctness!Marking these getter methods as
constis 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
validateAddressmethod only performs validation without modifying state, so marking it asconstis correct.
159-159: LGTM!Marking
isMultiwalletasconstis 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
BitcoinUnitenum instead ofintprevents invalid unit values from being passed.
43-48: Consistent type safety in AmountValidator.The class properly uses
BitcoinUnittype with appropriate default initialization toBitcoinUnit::DASH.Also applies to: 60-63
76-76: LGTM!Proper initialization with
BitcoinUnit::DASH.
129-129: Type-safe unit parameter.Properly updated to use
BitcoinUnitparameter.
149-149: Clear use of enum constant.Using
BitcoinUnit::DASHdirectly 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 tostop().
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
fprefix from boolean parameters improves readability and follows modern C++ conventions.
255-267: LGTM!Implementation properly updated to use the renamed
headerparameter 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
thispointer- Simplified cleanup via vector
- Direct signal emission instead of
QMetaObject::invokeMethodAll handlers, including the three Dash-specific ones (
handleNotifyAdditionalDataSyncProgressChanged,handleNotifyChainLock, andhandleNotifyMasternodeListChanged), 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 Unittoenum class Unitsignificantly improves type safety by preventing implicit conversions to integers. The addition ofQ_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
Unitparameter instead ofint. This ensures compile-time type checking and prevents incorrect unit values from being passed.
113-113: Consistent member variable type update.The
unitlistmember 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 unitand the switch statement properly handles all enum cases without a default clause, allowing the compiler to warn about missing cases. Theassert(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
Unitenum class parameter, maintaining consistency across the API.
240-240: Proper QVariant handling for enum class.The change from casting to
intto usingQVariant::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:
- Helper functions:
ToQint8()andFromQint8()provide safe conversion between the enum and a serializable integer type.- Exhaustive switches: Both conversion functions use exhaustive switch statements without default cases, ensuring compiler warnings for missing enum values.
- Stream operators: The
operator<<andoperator>>correctly use the helper functions to serialize/deserialize the enum viaqint8.- Anonymous namespace: Properly scopes the helper functions to avoid symbol pollution.
This design ensures type safety while providing efficient serialization.
src/qt/walletmodel.h
Outdated
There was a problem hiding this comment.
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:
- Error handling is now done through signals/exceptions
- All callers have been updated to not expect a return value
- The
SendCoinsReturnstruct (lines 91-100) is still needed forprepareTransaction
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 cppLength 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.cppLength 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.cppLength 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.
…gent during peer connection
…abel and tooltip
…rs details window
…tempting unlock
UdjinM6
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
light ACK a41f4e7
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.bitcoin-core/gui#581 affects three Dash-specific signal handlers,
m_handler_notify_additional_data_sync_progess_changed,m_handler_notify_chainlockandm_handler_notify_masternodelist_changedand their refactoring needs to be specially reviewed.Breaking Changes
None expected.
Checklist