mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
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.
This commit is contained in:
parent
cfe025ff0e
commit
6b63218ec2
2 changed files with 10 additions and 9 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<Txid> 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;
|
||||
|
|
Loading…
Add table
Reference in a new issue