Skip to content

Commit

Permalink
Merge bitcoin#18853: wallet: Fix typo in assert that is compile-time …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
laanwj authored and knst committed Sep 19, 2023
1 parent 220e18c commit d432ec7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/test/script_standard_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

BOOST_FIXTURE_TEST_SUITE(script_standard_tests, BasicTestingSetup)

BOOST_AUTO_TEST_CASE(dest_default_is_no_dest)
{
CTxDestination dest;
BOOST_CHECK(!IsValidDestination(dest));
}

BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
{
CKey keys[3];
Expand Down
7 changes: 5 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3474,7 +3474,10 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
error = _("Transaction needs a change address, but we can't generate it. Please call keypoolrefill first.");
}
scriptChange = GetScriptForDestination(dest);
assert(!dest.empty() || scriptChange.empty());
// A valid destination implies a change script (and
// vice-versa). An empty change script will abort later, if the
// change keypool ran out, but change is required.
CHECK_NONFATAL(IsValidDestination(dest) != scriptChange.empty());
}

nFeeRet = 0;
Expand Down Expand Up @@ -3725,7 +3728,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CTransac
return false;
}

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

0 comments on commit d432ec7

Please sign in to comment.