aboutsummaryrefslogtreecommitdiff
path: root/src/qt/addresstablemodel.cpp
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2022-09-15 11:15:06 -0400
committerRyan Ofsky <ryan@ofsky.org>2024-04-25 16:08:24 -0400
commit834f65e82405bbed336f98996bc8cef366bbed0f (patch)
tree2ed28b93420df882aee09cd69464ce3775bfcebc /src/qt/addresstablemodel.cpp
parent2eff198f4900c34442439ef2cbd9d82f4903f915 (diff)
downloadbitcoin-834f65e82405bbed336f98996bc8cef366bbed0f.tar.xz
refactor: Drop util::Result operator=
`util::Result` objects are aggregates that can hold multiple fields with different information. Currently Result objects can only hold a success value of an arbitrary type or a single bilingual_str error message. In followup PR https://github.com/bitcoin/bitcoin/pull/25722, Result objects may be able to hold both success and failure values of different types, plus error and warning messages. Having a Result::operator= assignment operator that completely erases all existing Result information before assigning new information is potentially dangerous in this case. For example, code that looks like it is assigning a warning value could erase previously-assigned success or failure values. Conversely, code that looks like it is just assigning a success or failure value could erase previously assigned error and warning messages. To prevent potential bugs like this, disable Result::operator= assignment operator. It is possible in the future we may want to re-enable operator= in limited cases (such as when implicit conversions are not used) or add a Replace() or Reset() method that mimicks default operator= behavior. Followup PR https://github.com/bitcoin/bitcoin/pull/25722 also adds a Result::Update() method providing another way to update an existing Result object. Co-authored-by: stickies-v <stickies-v@protonmail.com>
Diffstat (limited to 'src/qt/addresstablemodel.cpp')
-rw-r--r--src/qt/addresstablemodel.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp
index c52ef7cd67..efdc3966d1 100644
--- a/src/qt/addresstablemodel.cpp
+++ b/src/qt/addresstablemodel.cpp
@@ -369,21 +369,22 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
else if(type == Receive)
{
// Generate a new address to associate with given label
- auto op_dest = walletModel->wallet().getNewDestination(address_type, strLabel);
- if (!op_dest) {
+ if (auto dest{walletModel->wallet().getNewDestination(address_type, strLabel)}) {
+ strAddress = EncodeDestination(*dest);
+ } else {
WalletModel::UnlockContext ctx(walletModel->requestUnlock());
if (!ctx.isValid()) {
// Unlock wallet failed or was cancelled
editStatus = WALLET_UNLOCK_FAILURE;
return QString();
}
- op_dest = walletModel->wallet().getNewDestination(address_type, strLabel);
- if (!op_dest) {
+ if (auto dest_retry{walletModel->wallet().getNewDestination(address_type, strLabel)}) {
+ strAddress = EncodeDestination(*dest_retry);
+ } else {
editStatus = KEY_GENERATION_FAILURE;
return QString();
}
}
- strAddress = EncodeDestination(*op_dest);
}
else
{