Skip to content

Commit 6b63218

Browse files
committed
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.
1 parent cfe025f commit 6b63218

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ void TransactionTableModel::updateAmountColumnTitle()
276276

277277
void TransactionTableModel::updateTransaction(const QString &hash, int status, bool showTransaction)
278278
{
279-
uint256 updated;
280-
updated.SetHexDeprecated(hash.toStdString());
279+
Txid updated = Txid::FromHex(hash.toStdString()).value();
281280

282281
priv->updateWallet(walletModel->wallet(), updated, status, showTransaction);
283282
}

src/qt/transactionview.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,13 @@ void TransactionView::contextualMenu(const QPoint &point)
394394
if (selection.empty())
395395
return;
396396

397-
// check if transaction can be abandoned, disable context menu action in case it doesn't
398-
uint256 hash;
399-
hash.SetHexDeprecated(selection.at(0).data(TransactionTableModel::TxHashRole).toString().toStdString());
397+
// If the hash from the TxHashRole (QVariant / QString) is invalid, exit
398+
QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString();
399+
std::optional<Txid> maybeHash = Txid::FromHex(hashQStr.toStdString());
400+
if (!maybeHash)
401+
return;
402+
403+
Txid hash = *maybeHash;
400404
abandonAction->setEnabled(model->wallet().transactionCanBeAbandoned(hash));
401405
bumpFeeAction->setEnabled(model->wallet().transactionCanBeBumped(hash));
402406
copyAddressAction->setEnabled(GUIUtil::hasEntryData(transactionView, 0, TransactionTableModel::AddressRole));
@@ -414,9 +418,8 @@ void TransactionView::abandonTx()
414418
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
415419

416420
// get the hash from the TxHashRole (QVariant / QString)
417-
uint256 hash;
418421
QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString();
419-
hash.SetHexDeprecated(hashQStr.toStdString());
422+
Txid hash = Txid::FromHex(hashQStr.toStdString()).value();
420423

421424
// Abandon the wallet transaction over the walletModel
422425
model->wallet().abandonTransaction(hash);
@@ -429,9 +432,8 @@ void TransactionView::bumpFee([[maybe_unused]] bool checked)
429432
QModelIndexList selection = transactionView->selectionModel()->selectedRows(0);
430433

431434
// get the hash from the TxHashRole (QVariant / QString)
432-
uint256 hash;
433435
QString hashQStr = selection.at(0).data(TransactionTableModel::TxHashRole).toString();
434-
hash.SetHexDeprecated(hashQStr.toStdString());
436+
Txid hash = Txid::FromHex(hashQStr.toStdString()).value();
435437

436438
// Bump tx fee over the walletModel
437439
uint256 newHash;

0 commit comments

Comments
 (0)