mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
bugfix: Mark CNoDestination and PubKeyDestination constructor explicit
This should fix the bug reported in
https://github.com/bitcoin/bitcoin/pull/28246#discussion_r1371640502,
which caused the GUI to not detect the destination type of recipients,
thus picking the wrong change destination type.
Also, add missing lifetimebound attribute to a getter method.
GitHub-Pull: #28728
Rebased-From: 1111475b41
This commit is contained in:
parent
7d0e5b099c
commit
6544ffa01f
5 changed files with 12 additions and 11 deletions
|
@ -13,15 +13,16 @@
|
|||
#include <variant>
|
||||
#include <algorithm>
|
||||
|
||||
class CNoDestination {
|
||||
class CNoDestination
|
||||
{
|
||||
private:
|
||||
CScript m_script;
|
||||
|
||||
public:
|
||||
CNoDestination() = default;
|
||||
CNoDestination(const CScript& script) : m_script(script) {}
|
||||
explicit CNoDestination(const CScript& script) : m_script(script) {}
|
||||
|
||||
const CScript& GetScript() const { return m_script; }
|
||||
const CScript& GetScript() const LIFETIMEBOUND { return m_script; }
|
||||
|
||||
friend bool operator==(const CNoDestination& a, const CNoDestination& b) { return a.GetScript() == b.GetScript(); }
|
||||
friend bool operator<(const CNoDestination& a, const CNoDestination& b) { return a.GetScript() < b.GetScript(); }
|
||||
|
@ -32,7 +33,7 @@ private:
|
|||
CPubKey m_pubkey;
|
||||
|
||||
public:
|
||||
PubKeyDestination(const CPubKey& pubkey) : m_pubkey(pubkey) {}
|
||||
explicit PubKeyDestination(const CPubKey& pubkey) : m_pubkey(pubkey) {}
|
||||
|
||||
const CPubKey& GetPubKey() const LIFETIMEBOUND { return m_pubkey; }
|
||||
|
||||
|
|
|
@ -94,13 +94,14 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
|
|||
}
|
||||
|
||||
// Generate destinations
|
||||
CScript dest = GetScriptForDestination(getNewDestination(wallet, output_type));
|
||||
const auto dest{getNewDestination(wallet, output_type)};
|
||||
|
||||
// Generate chain; each coinbase will have two outputs to fill-up the wallet
|
||||
const auto& params = Params();
|
||||
const CScript coinbase_out{GetScriptForDestination(dest)};
|
||||
unsigned int chain_size = 5000; // 5k blocks means 10k UTXO for the wallet (minus 200 due COINBASE_MATURITY)
|
||||
for (unsigned int i = 0; i < chain_size; ++i) {
|
||||
generateFakeBlock(params, test_setup->m_node, wallet, dest);
|
||||
generateFakeBlock(params, test_setup->m_node, wallet, coinbase_out);
|
||||
}
|
||||
|
||||
// Check available balance
|
||||
|
@ -185,4 +186,4 @@ static void WalletAvailableCoins(benchmark::Bench& bench) { AvailableCoins(bench
|
|||
|
||||
BENCHMARK(WalletCreateTxUseOnlyPresetInputs, benchmark::PriorityLevel::LOW)
|
||||
BENCHMARK(WalletCreateTxUsePresetInputsAndCoinSelection, benchmark::PriorityLevel::LOW)
|
||||
BENCHMARK(WalletAvailableCoins, benchmark::PriorityLevel::LOW);
|
||||
BENCHMARK(WalletAvailableCoins, benchmark::PriorityLevel::LOW);
|
||||
|
|
|
@ -187,8 +187,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
|
|||
setAddress.insert(rcp.address);
|
||||
++nAddresses;
|
||||
|
||||
CScript scriptPubKey = GetScriptForDestination(DecodeDestination(rcp.address.toStdString()));
|
||||
CRecipient recipient = {scriptPubKey, rcp.amount, rcp.fSubtractFeeFromAmount};
|
||||
CRecipient recipient{DecodeDestination(rcp.address.toStdString()), rcp.amount, rcp.fSubtractFeeFromAmount};
|
||||
vecSend.push_back(recipient);
|
||||
|
||||
total += rcp.amount;
|
||||
|
|
|
@ -78,7 +78,7 @@ BOOST_FIXTURE_TEST_CASE(wallet_duplicated_preset_inputs_test, TestChain100Setup)
|
|||
|
||||
// Try to create a tx that spends more than what preset inputs + wallet selected inputs are covering for.
|
||||
// The wallet can cover up to 200 BTC, and the tx target is 299 BTC.
|
||||
std::vector<CRecipient> recipients = {{GetScriptForDestination(*Assert(wallet->GetNewDestination(OutputType::BECH32, "dummy"))),
|
||||
std::vector<CRecipient> recipients{{*Assert(wallet->GetNewDestination(OutputType::BECH32, "dummy")),
|
||||
/*nAmount=*/299 * COIN, /*fSubtractFeeFromAmount=*/true}};
|
||||
CCoinControl coin_control;
|
||||
coin_control.m_allow_other_inputs = true;
|
||||
|
|
|
@ -605,7 +605,7 @@ BOOST_FIXTURE_TEST_CASE(ListCoinsTest, ListCoinsTestingSetup)
|
|||
// returns the coin associated with the change address underneath the
|
||||
// coinbaseKey pubkey, even though the change address has a different
|
||||
// pubkey.
|
||||
AddTx(CRecipient{GetScriptForRawPubKey({}), 1 * COIN, /*subtract_fee=*/false});
|
||||
AddTx(CRecipient{PubKeyDestination{{}}, 1 * COIN, /*subtract_fee=*/false});
|
||||
{
|
||||
LOCK(wallet->cs_wallet);
|
||||
list = ListCoins(*wallet);
|
||||
|
|
Loading…
Add table
Reference in a new issue