Skip to content

Commit 88b2652

Browse files
committed
Merge #18853: wallet: Fix typo in assert that is compile-time true
fa47cf9 wallet: Fix typo in assert that is compile-time true (MarcoFalke) Pull request description: Commit 92bcd70 presumably added a check that a `dest` of type `CNoDestination` implies an empty `scriptChange`. However, it accidentally checked for `boost::variant::empty`, which always returns false: https://www.boost.org/doc/libs/1_72_0/doc/html/boost/variant.html#id-1_3_46_5_4_1_1_16_2-bb ACKs for top commit: Sjors: utACK fa47cf9 Tree-SHA512: 9626b1e2947039853703932a362c2ee204e002d3344856eb93eef0e0f833401336f2dfa80fd43b83c8ec6eac624e6302aee771fb67aec436ba6483be02b8d615
2 parents 6621be5 + fa47cf9 commit 88b2652

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/test/script_standard_tests.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
BOOST_FIXTURE_TEST_SUITE(script_standard_tests, BasicTestingSetup)
1515

16+
BOOST_AUTO_TEST_CASE(dest_default_is_no_dest)
17+
{
18+
CTxDestination dest;
19+
BOOST_CHECK(!IsValidDestination(dest));
20+
}
21+
1622
BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
1723
{
1824
CKey keys[3];

src/wallet/wallet.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
27132713
error = _("Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.");
27142714
}
27152715
scriptChange = GetScriptForDestination(dest);
2716-
assert(!dest.empty() || scriptChange.empty());
2716+
// A valid destination implies a change script (and
2717+
// vice-versa). An empty change script will abort later, if the
2718+
// change keypool ran out, but change is required.
2719+
CHECK_NONFATAL(IsValidDestination(dest) != scriptChange.empty());
27172720
}
27182721
CTxOut change_prototype_txout(0, scriptChange);
27192722
coin_selection_params.change_output_size = GetSerializeSize(change_prototype_txout);
@@ -2930,7 +2933,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
29302933
continue;
29312934
}
29322935

2933-
// Give up if change keypool ran out and we failed to find a solution without change:
2936+
// Give up if change keypool ran out and change is required
29342937
if (scriptChange.empty() && nChangePosInOut != -1) {
29352938
return false;
29362939
}

0 commit comments

Comments
 (0)