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.
This commit is contained in:
6 files changed
+7
-36
No files matched your search
@@ -37,7 +37,7 @@ static void WalletMigration(benchmark::Bench& bench)
|
|||||||
for (int w = 0; w < NUM_WATCH_ONLY_ADDR; ++w) {
|
for (int w = 0; w < NUM_WATCH_ONLY_ADDR; ++w) {
|
||||||
CKey key = GenerateRandomKey();
|
CKey key = GenerateRandomKey();
|
||||||
LOCK(wallet->cs_wallet);
|
LOCK(wallet->cs_wallet);
|
||||||
const auto& dest = GetDestinationForKey(key.GetPubKey(), OutputType::LEGACY);
|
const PKHash dest{key.GetPubKey()};
|
||||||
const CScript& script = scripts_watch_only.emplace_back(GetScriptForDestination(dest));
|
const CScript& script = scripts_watch_only.emplace_back(GetScriptForDestination(dest));
|
||||||
assert(legacy_spkm->LoadWatchOnly(script));
|
assert(legacy_spkm->LoadWatchOnly(script));
|
||||||
assert(wallet->SetAddressBook(dest, strprintf("watch_%d", w), /*purpose=*/std::nullopt));
|
assert(wallet->SetAddressBook(dest, strprintf("watch_%d", w), /*purpose=*/std::nullopt));
|
||||||
|
|||||||
@@ -46,27 +46,6 @@ const std::string& FormatOutputType(OutputType type)
|
|||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
|
|
||||||
{
|
|
||||||
switch (type) {
|
|
||||||
case OutputType::LEGACY: return PKHash(key);
|
|
||||||
case OutputType::P2SH_SEGWIT:
|
|
||||||
case OutputType::BECH32: {
|
|
||||||
if (!key.IsCompressed()) return PKHash(key);
|
|
||||||
CTxDestination witdest = WitnessV0KeyHash(key);
|
|
||||||
CScript witprog = GetScriptForDestination(witdest);
|
|
||||||
if (type == OutputType::P2SH_SEGWIT) {
|
|
||||||
return ScriptHash(witprog);
|
|
||||||
} else {
|
|
||||||
return witdest;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case OutputType::BECH32M:
|
|
||||||
case OutputType::UNKNOWN: {} // This function should never be used with BECH32M or UNKNOWN, so let it assert
|
|
||||||
} // no default case, so the compiler can warn about missing cases
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType type)
|
CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType type)
|
||||||
{
|
{
|
||||||
// Add script to keystore
|
// Add script to keystore
|
||||||
|
|||||||
@@ -32,12 +32,6 @@ static constexpr auto OUTPUT_TYPES = std::array{
|
|||||||
std::optional<OutputType> ParseOutputType(const std::string& str);
|
std::optional<OutputType> ParseOutputType(const std::string& str);
|
||||||
const std::string& FormatOutputType(OutputType type);
|
const std::string& FormatOutputType(OutputType type);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a destination of the requested type (if possible) to the specified key.
|
|
||||||
* The caller must make sure LearnRelatedScripts has been called beforehand.
|
|
||||||
*/
|
|
||||||
CTxDestination GetDestinationForKey(const CPubKey& key, OutputType);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a destination of the requested type (if possible) to the specified script.
|
* Get a destination of the requested type (if possible) to the specified script.
|
||||||
* This function will automatically add the script (and any other
|
* This function will automatically add the script (and any other
|
||||||
|
|||||||
@@ -84,13 +84,11 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
|
|||||||
wallet->SetupDescriptorScriptPubKeyMans();
|
wallet->SetupDescriptorScriptPubKeyMans();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto build_address = [&wallet]() {
|
auto build_address{[]() {
|
||||||
CKey key = GenerateRandomKey();
|
CKey key = GenerateRandomKey();
|
||||||
CTxDestination dest(GetDestinationForKey(
|
const PKHash dest{key.GetPubKey()};
|
||||||
key.GetPubKey(), wallet->m_default_address_type));
|
|
||||||
|
|
||||||
return std::make_pair(dest, QString::fromStdString(EncodeDestination(dest)));
|
return std::make_pair(dest, QString::fromStdString(EncodeDestination(dest)));
|
||||||
};
|
}};
|
||||||
|
|
||||||
CTxDestination r_key_dest, s_key_dest;
|
CTxDestination r_key_dest, s_key_dest;
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChai
|
|||||||
WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
|
WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
|
||||||
auto spk_manager = *Assert(wallet->AddWalletDescriptor(w_desc, provider, "", false));
|
auto spk_manager = *Assert(wallet->AddWalletDescriptor(w_desc, provider, "", false));
|
||||||
assert(spk_manager);
|
assert(spk_manager);
|
||||||
CTxDestination dest = GetDestinationForKey(test.coinbaseKey.GetPubKey(), wallet->m_default_address_type);
|
const PKHash dest{test.coinbaseKey.GetPubKey()};
|
||||||
wallet->SetAddressBook(dest, "", wallet::AddressPurpose::RECEIVE);
|
wallet->SetAddressBook(dest, "", wallet::AddressPurpose::RECEIVE);
|
||||||
wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
|
wallet->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
|
||||||
SyncUpWallet(wallet, node);
|
SyncUpWallet(wallet, node);
|
||||||
@@ -406,7 +406,7 @@ void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
|
|||||||
sendCoinsDialog.findChild<QLabel*>("labelBalance"));
|
sendCoinsDialog.findChild<QLabel*>("labelBalance"));
|
||||||
|
|
||||||
// Set change address
|
// Set change address
|
||||||
sendCoinsDialog.getCoinControl()->destChange = GetDestinationForKey(test.coinbaseKey.GetPubKey(), OutputType::LEGACY);
|
sendCoinsDialog.getCoinControl()->destChange = PKHash{test.coinbaseKey.GetPubKey()};
|
||||||
|
|
||||||
// Time to reject "save" PSBT dialog ('SendCoins' locks the main thread until the dialog receives the event).
|
// Time to reject "save" PSBT dialog ('SendCoins' locks the main thread until the dialog receives the event).
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ FUZZ_TARGET(key, .init = initialize_key)
|
|||||||
assert(v_solutions_ret_tx_multisig[2].size() == 1);
|
assert(v_solutions_ret_tx_multisig[2].size() == 1);
|
||||||
|
|
||||||
OutputType output_type{};
|
OutputType output_type{};
|
||||||
const CTxDestination tx_destination = GetDestinationForKey(pubkey, output_type);
|
const CTxDestination tx_destination{PKHash{pubkey}};
|
||||||
assert(output_type == OutputType::LEGACY);
|
assert(output_type == OutputType::LEGACY);
|
||||||
assert(IsValidDestination(tx_destination));
|
assert(IsValidDestination(tx_destination));
|
||||||
assert(PKHash{pubkey} == *std::get_if<PKHash>(&tx_destination));
|
assert(PKHash{pubkey} == *std::get_if<PKHash>(&tx_destination));
|
||||||
|
|||||||
Reference in new issue
Block a user