mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
wallet: switch to new shuffle, erase, push_back
switch to new methods, remove old code. this also updates the Size, All, and Clear methods to now use the coins map. this commit is not strictly a refactor because previously coin selection was never run over the UNKNOWN type until the last step when being run over all. now that we are iterating over each, it is run over UNKNOWN but this is expected to be empty most of the time. Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
This commit is contained in:
@@ -64,7 +64,7 @@ BOOST_FIXTURE_TEST_CASE(BasicOutputTypesTest, AvailableCoinsTestingSetup)
|
||||
// This UTXO is a P2PK, so it should show up in the Other bucket
|
||||
available_coins = AvailableCoins(*wallet);
|
||||
BOOST_CHECK_EQUAL(available_coins.Size(), 1U);
|
||||
BOOST_CHECK_EQUAL(available_coins.other.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(available_coins.coins[OutputType::UNKNOWN].size(), 1U);
|
||||
|
||||
// We will create a self transfer for each of the OutputTypes and
|
||||
// verify it is put in the correct bucket after running GetAvailablecoins
|
||||
@@ -78,27 +78,27 @@ BOOST_FIXTURE_TEST_CASE(BasicOutputTypesTest, AvailableCoinsTestingSetup)
|
||||
BOOST_ASSERT(dest);
|
||||
AddTx(CRecipient{{GetScriptForDestination(*dest)}, 1 * COIN, /*fSubtractFeeFromAmount=*/true});
|
||||
available_coins = AvailableCoins(*wallet);
|
||||
BOOST_CHECK_EQUAL(available_coins.bech32m.size(), 2U);
|
||||
BOOST_CHECK_EQUAL(available_coins.coins[OutputType::BECH32M].size(), 2U);
|
||||
|
||||
// Bech32
|
||||
dest = wallet->GetNewDestination(OutputType::BECH32, "");
|
||||
BOOST_ASSERT(dest);
|
||||
AddTx(CRecipient{{GetScriptForDestination(*dest)}, 2 * COIN, /*fSubtractFeeFromAmount=*/true});
|
||||
available_coins = AvailableCoins(*wallet);
|
||||
BOOST_CHECK_EQUAL(available_coins.bech32.size(), 2U);
|
||||
BOOST_CHECK_EQUAL(available_coins.coins[OutputType::BECH32].size(), 2U);
|
||||
|
||||
// P2SH-SEGWIT
|
||||
dest = wallet->GetNewDestination(OutputType::P2SH_SEGWIT, "");
|
||||
AddTx(CRecipient{{GetScriptForDestination(*dest)}, 3 * COIN, /*fSubtractFeeFromAmount=*/true});
|
||||
available_coins = AvailableCoins(*wallet);
|
||||
BOOST_CHECK_EQUAL(available_coins.P2SH_segwit.size(), 2U);
|
||||
BOOST_CHECK_EQUAL(available_coins.coins[OutputType::P2SH_SEGWIT].size(), 2U);
|
||||
|
||||
// Legacy (P2PKH)
|
||||
dest = wallet->GetNewDestination(OutputType::LEGACY, "");
|
||||
BOOST_ASSERT(dest);
|
||||
AddTx(CRecipient{{GetScriptForDestination(*dest)}, 4 * COIN, /*fSubtractFeeFromAmount=*/true});
|
||||
available_coins = AvailableCoins(*wallet);
|
||||
BOOST_CHECK_EQUAL(available_coins.legacy.size(), 2U);
|
||||
BOOST_CHECK_EQUAL(available_coins.coins[OutputType::LEGACY].size(), 2U);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -83,7 +83,7 @@ static void add_coin(CoinsResult& available_coins, CWallet& wallet, const CAmoun
|
||||
assert(ret.second);
|
||||
CWalletTx& wtx = (*ret.first).second;
|
||||
const auto& txout = wtx.tx->vout.at(nInput);
|
||||
available_coins.bech32.emplace_back(COutPoint(wtx.GetHash(), nInput), txout, nAge, CalculateMaximumSignedInputSize(txout, &wallet, /*coin_control=*/nullptr), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe, feerate);
|
||||
available_coins.coins[OutputType::BECH32].emplace_back(COutPoint(wtx.GetHash(), nInput), txout, nAge, CalculateMaximumSignedInputSize(txout, &wallet, /*coin_control=*/nullptr), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe, feerate);
|
||||
}
|
||||
|
||||
/** Check if SelectionResult a is equivalent to SelectionResult b.
|
||||
|
||||
Reference in New Issue
Block a user