Skip to content

Commit fafee85

Browse files
author
MarcoFalke
committed
remove unused GetDestinationForKey
It is only used in test. There it is problematic, because it sometimes relies on m_default_address_type. If the default were changed to BECH32M, those tests would fail the assert(false). So just use PKHash{} in all tests and remove GetDestinationForKey.
1 parent fac72fe commit fafee85

File tree

6 files changed

+7
-36
lines changed

6 files changed

+7
-36
lines changed

src/bench/wallet_migration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void WalletMigration(benchmark::Bench& bench)
3737
for (int w = 0; w < NUM_WATCH_ONLY_ADDR; ++w) {
3838
CKey key = GenerateRandomKey();
3939
LOCK(wallet->cs_wallet);
40-
const auto& dest = GetDestinationForKey(key.GetPubKey(), OutputType::LEGACY);
40+
const PKHash dest{key.GetPubKey()};
4141
const CScript& script = scripts_watch_only.emplace_back(GetScriptForDestination(dest));
4242
assert(legacy_spkm->LoadWatchOnly(script));
4343
assert(wallet->SetAddressBook(dest, strprintf("watch_%d", w), /*purpose=*/std::nullopt));

src/outputtype.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,6 @@ const std::string& FormatOutputType(OutputType type)
4646
assert(false);
4747
}
4848

49-
CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
50-
{
51-
switch (type) {
52-
case OutputType::LEGACY: return PKHash(key);
53-
case OutputType::P2SH_SEGWIT:
54-
case OutputType::BECH32: {
55-
if (!key.IsCompressed()) return PKHash(key);
56-
CTxDestination witdest = WitnessV0KeyHash(key);
57-
CScript witprog = GetScriptForDestination(witdest);
58-
if (type == OutputType::P2SH_SEGWIT) {
59-
return ScriptHash(witprog);
60-
} else {
61-
return witdest;
62-
}
63-
}
64-
case OutputType::BECH32M:
65-
case OutputType::UNKNOWN: {} // This function should never be used with BECH32M or UNKNOWN, so let it assert
66-
} // no default case, so the compiler can warn about missing cases
67-
assert(false);
68-
}
69-
7049
CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType type)
7150
{
7251
// Add script to keystore

src/outputtype.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ static constexpr auto OUTPUT_TYPES = std::array{
3232
std::optional<OutputType> ParseOutputType(const std::string& str);
3333
const std::string& FormatOutputType(OutputType type);
3434

35-
/**
36-
* Get a destination of the requested type (if possible) to the specified key.
37-
* The caller must make sure LearnRelatedScripts has been called beforehand.
38-
*/
39-
CTxDestination GetDestinationForKey(const CPubKey& key, OutputType);
40-
4135
/**
4236
* Get a destination of the requested type (if possible) to the specified script.
4337
* This function will automatically add the script (and any other

src/qt/test/addressbooktests.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,11 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
8484
wallet->SetupDescriptorScriptPubKeyMans();
8585
}
8686

87-
auto build_address = [&wallet]() {
87+
auto build_address{[]() {
8888
CKey key = GenerateRandomKey();
89-
CTxDestination dest(GetDestinationForKey(
90-
key.GetPubKey(), wallet->m_default_address_type));
91-
89+
const PKHash dest{key.GetPubKey()};
9290
return std::make_pair(dest, QString::fromStdString(EncodeDestination(dest)));
93-
};
91+
}};
9492

9593
CTxDestination r_key_dest, s_key_dest;
9694

src/qt/test/wallettests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChai
217217
WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
218218
auto spk_manager = *Assert(wallet->AddWalletDescriptor(w_desc, provider, "", false));
219219
assert(spk_manager);
220-
CTxDestination dest = GetDestinationForKey(test.coinbaseKey.GetPubKey(), wallet->m_default_address_type);
220+
const PKHash dest{test.coinbaseKey.GetPubKey()};
221221
wallet->SetAddressBook(dest, "", wallet::AddressPurpose::RECEIVE);
222222
wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
223223
SyncUpWallet(wallet, node);
@@ -406,7 +406,7 @@ void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
406406
sendCoinsDialog.findChild<QLabel*>("labelBalance"));
407407

408408
// Set change address
409-
sendCoinsDialog.getCoinControl()->destChange = GetDestinationForKey(test.coinbaseKey.GetPubKey(), OutputType::LEGACY);
409+
sendCoinsDialog.getCoinControl()->destChange = PKHash{test.coinbaseKey.GetPubKey()};
410410

411411
// Time to reject "save" PSBT dialog ('SendCoins' locks the main thread until the dialog receives the event).
412412
QTimer timer;

src/test/fuzz/key.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ FUZZ_TARGET(key, .init = initialize_key)
174174
assert(v_solutions_ret_tx_multisig[2].size() == 1);
175175

176176
OutputType output_type{};
177-
const CTxDestination tx_destination = GetDestinationForKey(pubkey, output_type);
177+
const CTxDestination tx_destination{PKHash{pubkey}};
178178
assert(output_type == OutputType::LEGACY);
179179
assert(IsValidDestination(tx_destination));
180180
assert(PKHash{pubkey} == *std::get_if<PKHash>(&tx_destination));

0 commit comments

Comments
 (0)