From 6b63218ec2acebf3555a22923fedf8f080543c61 Mon Sep 17 00:00:00 2001 From: marcofleon Date: Tue, 8 Apr 2025 14:28:43 +0100 Subject: [PATCH] qt: Update SetHexDeprecated to FromHex Replace `uint256::SetHexDeprecated()` calls with `Txid::FromHex()` in four locations: - TransactionTableModel::updateTransaction - TransactionView::contextualMenu - TransactionView::abandonTx - TransactionView::bumpFee The input strings are generally expected to be valid hex strings from `GetHex()`. However, due to the potentially unpredictable return value of `.data(TransactionTableModel::TxHashRole)`, check the `Txid::FromHex` result in `contextualMenu` and return early if the transaction hash is invalid. The other two functions, `abandonTx` and `bumpFee` will only be called if the context menu is enabled. --- src/qt/transactiontablemodel.cpp | 3 +-- src/qt/transactionview.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 9214e7723d..9a79a08df9 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -276,8 +276,7 @@ void TransactionTableModel::updateAmountColumnTitle() void TransactionTableModel::updateTransaction(const QString &hash, int status, bool showTransaction) { - uint256 updated; - updated.SetHexDeprecated(hash.toStdString()); + Txid updated = Txid::FromHex(hash.toStdString()).value(); priv->updateWallet(walletModel->wallet(), updated, status, showTransaction); } diff --git a/src/qt/transactionview.cpp b/src/qt/transactionview.cpp index 90a53fb2bb..574824b419 100644 --- a/src/qt/transactionview.cpp +++ b/src/qt/transactionview.cpp @@ -394,9 +394,13 @@ void TransactionView::contextualMenu(const QPoint &point) if (selection.empty()) return; - // check if transaction can be abandoned, disable context menu action in case it doesn't - uint256 hash; - hash.SetHexDeprecated(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString()); + // If the hash from the TxHashRole (QVariant / QString) is invalid, exit + QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString(); + std::optional maybeHash = Txid::FromHex(hashQStr.toStdString()); + if (!maybeHash) + return; + + Txid hash = *maybeHash; abandonAction->setEnabled(model->wallet().transactionCanBeAbandoned(hash)); bumpFeeAction->setEnabled(model->wallet().transactionCanBeBumped(hash)); copyAddressAction->setEnabled(GUIUtil::hasEntryData(transactionView, 0, TransactionTableModel::AddressRole)); @@ -414,9 +418,8 @@ void TransactionView::abandonTx() QModelIndexList selection = transactionView->selectionModel()->selectedRows(0); // get the hash from the TxHashRole (QVariant / QString) - uint256 hash; QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString(); - hash.SetHexDeprecated(hashQStr.toStdString()); + Txid hash = Txid::FromHex(hashQStr.toStdString()).value(); // Abandon the wallet transaction over the walletModel model->wallet().abandonTransaction(hash); @@ -429,9 +432,8 @@ void TransactionView::bumpFee([[maybe_unused]] bool checked) QModelIndexList selection = transactionView->selectionModel()->selectedRows(0); // get the hash from the TxHashRole (QVariant / QString) - uint256 hash; QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString(); - hash.SetHexDeprecated(hashQStr.toStdString()); + Txid hash = Txid::FromHex(hashQStr.toStdString()).value(); // Bump tx fee over the walletModel uint256 newHash;