Skip to content

Commit c461d15

Browse files
committed
Merge bitcoin/bitcoin#32511: refactor: bdb removals
fafee85 remove unused GetDestinationForKey (MarcoFalke) fac72fe remove unused GetAllDestinationsForKey (MarcoFalke) fa91d57 remove unused AddrToPubKey (MarcoFalke) faecf15 remove unused Import* function signatures (MarcoFalke) Pull request description: remove dead code ACKs for top commit: davidgumberg: crACK bitcoin/bitcoin@fafee85 achow101: ACK fafee85 rkrux: crACK fafee85 Tree-SHA512: e48d4bf5f50b97dbd11260efdaf88277bd6a2478665b84353637d63e783003e90d29718836ffdc2e251ac9b77b22e616a0983a59d1b6658b3645a5575b871eae
2 parents b15c386 + fafee85 commit c461d15

File tree

9 files changed

+14
-91
lines changed

9 files changed

+14
-91
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: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2022 The Bitcoin Core developers
2+
// Copyright (c) 2009-present The Bitcoin Core developers
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

@@ -9,9 +9,8 @@
99
#include <script/script.h>
1010
#include <script/sign.h>
1111
#include <script/signingprovider.h>
12-
#include <util/vector.h>
1312

14-
#include <assert.h>
13+
#include <cassert>
1514
#include <optional>
1615
#include <string>
1716

@@ -47,40 +46,6 @@ const std::string& FormatOutputType(OutputType type)
4746
assert(false);
4847
}
4948

50-
CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
51-
{
52-
switch (type) {
53-
case OutputType::LEGACY: return PKHash(key);
54-
case OutputType::P2SH_SEGWIT:
55-
case OutputType::BECH32: {
56-
if (!key.IsCompressed()) return PKHash(key);
57-
CTxDestination witdest = WitnessV0KeyHash(key);
58-
CScript witprog = GetScriptForDestination(witdest);
59-
if (type == OutputType::P2SH_SEGWIT) {
60-
return ScriptHash(witprog);
61-
} else {
62-
return witdest;
63-
}
64-
}
65-
case OutputType::BECH32M:
66-
case OutputType::UNKNOWN: {} // This function should never be used with BECH32M or UNKNOWN, so let it assert
67-
} // no default case, so the compiler can warn about missing cases
68-
assert(false);
69-
}
70-
71-
std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key)
72-
{
73-
PKHash keyid(key);
74-
CTxDestination p2pkh{keyid};
75-
if (key.IsCompressed()) {
76-
CTxDestination segwit = WitnessV0KeyHash(keyid);
77-
CTxDestination p2sh = ScriptHash(GetScriptForDestination(segwit));
78-
return Vector(std::move(p2pkh), std::move(p2sh), std::move(segwit));
79-
} else {
80-
return Vector(std::move(p2pkh));
81-
}
82-
}
83-
8449
CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, const CScript& script, OutputType type)
8550
{
8651
// Add script to keystore

src/outputtype.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2022 The Bitcoin Core developers
2+
// Copyright (c) 2009-present The Bitcoin Core developers
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

@@ -32,15 +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-
41-
/** Get all destinations (potentially) supported by the wallet for the given key. */
42-
std::vector<CTxDestination> GetAllDestinationsForKey(const CPubKey& key);
43-
4435
/**
4536
* Get a destination of the requested type (if possible) to the specified script.
4637
* 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/rpc/util.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2022 The Bitcoin Core developers
1+
// Copyright (c) 2017-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -234,27 +234,6 @@ CPubKey HexToPubKey(const std::string& hex_in)
234234
return vchPubKey;
235235
}
236236

237-
// Retrieves a public key for an address from the given FillableSigningProvider
238-
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in)
239-
{
240-
CTxDestination dest = DecodeDestination(addr_in);
241-
if (!IsValidDestination(dest)) {
242-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address: " + addr_in);
243-
}
244-
CKeyID key = GetKeyForDestination(keystore, dest);
245-
if (key.IsNull()) {
246-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("'%s' does not refer to a key", addr_in));
247-
}
248-
CPubKey vchPubKey;
249-
if (!keystore.GetPubKey(key, vchPubKey)) {
250-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("no full public key for address %s", addr_in));
251-
}
252-
if (!vchPubKey.IsFullyValid()) {
253-
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wallet contains an invalid public key");
254-
}
255-
return vchPubKey;
256-
}
257-
258237
// Creates a multisig address from a given list of public keys, number of signatures required, and the address type
259238
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FlatSigningProvider& keystore, CScript& script_out)
260239
{

src/rpc/util.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2022 The Bitcoin Core developers
1+
// Copyright (c) 2017-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -132,7 +132,6 @@ std::string HelpExampleRpc(const std::string& methodname, const std::string& arg
132132
std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args);
133133

134134
CPubKey HexToPubKey(const std::string& hex_in);
135-
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in);
136135
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FlatSigningProvider& keystore, CScript& script_out);
137136

138137
UniValue DescribeAddress(const CTxDestination& dest);

src/test/fuzz/key.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020-2022 The Bitcoin Core developers
1+
// Copyright (c) 2020-present The Bitcoin Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

@@ -104,7 +104,6 @@ FUZZ_TARGET(key, .init = initialize_key)
104104
assert(pubkey.IsValid());
105105
assert(pubkey.IsFullyValid());
106106
assert(HexToPubKey(HexStr(pubkey)) == pubkey);
107-
assert(GetAllDestinationsForKey(pubkey).size() == 3);
108107
}
109108

110109
{
@@ -175,7 +174,7 @@ FUZZ_TARGET(key, .init = initialize_key)
175174
assert(v_solutions_ret_tx_multisig[2].size() == 1);
176175

177176
OutputType output_type{};
178-
const CTxDestination tx_destination = GetDestinationForKey(pubkey, output_type);
177+
const CTxDestination tx_destination{PKHash{pubkey}};
179178
assert(output_type == OutputType::LEGACY);
180179
assert(IsValidDestination(tx_destination));
181180
assert(PKHash{pubkey} == *std::get_if<PKHash>(&tx_destination));
@@ -186,9 +185,6 @@ FUZZ_TARGET(key, .init = initialize_key)
186185
const std::string destination_address = EncodeDestination(tx_destination);
187186
assert(DecodeDestination(destination_address) == tx_destination);
188187

189-
const CPubKey pubkey_from_address_string = AddrToPubKey(fillable_signing_provider, destination_address);
190-
assert(pubkey_from_address_string == pubkey);
191-
192188
CKeyID key_id = pubkey.GetID();
193189
assert(!key_id.IsNull());
194190
assert(key_id == CKeyID{key_id});

src/wallet/wallet.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Copyright (c) 2009-2010 Satoshi Nakamoto
2-
// Copyright (c) 2009-2022 The Bitcoin Core developers
2+
// Copyright (c) 2009-present The Bitcoin Core developers
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

@@ -681,11 +681,6 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
681681
bool SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, std::string& err_string, bool relay) const
682682
EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
683683

684-
bool ImportScripts(const std::set<CScript> scripts, int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
685-
bool ImportPrivKeys(const std::map<CKeyID, CKey>& privkey_map, const int64_t timestamp) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
686-
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);
687-
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);
688-
689684
/** Updates wallet birth time if 'time' is below it */
690685
void MaybeUpdateBirthTime(int64_t time);
691686

0 commit comments

Comments
 (0)