Merge bitcoin/bitcoin#32511: refactor: bdb removals

fafee85358397289aa4c6b799d2603a5d89e83a2 remove unused GetDestinationForKey (MarcoFalke)
fac72fef27de6d8cece9b9d84325589a06fd2a8d remove unused GetAllDestinationsForKey (MarcoFalke)
fa91d57de36d74168e01909ae97d85bfdce2e0f1 remove unused AddrToPubKey (MarcoFalke)
faecf158d997c009a8a492bdf866a5e8cbb8f5e8 remove unused Import* function signatures (MarcoFalke)

Pull request description:

  remove dead code

ACKs for top commit:
  davidgumberg:
    crACK fafee85358
  achow101:
    ACK fafee85358397289aa4c6b799d2603a5d89e83a2
  rkrux:
    crACK fafee85358397289aa4c6b799d2603a5d89e83a2

Tree-SHA512: e48d4bf5f50b97dbd11260efdaf88277bd6a2478665b84353637d63e783003e90d29718836ffdc2e251ac9b77b22e616a0983a59d1b6658b3645a5575b871eae
This commit is contained in:
Ava Chow 2025-05-16 13:28:31 -07:00
commit c461d15287
No known key found for this signature in database
GPG Key ID: 17565732E08E5E41
9 changed files with 14 additions and 91 deletions

View File

