Skip to content

Commit a92955d

Browse files
committed
wallet: remove std::optional when PSBTResult is returned
PSBTResult has an enum value of OK, so it makes sense to return OK insead of a {}. This change makes it so we check for an OK value instead of null/{}
1 parent 125431e commit a92955d

14 files changed

+34
-34
lines changed

src/interfaces/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class Wallet
205205
int& num_blocks) = 0;
206206

207207
//! Fill PSBT.
208-
virtual std::optional<common::PSBTResult> fillPSBT(std::optional<int> sighash_type,
208+
virtual common::PSBTResult fillPSBT(std::optional<int> sighash_type,
209209
bool sign,
210210
bool bip32derivs,
211211
size_t* n_signed,

src/qt/psbtoperationsdialog.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ void PSBTOperationsDialog::openWithPSBT(PartiallySignedTransaction psbtx)
6060
if (m_wallet_model) {
6161
size_t n_could_sign;
6262
const auto err{m_wallet_model->wallet().fillPSBT(std::nullopt, /*sign=*/false, /*bip32derivs=*/true, &n_could_sign, m_transaction_data, complete)};
63-
if (err) {
63+
if (err != PSBTResult::OK) {
6464
showStatus(tr("Failed to load transaction: %1")
65-
.arg(QString::fromStdString(PSBTResultString(*err).translated)),
65+
.arg(QString::fromStdString(PSBTResultString(err).translated)),
6666
StatusLevel::ERR);
6767
return;
6868
}
@@ -85,9 +85,9 @@ void PSBTOperationsDialog::signTransaction()
8585

8686
const auto err{m_wallet_model->wallet().fillPSBT(std::nullopt, /*sign=*/true, /*bip32derivs=*/true, &n_signed, m_transaction_data, complete)};
8787

88-
if (err) {
88+
if (err != PSBTResult::OK) {
8989
showStatus(tr("Failed to sign transaction: %1")
90-
.arg(QString::fromStdString(PSBTResultString(*err).translated)), StatusLevel::ERR);
90+
.arg(QString::fromStdString(PSBTResultString(err).translated)), StatusLevel::ERR);
9191
return;
9292
}
9393

@@ -253,7 +253,7 @@ size_t PSBTOperationsDialog::couldSignInputs(const PartiallySignedTransaction &p
253253
bool complete;
254254
const auto err{m_wallet_model->wallet().fillPSBT(std::nullopt, /*sign=*/false, /*bip32derivs=*/false, &n_signed, m_transaction_data, complete)};
255255

256-
if (err) {
256+
if (err != PSBTResult::OK) {
257257
return 0;
258258
}
259259
return n_signed;

src/qt/sendcoinsdialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ void SendCoinsDialog::presentPSBT(PartiallySignedTransaction& psbtx)
448448
}
449449

450450
bool SendCoinsDialog::signWithExternalSigner(PartiallySignedTransaction& psbtx, CMutableTransaction& mtx, bool& complete) {
451-
std::optional<PSBTResult> result;
451+
PSBTResult result;
452452
try {
453453
result = model->wallet().fillPSBT(std::nullopt, /*sign=*/true, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete);
454454
} catch (const std::runtime_error& e) {
@@ -467,7 +467,7 @@ bool SendCoinsDialog::signWithExternalSigner(PartiallySignedTransaction& psbtx,
467467
QMessageBox::critical(nullptr, msg, msg);
468468
return false;
469469
}
470-
if (result) {
470+
if (result != PSBTResult::OK) {
471471
qWarning() << "Failed to sign PSBT";
472472
processSendCoinsReturn(WalletModel::TransactionCreationFailed);
473473
return false;
@@ -509,7 +509,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
509509
// Fill without signing
510510
const auto err{model->wallet().fillPSBT(std::nullopt, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete)};
511511
assert(!complete);
512-
assert(!err);
512+
assert(err == PSBTResult::OK);
513513

514514
// Copy PSBT to clipboard and offer to save
515515
presentPSBT(psbtx);
@@ -525,7 +525,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
525525
// from being called prematurely and is not expensive.
526526
const auto err{model->wallet().fillPSBT(std::nullopt, /*sign=*/false, /*bip32derivs=*/true, /*n_signed=*/nullptr, psbtx, complete)};
527527
assert(!complete);
528-
assert(!err);
528+
assert(err == PSBTResult::OK);
529529
send_failure = !signWithExternalSigner(psbtx, mtx, complete);
530530
// Don't broadcast when user rejects it on the device or there's a failure:
531531
broadcast = complete && !send_failure;

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ bool WalletModel::bumpFee(Txid hash, Txid& new_hash)
521521
PartiallySignedTransaction psbtx(mtx);
522522
bool complete = false;
523523
const auto err{wallet().fillPSBT(std::nullopt, /*sign=*/false, /*bip32derivs=*/true, nullptr, psbtx, complete)};
524-
if (err || complete) {
524+
if (err != PSBTResult::OK || complete) {
525525
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Can't draft transaction."));
526526
return false;
527527
}

src/wallet/external_signer_scriptpubkeyman.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ util::Result<void> ExternalSignerScriptPubKeyMan::DisplayAddress(const CTxDestin
7979
}
8080

8181
// If sign is true, transaction must previously have been filled
82-
std::optional<PSBTResult> ExternalSignerScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, std::optional<int> sighash_type, bool sign, bool bip32derivs, int* n_signed, bool finalize) const
82+
PSBTResult ExternalSignerScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, std::optional<int> sighash_type, bool sign, bool bip32derivs, int* n_signed, bool finalize) const
8383
{
8484
if (!sign) {
8585
return DescriptorScriptPubKeyMan::FillPSBT(psbt, txdata, sighash_type, false, bip32derivs, n_signed, finalize);
@@ -91,7 +91,7 @@ std::optional<PSBTResult> ExternalSignerScriptPubKeyMan::FillPSBT(PartiallySigne
9191
// TODO: for multisig wallets, we should only care if all _our_ inputs are signed
9292
complete &= PSBTInputSigned(input);
9393
}
94-
if (complete) return {};
94+
if (complete) return PSBTResult::OK;
9595

9696
auto signer{GetExternalSigner()};
9797
if (!signer) {
@@ -105,6 +105,6 @@ std::optional<PSBTResult> ExternalSignerScriptPubKeyMan::FillPSBT(PartiallySigne
105105
return PSBTResult::EXTERNAL_SIGNER_FAILED;
106106
}
107107
if (finalize) FinalizePSBT(psbt); // This won't work in a multisig setup
108-
return {};
108+
return PSBTResult::OK;
109109
}
110110
} // namespace wallet

src/wallet/external_signer_scriptpubkeyman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ExternalSignerScriptPubKeyMan : public DescriptorScriptPubKeyMan
3636
*/
3737
util::Result<void> DisplayAddress(const CTxDestination& dest, const ExternalSigner& signer) const;
3838

39-
std::optional<common::PSBTResult> FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, std::optional<int> sighash_type = std::nullopt, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const override;
39+
common::PSBTResult FillPSBT(PartiallySignedTransaction& psbt, const PrecomputedTransactionData& txdata, std::optional<int> sighash_type = std::nullopt, bool sign = true, bool bip32derivs = false, int* n_signed = nullptr, bool finalize = true) const override;
4040
};
4141
} // namespace wallet
4242
#endif // BITCOIN_WALLET_EXTERNAL_SIGNER_SCRIPTPUBKEYMAN_H

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx) {
340340
bool complete;
341341
wallet.FillPSBT(psbtx, complete, std::nullopt, /*sign=*/false, /*bip32derivs=*/true);
342342
auto err{wallet.FillPSBT(psbtx, complete, std::nullopt, /*sign=*/true, /*bip32derivs=*/false)};
343-
if (err) return false;
343+
if (err != PSBTResult::OK) return false;
344344
complete = FinalizeAndExtractPSBT(psbtx, mtx);
345345
return complete;
346346
} else {

src/wallet/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class WalletImpl : public Wallet
383383
}
384384
return {};
385385
}
386-
std::optional<PSBTResult> fillPSBT(std::optional<int> sighash_type,
386+
PSBTResult fillPSBT(std::optional<int> sighash_type,
387387
bool sign,
388388
bool bip32derivs,
389389
size_t* n_signed,

src/wallet/rpc/spend.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ static UniValue FinishTransaction(const std::shared_ptr<CWallet> pwallet, const
102102
bool complete;
103103
pwallet->FillPSBT(psbtx, complete, std::nullopt, /*sign=*/false, /*bip32derivs=*/true);
104104
const auto err{pwallet->FillPSBT(psbtx, complete, std::nullopt, /*sign=*/true, /*bip32derivs=*/false)};
105-
if (err) {
106-
throw JSONRPCPSBTError(*err);
105+
if (err != PSBTResult::OK) {
106+
throw JSONRPCPSBTError(err);
107107
}
108108

109109
CMutableTransaction mtx;
@@ -1171,7 +1171,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
11711171
PartiallySignedTransaction psbtx(mtx);
11721172
bool complete = false;
11731173
const auto err{pwallet->FillPSBT(psbtx, complete, std::nullopt, /*sign=*/false, /*bip32derivs=*/true)};
1174-
CHECK_NONFATAL(!err);
1174+
CHECK_NONFATAL(err == PSBTResult::OK);
11751175
CHECK_NONFATAL(!complete);
11761176
DataStream ssTx{};
11771177
ssTx << psbtx;
@@ -1631,8 +1631,8 @@ RPCHelpMan walletprocesspsbt()
16311631
if (sign) EnsureWalletIsUnlocked(*pwallet);
16321632

16331633
const auto err{wallet.FillPSBT(psbtx, complete, nHashType, sign, bip32derivs, nullptr, finalize)};
1634-
if (err) {
1635-
throw JSONRPCPSBTError(*err);
1634+
if (err != PSBTResult::OK) {
1635+
throw JSONRPCPSBTError(err);
16361636
}
16371637

16381638
UniValue result(UniValue::VOBJ);
@@ -1770,8 +1770,8 @@ RPCHelpMan walletcreatefundedpsbt()
17701770
bool bip32derivs = request.params[4].isNull() ? true : request.params[4].get_bool();
17711771
bool complete = true;
17721772
const auto err{wallet.FillPSBT(psbtx, complete, std::nullopt, /*sign=*/false, /*bip32derivs=*/bip32derivs)};
1773-
if (err) {
1774-
throw JSONRPCPSBTError(*err);
1773+
if (err != PSBTResult::OK) {
1774+
throw JSONRPCPSBTError(err);
17751775
}
17761776

17771777
// Serialize the PSBT

src/wallet/scriptpubkeyman.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ SigningResult DescriptorScriptPubKeyMan::SignMessage(const std::string& message,
13031303
return SigningResult::OK;
13041304
}
13051305

1306-
std::optional<PSBTResult> DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psbtx, const PrecomputedTransactionData& txdata, std::optional<int> sighash_type, bool sign, bool bip32derivs, int* n_signed, bool finalize) const
1306+
PSBTResult DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psbtx, const PrecomputedTransactionData& txdata, std::optional<int> sighash_type, bool sign, bool bip32derivs, int* n_signed, bool finalize) const
13071307
{
13081308
if (n_signed) {
13091309
*n_signed = 0;
@@ -1396,7 +1396,7 @@ std::optional<PSBTResult> DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTra
13961396
UpdatePSBTOutput(HidingSigningProvider(keys.get(), /*hide_secret=*/true, /*hide_origin=*/!bip32derivs), psbtx, i);
13971397
}
13981398

1399-
return {};
1399+
return PSBTResult::OK;
14001400
}
14011401

14021402
std::unique_ptr<CKeyMetadata> DescriptorScriptPubKeyMan::GetMetadata(const CTxDestination& dest) const

0 commit comments

Comments
 (0)