aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAurèle Oulès <aurele@oules.com>2022-09-12 12:03:07 +0200
committerAurèle Oulès <aurele@oules.com>2023-04-26 10:16:16 +0200
commit1db23da6e163e793458ec702a9601d2837aea9cb (patch)
tree46c8131d1899455f73f2bd33acd29e546d49c14c /src
parentbecc45b589d07c4523276e4ba2dad8852d0d2632 (diff)
wallet: Use std::optional for GetExternalOutput and fixups
Diffstat (limited to 'src')
-rw-r--r--src/wallet/coincontrol.h16
-rw-r--r--src/wallet/spend.cpp17
2 files changed, 16 insertions, 17 deletions
diff --git a/src/wallet/coincontrol.h b/src/wallet/coincontrol.h
index 86069d005e..04f524028f 100644
--- a/src/wallet/coincontrol.h
+++ b/src/wallet/coincontrol.h
@@ -13,9 +13,9 @@
#include <script/signingprovider.h>
#include <script/standard.h>
-#include <optional>
#include <algorithm>
#include <map>
+#include <optional>
#include <set>
namespace wallet {
@@ -65,27 +65,27 @@ public:
bool HasSelected() const
{
- return (m_selected_inputs.size() > 0);
+ return !m_selected_inputs.empty();
}
bool IsSelected(const COutPoint& output) const
{
- return (m_selected_inputs.count(output) > 0);
+ return m_selected_inputs.count(output) > 0;
}
bool IsExternalSelected(const COutPoint& output) const
{
- return (m_external_txouts.count(output) > 0);
+ return m_external_txouts.count(output) > 0;
}
- bool GetExternalOutput(const COutPoint& outpoint, CTxOut& txout) const
+ std::optional<CTxOut> GetExternalOutput(const COutPoint& outpoint) const
{
const auto ext_it = m_external_txouts.find(outpoint);
if (ext_it == m_external_txouts.end()) {
- return false;
+ return std::nullopt;
}
- txout = ext_it->second;
- return true;
+
+ return std::make_optional(ext_it->second);
}
void Select(const COutPoint& output)
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 748f40dce8..7379490f9b 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -52,9 +52,7 @@ int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* wallet,
TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, const CCoinControl* coin_control)
{
CMutableTransaction txNew(tx);
- if (!wallet->DummySignTx(txNew, txouts, coin_control)) {
- return TxSize{-1, -1};
- }
+ if (!wallet->DummySignTx(txNew, txouts, coin_control)) return TxSize{-1, -1};
CTransaction ctx(txNew);
int64_t vsize = GetVirtualTransactionSize(ctx);
int64_t weight = GetTransactionWeight(ctx);
@@ -72,11 +70,9 @@ TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *walle
assert(input.prevout.n < mi->second.tx->vout.size());
txouts.emplace_back(mi->second.tx->vout.at(input.prevout.n));
} else if (coin_control) {
- CTxOut txout;
- if (!coin_control->GetExternalOutput(input.prevout, txout)) {
- return TxSize{-1, -1};
- }
- txouts.emplace_back(txout);
+ const auto& txout{coin_control->GetExternalOutput(input.prevout)};
+ if (!txout) return TxSize{-1, -1};
+ txouts.emplace_back(*txout);
} else {
return TxSize{-1, -1};
}
@@ -178,9 +174,12 @@ util::Result<PreSelectedInputs> FetchSelectedInputs(const CWallet& wallet, const
input_bytes = CalculateMaximumSignedInputSize(txout, &wallet, &coin_control);
} else {
// The input is external. We did not find the tx in mapWallet.
- if (!coin_control.GetExternalOutput(outpoint, txout)) {
+ const auto out{coin_control.GetExternalOutput(outpoint)};
+ if (!out) {
return util::Error{strprintf(_("Not found pre-selected input %s"), outpoint.ToString())};
}
+
+ txout = *out;
}
if (input_bytes == -1) {