@ -37,7 +37,7 @@ static void WalletMigration(benchmark::Bench& bench)
for (int w = 0; w < NUM_WATCH_ONLY_ADDR; ++w) {
CKey key = GenerateRandomKey();
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));
assert(legacy_spkm->LoadWatchOnly(script));
assert(wallet->SetAddressBook(dest, strprintf("watch_%d", w), /*purpose=*/std::nullopt));

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2022 The Bitcoin Core developers
// Copyright (c) 2009-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -9,9 +9,8 @@
#include <script/script.h>
#include <script/sign.h>
#include <script/signingprovider.h>
#include <util/vector.h>
#include <assert.h>
#include <cassert>
#include <optional>
#include <string>
@ -47,40 +46,6 @@ const std::string& FormatOutputType(OutputType type)
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);
}
std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key)
{
PKHash keyid(key);
CTxDestination p2pkh{keyid};
if (key.IsCompressed()) {
CTxDestination segwit = WitnessV0KeyHash(keyid);
CTxDestination p2sh = ScriptHash(GetScriptForDestination(segwit));
return Vector(std::move(p2pkh), std::move(p2sh), std::move(segwit));
} else {
return Vector(std::move(p2pkh));
}
}
CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType type)
{
// Add script to keystore

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2022 The Bitcoin Core developers
// Copyright (c) 2009-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -32,15 +32,6 @@ static constexpr auto OUTPUT_TYPES = std::array{
std::optional<OutputType> ParseOutputType(const std::string& str);
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 all destinations (potentially) supported by the wallet for the given key. */
std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key);
/**
* Get a destination of the requested type (if possible) to the specified script.
* This function will automatically add the script (and any other

View File

@ -84,13 +84,11 @@ void TestAddAddressesToSendBook(interfaces::Node& node)
wallet->SetupDescriptorScriptPubKeyMans();
}
auto build_address = [&wallet]() {
auto build_address{[]() {
CKey key = GenerateRandomKey();
CTxDestination dest(GetDestinationForKey(
key.GetPubKey(), wallet->m_default_address_type));
const PKHash dest{key.GetPubKey()};
return std::make_pair(dest, QString::fromStdString(EncodeDestination(dest)));
};
}};
CTxDestination r_key_dest, s_key_dest;

View File

@ -217,7 +217,7 @@ std::shared_ptr<CWallet> SetupDescriptorsWallet(interfaces::Node& node, TestChai
WalletDescriptor w_desc(std::move(desc), 0, 0, 1, 1);
auto spk_manager = *Assert(wallet->AddWalletDescriptor(w_desc, provider, "", false));
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->SetLastBlockProcessed(105, WITH_LOCK(node.context()->chainman->GetMutex(), return node.context()->chainman->ActiveChain().Tip()->GetBlockHash()));
SyncUpWallet(wallet, node);
@ -406,7 +406,7 @@ void TestGUIWatchOnly(interfaces::Node& node, TestChain100Setup& test)
sendCoinsDialog.findChild<QLabel*>("labelBalance"));
// 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).
QTimer timer;

View File

@ -1,4 +1,4 @@
// Copyright (c) 2017-2022 The Bitcoin Core developers
// Copyright (c) 2017-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -234,27 +234,6 @@ CPubKey HexToPubKey(const std::string& hex_in)
return vchPubKey;
}
// Retrieves a public key for an address from the given FillableSigningProvider
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in)
{
CTxDestination dest = DecodeDestination(addr_in);
if (!IsValidDestination(dest)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address: " + addr_in);
}
CKeyID key = GetKeyForDestination(keystore, dest);
if (key.IsNull()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("'%s' does not refer to a key", addr_in));
}
CPubKey vchPubKey;
if (!keystore.GetPubKey(key, vchPubKey)) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("no full public key for address %s", addr_in));
}
if (!vchPubKey.IsFullyValid()) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wallet contains an invalid public key");
}
return vchPubKey;
}
// Creates a multisig address from a given list of public keys, number of signatures required, and the address type
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FlatSigningProvider& keystore, CScript& script_out)
{

View File

@ -1,4 +1,4 @@
// Copyright (c) 2017-2022 The Bitcoin Core developers
// Copyright (c) 2017-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -132,7 +132,6 @@ std::string HelpExampleRpc(const std::string& methodname, const std::string& arg
std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args);
CPubKey HexToPubKey(const std::string& hex_in);
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in);
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FlatSigningProvider& keystore, CScript& script_out);
UniValue DescribeAddress(const CTxDestination& dest);

View File

@ -1,4 +1,4 @@
// Copyright (c) 2020-2022 The Bitcoin Core developers
// Copyright (c) 2020-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -104,7 +104,6 @@ FUZZ_TARGET(key, .init = initialize_key)
assert(pubkey.IsValid());
assert(pubkey.IsFullyValid());
assert(HexToPubKey(HexStr(pubkey)) == pubkey);
assert(GetAllDestinationsForKey(pubkey).size() == 3);
}
{
@ -175,7 +174,7 @@ FUZZ_TARGET(key, .init = initialize_key)
assert(v_solutions_ret_tx_multisig[2].size() == 1);
OutputType output_type{};
const CTxDestination tx_destination = GetDestinationForKey(pubkey, output_type);
const CTxDestination tx_destination{PKHash{pubkey}};
assert(output_type == OutputType::LEGACY);
assert(IsValidDestination(tx_destination));
assert(PKHash{pubkey} == *std::get_if<PKHash>(&tx_destination));
@ -186,9 +185,6 @@ FUZZ_TARGET(key, .init = initialize_key)
const std::string destination_address = EncodeDestination(tx_destination);
assert(DecodeDestination(destination_address) == tx_destination);
const CPubKey pubkey_from_address_string = AddrToPubKey(fillable_signing_provider, destination_address);
assert(pubkey_from_address_string == pubkey);
CKeyID key_id = pubkey.GetID();
assert(!key_id.IsNull());
assert(key_id == CKeyID{key_id});

View File

@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2022 The Bitcoin Core developers
// Copyright (c) 2009-present The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -681,11 +681,6 @@ public:
bool SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string, bool relay) const
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool ImportPubKeys(const std::vector<std::pair<CKeyID, bool>>& ordered_pubkeys, const std::map<CKeyID, CPubKey>& pubkey_map, const std::map<CKeyID, std::pair<CPubKey, KeyOriginInfo>>& key_origins, const bool add_keypool, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
bool ImportScriptPubKeys(const std::string& label, const std::set<CScript>& script_pub_keys, const bool have_solving_data, const bool apply_label, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
/** Updates wallet birth time if 'time' is below it */
void MaybeUpdateBirthTime(int64_t time);